Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.13
1.1.1.1 knu 1: #!/usr/bin/perl5 -ws
1.1 jfieber 2: #
1.1.1.1 knu 3: # cvsweb - a CGI interface to CVS trees.
1.1 jfieber 4: #
1.1.1.2 knu 5: # Written in their spare time by
1.1.1.1 knu 6: # Bill Fenner <fenner@FreeBSD.org> (original work)
7: # extended by Henner Zeller <zeller@think.de>,
1.1.1.2 knu 8: # Henrik Nordstrom <hno@hem.passagen.se>
1.1.1.1 knu 9: # Ken Coar <coar@Apache.Org>
10: # Dick Balaska <dick@buckosoft.com>
11: # Akinori MUSHA <knu@FreeBSD.org>
1.1.1.6 knu 12: # Jens-Uwe Mager <jum@helios.de>
1.1 jfieber 13: #
1.1.1.1 knu 14: # Based on:
15: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
16: # http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
17: #
18: # Copyright (c) 1996-1998 Bill Fenner
19: # (c) 1998-1999 Henner Zeller
20: # (c) 1999 Henrik Nordstrom
21: # (c) 2000 Akinori MUSHA
22: # All rights reserved.
23: #
24: # Redistribution and use in source and binary forms, with or without
25: # modification, are permitted provided that the following conditions
26: # are met:
27: # 1. Redistributions of source code must retain the above copyright
28: # notice, this list of conditions and the following disclaimer.
29: # 2. Redistributions in binary form must reproduce the above copyright
30: # notice, this list of conditions and the following disclaimer in the
31: # documentation and/or other materials provided with the distribution.
32: #
33: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
34: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
37: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43: # SUCH DAMAGE.
44: #
1.1.1.12 knu 45: # $zId: cvsweb.cgi,v 1.104 2000/11/01 22:05:12 hnordstrom Exp $
1.1.1.13! knu 46: # $kId: cvsweb.cgi,v 1.41 2000/12/06 18:19:12 knu Exp $
1.1.1.1 knu 47: #
48: ###
49:
50: use strict;
51:
52: use vars qw (
53: $config $allow_version_select $verbose
54: %CVSROOT %CVSROOTdescr %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
1.1.1.11 knu 55: @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS
1.1.1.1 knu 56: %alltags @tabcolors %fileinfo %tags @branchnames %nameprinted
57: %symrev %revsym @allrevisions %date %author @revdisplayorder
1.1.1.4 knu 58: @revisions %state %difflines %log %branchpoint @revorder
59: $prcgi @prcategories $prcategories $mancgi
1.1.1.1 knu 60: $checkoutMagic $doCheckout $scriptname $scriptwhere
61: $where $pathinfo $Browser $nofilelinks $maycompress @stickyvars
62: %funcline_regexp $is_mod_perl
1.1.1.11 knu 63: $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
1.1.1.1 knu 64: %input $query $barequery $sortby $bydate $byrev $byauthor
1.1.1.11 knu 65: $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot
1.1.1.13! knu 66: $mimetype $charset $defaultTextPlain $defaultViewable
! 67: $allow_compress $GZIPBIN $backicon $diricon $fileicon
! 68: $fullname $newname $cvstreedefault
! 69: $body_tag $body_tag_for_src $logo $defaulttitle $address
1.1.1.7 knu 70: $long_intro $short_instruction $shortLogLen
1.1.1.1 knu 71: $show_author $dirtable $tablepadding $columnHeaderColorDefault
72: $columnHeaderColorSorted $hr_breakable $showfunc $hr_ignwhite
73: $hr_ignkeysubst $diffcolorHeading $diffcolorEmpty $diffcolorRemove
74: $diffcolorChange $diffcolorAdd $diffcolorDarkChange $difffontface
75: $difffontsize $inputTextSize $mime_types $allow_annotate
76: $allow_markup $use_java_script $open_extern_window
77: $extern_window_width $extern_window_height $edit_option_form
1.1.1.11 knu 78: $show_subdir_lastmod $show_log_in_markup $v
1.1.1.1 knu 79: $navigationHeaderColor $tableBorderColor $markupLogColor
80: $tabstop $state $annTable $sel $curbranch @HideModules
81: $module $use_descriptions %descriptions @mytz $dwhere $moddate
1.1.1.6 knu 82: $use_moddate $has_zlib $gzip_open
1.1.1.10 knu 83: $LOG_FILESEPARATOR $LOG_REVSEPARATOR
1.1.1.1 knu 84: );
85:
1.1.1.2 knu 86: sub printDiffSelect($);
1.1.1.11 knu 87: sub printDiffLinks($$);
88: sub printLogSortSelect($);
1.1.1.2 knu 89: sub findLastModifiedSubdirs(@);
1.1.1.11 knu 90: sub htmlify_sub(&$);
1.1.1.2 knu 91: sub htmlify($;$);
1.1.1.6 knu 92: sub spacedHtmlText($;$);
1.1.1.2 knu 93: sub link($$);
94: sub revcmp($$);
95: sub fatal($$);
96: sub redirect($);
97: sub safeglob($);
98: sub getMimeTypeFromSuffix($);
1.1.1.6 knu 99: sub head($;$);
100: sub scan_directives(@);
1.1.1.2 knu 101: sub doAnnotate($$);
102: sub doCheckout($$);
103: sub cvswebMarkup($$$);
104: sub viewable($);
105: sub doDiff($$$$$$);
106: sub getDirLogs($$@);
107: sub readLog($;$);
108: sub printLog($;$);
109: sub doLog($);
110: sub flush_diff_rows($$$$);
111: sub human_readable_diff($);
112: sub navigateHeader($$$$$);
113: sub plural_write($$);
114: sub readableTime($$);
115: sub clickablePath($$);
116: sub chooseCVSRoot();
117: sub chooseMirror();
118: sub fileSortCmp();
119: sub download_url($$;$);
120: sub download_link($$$;$);
121: sub toggleQuery($$);
122: sub urlencode($);
1.1.1.11 knu 123: sub htmlquote($);
124: sub htmlunquote($);
1.1.1.2 knu 125: sub http_header(;$);
126: sub html_header($);
127: sub html_footer();
128: sub link_tags($);
129: sub forbidden_module($);
130:
1.1.1.1 knu 131: ##### Start of Configuration Area ########
132: use Cwd;
133:
1.1.1.2 knu 134: # == EDIT this ==
1.1.1.8 knu 135: # Locations to search for user configuration, in order:
136: for (
137: $ENV{CVSWEB_CONFIG},
1.1.1.2 knu 138: '/usr/local/etc/cvsweb.conf',
1.1.1.8 knu 139: getcwd() . '/cvsweb.conf'
140: ) {
141: $config = $_ if defined($_) && -r $_;
1.1.1.1 knu 142: }
143:
144: # == Configuration defaults ==
145: # Defaults for configuration variables that shouldn't need
146: # to be configured..
147: $allow_version_select = 1;
148:
149: ##### End of Configuration Area ########
150:
151: ######## Configuration variables #########
152: # These are defined to allow checking with perl -cw
153: %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS = %MTYPES =
154: %tags = %alltags = @tabcolors = ();
1.1.1.8 knu 155: $cvstreedefault = $body_tag = $body_tag_for_src =
1.1.1.7 knu 156: $logo = $defaulttitle = $address =
157: $long_intro = $short_instruction = $shortLogLen =
1.1.1.1 knu 158: $show_author = $dirtable = $tablepadding = $columnHeaderColorDefault =
159: $columnHeaderColorSorted = $hr_breakable = $showfunc = $hr_ignwhite =
160: $hr_ignkeysubst = $diffcolorHeading = $diffcolorEmpty = $diffcolorRemove =
161: $diffcolorChange = $diffcolorAdd = $diffcolorDarkChange = $difffontface =
162: $difffontsize = $inputTextSize = $mime_types = $allow_annotate =
163: $allow_markup = $use_java_script = $open_extern_window =
164: $extern_window_width = $extern_window_height = $edit_option_form =
1.1.1.11 knu 165: $show_subdir_lastmod = $show_log_in_markup = $v =
1.1.1.2 knu 166: $navigationHeaderColor = $tableBorderColor = $markupLogColor =
1.1.1.7 knu 167: $tabstop = $use_moddate = $moddate = $gzip_open = undef;
1.1.1.1 knu 168:
1.1.1.10 knu 169: $LOG_FILESEPARATOR = q/^={77}$/;
170: $LOG_REVSEPARATOR = q/^-{28}$/;
171:
1.1.1.11 knu 172: @DIFFTYPES = qw(h H u c s);
173: @DIFFTYPES{@DIFFTYPES} = (
174: {
175: 'descr' => 'colored',
176: 'opts' => [ '-u' ],
177: 'colored' => 1,
178: },
179: {
180: 'descr' => 'long colored',
181: 'opts' => [ '--unified=15' ],
182: 'colored' => 1,
183: },
184: {
185: 'descr' => 'unified',
186: 'opts' => [ '-u' ],
187: 'colored' => 0,
188: },
189: {
190: 'descr' => 'context',
191: 'opts' => [ '-c' ],
192: 'colored' => 0,
193: },
194: {
195: 'descr' => 'side by side',
196: 'opts' => [ '--side-by-side', '--width=164' ],
197: 'colored' => 0,
198: },
199: );
200:
201: @LOGSORTKEYS = qw(cvs date rev);
202: @LOGSORTKEYS{@LOGSORTKEYS} = (
203: {
204: 'descr' => 'Not sorted',
205: },
206: {
207: 'descr' => 'Commit date',
208: },
209: {
210: 'descr' => 'Revision',
211: },
212: );
213:
214:
1.1.1.1 knu 215: ##### End of configuration variables #####
216:
217: use Time::Local;
218: use IPC::Open2;
1.1 jfieber 219:
1.1.1.6 knu 220: # Check if the zlib C library interface is installed, and if yes
221: # we can avoid using the extra gzip process.
222: eval {
223: require Compress::Zlib;
224: };
225: $has_zlib = !$@;
226:
1.1 jfieber 227: $verbose = $v;
1.1.1.1 knu 228: $checkoutMagic = "~checkout~";
229: $pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
230: $where = $pathinfo;
231: $doCheckout = ($where =~ /^\/$checkoutMagic/);
232: $where =~ s|^/($checkoutMagic)?||;
233: $where =~ s|/+$||;
234: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
235: $scriptname =~ s|^/?|/|;
236: $scriptname =~ s|/+$||;
237: $scriptwhere = $scriptname;
238: if ($where) {
239: $scriptwhere .= '/' . urlencode($where);
240: }
241:
242: $is_mod_perl = defined($ENV{MOD_PERL});
243:
244: # in lynx, it it very annoying to have two links
245: # per file, so disable the link at the icon
246: # in this case:
1.1.1.2 knu 247: $Browser = $ENV{HTTP_USER_AGENT};
1.1.1.11 knu 248: $is_links = ($Browser =~ m`^Links `);
1.1.1.1 knu 249: $is_lynx = ($Browser =~ m`^Lynx/`i);
250: $is_w3m = ($Browser =~ m`^w3m/`i);
251: $is_msie = ($Browser =~ m`MSIE`);
252: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
253:
1.1.1.11 knu 254: $is_textbased = ($is_links || $is_lynx || $is_w3m);
1.1.1.1 knu 255:
256: $nofilelinks = $is_textbased;
257:
258: # newer browsers accept gzip content encoding
259: # and state this in a header
260: # (netscape did always but didn't state it)
261: # It has been reported that these
262: # braindamaged MS-Internet Exploders claim that they
263: # accept gzip .. but don't in fact and
264: # display garbage then :-/
1.1.1.6 knu 265: # Turn off gzip if running under mod_perl and no zlib is available,
266: # piping does not work as expected inside the server.
1.1.1.7 knu 267: $maycompress = (((defined($ENV{HTTP_ACCEPT_ENCODING})
268: && $ENV{HTTP_ACCEPT_ENCODING} =~ m`gzip`)
1.1.1.2 knu 269: || $is_mozilla3)
270: && !$is_msie
1.1.1.6 knu 271: && !($is_mod_perl && !$has_zlib));
1.1.1.1 knu 272:
273: # put here the variables we need in order
274: # to hold our state - they will be added (with
1.1.1.2 knu 275: # their current value) to any link/query string
1.1.1.1 knu 276: # you construct
277: @stickyvars = qw(cvsroot hideattic sortby logsort f only_with_tag);
278:
279: if (-f $config) {
1.1.1.8 knu 280: do $config
281: || &fatal("500 Internal Error",
282: sprintf('Error in loading configuration file: %s<BR><BR>%s<BR>',
283: $config, &htmlify($@)));
284: } else {
1.1.1.1 knu 285: &fatal("500 Internal Error",
286: 'Configuration not found. Set the variable <code>$config</code> '
287: . 'in cvsweb.cgi, or the environment variable '
288: . '<code>CVSWEB_CONFIG</code>, to your <b>cvsweb.conf</b> '
289: . 'configuration file first.');
290: }
291:
292: undef %input;
293: $query = $ENV{QUERY_STRING};
294:
1.1.1.2 knu 295: if (defined($query) && $query ne '') {
1.1.1.1 knu 296: foreach (split(/&/, $query)) {
297: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
298: if (/(\S+)=(.*)/) {
299: $input{$1} = $2 if ($2 ne "");
300: }
301: else {
302: $input{$_}++;
303: }
304: }
305: }
306:
1.1.1.2 knu 307: # For backwards compability, set only_with_tag to only_on_branch if set.
1.1.1.1 knu 308: $input{only_with_tag} = $input{only_on_branch}
309: if (defined($input{only_on_branch}));
310:
311: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
312:
313: foreach (keys %DEFAULTVALUE)
314: {
315: # replace not given parameters with the default parameters
316: if (!defined($input{$_}) || $input{$_} eq "") {
317: # Empty Checkboxes in forms return -- nothing. So we define a helper
318: # variable in these forms (copt) which indicates that we just set
319: # parameters with a checkbox
320: if (!defined($input{"copt"})) {
321: # 'copt' isn't defined --> empty input is not the result
322: # of empty input checkbox --> set default
323: $input{$_} = $DEFAULTVALUE{$_} if (defined($DEFAULTVALUE{$_}));
324: }
325: else {
326: # 'copt' is defined -> the result of empty input checkbox
327: # -> set to zero (disable) if default is a boolean (0|1).
328: $input{$_} = 0
329: if (defined($DEFAULTVALUE{$_})
330: && ($DEFAULTVALUE{$_} eq "0" || $DEFAULTVALUE{$_} eq "1"));
331: }
332: }
333: }
1.1.1.2 knu 334:
1.1.1.1 knu 335: $barequery = "";
1.1.1.10 knu 336: my @barequery;
1.1.1.1 knu 337: foreach (@stickyvars) {
338: # construct a query string with the sticky non default parameters set
1.1.1.2 knu 339: if (defined($input{$_}) && $input{$_} ne '' &&
1.1.1.1 knu 340: !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_})) {
1.1.1.10 knu 341: push @barequery, join('=', urlencode($_), urlencode($input{$_}));
1.1.1.1 knu 342: }
343: }
344: # is there any query ?
1.1.1.10 knu 345: if (@barequery) {
1.1.1.11 knu 346: $barequery = join('&', @barequery);
1.1.1.1 knu 347: $query = "?$barequery";
1.1.1.11 knu 348: $barequery = "&$barequery";
1.1.1.1 knu 349: }
350: else {
351: $query = "";
352: }
1.1.1.10 knu 353: undef @barequery;
1.1.1.1 knu 354:
355: # get actual parameters
356: $sortby = $input{"sortby"};
357: $bydate = 0;
358: $byrev = 0;
359: $byauthor = 0;
360: $bylog = 0;
361: $byfile = 0;
362: if ($sortby eq "date") {
363: $bydate = 1;
364: }
365: elsif ($sortby eq "rev") {
366: $byrev = 1;
367: }
368: elsif ($sortby eq "author") {
369: $byauthor = 1;
370: }
371: elsif ($sortby eq "log") {
372: $bylog = 1;
373: }
374: else {
375: $byfile = 1;
376: }
377:
1.1.1.11 knu 378: $defaultDiffType = $input{'f'};
1.1.1.1 knu 379:
380: $logsort = $input{'logsort'};
381:
382:
383: ## Default CVS-Tree
384: if (!defined($CVSROOT{$cvstreedefault})) {
385: &fatal("500 Internal Error",
386: "<code>\$cvstreedefault</code> points to a repository "
387: . "not defined in <code>%CVSROOT</code> "
388: . "(edit your configuration file $config)");
389: }
390:
391: # alternate CVS-Tree, configured in cvsweb.conf
392: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
393: $cvstree = $input{'cvsroot'};
394: } else {
395: $cvstree = $cvstreedefault;
396: }
397:
398: $cvsroot = $CVSROOT{$cvstree};
399:
400: # create icons out of description
1.1.1.10 knu 401: my $k;
402: foreach $k (keys %ICONS) {
1.1.1.1 knu 403: no strict 'refs';
404: my ($itxt,$ipath,$iwidth,$iheight) = @{$ICONS{$k}};
405: if ($ipath) {
1.1.1.11 knu 406: ${"${k}icon"} = sprintf('<IMG SRC="%s" ALT="%s" BORDER="0" WIDTH="%d" HEIGHT="%d">',
407: htmlquote($ipath), htmlquote($itxt), $iwidth, $iheight)
1.1.1.1 knu 408: }
409: else {
410: ${"${k}icon"} = $itxt;
411: }
412: }
1.1.1.10 knu 413: undef $k;
1.1.1.1 knu 414:
1.1.1.8 knu 415: my $config_cvstree = "$config-$cvstree";
416:
1.1.1.1 knu 417: # Do some special configuration for cvstrees
1.1.1.8 knu 418: if (-f $config_cvstree) {
419: do $config_cvstree
420: || &fatal("500 Internal Error",
421: sprintf('Error in loading configuration file: %s<BR><BR>%s<BR>',
422: $config_cvstree, &htmlify($@)));
423: }
1.1.1.10 knu 424: undef $config_cvstree;
1.1.1.1 knu 425:
426: $prcategories = '(?:' . join('|', @prcategories) . ')';
1.1.1.4 knu 427: $prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.1.1.1 knu 428:
1.1 jfieber 429: $fullname = $cvsroot . '/' . $where;
1.1.1.1 knu 430: $mimetype = &getMimeTypeFromSuffix ($fullname);
431: $defaultTextPlain = ($mimetype eq "text/plain");
432: $defaultViewable = $allow_markup && viewable($mimetype);
1.1 jfieber 433:
1.1.1.1 knu 434: # search for GZIP if compression allowed
435: # We've to find out if the GZIP-binary exists .. otherwise
436: # ge get an Internal Server Error if we try to pipe the
1.1.1.2 knu 437: # output through the nonexistent gzip ..
1.1.1.1 knu 438: # any more elegant ways to prevent this are welcome!
1.1.1.6 knu 439: if ($allow_compress && $maycompress && !$has_zlib) {
1.1.1.1 knu 440: foreach (split(/:/, $ENV{PATH})) {
441: if (-x "$_/gzip") {
442: $GZIPBIN = "$_/gzip";
443: last;
444: }
445: }
1.1 jfieber 446: }
1.1.1.1 knu 447:
1.1 jfieber 448: if (-d $fullname) {
1.1.1.1 knu 449: #
450: # ensure, that directories always end with (exactly) one '/'
451: # to allow relative URL's. If they're not, make a redirect.
452: ##
453: if (!($pathinfo =~ m|/$|) || ($pathinfo =~ m |/{2,}$|)) {
454: redirect ($scriptwhere . '/' . $query);
455: }
456: else {
457: $where .= '/';
458: $scriptwhere .= '/';
459: }
460: }
461:
462: if (!-d $cvsroot) {
463: &fatal("500 Internal Error",'$CVSROOT not found!<P>The server on which the CVS tree lives is probably down. Please try again in a few minutes.');
464: }
465:
466: #
467: # See if the module is in our forbidden list.
468: #
469: $where =~ m:([^/]*):;
470: $module = $1;
471: if ($module && &forbidden_module($module)) {
472: &fatal("403 Forbidden", "Access to $where forbidden.");
473: }
474: ##############################
475: # View a directory
476: ###############################
477: elsif (-d $fullname) {
478: my $dh = do {local(*DH);};
479: opendir($dh, $fullname) || &fatal("404 Not Found","$where: $!");
480: my @dir = readdir($dh);
481: closedir($dh);
482: my @subLevelFiles = findLastModifiedSubdirs(@dir)
483: if ($show_subdir_lastmod);
484: getDirLogs($cvsroot,$where,@subLevelFiles);
485:
486: if ($where eq '/') {
487: html_header($defaulttitle);
488: $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
489: print $long_intro;
490: }
491: else {
492: html_header($where);
493: print $short_instruction;
494: }
495:
496: my $descriptions;
497: if (($use_descriptions) && open (DESC, "<$cvsroot/CVSROOT/descriptions")) {
498: while (<DESC>) {
499: chomp;
500: my ($dir,$description) = /(\S+)\s+(.*)/;
501: $descriptions{$dir} = $description;
502: }
1.1 jfieber 503: }
1.1.1.1 knu 504:
505: print "<P><a name=\"dirlist\"></a>\n";
506: # give direct access to dirs
507: if ($where eq '/') {
508: chooseMirror();
509: chooseCVSRoot();
510: }
511: else {
512: print "<p>Current directory: <b>", &clickablePath($where,0), "</b>\n";
513:
514: print "<P>Current tag: <B>", $input{only_with_tag}, "</b>\n" if
515: $input{only_with_tag};
516:
517: }
1.1.1.2 knu 518:
1.1.1.1 knu 519:
520: print "<HR NOSHADE>\n";
1.1 jfieber 521: # Using <MENU> in this manner violates the HTML2.0 spec but
522: # provides the results that I want in most browsers. Another
523: # case of layout spooging up HTML.
1.1.1.2 knu 524:
1.1.1.1 knu 525: my $infocols = 0;
526: if ($dirtable) {
527: if (defined($tableBorderColor)) {
528: # Can't this be done by defining the border for the inner table?
529: print "<table border=0 cellpadding=0 width=\"100%\"><tr><td bgcolor=\"$tableBorderColor\">";
530: }
531: print "<table width=\"100%\" border=0 cellspacing=1 cellpadding=$tablepadding>\n";
532: $infocols++;
1.1.1.11 knu 533: printf '<tr><th align=left bgcolor="%s">',
534: $byfile ? $columnHeaderColorSorted : $columnHeaderColorDefault;
535: if ($byfile) {
536: print 'File';
537: } else {
538: print &link('File', sprintf('./%s#dirlist',
539: &toggleQuery("sortby", "file")));
540: }
1.1.1.1 knu 541: print "</th>";
542: # do not display the other column-headers, if we do not have any files
543: # with revision information:
544: if (scalar(%fileinfo)) {
545: $infocols++;
1.1.1.11 knu 546: printf '<th align=left bgcolor="%s">',
547: $byrev ? $columnHeaderColorSorted : $columnHeaderColorDefault;
548: if ($byrev) {
549: print 'Rev.';
550: } else {
551: print &link('Rev.', sprintf('./%s#dirlist',
552: &toggleQuery("sortby", "rev")));
553: }
1.1.1.1 knu 554: print "</th>";
555: $infocols++;
1.1.1.11 knu 556: printf '<th align=left bgcolor="%s">',
557: $bydate ? $columnHeaderColorSorted : $columnHeaderColorDefault;
558: if ($bydate) {
559: print 'Age';
560: } else {
561: print &link('Age', sprintf('./%s#dirlist',
562: &toggleQuery("sortby", "date")));
563: }
1.1.1.1 knu 564: print "</th>";
565: if ($show_author) {
566: $infocols++;
1.1.1.11 knu 567: printf '<th align=left bgcolor="%s">',
568: $byauthor ? $columnHeaderColorSorted : $columnHeaderColorDefault;
569: if ($byauthor) {
570: print 'Author';
571: } else {
572: print &link('Author', sprintf('./%s#dirlist',
573: &toggleQuery("sortby", "author")));
574: }
1.1.1.1 knu 575: print "</th>";
576: }
577: $infocols++;
1.1.1.11 knu 578: printf '<th align=left bgcolor="%s">',
579: $bylog ? $columnHeaderColorSorted : $columnHeaderColorDefault;
580: if ($bylog) {
581: print 'Last log entry';
582: } else {
583: print &link('Last log entry', sprintf('./%s#dirlist',
584: &toggleQuery("sortby", "log")));
585: }
1.1.1.1 knu 586: print "</th>";
587: }
588: elsif ($use_descriptions) {
1.1.1.11 knu 589: printf '<th align=left bgcolor="%s">', $columnHeaderColorDefault;
1.1.1.1 knu 590: print "Description";
591: $infocols++;
592: }
593: print "</tr>\n";
594: }
595: else {
596: print "<menu>\n";
597: }
598: my $dirrow = 0;
1.1.1.2 knu 599:
1.1.1.1 knu 600: my $i;
601: lookingforattic:
602: for ($i = 0; $i <= $#dir; $i++) {
603: if ($dir[$i] eq "Attic") {
604: last lookingforattic;
605: }
606: }
607: if (!$input{'hideattic'} && ($i <= $#dir) &&
608: opendir($dh, $fullname . "/Attic")) {
609: splice(@dir, $i, 1,
610: grep((s|^|Attic/|,!m|/\.|), readdir($dh)));
611: closedir($dh);
612: }
613:
1.1.1.11 knu 614: my $hideAtticToggleLink = $input{'hideattic'} ? '' :
615: &link('[Hide]', sprintf('./%s#dirlist',
616: &toggleQuery ("hideattic")));
1.1.1.1 knu 617:
618: # Sort without the Attic/ pathname.
619: # place directories first
620:
621: my $attic;
622: my $url;
623: my $fileurl;
624: my $filesexists;
625: my $filesfound;
626:
627: foreach (sort { &fileSortCmp } @dir) {
1.1 jfieber 628: if ($_ eq '.') {
629: next;
630: }
1.1.1.1 knu 631: # ignore CVS lock and stale NFS files
632: next if (/^#cvs\.|^,|^\.nfs/);
633:
634: # Check whether to show the CVSROOT path
635: next if ($input{'hidecvsroot'} && ($_ eq 'CVSROOT'));
636:
637: # Check whether the module is in the restricted list
638: next if ($_ && &forbidden_module($_));
639:
640: # Ignore non-readable files
641: next if ($input{'hidenonreadable'} && !(-r "$fullname/$_"));
642:
643: if (s|^Attic/||) {
644: $attic = " (in the Attic) " . $hideAtticToggleLink;
645: }
646: else {
647: $attic = "";
648: }
649:
650: if ($_ eq '..' || -d "$fullname/$_") {
651: next if ($_ eq '..' && $where eq '/');
652: my ($rev,$date,$log,$author,$filename) = @{$fileinfo{$_}}
653: if (defined($fileinfo{$_}));
1.1.1.11 knu 654: printf '<tr bgcolor="%s"><td>', $tabcolors[$dirrow % 2] if $dirtable;
1.1.1.1 knu 655: if ($_ eq '..') {
1.1.1.11 knu 656: $url = "../$query";
1.1.1.1 knu 657: if ($nofilelinks) {
658: print $backicon;
659: }
660: else {
1.1.1.11 knu 661: print &link($backicon, $url);
1.1.1.1 knu 662: }
1.1.1.11 knu 663: print " ", &link("Previous Directory", $url);
1.1.1.1 knu 664: }
665: else {
1.1.1.11 knu 666: $url = urlencode($_) . "/$query";
1.1.1.1 knu 667: print "<A NAME=\"$_\"></A>";
668: if ($nofilelinks) {
669: print $diricon;
670: }
671: else {
1.1.1.11 knu 672: print &link($diricon, $url);
1.1.1.1 knu 673: }
1.1.1.11 knu 674: print " ", &link("$_/", $url), $attic;
1.1.1.1 knu 675: if ($_ eq "Attic") {
1.1.1.11 knu 676: print " ";
677: print &link("[Don't hide]", sprintf('./%s#dirlist',
678: &toggleQuery ("hideattic")));
1.1.1.1 knu 679: }
1.1.1.2 knu 680: }
1.1.1.1 knu 681: # Show last change in dir
682: if ($filename) {
683: print "</td><td> </td><td> " if ($dirtable);
684: if ($date) {
1.1.1.11 knu 685: print " <i>", readableTime(time() - $date,0), "</i>";
1.1.1.1 knu 686: }
687: if ($show_author) {
688: print "</td><td> " if ($dirtable);
689: print $author;
690: }
691: print "</td><td> " if ($dirtable);
692: $filename =~ s%^[^/]+/%%;
693: print "$filename/$rev";
694: print "<BR>" if ($dirtable);
695: if ($log) {
1.1.1.11 knu 696: print " <font size=-1>",
697: &htmlify(substr($log,0,$shortLogLen));
1.1.1.1 knu 698: if (length $log > 80) {
699: print "...";
700: }
701: print "</font>";
702: }
703: }
704: else {
705: my ($dwhere) = ($where ne "/" ? $where : "") . $_;
706: if ($use_descriptions && defined $descriptions{$dwhere}) {
1.1.1.11 knu 707: print "<TD COLSPAN=", ($infocols-1), "> " if $dirtable;
1.1.1.1 knu 708: print $descriptions{$dwhere};
709: } elsif ($dirtable && $infocols > 1) {
710: # close the row with the appropriate number of
711: # columns, so that the vertical seperators are visible
712: my($cols) = $infocols;
713: while ($cols > 1) {
714: print "</td><td> ";
715: $cols--;
716: }
717: }
718: }
719: if ($dirtable) {
720: print "</td></tr>\n";
721: }
722: else {
723: print "<br>\n";
724: }
725: $dirrow++;
726: }
727: elsif (s/,v$//) {
728: $fileurl = ($attic ? "Attic/" : "") . urlencode($_);
729: $url = $fileurl . $query;
730: my $rev = '';
731: my $date = '';
732: my $log = '';
733: my $author = '';
734: $filesexists++;
735: next if (!defined($fileinfo{$_}));
736: ($rev,$date,$log,$author) = @{$fileinfo{$_}};
737: $filesfound++;
1.1.1.11 knu 738: printf '<tr bgcolor="%s"><td>', $tabcolors[$dirrow % 2] if $dirtable;
1.1.1.1 knu 739: print "<A NAME=\"$_\"></A>";
740: if ($nofilelinks) {
741: print $fileicon;
742: }
743: else {
744: print &link($fileicon,$url);
745: }
746: print " ", &link($_, $url), $attic;
747: print "</td><td> " if ($dirtable);
748: download_link($fileurl,
1.1.1.11 knu 749: $rev, $rev,
750: $defaultViewable ? "text/x-cvsweb-markup" : undef);
1.1.1.1 knu 751: print "</td><td> " if ($dirtable);
752: if ($date) {
1.1.1.11 knu 753: print " <i>", readableTime(time() - $date,0), "</i>";
1.1.1.1 knu 754: }
755: if ($show_author) {
756: print "</td><td> " if ($dirtable);
757: print $author;
758: }
759: print "</td><td> " if ($dirtable);
760: if ($log) {
1.1.1.11 knu 761: print " <font size=-1>", &htmlify(substr($log,0,$shortLogLen));
1.1.1.1 knu 762: if (length $log > 80) {
763: print "...";
764: }
765: print "</font>";
766: }
767: print "</td>" if ($dirtable);
768: print (($dirtable) ? "</tr>" : "<br>");
769: $dirrow++;
770: }
771: print "\n";
772: }
773: if ($dirtable && defined($tableBorderColor)) {
774: print "</td></tr></table>";
775: }
1.1.1.11 knu 776: print( $dirtable == 1 ? "</table>\n" : "</menu>\n" );
1.1.1.2 knu 777:
1.1.1.1 knu 778: if ($filesexists && !$filesfound) {
779: print "<P><B>NOTE:</B> There are $filesexists files, but none matches the current tag ($input{only_with_tag})\n";
780: }
781: if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
782: %tags = %alltags
783: }
1.1.1.2 knu 784: if (scalar %tags
785: || $input{only_with_tag}
1.1.1.1 knu 786: || $edit_option_form
787: || defined($input{"options"})) {
788: print "<hr size=1 NOSHADE>";
789: }
790:
791: if (scalar %tags || $input{only_with_tag}) {
792: print "<FORM METHOD=\"GET\" ACTION=\"./\">\n";
793: foreach my $var (@stickyvars) {
794: print "<INPUT TYPE=HIDDEN NAME=\"$var\" VALUE=\"$input{$var}\">\n"
795: if (defined($input{$var})
1.1.1.6 knu 796: && (!defined($DEFAULTVALUE{$var})
797: || $input{$var} ne $DEFAULTVALUE{$var})
1.1.1.1 knu 798: && $input{$var} ne ""
799: && $var ne "only_with_tag");
800: }
801: print "Show only files with tag:\n";
802: print "<SELECT NAME=only_with_tag";
803: print " onchange=\"submit()\"" if ($use_java_script);
804: print ">";
805: print "<OPTION VALUE=\"\">All tags / default branch\n";
806: foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
1.1.1.2 knu 807: print "<OPTION",defined($input{only_with_tag}) &&
808: $input{only_with_tag} eq $tag ? " SELECTED" : "",
1.1.1.1 knu 809: ">$tag\n";
810: }
811: print "</SELECT>\n";
812: print "<INPUT TYPE=SUBMIT VALUE=\"Go\">\n";
813: print "</FORM>\n";
814: }
815: my $formwhere = $scriptwhere;
816: $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
817:
818: if ($edit_option_form || defined($input{"options"})) {
819: print "<FORM METHOD=\"GET\" ACTION=\"${formwhere}\">\n";
820: print "<INPUT TYPE=HIDDEN NAME=\"copt\" VALUE=\"1\">\n";
821: if ($cvstree ne $cvstreedefault) {
822: print "<INPUT TYPE=HIDDEN NAME=\"cvsroot\" VALUE=\"$cvstree\">\n";
823: }
824: print "<center><table cellpadding=0 cellspacing=0>";
825: print "<tr bgcolor=\"$columnHeaderColorDefault\"><th colspan=2>Preferences</th></tr>";
826: print "<tr><td>Sort files by <SELECT name=\"sortby\">";
827: print "<OPTION VALUE=\"\">File";
828: print "<OPTION",$bydate ? " SELECTED" : ""," VALUE=date>Age";
829: print "<OPTION",$byauthor ? " SELECTED" : ""," VALUE=author>Author"
830: if ($show_author);
831: print "<OPTION",$byrev ? " SELECTED" : ""," VALUE=rev>Revision";
832: print "<OPTION",$bylog ? " SELECTED" : ""," VALUE=log>Log message";
833: print "</SELECT></td>";
1.1.1.11 knu 834: print "<td>Sort log by: ";
835: printLogSortSelect(0);
836: print "</td></tr>";
1.1.1.1 knu 837: print "<tr><td>Diff format: ";
1.1.1.2 knu 838: printDiffSelect(0);
1.1.1.1 knu 839: print "</td>";
840: print "<td>Show Attic files: ";
1.1.1.2 knu 841: print "<INPUT NAME=hideattic TYPE=CHECKBOX", $input{'hideattic'} ? " CHECKED" : "",
1.1.1.1 knu 842: "></td></tr>\n";
843: print "<tr><td align=center colspan=2><input type=submit value=\"Change Options\">";
844: print "</td></tr></table></center></FORM>\n";
845: }
846: print &html_footer;
1.1 jfieber 847: print "</BODY></HTML>\n";
1.1.1.2 knu 848: }
1.1.1.1 knu 849:
850: ###############################
851: # View Files
852: ###############################
853: elsif (-f $fullname . ',v') {
854: if (defined($input{'rev'}) || $doCheckout) {
855: &doCheckout($fullname, $input{'rev'});
1.1.1.7 knu 856: gzipclose();
1.1.1.1 knu 857: exit;
858: }
859: if (defined($input{'annotate'}) && $allow_annotate) {
860: &doAnnotate($input{'annotate'});
1.1.1.7 knu 861: gzipclose();
1.1.1.1 knu 862: exit;
863: }
864: if (defined($input{'r1'}) && defined($input{'r2'})) {
865: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
866: $input{'r2'}, $input{'tr2'}, $input{'f'});
1.1.1.7 knu 867: gzipclose();
1.1.1.1 knu 868: exit;
869: }
870: print("going to dolog($fullname)\n") if ($verbose);
871: &doLog($fullname);
872: ##############################
873: # View Diff
874: ##############################
875: }
876: elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" &&
877: $input{'r1'} && $input{'r2'}) {
878:
879: # $where-diff-removal if 'cvs rdiff' is used
880: # .. but 'cvs rdiff'doesn't support some options
881: # rcsdiff does (-w and -p), so it is disabled
882: # $where =~ s/\.diff$//;
883:
884: # Allow diffs using the ".diff" extension
885: # so that browsers that default to the URL
886: # for a save filename don't save diff's as
887: # e.g. foo.c
888: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
889: $input{'r2'}, $input{'tr2'}, $input{'f'});
1.1.1.7 knu 890: gzipclose();
1.1.1.1 knu 891: exit;
892: }
893: elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| &&
894: -f $newname . ",v") {
895: # The file has been removed and is in the Attic.
896: # Send a redirect pointing to the file in the Attic.
897: (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
898: &redirect($newplace);
899: exit;
900: }
901: elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
902: http_header("text/plain");
903: print "You matched the following files:\n";
904: print join("\n", @files);
905: # Find the tags from each file
906: # Display a form offering diffs between said tags
907: }
908: else {
909: my $fh = do {local(*FH);};
910: my ($xtra, $module);
911: # Assume it's a module name with a potential path following it.
912: $xtra = $& if (($module = $where) =~ s|/.*||);
913: # Is there an indexed version of modules?
914: if (open($fh, "$cvsroot/CVSROOT/modules")) {
915: while (<$fh>) {
916: if (/^(\S+)\s+(\S+)/o && $module eq $1
917: && -d "${cvsroot}/$2" && $module ne $2) {
918: &redirect($scriptname . '/' . $2 . $xtra);
919: }
920: }
921: }
922: &fatal("404 Not Found","$where: no such file or directory");
923: }
1.1.1.6 knu 924:
1.1.1.7 knu 925: gzipclose();
1.1.1.1 knu 926: ## End MAIN
927:
1.1.1.2 knu 928: sub printDiffSelect($) {
1.1.1.1 knu 929: my ($use_java_script) = @_;
1.1.1.11 knu 930: my $f = $input{'f'};
931:
932: print '<SELECT NAME="f"';
933: print ' onchange="submit()"' if $use_java_script;
934: print '>';
935:
936: local $_;
937: for (@DIFFTYPES) {
938: printf('<OPTION VALUE="%s"%s>%s',
939: $_,
940: $f eq $_ ? ' SELECTED' : '',
941: "\u$DIFFTYPES{$_}{'descr'}"
942: );
943: }
944:
945: print "</SELECT>";
946: }
947:
948: sub printLogSortSelect($) {
949: my ($use_java_script) = @_;
950:
951: print '<SELECT NAME="logsort"';
952: print ' onchange="submit()"' if $use_java_script;
953: print '>';
954:
955: local $_;
956: for (@LOGSORTKEYS) {
957: printf('<OPTION VALUE="%s"%s>%s',
958: $_,
959: $logsort eq $_ ? ' SELECTED' : '',
960: "\u$LOGSORTKEYS{$_}{'descr'}"
961: );
962: }
963:
1.1.1.1 knu 964: print "</SELECT>";
965: }
966:
1.1.1.2 knu 967: sub findLastModifiedSubdirs(@) {
1.1.1.1 knu 968: my (@dirs) = @_;
969: my ($dirname, @files);
970:
971: foreach $dirname (@dirs) {
972: next if ($dirname eq ".");
973: next if ($dirname eq "..");
974: my ($dir) = "$fullname/$dirname";
975: next if (!-d $dir);
976:
977: my ($lastmod) = undef;
978: my ($lastmodtime) = undef;
979: my $dh = do {local(*DH);};
980:
981: opendir($dh,$dir) || next;
982: my (@filenames) = readdir($dh);
983: closedir($dh);
984:
985: foreach my $filename (@filenames) {
986: $filename = "$dirname/$filename";
987: my ($file) = "$fullname/$filename";
988: next if ($filename !~ /,v$/ || !-f $file);
989: $filename =~ s/,v$//;
990: my $modtime = -M $file;
991: if (!defined($lastmod) || $modtime < $lastmodtime) {
992: $lastmod = $filename;
993: $lastmodtime = $modtime;
994: }
995: }
996: push(@files, $lastmod) if (defined($lastmod));
997: }
998: return @files;
999: }
1000:
1.1.1.11 knu 1001: sub htmlify_sub(&$) {
1002: (my $proc, local $_) = @_;
1003: local @_ = split(m`(<a [^>]+>[^<]*</a>)`i);
1.1.1.12 knu 1004: my $linked;
1005: my $result = '';
1.1.1.11 knu 1006:
1007: while (($_, $linked) = splice(@_, 0, 2)) {
1008: &$proc();
1.1.1.12 knu 1009: $result .= $_ if defined($_);
1010: $result .= $linked if defined($linked);
1.1.1.11 knu 1011: }
1.1.1.1 knu 1012:
1.1.1.11 knu 1013: $result;
1014: }
1.1.1.1 knu 1015:
1.1.1.11 knu 1016: sub htmlify($;$) {
1017: (local $_, my $extra) = @_;
1.1.1.1 knu 1018:
1.1.1.11 knu 1019: $_ = htmlquote($_);
1.1.1.4 knu 1020:
1.1.1.11 knu 1021: # get URL's as link
1022: s{
1023: (http|ftp|https)://\S+
1024: }{
1025: &link($&, htmlunquote($&))
1026: }egx;
1027:
1028: # get e-mails as link
1029: $_ = htmlify_sub {
1030: s<
1031: [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
1032: ><
1033: &link($&, "mailto:$&")
1034: >egix;
1035: } $_;
1036:
1037: if ($extra) {
1038: # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
1039: if (defined($prcgi)) {
1040: my $prev;
1041:
1042: do {
1043: $prev = $_;
1044:
1045: $_ = htmlify_sub {
1046: s{
1047: (\bPR[:\#]?\s*
1048: (?:
1049: \#?
1050: \d+[,\s]\s*
1051: )*
1052: \#?)
1053: (\d+)\b
1054: }{
1055: $1 . &link($2, sprintf($prcgi, $2)) . $3
1056: }egix;
1057: } $_;
1058: } while ($_ ne $prev);
1059:
1060: $_ = htmlify_sub {
1061: s{
1062: (\b$prcategories/(\d+)\b)
1063: }{
1064: &link($1, sprintf($prcgi, $2)) . $3
1065: }egox;
1066: } $_;
1067: }
1068:
1069: # get manpage specs as link: "foo.1" "foo(1)"
1070: if (defined($mancgi)) {
1071: $_ = htmlify_sub {
1072: s{
1073: (\b([a-zA-Z][\w_.]+)
1074: (?:
1075: \( ([0-9n]) \)\B
1076: |
1077: \.([0-9n])\b
1078: )
1079: )
1080: }{
1081: &link($1, sprintf($mancgi, $3 ne '' ? $3 : $4, $2)) . $5
1082: }egx;
1083: } $_;
1.1.1.1 knu 1084: }
1.1.1.11 knu 1085: }
1.1.1.1 knu 1086:
1.1.1.11 knu 1087: $_;
1.1.1.1 knu 1088: }
1089:
1.1.1.6 knu 1090: sub spacedHtmlText($;$) {
1.1.1.2 knu 1091: local $_ = $_[0];
1.1.1.6 knu 1092: my $ts = $_[1] || $tabstop;
1.1.1.1 knu 1093:
1.1.1.6 knu 1094: # Cut trailing spaces and tabs
1095: s/[ \t]+$//;
1.1.1.1 knu 1096:
1.1.1.6 knu 1097: if (defined($ts)) {
1098: # Expand tabs
1099: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e
1100: }
1.1.1.1 knu 1101:
1102: # replace <tab> and <space> (\001 is to protect us from htmlify)
1103: # gzip can make excellent use of this repeating pattern :-)
1104: if ($hr_breakable) {
1105: # make every other space 'breakable'
1.1.1.2 knu 1106: s/ / \001nbsp;/g; # 2 * <space>
1.1.1.1 knu 1107: # leave single space as it is
1.1.1.6 knu 1108: } else {
1.1.1.2 knu 1109: s/ /\001nbsp;/g;
1.1.1.1 knu 1110: }
1111:
1.1.1.2 knu 1112: $_ = htmlify($_);
1.1.1.1 knu 1113:
1114: # unescape
1.1.1.6 knu 1115: y/\001/&/;
1.1.1.1 knu 1116:
1.1.1.2 knu 1117: return $_;
1.1.1.1 knu 1118: }
1119:
1.1.1.2 knu 1120: sub link($$) {
1.1.1.1 knu 1121: my($name, $where) = @_;
1122:
1.1.1.11 knu 1123: sprintf '<A HREF="%s">%s</A>', htmlquote($where), $name;
1.1.1.1 knu 1124: }
1125:
1.1.1.2 knu 1126: sub revcmp($$) {
1.1.1.1 knu 1127: my($rev1, $rev2) = @_;
1.1.1.3 knu 1128:
1129: # make no comparison for a tag or a branch
1130: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1131:
1.1.1.1 knu 1132: my(@r1) = split(/\./, $rev1);
1133: my(@r2) = split(/\./, $rev2);
1134: my($a,$b);
1135:
1136: while (($a = shift(@r1)) && ($b = shift(@r2))) {
1137: if ($a != $b) {
1138: return $a <=> $b;
1.1 jfieber 1139: }
1.1.1.1 knu 1140: }
1141: if (@r1) { return 1; }
1142: if (@r2) { return -1; }
1143: return 0;
1144: }
1145:
1.1.1.2 knu 1146: sub fatal($$) {
1.1.1.1 knu 1147: my($errcode, $errmsg) = @_;
1148: if ($is_mod_perl) {
1149: Apache->request->status((split(/ /, $errcode))[0]);
1150: }
1151: else {
1152: print "Status: $errcode\r\n";
1153: }
1154: html_header("Error");
1155: print "Error: $errmsg\n";
1156: print &html_footer;
1157: exit(1);
1158: }
1159:
1.1.1.2 knu 1160: sub redirect($) {
1.1.1.1 knu 1161: my($url) = @_;
1162: if ($is_mod_perl) {
1163: Apache->request->status(301);
1164: Apache->request->header_out(Location => $url);
1165: }
1166: else {
1167: print "Status: 301 Moved\r\n";
1168: print "Location: $url\r\n";
1169: }
1170: html_header("Moved");
1.1.1.11 knu 1171: print "This document is located ", &link('here', $url), "\n";
1.1.1.1 knu 1172: print &html_footer;
1173: exit(1);
1174: }
1175:
1.1.1.2 knu 1176: sub safeglob($) {
1.1.1.1 knu 1177: my ($filename) = @_;
1178: my ($dirname);
1179: my (@results);
1180: my $dh = do {local(*DH);};
1181:
1182: ($dirname = $filename) =~ s|/[^/]+$||;
1183: $filename =~ s|.*/||;
1184:
1185: if (opendir($dh, $dirname)) {
1186: my $glob = $filename;
1187: my $t;
1188: # transform filename from glob to regex. Deal with:
1189: # [, {, ?, * as glob chars
1190: # make sure to escape all other regex chars
1191: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1192: $glob =~ s/\*/.*/g;
1193: $glob =~ s/\?/./g;
1194: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1195: foreach (readdir($dh)) {
1196: if (/^${glob}$/) {
1.1.1.11 knu 1197: push(@results, "$dirname/" .$_);
1.1.1.1 knu 1198: }
1199: }
1200: }
1201:
1202: @results;
1203: }
1204:
1.1.1.2 knu 1205: sub getMimeTypeFromSuffix($) {
1.1.1.1 knu 1206: my ($fullname) = @_;
1207: my ($mimetype, $suffix);
1208: my $fh = do {local(*FH);};
1209:
1210: ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1211: $mimetype = $MTYPES{$suffix};
1212: $mimetype = $MTYPES{'*'} if (!$mimetype);
1.1.1.2 knu 1213:
1.1.1.1 knu 1214: if (!$mimetype && -f $mime_types) {
1215: # okey, this is something special - search the
1216: # mime.types database
1217: open ($fh, "<$mime_types");
1218: while (<$fh>) {
1219: if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
1220: $mimetype = $1;
1221: last;
1222: }
1223: }
1224: close ($fh);
1225: }
1.1.1.2 knu 1226:
1.1.1.1 knu 1227: # okey, didn't find anything useful ..
1228: if (!($mimetype =~ /\S\/\S/)) {
1229: $mimetype = "text/plain";
1230: }
1231: return $mimetype;
1232: }
1233:
1234: ###############################
1.1.1.6 knu 1235: # read first lines like head(1)
1236: ###############################
1237: sub head($;$) {
1238: my $fh = $_[0];
1239: my $linecount = $_[1] || 10;
1240:
1241: my @buf;
1242:
1243: if ($linecount > 0) {
1244: my $i;
1245: for ($i = 0; !eof($fh) && $i < $linecount; $i++) {
1246: push @buf, scalar <$fh>;
1247: }
1248: } else {
1249: @buf = <$fh>;
1250: }
1251:
1252: @buf;
1253: }
1254:
1255: ###############################
1256: # scan vim and Emacs directives
1257: ###############################
1258: sub scan_directives(@) {
1259: my $ts = undef;
1260:
1261: for (@_) {
1262: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1263: }
1264:
1265: ('tabstop' => $ts);
1266: }
1267:
1268: ###############################
1.1.1.1 knu 1269: # show Annotation
1270: ###############################
1.1.1.2 knu 1271: sub doAnnotate($$) {
1.1.1.1 knu 1272: my ($rev) = @_;
1273: my ($pid);
1274: my ($pathname, $filename);
1275: my $reader = do {local(*FH);};
1276: my $writer = do {local(*FH);};
1277:
1278: # make sure the revisions a wellformed, for security
1279: # reasons ..
1.1.1.3 knu 1280: if ($rev =~ /[^\w.]/) {
1.1.1.1 knu 1281: &fatal("404 Not Found",
1282: "Malformed query \"$ENV{QUERY_STRING}\"");
1283: }
1284:
1285: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1286: ($filename = $where) =~ s/^.*\///;
1287:
1288: # this seems to be necessary
1289: $| = 1; $| = 0; # Flush
1290:
1291: # this annotate version is based on the
1292: # cvs annotate-demo Perl script by Cyclic Software
1293: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1294: # the public domain.
1295: # we could abandon the use of rlog, rcsdiff and co using
1296: # the cvsserver in a similiar way one day (..after rewrite)
1.1.1.8 knu 1297: $pid = open2($reader, $writer, "cvs -Rl server") || fatal ("500 Internal Error",
1.1.1.1 knu 1298: "Fatal Error - unable to open cvs for annotation");
1.1.1.2 knu 1299:
1.1.1.1 knu 1300: # OK, first send the request to the server. A simplified example is:
1301: # Root /home/kingdon/zwork/cvsroot
1302: # Argument foo/xx
1303: # Directory foo
1304: # /home/kingdon/zwork/cvsroot/foo
1305: # Directory .
1306: # /home/kingdon/zwork/cvsroot
1307: # annotate
1308: # although as you can see there are a few more details.
1.1.1.2 knu 1309:
1.1.1.1 knu 1310: print $writer "Root $cvsroot\n";
1311: print $writer "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1312: # Don't worry about sending valid-requests, the server just needs to
1313: # support "annotate" and if it doesn't, there isn't anything to be done.
1314: print $writer "UseUnchanged\n";
1315: print $writer "Argument -r\n";
1316: print $writer "Argument $rev\n";
1317: print $writer "Argument $where\n";
1318:
1319: # The protocol requires us to fully fake a working directory (at
1320: # least to the point of including the directories down to the one
1321: # containing the file in question).
1322: # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
1323: my @dirs = split('/', $where);
1324: my $path = "";
1325: foreach (@dirs) {
1326: if ($path eq "") {
1327: # In our example, $_ is "dir".
1328: $path = $_;
1.1.1.2 knu 1329: }
1.1.1.1 knu 1330: else {
1331: print $writer "Directory $path\n";
1332: print $writer "$cvsroot/$path\n";
1333: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1334: # And the next time, "file" and "dir/sdir/file" (which then gets
1335: # ignored, because we don't need to send Directory for the file).
1336: $path .= "/$_";
1337: }
1338: }
1339: # And the last "Directory" before "annotate" is the top level.
1340: print $writer "Directory .\n";
1341: print $writer "$cvsroot\n";
1.1.1.2 knu 1342:
1.1.1.1 knu 1343: print $writer "annotate\n";
1344: # OK, we've sent our command to the server. Thing to do is to
1345: # close the writer side and get all the responses. If "cvs server"
1346: # were nicer about buffering, then we could just leave it open, I think.
1347: close ($writer) || die "cannot close: $!";
1.1.1.2 knu 1348:
1.1.1.9 knu 1349: http_header();
1350:
1351: navigateHeader($scriptwhere,$pathname,$filename,$rev, "annotate");
1352: print "<h3 align=center>Annotation of $pathname$filename, Revision $rev</h3>\n";
1353:
1.1.1.1 knu 1354: # Ready to get the responses from the server.
1355: # For example:
1356: # E Annotations for foo/xx
1357: # E ***************
1.1.1.2 knu 1358: # M 1.3 (kingdon 06-Sep-97): hello
1.1.1.1 knu 1359: # ok
1360: my ($lineNr) = 0;
1361: my ($oldLrev, $oldLusr) = ("", "");
1362: my ($revprint, $usrprint);
1363: if ($annTable) {
1364: print "<table border=0 cellspacing=0 cellpadding=0>\n";
1365: }
1366: else {
1367: print "<pre>";
1368: }
1.1.1.6 knu 1369:
1370: # prefetch several lines
1371: my @buf = head($reader);
1372:
1373: my %d = scan_directives(@buf);
1374:
1375: while (@buf || !eof($reader)) {
1376: $_ = @buf ? shift @buf : <$reader>;
1377:
1.1.1.1 knu 1378: my @words = split;
1379: # Adding one is for the (single) space which follows $words[0].
1380: my $rest = substr ($_, length ($words[0]) + 1);
1381: if ($words[0] eq "E") {
1382: next;
1383: }
1384: elsif ($words[0] eq "M") {
1385: $lineNr++;
1.1.1.9 knu 1386: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1387: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1388: my $line = substr($_, 36);
1389: my $isCurrentRev = ($rev eq $lrev);
1.1.1.1 knu 1390: # we should parse the date here ..
1391: if ($lrev eq $oldLrev) {
1.1.1.9 knu 1392: $revprint = sprintf('%-8s', '');
1.1.1.1 knu 1393: }
1394: else {
1.1.1.9 knu 1395: $revprint = sprintf('%-8s', $lrev);
1.1.1.11 knu 1396: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
1.1.1.9 knu 1397: $oldLusr = '';
1.1.1.1 knu 1398: }
1399: if ($lusr eq $oldLusr) {
1.1.1.9 knu 1400: $usrprint = '';
1.1.1.1 knu 1401: }
1402: else {
1403: $usrprint = $lusr;
1404: }
1405: $oldLrev = $lrev;
1406: $oldLusr = $lusr;
1.1.1.2 knu 1407:
1.1.1.9 knu 1408: # Set bold for text-based browsers only - graphical
1409: # browsers show bold fonts a bit wider than regular fonts,
1410: # so it looks irregular.
1411: print "<b>" if ($isCurrentRev && $is_textbased);
1412:
1.1.1.10 knu 1413: printf "%s%s %-8s %4d:",
1.1.1.9 knu 1414: $revprint,
1415: $isCurrentRev ? '!' : ' ',
1416: $usrprint,
1.1.1.10 knu 1417: $lineNr;
1.1.1.6 knu 1418: print spacedHtmlText($line, $d{'tabstop'});
1.1.1.9 knu 1419:
1420: print "</b>" if ($isCurrentRev && $is_textbased);
1.1.1.1 knu 1421: }
1422: elsif ($words[0] eq "ok") {
1423: # We could complain about any text received after this, like the
1424: # CVS command line client. But for simplicity, we don't.
1425: }
1426: elsif ($words[0] eq "error") {
1.1.1.11 knu 1427: fatal("500 Internal Error", "Error occured during annotate: <b>$_</b>");
1.1.1.1 knu 1428: }
1429: }
1430: if ($annTable) {
1431: print "</table>";
1432: }
1433: else {
1434: print "</pre>";
1435: }
1436: close ($reader) || warn "cannot close: $!";
1437: wait;
1438: }
1439:
1440: ###############################
1441: # make Checkout
1442: ###############################
1.1.1.2 knu 1443: sub doCheckout($$) {
1.1.1.1 knu 1444: my ($fullname, $rev) = @_;
1445: my ($mimetype,$revopt);
1446: my $fh = do {local(*FH);};
1447:
1.1.1.3 knu 1448: if ($rev eq 'HEAD' || $rev eq '.') {
1449: $rev = undef;
1450: }
1451:
1.1.1.1 knu 1452: # make sure the revisions a wellformed, for security
1453: # reasons ..
1.1.1.3 knu 1454: if (defined($rev) && $rev =~ /[^\w.]/) {
1.1.1.1 knu 1455: &fatal("404 Not Found",
1456: "Malformed query \"$ENV{QUERY_STRING}\"");
1457: }
1458:
1459: # get mimetype
1460: if (defined($input{"content-type"}) && ($input{"content-type"} =~ /\S\/\S/)) {
1461: $mimetype = $input{"content-type"}
1462: }
1463: else {
1464: $mimetype = &getMimeTypeFromSuffix($fullname);
1465: }
1466:
1467: if (defined($rev)) {
1468: $revopt = "-r$rev";
1469: if ($use_moddate) {
1470: readLog($fullname,$rev);
1471: $moddate=$date{$rev};
1472: }
1473: }
1474: else {
1475: $revopt = "-rHEAD";
1476: if ($use_moddate) {
1477: readLog($fullname);
1478: $moddate=$date{$symrev{HEAD}};
1479: }
1480: }
1.1.1.2 knu 1481:
1.1.1.1 knu 1482: ### just for the record:
1483: ### 'cvs co' seems to have a bug regarding single checkout of
1484: ### directories/files having spaces in it;
1485: ### this is an issue that should be resolved on cvs's side
1486: #
1487: # Safely for a child process to read from.
1488: if (! open($fh, "-|")) { # child
1489: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1.1.1.3 knu 1490: exec("cvs", "-Rld", $cvsroot, "co", "-p", $revopt, $where);
1.1.1.2 knu 1491: }
1.1.1.13! knu 1492:
! 1493: if (eof($fh)) {
! 1494: &fatal("404 Not Found",
! 1495: "$where is not (any longer) pertinent");
! 1496: }
1.1.1.1 knu 1497: #===================================================================
1498: #Checking out squid/src/ftp.c
1499: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1500: #VERS: 1.1.1.28.6.2
1501: #***************
1502:
1503: # Parse CVS header
1504: my ($revision, $filename, $cvsheader);
1505: while(<$fh>) {
1506: last if (/^\*\*\*\*/);
1507: $revision = $1 if (/^VERS: (.*)$/);
1508: if (/^Checking out (.*)$/) {
1509: $filename = $1;
1510: $filename =~ s/^\.\/*//;
1511: }
1512: $cvsheader .= $_;
1513: }
1514: if ($filename ne $where) {
1515: &fatal("500 Internal Error",
1.1.1.13! knu 1516: "Unexpected output from cvs co: $cvsheader");
1.1.1.1 knu 1517: }
1518: $| = 1;
1519:
1520: if ($mimetype eq "text/x-cvsweb-markup") {
1521: &cvswebMarkup($fh,$fullname,$revision);
1522: }
1523: else {
1524: http_header($mimetype);
1525: print <$fh>;
1526: }
1527: close($fh);
1528: }
1529:
1.1.1.2 knu 1530: sub cvswebMarkup($$$) {
1.1.1.1 knu 1531: my ($filehandle,$fullname,$revision) = @_;
1532: my ($pathname, $filename);
1533:
1534: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1535: ($filename = $where) =~ s/^.*\///;
1536: my ($fileurl) = urlencode($filename);
1537:
1538: http_header();
1539:
1.1.1.2 knu 1540: navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
1.1.1.1 knu 1541: print "<HR noshade>";
1542: print "<table width=\"100%\"><tr><td bgcolor=\"$markupLogColor\">";
1543: print "File: ", &clickablePath($where, 1);
1.1.1.11 knu 1544: print " (";
1545: &download_link($fileurl, $revision, "download");
1546: print ")";
1.1.1.1 knu 1547: if (!$defaultTextPlain) {
1.1.1.11 knu 1548: print " (";
1549: &download_link($fileurl, $revision, "as text",
1.1.1.1 knu 1550: "text/plain");
1.1.1.11 knu 1551: print ")";
1.1.1.1 knu 1552: }
1553: print "<BR>\n";
1554: if ($show_log_in_markup) {
1555: readLog($fullname); #,$revision);
1556: printLog($revision,0);
1557: }
1558: else {
1559: print "Version: <B>$revision</B><BR>\n";
1560: print "Tag: <B>", $input{only_with_tag}, "</b><br>\n" if
1561: $input{only_with_tag};
1562: }
1563: print "</td></tr></table>";
1564: my $url = download_url($fileurl, $revision, $mimetype);
1565: print "<HR noshade>";
1566: if ($mimetype =~ /^image/) {
1.1.1.11 knu 1567: printf '<IMG SRC="%s"><BR>', htmlquote("$url$barequery");
1.1.1.1 knu 1568: }
1.1.1.6 knu 1569: elsif ($mimetype =~ m%^application/pdf%) {
1.1.1.11 knu 1570: printf '<EMBED SRC="%s" WIDTH="100%"><BR>', htmlquote("$url$barequery");
1.1.1.6 knu 1571: }
1.1.1.1 knu 1572: else {
1573: print "<PRE>";
1.1.1.6 knu 1574:
1575: # prefetch several lines
1576: my @buf = head($filehandle);
1577:
1578: my %d = scan_directives(@buf);
1579:
1580: while (@buf || !eof($filehandle)) {
1581: $_ = @buf ? shift @buf : <$filehandle>;
1582:
1583: print spacedHtmlText($_, $d{'tabstop'});
1.1.1.1 knu 1584: }
1585: print "</PRE>";
1586: }
1587: }
1588:
1589: sub viewable($) {
1590: my ($mimetype) = @_;
1591:
1.1.1.6 knu 1592: $mimetype =~ m%^((text|image)/|application/pdf)% ;
1.1.1.1 knu 1593: }
1594:
1595: ###############################
1596: # Show Colored Diff
1597: ###############################
1.1.1.2 knu 1598: sub doDiff($$$$$$) {
1.1.1.1 knu 1599: my($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1600: my $fh = do {local(*FH);};
1.1.1.11 knu 1601: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1.1.1.1 knu 1602:
1603: if ($r1 =~ /([^:]+)(:(.+))?/) {
1604: $rev1 = $1;
1605: $sym1 = $3;
1606: }
1607: if ($r1 eq 'text') {
1608: $rev1 = $tr1;
1609: $sym1 = "";
1610: }
1611: if ($r2 =~ /([^:]+)(:(.+))?/) {
1612: $rev2 = $1;
1613: $sym2 = $3;
1614: }
1615: if ($r2 eq 'text') {
1616: $rev2 = $tr2;
1617: $sym2 = "";
1618: }
1.1.1.3 knu 1619:
1.1.1.1 knu 1620: # make sure the revisions a wellformed, for security
1621: # reasons ..
1.1.1.3 knu 1622: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1.1.1.1 knu 1623: &fatal("404 Not Found",
1624: "Malformed query \"$ENV{QUERY_STRING}\"");
1625: }
1.1 jfieber 1626: #
1627: # rev1 and rev2 are now both numeric revisions.
1628: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1629: # XXX should we warn about the fact that we do this?
1.1.1.1 knu 1630: if (&revcmp($rev1,$rev2) > 0) {
1631: my ($tmp1, $tmp2) = ($rev1, $sym1);
1632: ($rev1, $sym1) = ($rev2, $sym2);
1633: ($rev2, $sym2) = ($tmp1, $tmp2);
1634: }
1.1.1.11 knu 1635: my $difftype = $DIFFTYPES{$f};
1636:
1637: if (!$difftype) {
1.1.1.1 knu 1638: fatal ("400 Bad arguments", "Diff format $f not understood");
1639: }
1640:
1.1.1.11 knu 1641: my @difftype = @{$difftype->{'opts'}};
1642: my $human_readable = $difftype->{'colored'};
1643:
1.1.1.1 knu 1644: # apply special options
1645: if ($showfunc) {
1.1.1.11 knu 1646: push @difftype, '-p' if $f ne 's';
1.1.1.1 knu 1647:
1648: my($re1, $re2);
1649:
1650: while (($re1, $re2) = each %funcline_regexp) {
1651: if ($fullname =~ /$re1/) {
1652: push @difftype, '-F', '$re2';
1653: last;
1.1 jfieber 1654: }
1655: }
1.1.1.1 knu 1656: }
1657: if ($human_readable) {
1658: if ($hr_ignwhite) {
1659: push @difftype, '-w';
1660: }
1661: if ($hr_ignkeysubst) {
1662: push @difftype, '-kk';
1663: }
1664: }
1665: if (! open($fh, "-|")) { # child
1666: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1667: exec("rcsdiff",@difftype,"-r$rev1","-r$rev2",$fullname);
1668: }
1669: if ($human_readable) {
1670: http_header();
1671: &human_readable_diff($fh, $rev2);
1.1.1.7 knu 1672: gzipclose();
1.1.1.1 knu 1673: exit;
1674: }
1675: else {
1676: http_header("text/plain");
1677: }
1.1 jfieber 1678: #
1679: #===================================================================
1680: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
1681: #retrieving revision 1.16
1682: #retrieving revision 1.17
1683: #diff -c -r1.16 -r1.17
1684: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1685: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
1686: #
1687: # Ideas:
1688: # - nuke the stderr output if it's what we expect it to be
1689: # - Add "no differences found" if the diff command supplied no output.
1690: #
1691: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1692: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
1693: # (bogus example, but...)
1694: #
1.1.1.1 knu 1695: if (grep { $_ eq '-u'} @difftype) {
1696: $f1 = '---';
1697: $f2 = '\+\+\+';
1698: }
1699: else {
1700: $f1 = '\*\*\*';
1701: $f2 = '---';
1702: }
1703: while (<$fh>) {
1704: if (m|^$f1 $cvsroot|o) {
1705: s|$cvsroot/||o;
1706: if ($sym1) {
1707: chop;
1.1.1.11 knu 1708: $_ .= " $sym1\n";
1.1 jfieber 1709: }
1710: }
1.1.1.1 knu 1711: elsif (m|^$f2 $cvsroot|o) {
1712: s|$cvsroot/||o;
1713: if ($sym2) {
1714: chop;
1.1.1.11 knu 1715: $_ .= " $sym2\n";
1.1.1.1 knu 1716: }
1717: }
1718: print $_;
1719: }
1720: close($fh);
1721: }
1722:
1723: ###############################
1724: # Show Logs ..
1725: ###############################
1.1.1.2 knu 1726: sub getDirLogs($$@) {
1.1.1.1 knu 1727: my ($cvsroot,$dirname,@otherFiles) = @_;
1728: my ($state,$otherFiles,$tag, $file, $date, $branchpoint, $branch, $log);
1729: my ($rev, $revision, $revwanted, $filename, $head, $author);
1730:
1731: $tag = $input{only_with_tag};
1732:
1733: my ($DirName) = "$cvsroot/$where";
1734: my (@files, @filetags);
1735: my $fh = do {local(*FH);};
1736:
1737: push(@files, &safeglob("$DirName/*,v"));
1738: push(@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
1739: foreach $file (@otherFiles) {
1740: push(@files, "$DirName/$file");
1741: }
1742:
1743: # just execute rlog if there are any files
1.1.1.2 knu 1744: if ($#files < 0) {
1.1.1.1 knu 1745: return;
1746: }
1747:
1748: if ($tag) {
1749: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
1750: if (! open($fh, "-|")) {
1751: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1752: exec('rlog', @files);
1753: }
1754: }
1755: else {
1756: my $kidpid = open($fh, "-|");
1757: if (! $kidpid) {
1758: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1759: exec('rlog', '-r', @files);
1760: }
1761: }
1762: $state = "start";
1763: while (<$fh>) {
1764: if ($state eq "start") {
1765: #Next file. Initialize file variables
1766: $rev = undef;
1767: $revwanted = undef;
1768: $branch = undef;
1769: $branchpoint = undef;
1770: $filename = undef;
1771: $log = undef;
1772: $revision = undef;
1773: $branch = undef;
1774: %symrev = ();
1775: @filetags = ();
1776: #jump to head state
1777: $state = "head";
1.1 jfieber 1778: }
1.1.1.1 knu 1779: print "$state:$_" if ($verbose);
1780: again:
1781: if ($state eq "head") {
1782: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
1.1.1.13! knu 1783:
! 1784: if (/^Working file: (.+)$/) {
! 1785: $filename = $1;
! 1786: } elsif (/^head: (.+)$/) {
! 1787: $head = $1;
! 1788: } elsif (/^branch: (.+)$/) {
! 1789: $branch = $1
! 1790: } elsif (/^symbolic names:/) {
! 1791: $state = "tags";
! 1792: ($branch = $head) =~ s/\.\d+$// if (!defined($branch));
! 1793: $branch =~ s/(\.?)(\d+)$/${1}0.$2/;
! 1794: $symrev{MAIN} = $branch;
! 1795: $symrev{HEAD} = $branch;
! 1796: $alltags{MAIN} = 1;
! 1797: $alltags{HEAD} = 1;
! 1798: push (@filetags, "MAIN", "HEAD");
! 1799: } elsif (/$LOG_REVSEPARATOR/o) {
! 1800: $state = "log";
! 1801: $rev = undef;
! 1802: $date = undef;
! 1803: $log = "";
! 1804: # Try to reconstruct the relative filename if RCS spits out a full path
! 1805: $filename =~ s%^\Q$DirName\E/%%;
! 1806: }
1.1.1.1 knu 1807: next;
1808: }
1.1.1.13! knu 1809: if ($state eq "tags") {
! 1810: if (/^\s+(.+):\s+([\d\.]+)\s+$/) {
! 1811: push (@filetags, $1);
! 1812: $symrev{$1} = $2;
! 1813: $alltags{$1} = 1;
1.1.1.1 knu 1814: next;
1.1.1.13! knu 1815: } elsif (/^\S/) {
! 1816: if (defined($tag)) {
! 1817: if(defined($symrev{$tag}) || $tag eq "HEAD") {
! 1818: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
! 1819: ($branch = $revwanted) =~ s/\.0\././;
! 1820: ($branchpoint = $branch) =~ s/\.?\d+$//;
! 1821: $revwanted = undef if ($revwanted ne $branch);
! 1822: #print "\n[revwanted=$revwanted]";
! 1823: } elsif ($tag ne "HEAD") {
! 1824: print "Tag not found, skip this file" if ($verbose);
! 1825: $state = "skip";
! 1826: next;
! 1827: }
! 1828: }
! 1829: foreach my $tagfound (@filetags) {
! 1830: $tags{$tagfound} = 1;
! 1831: }
! 1832: $state = "head";
! 1833: goto again;
1.1.1.1 knu 1834: }
1835: }
1836: if ($state eq "log") {
1.1.1.10 knu 1837: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
1.1.1.1 knu 1838: # End of a log entry.
1839: my $revbranch;
1840: ($revbranch = $rev) =~ s/\.\d+$//;
1.1.1.11 knu 1841: print "$filename $rev Wanted: $revwanted ",
1842: "Revbranch: $revbranch Branch: $branch ",
1843: "Branchpoint: $branchpoint\n" if ($verbose);
1.1.1.1 knu 1844: if (!defined($revwanted) && defined($branch)
1845: && $branch eq $revbranch || !defined($tag)) {
1846: print "File revision $rev found for branch $branch\n"
1847: if ($verbose);
1848: $revwanted = $rev;
1849: }
1850: if (defined($revwanted) ? $rev eq $revwanted :
1851: defined($branchpoint) ? $rev eq $branchpoint :
1852: 0 && ($rev eq $head)) { # Don't think head is needed here..
1853: print "File info $rev found for $filename\n" if ($verbose);
1854: my @finfo = ($rev,$date,$log,$author,$filename);
1855: my ($name);
1856: ($name = $filename) =~ s%/.*%%;
1857: $fileinfo{$name} = [ @finfo ];
1858: $state = "done" if ($rev eq $revwanted);
1859: }
1860: $rev = undef;
1861: $date = undef;
1862: $log = "";
1863: }
1864: elsif (!defined($date) && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
1865: my $yr = $1;
1866: # damn 2-digit year routines :-)
1867: if ($yr > 100) {
1868: $yr -= 1900;
1869: }
1870: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1871: ($author) = /author: ([^;]+)/;
1872: $state = "log";
1873: $log = '';
1874: next;
1875: }
1876: elsif (!defined($rev) && m/^revision (.*)$/) {
1877: $rev = $1;
1878: next;
1879: }
1880: else {
1.1.1.11 knu 1881: $log .= $_;
1.1.1.1 knu 1882: }
1883: }
1.1.1.10 knu 1884: if (/$LOG_FILESEPARATOR/o) {
1.1.1.1 knu 1885: $state = "start";
1886: next;
1887: }
1888: }
1889: if ($. == 0) {
1.1.1.2 knu 1890: fatal("500 Internal Error",
1.1.1.1 knu 1891: "Failed to spawn GNU rlog on <em>'".join(", ", @files)."'</em><p>did you set the <b>\$ENV{PATH}</b> in your configuration file correctly ?");
1892: }
1893: close($fh);
1894: }
1895:
1.1.1.2 knu 1896: sub readLog($;$) {
1.1.1.1 knu 1897: my($fullname,$revision) = @_;
1898: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
1899: my $fh = do {local(*FH);};
1900:
1901: if (defined($revision)) {
1902: $revision = "-r$revision";
1903: }
1904: else {
1905: $revision = "";
1906: }
1907:
1908: undef %symrev;
1909: undef %revsym;
1910: undef @allrevisions;
1911: undef %date;
1912: undef %author;
1913: undef %state;
1914: undef %difflines;
1915: undef %log;
1916:
1917: print("Going to rlog '$fullname'\n") if ($verbose);
1918: if (! open($fh, "-|")) { # child
1919: if ($revision ne '') {
1920: exec("rlog",$revision,$fullname);
1921: }
1922: else {
1923: exec("rlog",$fullname);
1924: }
1925: }
1926: while (<$fh>) {
1.1 jfieber 1927: print if ($verbose);
1928: if ($symnames) {
1929: if (/^\s+([^:]+):\s+([\d\.]+)/) {
1930: $symrev{$1} = $2;
1.1.1.1 knu 1931: }
1932: else {
1.1 jfieber 1933: $symnames = 0;
1934: }
1.1.1.1 knu 1935: }
1936: elsif (/^head:\s+([\d\.]+)/) {
1937: $head = $1;
1938: }
1939: elsif (/^branch:\s+([\d\.]+)/) {
1940: $curbranch = $1;
1941: }
1942: elsif (/^symbolic names/) {
1.1 jfieber 1943: $symnames = 1;
1.1.1.1 knu 1944: }
1945: elsif (/^-----/) {
1.1 jfieber 1946: last;
1947: }
1948: }
1.1.1.1 knu 1949: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1950:
1.1 jfieber 1951: # each log entry is of the form:
1952: # ----------------------------
1953: # revision 3.7.1.1
1954: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
1955: # log info
1956: # ----------------------------
1957: logentry:
1.1.1.10 knu 1958: while (!/$LOG_FILESEPARATOR/o) {
1.1.1.1 knu 1959: $_ = <$fh>;
1960: last logentry if (!defined($_)); # EOF
1.1 jfieber 1961: print "R:", $_ if ($verbose);
1962: if (/^revision ([\d\.]+)/) {
1963: $rev = $1;
1.1.1.1 knu 1964: unshift(@allrevisions,$rev);
1965: }
1.1.1.10 knu 1966: elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
1.1.1.1 knu 1967: next logentry;
1968: }
1969: else {
1970: # The rlog output is syntactically ambiguous. We must
1971: # have guessed wrong about where the end of the last log
1972: # message was.
1973: # Since this is likely to happen when people put rlog output
1974: # in their commit messages, don't even bother keeping
1975: # these lines since we don't know what revision they go with
1976: # any more.
1.1 jfieber 1977: next logentry;
1.1.1.1 knu 1978: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 1979: }
1.1.1.1 knu 1980: $_ = <$fh>;
1.1 jfieber 1981: print "D:", $_ if ($verbose);
1.1.1.1 knu 1982: if (m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|) {
1983: my $yr = $1;
1984: # damn 2-digit year routines :-)
1985: if ($yr > 100) {
1986: $yr -= 1900;
1987: }
1988: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 1989: $author{$rev} = $7;
1.1.1.1 knu 1990: $state{$rev} = $8;
1991: $difflines{$rev} = $10;
1992: }
1993: else {
1.1 jfieber 1994: &fatal("500 Internal Error", "Error parsing RCS output: $_");
1995: }
1996: line:
1.1.1.1 knu 1997: while (<$fh>) {
1.1 jfieber 1998: print "L:", $_ if ($verbose);
1999: next line if (/^branches:\s/);
1.1.1.10 knu 2000: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
1.1 jfieber 2001: $log{$rev} .= $_;
2002: }
2003: print "E:", $_ if ($verbose);
2004: }
1.1.1.1 knu 2005: close($fh);
1.1 jfieber 2006: print "Done reading RCS file\n" if ($verbose);
1.1.1.1 knu 2007:
2008: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
2009: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
2010:
1.1 jfieber 2011: #
2012: # HEAD is an artificial tag which is simply the highest tag number on the main
1.1.1.1 knu 2013: # branch, unless there is a branch tag in the RCS file in which case it's the
2014: # highest revision on that branch. Find it by looking through @revorder; it
2015: # is the first commit listed on the appropriate branch.
2016: # This is not neccesary the same revision as marked as head in the RCS file.
2017: my $headrev = $curbranch || "1";
2018: ($symrev{"MAIN"} = $headrev) =~ s/(\.?)(\d+)$/${1}0.$2/;
2019: foreach $rev (@revorder) {
2020: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2021: $symrev{"HEAD"} = $rev;
1.1.1.13! knu 2022: last;
1.1 jfieber 2023: }
2024: }
1.1.1.1 knu 2025: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2026: if (!defined($symrev{"HEAD"}));
1.1 jfieber 2027: print "Done finding HEAD\n" if ($verbose);
2028: #
2029: # Now that we know all of the revision numbers, we can associate
2030: # absolute revision numbers with all of the symbolic names, and
2031: # pass them to the form so that the same association doesn't have
2032: # to be built then.
2033: #
1.1.1.1 knu 2034: undef @branchnames;
2035: undef %branchpoint;
2036: undef $sel;
2037:
2038: foreach (reverse sort keys %symrev) {
1.1 jfieber 2039: $rev = $symrev{$_};
1.1.1.12 knu 2040: if ($rev =~ /^((.*)\.)0\.(\d+)$/) {
1.1.1.1 knu 2041: push(@branchnames, $_);
1.1 jfieber 2042: #
2043: # A revision number of A.B.0.D really translates into
2044: # "the highest current revision on branch A.B.D".
2045: #
2046: # If there is no branch A.B.D, then it translates into
2047: # the head A.B .
2048: #
1.1.1.1 knu 2049: # This reasoning also applies to the main branch A.B,
2050: # with the branch number 0.A, with the exception that
2051: # it has no head to translate to if there is nothing on
2052: # the branch, but I guess this can never happen?
1.1.1.12 knu 2053: #
2054: # Since some stupid people actually import/check in
2055: # files with version 0.X we assume that the above cannot
2056: # happen, and regard 0.X(.*) as a revision and not a branch.
1.1 jfieber 2057: #
1.1.1.1 knu 2058: $head = defined($2) ? $2 : "";
1.1 jfieber 2059: $branch = $3;
1.1.1.1 knu 2060: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2061: my $regex;
1.1.1.13! knu 2062: $regex = quotemeta $branchrev;
1.1 jfieber 2063: $rev = $head;
2064:
1.1.1.1 knu 2065: foreach my $r (@revorder) {
2066: if ($r =~ /^${regex}\b/) {
2067: $rev = $branchrev;
1.1.1.13! knu 2068: last;
1.1 jfieber 2069: }
2070: }
1.1.1.1 knu 2071: next if ($rev eq "");
2072: if ($rev ne $head && $head ne "") {
2073: $branchpoint{$head} .= ", " if ($branchpoint{$head});
2074: $branchpoint{$head} .= $_;
2075: }
1.1 jfieber 2076: }
1.1.1.1 knu 2077: $revsym{$rev} .= ", " if ($revsym{$rev});
2078: $revsym{$rev} .= $_;
1.1 jfieber 2079: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
2080: }
2081: print "Done associating revisions with branches\n" if ($verbose);
1.1.1.1 knu 2082:
2083: my ($onlyonbranch, $onlybranchpoint);
2084: if ($onlyonbranch = $input{'only_with_tag'}) {
2085: $onlyonbranch = $symrev{$onlyonbranch};
1.1.1.12 knu 2086: if ($onlyonbranch =~ s/\.0\././) {
1.1.1.1 knu 2087: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2088: }
2089: else {
2090: $onlybranchpoint = $onlyonbranch;
2091: }
2092: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2093: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
2094: }
2095: }
2096:
2097: undef @revisions;
2098:
2099: foreach (@allrevisions) {
2100: ($br = $_) =~ s/\.\d+$//;
2101: ($brp = $br) =~ s/\.\d+$//;
2102: next if ($onlyonbranch && $br ne $onlyonbranch &&
2103: $_ ne $onlybranchpoint);
2104: unshift(@revisions,$_);
2105: }
2106:
2107: if ($logsort eq "date") {
2108: # Sort the revisions in commit order an secondary sort on revision
2109: # (secondary sort needed for imported sources, or the first main
2110: # revision gets before the same revision on the 1.1.1 branch)
2111: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
2112: }
2113: elsif ($logsort eq "rev") {
2114: # Sort the revisions in revision order, highest first
2115: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
2116: }
2117: else {
2118: # No sorting. Present in the same order as rlog / cvs log
2119: @revdisplayorder = @revisions;
2120: }
2121:
2122: }
2123:
1.1.1.11 knu 2124: sub printDiffLinks($$) {
2125: my($text, $url) = @_;
2126: my @extra;
2127:
2128: local $_;
2129: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2130: my $f = $_ eq $defaultDiffType ? '' : $_;
2131:
2132: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2133: }
2134:
2135: print &link($text, $url), ' (', join(', ', @extra), ')';
2136: }
2137:
1.1.1.1 knu 2138: sub printLog($;$) {
2139: my ($link, $br, $brp);
2140: ($_,$link) = @_;
2141: ($br = $_) =~ s/\.\d+$//;
2142: ($brp = $br) =~ s/\.?\d+$//;
2143: my ($isDead, $prev);
2144:
2145: $link = 1 if (!defined($link));
2146: $isDead = ($state{$_} eq "dead");
2147:
2148: if ($link && !$isDead) {
2149: my ($filename);
2150: ($filename = $where) =~ s/^.*\///;
2151: my ($fileurl) = urlencode($filename);
2152: print "<a NAME=\"rev$_\"></a>";
2153: if (defined($revsym{$_})) {
2154: foreach my $sym (split(", ", $revsym{$_})) {
2155: print "<a NAME=\"$sym\"></a>";
2156: }
2157: }
2158: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
2159: foreach my $sym (split(", ", $revsym{$br})) {
2160: print "<a NAME=\"$sym\"></a>";
2161: }
2162: $nameprinted{$br} = 1;
2163: }
2164: print "\n Revision ";
2165: &download_link($fileurl, $_, $_,
1.1.1.11 knu 2166: $defaultViewable ? "text/x-cvsweb-markup" : undef);
1.1.1.1 knu 2167: if ($defaultViewable) {
1.1.1.11 knu 2168: print " / (";
2169: &download_link($fileurl, $_, "download", $mimetype);
2170: print ")";
1.1.1.1 knu 2171: }
2172: if (not $defaultTextPlain) {
1.1.1.11 knu 2173: print " / (";
2174: &download_link($fileurl, $_, "as text", "text/plain");
2175: print ")";
1.1.1.1 knu 2176: }
2177: if (!$defaultViewable) {
1.1.1.11 knu 2178: print " / (";
2179: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2180: print ")";
1.1.1.1 knu 2181: }
2182: if ($allow_annotate) {
1.1.1.11 knu 2183: print " - ";
2184: print &link('annotate',
2185: sprintf('%s/%s?annotate=%s%s',
2186: $scriptname,
2187: urlencode($where),
2188: $_,
2189: $barequery));
1.1.1.1 knu 2190: }
2191: # Plus a select link if enabled, and this version isn't selected
2192: if ($allow_version_select) {
2193: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
1.1.1.11 knu 2194: print " - ";
2195: print &link('[select for diffs]',
2196: sprintf('%s?r1=%s%s',
2197: $scriptwhere,
2198: $_,
2199: $barequery));
1.1.1.1 knu 2200: }
2201: else {
2202: print " - <b>[selected]</b>";
2203: }
2204: }
2205: }
2206: else {
2207: print "Revision <B>$_</B>";
2208: }
2209: if (/^1\.1\.1\.\d+$/) {
2210: print " <i>(vendor branch)</i>";
2211: }
2212: if (defined @mytz) {
2213: my ($est) = $mytz[(localtime($date{$_}))[8]];
1.1.1.11 knu 2214: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
1.1.1.1 knu 2215: } else {
1.1.1.11 knu 2216: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
1.1.1.1 knu 2217: }
1.1.1.11 knu 2218: print readableTime(time() - $date{$_},1), " ago)";
1.1.1.1 knu 2219: print " by ";
1.1.1.11 knu 2220: print "<i>", $author{$_}, "</i>\n";
1.1.1.1 knu 2221: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
2222: if ($revsym{$br});
2223: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
2224: if ($revsym{$_});
2225: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
2226: if ($branchpoint{$_});
2227: # Find the previous revision
2228: my @prevrev = split(/\./, $_);
2229: do {
2230: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 2231: # If it was X.Y.Z.1, just make it X.Y
1.1.1.1 knu 2232: pop(@prevrev);
2233: pop(@prevrev);
2234: }
2235: $prev = join(".", @prevrev);
2236: } until (defined($date{$prev}) || $prev eq "");
2237: if ($prev ne "") {
2238: if ($difflines{$_}) {
2239: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
2240: }
2241: }
2242: if ($isDead) {
2243: print "<BR><B><I>FILE REMOVED</I></B>\n";
2244: }
2245: elsif ($link) {
2246: my %diffrev = ();
2247: $diffrev{$_} = 1;
2248: $diffrev{""} = 1;
2249: print "<BR>Diff";
2250: #
2251: # Offer diff to previous revision
2252: if ($prev) {
2253: $diffrev{$prev} = 1;
1.1.1.11 knu 2254:
2255: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2256: $scriptwhere,
2257: $prev,
2258: $_,
2259: $barequery);
2260:
2261: print " to previous ";
2262: printDiffLinks($prev, $url);
1.1 jfieber 2263: }
1.1.1.1 knu 2264: #
2265: # Plus, if it's on a branch, and it's not a vendor branch,
2266: # offer a diff with the branch point.
2267: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
1.1.1.11 knu 2268: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2269: $scriptwhere,
2270: $brp,
2271: $_,
2272: $barequery);
2273:
2274: print " to branchpoint ";
2275: printDiffLinks($brp, $url);
1.1.1.1 knu 2276: }
2277: #
2278: # Plus, if it's on a branch, and it's not a vendor branch,
2279: # offer to diff with the next revision of the higher branch.
2280: # (e.g. change gets committed and then brought
2281: # over to -stable)
2282: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2283: my ($i,$nextmain);
2284: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
2285: my (@tmp2) = split(/\./, $_);
2286: for ($nextmain = ""; $i > 0; $i--) {
2287: my ($next) = $revorder[$i-1];
2288: my (@tmp1) = split(/\./, $next);
1.1 jfieber 2289: if ($#tmp1 < $#tmp2) {
1.1.1.1 knu 2290: $nextmain = $next;
2291: last;
1.1 jfieber 2292: }
1.1.1.1 knu 2293: # Only the highest version on a branch should have
2294: # a diff for the "next main".
2295: last if (join(".",@tmp1[0..$#tmp1-1])
2296: eq join(".",@tmp2[0..$#tmp1-1]));
2297: }
2298: if (!defined($diffrev{$nextmain})) {
2299: $diffrev{$nextmain} = 1;
1.1.1.11 knu 2300:
2301: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2302: $scriptwhere,
2303: $nextmain,
2304: $_,
2305: $barequery);
2306:
2307: print " next main ";
2308: printDiffLinks($nextmain, $url);
1.1.1.1 knu 2309: }
2310: }
2311: # Plus if user has selected only r1, then present a link
2312: # to make a diff to that revision
2313: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2314: $diffrev{$input{"r1"}} = 1;
2315:
1.1.1.11 knu 2316: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2317: $scriptwhere,
2318: $input{'r1'},
2319: $_,
2320: $barequery);
2321:
2322: print " to selected ";
2323: printDiffLinks($input{'r1'}, $url);
1.1 jfieber 2324: }
2325: }
1.1.1.1 knu 2326: print "<PRE>\n";
2327: print &htmlify($log{$_}, 1);
2328: print "</PRE>\n";
2329: }
2330:
1.1.1.2 knu 2331: sub doLog($) {
1.1.1.1 knu 2332: my($fullname) = @_;
2333: my ($diffrev, $upwhere, $filename, $backurl);
1.1.1.2 knu 2334:
1.1.1.1 knu 2335: readLog($fullname);
2336:
2337: html_header("CVS log for $where");
2338: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2339: ($filename = $where) =~ s|^.*/||;
2340: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2341: print &link($backicon, "$backurl#$filename"),
1.1.1.11 knu 2342: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
2343: print &link('Request diff between arbitrary revisions', '#diff');
2344: print '<HR NOSHADE>';
2345:
1.1.1.1 knu 2346: if ($curbranch) {
2347: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
2348: }
2349: else {
2350: print "No default branch";
2351: }
2352: print "<BR>\n";
2353: if ($input{only_with_tag}) {
2354: print "Current tag: $input{only_with_tag}<BR>\n";
2355: }
2356:
2357: undef %nameprinted;
2358:
2359: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2360: print "<HR size=1 NOSHADE>";
2361: printLog($revdisplayorder[$i]);
2362: }
2363:
2364: print "<HR NOSHADE>";
1.1 jfieber 2365: print "<A NAME=diff>\n";
2366: print "This form allows you to request diff's between any two\n";
2367: print "revisions of a file. You may select a symbolic revision\n";
2368: print "name using the selection box or you may type in a numeric\n";
2369: print "name using the type-in text box.\n";
2370: print "</A><P>\n";
1.1.1.1 knu 2371: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2372: foreach (@stickyvars) {
1.1.1.11 knu 2373: printf('<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">', $_, $input{$_})
1.1.1.1 knu 2374: if (defined($input{$_})
1.1.1.6 knu 2375: && ((!defined($DEFAULTVALUE{$_})
2376: || $input{$_} ne $DEFAULTVALUE{$_})
2377: && $input{$_} ne ""));
1.1.1.1 knu 2378: }
1.1.1.6 knu 2379: print "<TABLE><TR>\n";
2380: print "<TD align=right>Diffs between \n";
1.1 jfieber 2381: print "<SELECT NAME=\"r1\">\n";
2382: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2383: print $sel;
2384: print "</SELECT>\n";
1.1.1.1 knu 2385: $diffrev = $revdisplayorder[$#revdisplayorder];
2386: $diffrev = $input{"r1"} if (defined($input{"r1"}));
1.1.1.6 knu 2387: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
2388: print "<TD><BR></TD></TR>\n";
2389: print "<TR><TD align=right>and \n";
1.1 jfieber 2390: print "<SELECT NAME=\"r2\">\n";
2391: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2392: print $sel;
2393: print "</SELECT>\n";
1.1.1.1 knu 2394: $diffrev = $revdisplayorder[0];
2395: $diffrev = $input{"r2"} if (defined($input{"r2"}));
1.1.1.6 knu 2396: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
2397: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Get Diffs \"></TD>\n";
1.1.1.1 knu 2398: print "</FORM>\n";
1.1.1.6 knu 2399: print "</TR></TABLE>\n";
1.1.1.1 knu 2400: print "<HR noshade>\n";
1.1.1.6 knu 2401: print "<TABLE>";
2402: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
1.1.1.11 knu 2403: print "<TR><TD align=right>Preferred Diff type:</TD>";
2404: print "<TD>";
1.1.1.6 knu 2405: printDiffSelect($use_java_script);
2406: print "</TD><TD></TD></TR>\n";
1.1.1.1 knu 2407: if (@branchnames) {
1.1.1.6 knu 2408: print "<TR><TD align=right>View only Branch:</TD>";
2409: print "<TD>";
1.1.1.1 knu 2410: print "<A name=branch></A>\n";
2411: print "<SELECT NAME=\"only_with_tag\"";
2412: print " onchange=\"submit()\"" if ($use_java_script);
2413: print ">\n";
2414: print "<OPTION VALUE=\"\"";
2415: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2416: $input{"only_with_tag"} eq "");
2417: print ">Show all branches\n";
2418: foreach (reverse sort @branchnames) {
2419: print "<OPTION";
2420: print " SELECTED" if (defined($input{"only_with_tag"})
2421: && $input{"only_with_tag"} eq $_);
2422: print ">${_}\n";
2423: }
1.1.1.6 knu 2424: print "</SELECT></TD><TD></TD></TR>\n";
1.1.1.1 knu 2425: }
2426: foreach (@stickyvars) {
1.1.1.6 knu 2427: next if ($_ eq "f");
1.1.1.1 knu 2428: next if ($_ eq "only_with_tag");
2429: next if ($_ eq "logsort");
2430: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
1.1.1.6 knu 2431: if (defined($input{$_})
2432: && (!defined($DEFAULTVALUE{$_})
2433: || $input{$_} ne $DEFAULTVALUE{$_})
1.1.1.1 knu 2434: && $input{$_} ne "");
2435: }
1.1.1.6 knu 2436: print "<TR><TD align=right>";
2437: print "<A name=logsort></A>\n";
2438: print "Sort log by:</TD>";
1.1.1.11 knu 2439: print "<TD>";
2440: printLogSortSelect($use_java_script);
2441: print "</TD>";
1.1.1.6 knu 2442: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Set \"></TD>";
1.1 jfieber 2443: print "</FORM>\n";
1.1.1.6 knu 2444: print "</TR></TABLE>";
1.1.1.1 knu 2445: print &html_footer;
1.1 jfieber 2446: print "</BODY></HTML>\n";
2447: }
2448:
1.1.1.2 knu 2449: sub flush_diff_rows($$$$) {
1.1.1.1 knu 2450: my $j;
2451: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2452: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2453: for ($j = 0 ; $j < $leftRow; $j++) {
2454: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2455: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2456: }
2457: }
2458: elsif ($state eq "PreChange") { # state eq "PreChange"
2459: # we got removes with subsequent adds
2460: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2461: print "<tr>";
2462: if ($j < $leftRow) {
2463: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2464: }
2465: else {
2466: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2467: }
2468: if ($j < $rightRow) {
2469: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2470: }
2471: else {
2472: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2473: }
2474: print "</tr>\n";
2475: }
2476: }
2477: }
1.1 jfieber 2478:
1.1.1.1 knu 2479: ##
2480: # Function to generate Human readable diff-files
2481: # human_readable_diff(String revision_to_return_to);
2482: ##
2483: sub human_readable_diff($){
1.1.1.6 knu 2484: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
1.1.1.1 knu 2485: my ($fh, $rev) = @_;
2486: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2487: my (@rightCol, @leftCol);
2488:
2489: ($where_nd = $where) =~ s/.diff$//;
2490: ($filename = $where_nd) =~ s/^.*\///;
2491: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2492: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2493:
1.1.1.2 knu 2494: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
1.1 jfieber 2495:
1.1.1.1 knu 2496: # Read header to pick up read revision and date, if possible
2497: while (<$fh>) {
2498: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2499: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2500: last if (/^\+\+\+ /);
2501: }
2502: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2503: $rev1 = $r1r;
2504: $date1 = $r1d;
2505: }
2506: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2507: $rev2 = $r2r;
2508: $date2 = $r2d;
2509: }
1.1.1.2 knu 2510:
1.1.1.11 knu 2511: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
2512: "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n",
2513: "<tr bgcolor=\"#ffffff\">\n",
2514: "<th width=\"50%\" valign=TOP>",
2515: "version $rev1";
1.1.1.1 knu 2516: print ", $date1" if (defined($date1));
2517: print "<br>Tag: $sym1\n" if ($sym1);
1.1.1.11 knu 2518: print "</th>\n",
2519: "<th width=\"50%\" valign=TOP>",
2520: "version $rev2";
1.1.1.1 knu 2521: print ", $date2" if (defined($date2));
2522: print "<br>Tag: $sym2\n" if ($sym1);
2523: print "</th>\n";
2524:
2525: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\">";
2526: my $fe = "</font>";
2527:
2528: my $leftRow = 0;
2529: my $rightRow = 0;
2530: my ($oldline, $newline, $funname, $diffcode, $rest);
2531:
2532: # Process diff text
2533: # The diffrows are could make excellent use of
2534: # cascading style sheets because we've to set the
2535: # font and color for each row. anyone ...?
2536: ####
1.1.1.6 knu 2537:
2538: # prefetch several lines
2539: my @buf = head($fh);
2540:
2541: my %d = scan_directives(@buf);
2542:
2543: while (@buf || !eof($fh)) {
2544: $difftxt = @buf ? shift @buf : <$fh>;
1.1.1.2 knu 2545:
1.1.1.1 knu 2546: if ($difftxt =~ /^@@/) {
2547: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2548: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2549: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2550: print " <font size=-1>$funname</font></td></tr></table>";
2551: print "</td><td width=\"50%\">";
2552: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2553: print " <font size=-1>$funname</font></td></tr></table>";
2554: print "</td>\n";
2555: $state = "dump";
2556: $leftRow = 0;
2557: $rightRow = 0;
2558: }
2559: else {
2560: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
1.1.1.6 knu 2561: $_ = spacedHtmlText($rest, $d{'tabstop'});
1.1.1.1 knu 2562:
2563: # Add fontface, size
2564: $_ = "$fs $_$fe";
1.1.1.2 knu 2565:
1.1.1.1 knu 2566: #########
2567: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2568: # in order to get some nice 'ediff'-mode output
2569: # states:
2570: # "dump" - just dump the value
2571: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2572: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2573: ##########
2574:
2575: if ($diffcode eq '+') {
2576: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2577: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2578: }
2579: else { # we got minus before
2580: $state = "PreChange";
2581: $rightCol[$rightRow++] = $_;
2582: }
1.1.1.2 knu 2583: }
1.1.1.1 knu 2584: elsif ($diffcode eq '-') {
2585: $state = "PreChangeRemove";
2586: $leftCol[$leftRow++] = $_;
2587: }
2588: else { # empty diffcode
2589: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2590: print "<tr><td>$_</td><td>$_</td></tr>\n";
2591: $state = "dump";
2592: $leftRow = 0;
2593: $rightRow = 0;
2594: }
2595: }
2596: }
2597: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2598:
2599: # state is empty if we didn't have any change
2600: if (!$state) {
2601: print "<tr><td colspan=2> </td></tr>";
2602: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2603: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2604: }
2605: print "</table>";
2606: close($fh);
2607:
2608: print "<br><hr noshade width=\"100%\">\n";
2609:
2610: print "<table border=0>";
2611:
2612: print "<tr><td>";
2613: # print legend
2614: print "<table border=1><tr><td>";
2615: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2616: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2617: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2618: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2619: print "</table></td></tr></table>\n";
2620:
2621: print "<td>";
2622: # Print format selector
2623: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2624: foreach my $var (keys %input) {
2625: next if ($var eq "f");
2626: next if (defined($DEFAULTVALUE{$var})
2627: && $DEFAULTVALUE{$var} eq $input{$var});
2628: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2629: urlencode($input{$var}),"\">\n";
2630: }
2631: printDiffSelect($use_java_script);
2632: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2633: print "</FORM>\n";
2634: print "</td>";
2635:
2636: print "</tr></table>";
1.1 jfieber 2637: }
2638:
1.1.1.2 knu 2639: sub navigateHeader($$$$$) {
1.1.1.1 knu 2640: my ($swhere,$path,$filename,$rev,$title) = @_;
2641: $swhere = "" if ($swhere eq $scriptwhere);
2642: $swhere = urlencode($filename) if ($swhere eq "");
2643: print "<\!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
2644: print "<HTML>\n<HEAD>\n";
1.1.1.13! knu 2645: print '<!-- CVSweb $zRevision: 1.104 $ $kRevision: 1.41 $ -->';
1.1.1.1 knu 2646: print "\n<TITLE>$path$filename - $title - $rev</TITLE></HEAD>\n";
1.1.1.7 knu 2647: print "$body_tag_for_src\n";
1.1.1.1 knu 2648: print "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$navigationHeaderColor\">";
2649: print "<tr valign=bottom><td>";
1.1.1.11 knu 2650: print &link($backicon, "$swhere$query#rev$rev");
1.1.1.1 knu 2651: print "</a> <b>Return to ", &link("$filename","$swhere$query#rev$rev")," CVS log";
2652: print "</b> $fileicon</td>";
1.1.1.2 knu 2653:
1.1.1.1 knu 2654: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2655: print "</tr></table>";
2656: }
1.1 jfieber 2657:
1.1.1.2 knu 2658: sub plural_write($$) {
1.1.1.1 knu 2659: my ($num,$text) = @_;
2660: if ($num != 1) {
1.1.1.11 knu 2661: $text .= "s";
1.1.1.1 knu 2662: }
2663: if ($num > 0) {
1.1.1.11 knu 2664: return join(' ', $num, $text);
1.1.1.1 knu 2665: }
2666: else {
2667: return "";
2668: }
1.1 jfieber 2669: }
2670:
1.1.1.1 knu 2671: ##
2672: # print readable timestamp in terms of
2673: # '..time ago'
2674: # H. Zeller <zeller@think.de>
2675: ##
1.1.1.2 knu 2676: sub readableTime($$) {
1.1.1.1 knu 2677: my ($i, $break, $retval);
2678: my ($secs,$long) = @_;
1.1 jfieber 2679:
1.1.1.1 knu 2680: # this function works correct for time >= 2 seconds
2681: if ($secs < 2) {
2682: return "very little time";
2683: }
2684:
2685: my %desc = (1 , 'second',
2686: 60, 'minute',
2687: 3600, 'hour',
2688: 86400, 'day',
2689: 604800, 'week',
2690: 2628000, 'month',
2691: 31536000, 'year');
2692: my @breaks = sort {$a <=> $b} keys %desc;
2693: $i = 0;
1.1.1.2 knu 2694: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
1.1.1.1 knu 2695: $i++;
2696: }
2697: $i--;
2698: $break = $breaks[$i];
2699: $retval = plural_write(int ($secs / $break), $desc{$break});
2700:
2701: if ($long == 1 && $i > 0) {
2702: my $rest = $secs % $break;
2703: $i--;
2704: $break = $breaks[$i];
1.1.1.2 knu 2705: my $resttime = plural_write(int ($rest / $break),
1.1.1.1 knu 2706: $desc{$break});
2707: if ($resttime) {
1.1.1.11 knu 2708: $retval .= ", $resttime";
1.1.1.1 knu 2709: }
2710: }
2711:
2712: return $retval;
2713: }
2714:
2715: ##
2716: # clickablePath(String pathname, boolean last_item_clickable)
2717: #
2718: # returns a html-ified path whereas each directory is a link for
2719: # faster navigation. last_item_clickable controls whether the
2720: # basename (last directory/file) is a link as well
2721: ##
2722: sub clickablePath($$) {
1.1.1.2 knu 2723: my ($pathname,$clickLast) = @_;
1.1.1.1 knu 2724: my $retval = '';
1.1.1.2 knu 2725:
1.1.1.1 knu 2726: if ($pathname eq '/') {
2727: # this should never happen - chooseCVSRoot() is
2728: # intended to do this
2729: $retval = "[$cvstree]";
2730: }
2731: else {
1.1.1.11 knu 2732: $retval .= ' ' . &link("[$cvstree]", sprintf('%s/%s#dirlist',
2733: $scriptname,
2734: $query));
1.1.1.1 knu 2735: my $wherepath = '';
2736: my ($lastslash) = $pathname =~ m|/$|;
2737: foreach (split(/\//, $pathname)) {
1.1.1.11 knu 2738: $retval .= " / ";
2739: $wherepath .= "/$_";
1.1.1.1 knu 2740: my ($last) = "$wherepath/" eq "/$pathname"
2741: || $wherepath eq "/$pathname";
2742: if ($clickLast || !$last) {
1.1.1.11 knu 2743: $retval .= &link($_, join('',
2744: $scriptname,
2745: urlencode($wherepath),
2746: (!$last || $lastslash ? '/' : ''),
2747: $query,
2748: (!$last || $lastslash ? "#dirlist" : "")));
1.1.1.1 knu 2749: }
2750: else { # do not make a link to the current dir
1.1.1.11 knu 2751: $retval .= $_;
1.1 jfieber 2752: }
2753: }
1.1.1.1 knu 2754: }
2755: return $retval;
1.1 jfieber 2756: }
2757:
1.1.1.1 knu 2758: sub chooseCVSRoot() {
2759: my @foo;
2760: foreach (sort keys %CVSROOT) {
2761: if (-d $CVSROOT{$_}) {
2762: push(@foo, $_);
2763: }
2764: }
2765: if (@foo > 1) {
2766: my ($k);
2767: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2768: foreach $k (keys %input) {
1.1.1.2 knu 2769: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
1.1.1.1 knu 2770: if ($input{$k}) && ($k ne "cvsroot");
2771: }
2772: # Form-Elements look wierd in Netscape if the background
2773: # isn't gray and the form elements are not placed
2774: # within a table ...
2775: print "<table><tr>";
2776: print "<td>CVS Root:</td>";
2777: print "<td>\n<select name=\"cvsroot\"";
2778: print " onchange=\"submit()\"" if ($use_java_script);
2779: print ">\n";
2780: foreach $k (@foo) {
2781: print "<option value=\"$k\"";
2782: print " selected" if ($k eq $cvstree);
1.1.1.11 knu 2783: print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k), "</option>\n";
1.1.1.1 knu 2784: }
2785: print "</select>\n</td>";
2786: print "<td><input type=submit value=\"Go\"></td>";
2787: print "</tr></table></form>";
2788: }
2789: else {
2790: # no choice ..
2791: print "CVS Root: <b>[$cvstree]</b>";
2792: }
2793: }
2794:
2795: sub chooseMirror() {
2796: my ($mirror,$moremirrors);
2797: $moremirrors = 0;
2798: # This code comes from the original BSD-cvsweb
2799: # and may not be useful for your site; If you don't
2800: # set %MIRRORS this won't show up, anyway
2801: #
1.1.1.2 knu 2802: # Should perhaps exlude the current site somehow..
1.1.1.1 knu 2803: if (keys %MIRRORS) {
2804: print "\nThis cvsweb is mirrored in:\n";
2805: foreach $mirror (keys %MIRRORS) {
2806: print ", " if ($moremirrors);
1.1.1.11 knu 2807: print &link(htmlquote($mirror),$MIRRORS{$mirror});
1.1.1.1 knu 2808: $moremirrors = 1;
2809: }
2810: print "<p>\n";
2811: }
2812: }
2813:
1.1.1.2 knu 2814: sub fileSortCmp() {
1.1.1.1 knu 2815: my ($comp) = 0;
2816: my ($c,$d,$af,$bf);
2817:
2818: ($af = $a) =~ s/,v$//;
2819: ($bf = $b) =~ s/,v$//;
2820: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2821: if (defined($fileinfo{$af}));
2822: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2823: if (defined($fileinfo{$bf}));
2824:
2825: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2826: # Two files
2827: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2828: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2829: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2830: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2831: }
2832: if ($comp == 0) {
2833: # Directories first, then sorted on name if no other sort critera
2834: # available.
2835: my $ad = ((-d "$fullname/$a")?"D":"F");
2836: my $bd = ((-d "$fullname/$b")?"D":"F");
2837: ($c=$a) =~ s|.*/||;
2838: ($d=$b) =~ s|.*/||;
2839: $comp = ("$ad$c" cmp "$bd$d");
2840: }
2841: return $comp;
2842: }
2843:
2844: # make A url for downloading
1.1.1.2 knu 2845: sub download_url($$;$) {
1.1.1.1 knu 2846: my ($url,$revision,$mimetype) = @_;
2847:
1.1.1.12 knu 2848: $revision =~ s/\.0\././;
1.1.1.1 knu 2849:
1.1.1.11 knu 2850: if (defined($checkoutMagic)
1.1.1.1 knu 2851: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
1.1.1.11 knu 2852: my $path = $where;
2853: $path =~ s|/[^/]*$|/|;
1.1.1.1 knu 2854: $url = "$scriptname/$checkoutMagic/${path}$url";
2855: }
2856: $url .= "?rev=$revision";
1.1.1.11 knu 2857: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
1.1.1.1 knu 2858:
1.1.1.11 knu 2859: $url;
1.1.1.1 knu 2860: }
2861:
1.1.1.2 knu 2862: # Presents a link to download the
1.1.1.1 knu 2863: # selected revision
1.1.1.2 knu 2864: sub download_link($$$;$) {
1.1.1.11 knu 2865: my ($url, $revision, $textlink, $mimetype) = @_;
2866: my ($fullurl) = download_url($url, $revision, $mimetype);
2867:
2868: printf '<A HREF="%s"', htmlquote("$fullurl$barequery");
2869:
1.1.1.1 knu 2870: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
1.1.1.11 knu 2871: print ' target="cvs_checkout"';
1.1.1.1 knu 2872: # we should have
2873: # 'if (document.cvswin==null) document.cvswin=window.open(...'
2874: # in order to allow the user to resize the window; otherwise
2875: # the user may resize the window, but on next checkout - zap -
2876: # its original (configured s. cvsweb.conf) size is back again
2877: # .. annoying (if $extern_window_(width|height) is defined)
2878: # but this if (..) solution is far from perfect
2879: # what we need to do as well is
2880: # 1) save cvswin in an invisible frame that always exists
2881: # (document.cvswin will be void on next load)
2882: # 2) on close of the cvs_checkout - window set the cvswin
2883: # variable to 'null' again - so that it will be
2884: # reopenend with the configured size
2885: # anyone a JavaScript programmer ?
2886: # .. so here without if (..):
2887: # currently, the best way is to comment out the size parameters
2888: # ($extern_window...) in cvsweb.conf.
2889: if ($use_java_script) {
1.1.1.11 knu 2890: my @attr = qw(resizeable scrollbars);
2891:
2892: push @attr, qw(status toolbar)
2893: if (defined($mimetype) && $mimetype eq "text/html");
2894:
2895: push @attr, "width=$extern_window_width"
2896: if (defined($extern_window_width));
2897:
2898: push @attr, "height=$extern_window_height"
2899: if (defined($extern_window_height));
2900:
2901: printf q` onClick="window.open('%s','cvs_checkout','%s');"`,
2902: htmlquote($fullurl), join(',', @attr);
1.1.1.1 knu 2903: }
2904: }
2905: print "><b>$textlink</b></A>";
2906: }
2907:
2908: # Returns a Query string with the
2909: # specified parameter toggled
2910: sub toggleQuery($$) {
2911: my ($toggle,$value) = @_;
2912: my ($newquery,$var);
2913: my (%vars);
2914: %vars = %input;
2915: if (defined($value)) {
2916: $vars{$toggle} = $value;
2917: }
2918: else {
2919: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
2920: }
2921: # Build a new query of non-default paramenters
2922: $newquery = "";
2923: foreach $var (@stickyvars) {
2924: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
2925: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
2926: if ($value ne $default) {
1.1.1.11 knu 2927: $newquery .= "&" if ($newquery ne "");
1.1.1.1 knu 2928: $newquery .= urlencode($var) . "=" . urlencode($value);
2929: }
2930: }
2931: if ($newquery) {
2932: return '?' . $newquery;
2933: }
2934: return "";
2935: }
2936:
1.1.1.2 knu 2937: sub urlencode($) {
1.1.1.11 knu 2938: local($_) = @_;
2939:
2940: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
2941:
2942:
2943: $_;
2944: }
2945:
2946: sub htmlquote($) {
2947: local($_) = @_;
2948:
2949: # Special Characters; RFC 1866
2950: s/&/&/g;
2951: s/\"/"/g;
2952: s/</</g;
2953: s/>/>/g;
2954:
2955: $_;
2956: }
2957:
2958: sub htmlunquote($) {
2959: local($_) = @_;
2960:
2961: # Special Characters; RFC 1866
2962: s/"/\"/g;
2963: s/</</g;
2964: s/>/>/g;
2965: s/&/&/g;
2966:
2967: $_;
1.1.1.1 knu 2968: }
2969:
1.1.1.2 knu 2970: sub http_header(;$) {
1.1.1.1 knu 2971: my $content_type = shift || "text/html";
2972: if (defined($moddate)) {
2973: if ($is_mod_perl) {
1.1.1.6 knu 2974: Apache->request->header_out("Last-Modified" => scalar gmtime($moddate) . " GMT");
1.1.1.1 knu 2975: }
2976: else {
1.1.1.11 knu 2977: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
1.1.1.1 knu 2978: }
2979: }
2980: if ($is_mod_perl) {
2981: Apache->request->content_type($content_type);
2982: }
2983: else {
2984: print "Content-type: $content_type\r\n";
2985: }
2986: if ($allow_compress && $maycompress) {
1.1.1.6 knu 2987: if ($has_zlib || (defined($GZIPBIN) && open(GZIP, "|$GZIPBIN -1 -c"))) {
1.1.1.1 knu 2988: if ($is_mod_perl) {
2989: Apache->request->content_encoding("x-gzip");
2990: Apache->request->header_out(Vary => "Accept-Encoding");
2991: Apache->request->send_http_header;
2992: }
2993: else {
2994: print "Content-encoding: x-gzip\r\n";
2995: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
2996: print "\r\n"; # Close headers
2997: }
2998: $| = 1; $| = 0; # Flush header output
1.1.1.6 knu 2999: if ($has_zlib) {
3000: tie *GZIP, __PACKAGE__, \*STDOUT;
3001: }
3002: select(GZIP);
3003: $gzip_open = 1;
1.1.1.13! knu 3004: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
1.1.1.1 knu 3005: }
3006: else {
3007: if ($is_mod_perl) {
3008: Apache->request->send_http_header;
3009: }
3010: else {
3011: print "\r\n"; # Close headers
3012: }
3013: print "<font size=-1>Unable to find gzip binary in the \$PATH to compress output</font><br>";
3014: }
3015: }
3016: else {
3017: if ($is_mod_perl) {
3018: Apache->request->send_http_header;
3019: }
3020: else {
3021: print "\r\n"; # Close headers
3022: }
3023: }
3024: }
3025:
3026: sub html_header($) {
3027: my ($title) = @_;
1.1.1.13! knu 3028: my $version = '$zRevision: 1.104 $ $kRevision: 1.41 $'; #'
! 3029: http_header($charset ne "" ? "text/html; charset=$charset" : "text/html");
1.1.1.1 knu 3030: print <<EOH;
3031: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
3032: "http://www.w3.org/TR/REC-html40/loose.dtd">
3033: <html>
1.1.1.13! knu 3034: <head>
1.1.1.1 knu 3035: <title>$title</title>
3036: <!-- CVSweb $version -->
3037: </head>
3038: $body_tag
3039: $logo <h1 align="center">$title</h1>
3040: EOH
3041: }
3042:
1.1.1.2 knu 3043: sub html_footer() {
1.1.1.1 knu 3044: return "<hr noshade><address>$address</address>\n";
3045: }
3046:
1.1.1.2 knu 3047: sub link_tags($) {
1.1.1.1 knu 3048: my ($tags) = @_;
3049: my ($ret) = "";
3050: my ($fileurl,$filename);
3051:
3052: ($filename = $where) =~ s/^.*\///;
3053: $fileurl = urlencode($filename);
3054:
3055: foreach my $sym (split(", ", $tags)) {
3056: $ret .= ",\n" if ($ret ne "");
1.1.1.11 knu 3057: $ret .= &link($sym, $fileurl . toggleQuery('only_with_tag',$sym));
1.1.1.1 knu 3058: }
1.1.1.11 knu 3059: return "$ret\n";
1.1.1.1 knu 3060: }
3061:
3062: #
3063: # See if a module is listed in the config file's @HideModule list.
3064: #
1.1.1.2 knu 3065: sub forbidden_module($) {
1.1.1.1 knu 3066: my($module) = @_;
1.1.1.2 knu 3067:
1.1.1.1 knu 3068: for (my $i=0; $i < @HideModules; $i++) {
3069: return 1 if $module eq $HideModules[$i];
3070: }
3071:
3072: return 0;
1.1.1.7 knu 3073: }
3074:
3075: # Close the GZIP handle remove the tie.
3076:
3077: sub gzipclose {
3078: if ($gzip_open) {
3079: select(STDOUT);
3080: close(GZIP);
3081: untie *GZIP;
3082: $gzip_open = 0;
3083: }
1.1.1.6 knu 3084: }
3085:
3086: # implement a gzipped file handle via the Compress:Zlib compression
3087: # library.
3088:
3089: sub MAGIC1() { 0x1f }
3090: sub MAGIC2() { 0x8b }
3091: sub OSCODE() { 3 }
3092:
3093: sub TIEHANDLE {
3094: my ($class, $out) = @_;
3095: my ($d) = Compress::Zlib::deflateInit(-Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3096: -WindowBits => -Compress::Zlib::MAX_WBITS()) or return undef;
3097: my ($o) = {
3098: handle => $out,
3099: dh => $d,
3100: crc => 0,
3101: len => 0,
3102: };
3103: my ($header) = pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0,0,0,0,0,0, OSCODE);
3104: print {$o->{handle}} $header;
3105: return bless($o, $class);
3106: }
3107:
3108: sub PRINT {
3109: my ($o) = shift;
3110: my ($buf) = join(defined $, ? $, : "",@_);
3111: my ($len) = length($buf);
3112: my ($compressed, $status) = $o->{dh}->deflate($buf);
3113: print {$o->{handle}} $compressed if defined($compressed);
3114: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3115: $o->{len} += $len;
3116: return $len;
3117: }
3118:
3119: sub PRINTF {
3120: my ($o) = shift;
CVSweb