Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.12
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 $
! 46: # $kId: cvsweb.cgi,v 1.39 2000/11/04 15:32:17 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.1 knu 66: $mimetype $defaultTextPlain $defaultViewable $allow_compress
67: $GZIPBIN $backicon $diricon $fileicon $fullname $newname
1.1.1.7 knu 68: $cvstreedefault $body_tag $body_tag_for_src
69: $logo $defaulttitle $address
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.1 knu 1492: #===================================================================
1493: #Checking out squid/src/ftp.c
1494: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1495: #VERS: 1.1.1.28.6.2
1496: #***************
1497:
1498: # Parse CVS header
1499: my ($revision, $filename, $cvsheader);
1500: while(<$fh>) {
1501: last if (/^\*\*\*\*/);
1502: $revision = $1 if (/^VERS: (.*)$/);
1503: if (/^Checking out (.*)$/) {
1504: $filename = $1;
1505: $filename =~ s/^\.\/*//;
1506: }
1507: $cvsheader .= $_;
1508: }
1509: if ($filename ne $where) {
1510: &fatal("500 Internal Error",
1511: "Unexpected output from cvs co: $cvsheader"
1512: . "<p><b>Check whether the directory $cvsroot/CVSROOT exists "
1513: . "and the script has write-access to the CVSROOT/history "
1514: . "file if it exists."
1515: . "<br>The script needs to place lock files in the "
1516: . "directory the file is in as well.</b>");
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)
1783: $filename = $1 if (/^Working file: (.+)$/);
1784: $head = $1 if (/^head: (.+)$/);
1785: $branch = $1 if (/^branch: (.+)$/);
1786: }
1787: if ($state eq "head" && /^symbolic names/) {
1788: $state = "tags";
1.1.1.2 knu 1789: ($branch = $head) =~ s/\.\d+$// if (!defined($branch));
1.1.1.1 knu 1790: $branch =~ s/(\.?)(\d+)$/${1}0.$2/;
1791: $symrev{MAIN} = $branch;
1792: $symrev{HEAD} = $branch;
1793: $alltags{MAIN} = 1;
1794: $alltags{HEAD} = 1;
1795: push (@filetags, "MAIN", "HEAD");
1796: next;
1797: }
1798: if ($state eq "tags" &&
1799: /^\s+(.+):\s+([\d\.]+)\s+$/) {
1800: push (@filetags, $1);
1801: $symrev{$1} = $2;
1802: $alltags{$1} = 1;
1803: next;
1804: }
1805: if ($state eq "tags" && /^\S/) {
1806: if (defined($tag) && (defined($symrev{$tag}) || $tag eq "HEAD")) {
1807: $revwanted = $tag eq "HEAD" ? $symrev{"MAIN"} : $symrev{$tag};
1.1.1.12! knu 1808: ($branch = $revwanted) =~ s/\.0\././;
1.1.1.1 knu 1809: ($branchpoint = $branch) =~ s/\.?\d+$//;
1810: $revwanted = undef if ($revwanted ne $branch);
1811: }
1812: elsif (defined($tag) && $tag ne "HEAD") {
1813: print "Tag not found, skip this file" if ($verbose);
1814: $state = "skip";
1815: next;
1816: }
1817: foreach my $tagfound (@filetags) {
1818: $tags{$tagfound} = 1;
1819: }
1820: $state = "head";
1821: goto again;
1822: }
1.1.1.10 knu 1823: if ($state eq "head" && /$LOG_REVSEPARATOR/o) {
1.1.1.1 knu 1824: $state = "log";
1825: $rev = undef;
1826: $date = undef;
1827: $log = "";
1828: # Try to reconstruct the relative filename if RCS spits out a full path
1829: $filename =~ s%^\Q$DirName\E/%%;
1830: next;
1831: }
1832: if ($state eq "log") {
1.1.1.10 knu 1833: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
1.1.1.1 knu 1834: # End of a log entry.
1835: my $revbranch;
1836: ($revbranch = $rev) =~ s/\.\d+$//;
1.1.1.11 knu 1837: print "$filename $rev Wanted: $revwanted ",
1838: "Revbranch: $revbranch Branch: $branch ",
1839: "Branchpoint: $branchpoint\n" if ($verbose);
1.1.1.1 knu 1840: if (!defined($revwanted) && defined($branch)
1841: && $branch eq $revbranch || !defined($tag)) {
1842: print "File revision $rev found for branch $branch\n"
1843: if ($verbose);
1844: $revwanted = $rev;
1845: }
1846: if (defined($revwanted) ? $rev eq $revwanted :
1847: defined($branchpoint) ? $rev eq $branchpoint :
1848: 0 && ($rev eq $head)) { # Don't think head is needed here..
1849: print "File info $rev found for $filename\n" if ($verbose);
1850: my @finfo = ($rev,$date,$log,$author,$filename);
1851: my ($name);
1852: ($name = $filename) =~ s%/.*%%;
1853: $fileinfo{$name} = [ @finfo ];
1854: $state = "done" if ($rev eq $revwanted);
1855: }
1856: $rev = undef;
1857: $date = undef;
1858: $log = "";
1859: }
1860: elsif (!defined($date) && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
1861: my $yr = $1;
1862: # damn 2-digit year routines :-)
1863: if ($yr > 100) {
1864: $yr -= 1900;
1865: }
1866: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1867: ($author) = /author: ([^;]+)/;
1868: $state = "log";
1869: $log = '';
1870: next;
1871: }
1872: elsif (!defined($rev) && m/^revision (.*)$/) {
1873: $rev = $1;
1874: next;
1875: }
1876: else {
1.1.1.11 knu 1877: $log .= $_;
1.1.1.1 knu 1878: }
1879: }
1.1.1.10 knu 1880: if (/$LOG_FILESEPARATOR/o) {
1.1.1.1 knu 1881: $state = "start";
1882: next;
1883: }
1884: }
1885: if ($. == 0) {
1.1.1.2 knu 1886: fatal("500 Internal Error",
1.1.1.1 knu 1887: "Failed to spawn GNU rlog on <em>'".join(", ", @files)."'</em><p>did you set the <b>\$ENV{PATH}</b> in your configuration file correctly ?");
1888: }
1889: close($fh);
1890: }
1891:
1.1.1.2 knu 1892: sub readLog($;$) {
1.1.1.1 knu 1893: my($fullname,$revision) = @_;
1894: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
1895: my $fh = do {local(*FH);};
1896:
1897: if (defined($revision)) {
1898: $revision = "-r$revision";
1899: }
1900: else {
1901: $revision = "";
1902: }
1903:
1904: undef %symrev;
1905: undef %revsym;
1906: undef @allrevisions;
1907: undef %date;
1908: undef %author;
1909: undef %state;
1910: undef %difflines;
1911: undef %log;
1912:
1913: print("Going to rlog '$fullname'\n") if ($verbose);
1914: if (! open($fh, "-|")) { # child
1915: if ($revision ne '') {
1916: exec("rlog",$revision,$fullname);
1917: }
1918: else {
1919: exec("rlog",$fullname);
1920: }
1921: }
1922: while (<$fh>) {
1.1 jfieber 1923: print if ($verbose);
1924: if ($symnames) {
1925: if (/^\s+([^:]+):\s+([\d\.]+)/) {
1926: $symrev{$1} = $2;
1.1.1.1 knu 1927: }
1928: else {
1.1 jfieber 1929: $symnames = 0;
1930: }
1.1.1.1 knu 1931: }
1932: elsif (/^head:\s+([\d\.]+)/) {
1933: $head = $1;
1934: }
1935: elsif (/^branch:\s+([\d\.]+)/) {
1936: $curbranch = $1;
1937: }
1938: elsif (/^symbolic names/) {
1.1 jfieber 1939: $symnames = 1;
1.1.1.1 knu 1940: }
1941: elsif (/^-----/) {
1.1 jfieber 1942: last;
1943: }
1944: }
1.1.1.1 knu 1945: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1946:
1.1 jfieber 1947: # each log entry is of the form:
1948: # ----------------------------
1949: # revision 3.7.1.1
1950: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
1951: # log info
1952: # ----------------------------
1953: logentry:
1.1.1.10 knu 1954: while (!/$LOG_FILESEPARATOR/o) {
1.1.1.1 knu 1955: $_ = <$fh>;
1956: last logentry if (!defined($_)); # EOF
1.1 jfieber 1957: print "R:", $_ if ($verbose);
1958: if (/^revision ([\d\.]+)/) {
1959: $rev = $1;
1.1.1.1 knu 1960: unshift(@allrevisions,$rev);
1961: }
1.1.1.10 knu 1962: elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
1.1.1.1 knu 1963: next logentry;
1964: }
1965: else {
1966: # The rlog output is syntactically ambiguous. We must
1967: # have guessed wrong about where the end of the last log
1968: # message was.
1969: # Since this is likely to happen when people put rlog output
1970: # in their commit messages, don't even bother keeping
1971: # these lines since we don't know what revision they go with
1972: # any more.
1.1 jfieber 1973: next logentry;
1.1.1.1 knu 1974: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 1975: }
1.1.1.1 knu 1976: $_ = <$fh>;
1.1 jfieber 1977: print "D:", $_ if ($verbose);
1.1.1.1 knu 1978: 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+-]+))?|) {
1979: my $yr = $1;
1980: # damn 2-digit year routines :-)
1981: if ($yr > 100) {
1982: $yr -= 1900;
1983: }
1984: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 1985: $author{$rev} = $7;
1.1.1.1 knu 1986: $state{$rev} = $8;
1987: $difflines{$rev} = $10;
1988: }
1989: else {
1.1 jfieber 1990: &fatal("500 Internal Error", "Error parsing RCS output: $_");
1991: }
1992: line:
1.1.1.1 knu 1993: while (<$fh>) {
1.1 jfieber 1994: print "L:", $_ if ($verbose);
1995: next line if (/^branches:\s/);
1.1.1.10 knu 1996: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
1.1 jfieber 1997: $log{$rev} .= $_;
1998: }
1999: print "E:", $_ if ($verbose);
2000: }
1.1.1.1 knu 2001: close($fh);
1.1 jfieber 2002: print "Done reading RCS file\n" if ($verbose);
1.1.1.1 knu 2003:
2004: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
2005: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
2006:
1.1 jfieber 2007: #
2008: # HEAD is an artificial tag which is simply the highest tag number on the main
1.1.1.1 knu 2009: # branch, unless there is a branch tag in the RCS file in which case it's the
2010: # highest revision on that branch. Find it by looking through @revorder; it
2011: # is the first commit listed on the appropriate branch.
2012: # This is not neccesary the same revision as marked as head in the RCS file.
2013: my $headrev = $curbranch || "1";
2014: ($symrev{"MAIN"} = $headrev) =~ s/(\.?)(\d+)$/${1}0.$2/;
1.1 jfieber 2015: revision:
1.1.1.1 knu 2016: foreach $rev (@revorder) {
2017: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2018: $symrev{"HEAD"} = $rev;
1.1 jfieber 2019: last revision;
2020: }
2021: }
1.1.1.1 knu 2022: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2023: if (!defined($symrev{"HEAD"}));
1.1 jfieber 2024: print "Done finding HEAD\n" if ($verbose);
2025: #
2026: # Now that we know all of the revision numbers, we can associate
2027: # absolute revision numbers with all of the symbolic names, and
2028: # pass them to the form so that the same association doesn't have
2029: # to be built then.
2030: #
1.1.1.1 knu 2031: undef @branchnames;
2032: undef %branchpoint;
2033: undef $sel;
2034:
2035: foreach (reverse sort keys %symrev) {
1.1 jfieber 2036: $rev = $symrev{$_};
1.1.1.12! knu 2037: if ($rev =~ /^((.*)\.)0\.(\d+)$/) {
1.1.1.1 knu 2038: push(@branchnames, $_);
1.1 jfieber 2039: #
2040: # A revision number of A.B.0.D really translates into
2041: # "the highest current revision on branch A.B.D".
2042: #
2043: # If there is no branch A.B.D, then it translates into
2044: # the head A.B .
2045: #
1.1.1.1 knu 2046: # This reasoning also applies to the main branch A.B,
2047: # with the branch number 0.A, with the exception that
2048: # it has no head to translate to if there is nothing on
2049: # the branch, but I guess this can never happen?
1.1.1.12! knu 2050: #
! 2051: # Since some stupid people actually import/check in
! 2052: # files with version 0.X we assume that the above cannot
! 2053: # happen, and regard 0.X(.*) as a revision and not a branch.
1.1 jfieber 2054: #
1.1.1.1 knu 2055: $head = defined($2) ? $2 : "";
1.1 jfieber 2056: $branch = $3;
1.1.1.1 knu 2057: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2058: my $regex;
2059: ($regex = $branchrev) =~ s/\./\\./g;
1.1 jfieber 2060: $rev = $head;
2061:
2062: revision:
1.1.1.1 knu 2063: foreach my $r (@revorder) {
2064: if ($r =~ /^${regex}\b/) {
2065: $rev = $branchrev;
1.1 jfieber 2066: last revision;
2067: }
2068: }
1.1.1.1 knu 2069: next if ($rev eq "");
2070: if ($rev ne $head && $head ne "") {
2071: $branchpoint{$head} .= ", " if ($branchpoint{$head});
2072: $branchpoint{$head} .= $_;
2073: }
1.1 jfieber 2074: }
1.1.1.1 knu 2075: $revsym{$rev} .= ", " if ($revsym{$rev});
2076: $revsym{$rev} .= $_;
1.1 jfieber 2077: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
2078: }
2079: print "Done associating revisions with branches\n" if ($verbose);
1.1.1.1 knu 2080:
2081: my ($onlyonbranch, $onlybranchpoint);
2082: if ($onlyonbranch = $input{'only_with_tag'}) {
2083: $onlyonbranch = $symrev{$onlyonbranch};
1.1.1.12! knu 2084: if ($onlyonbranch =~ s/\.0\././) {
1.1.1.1 knu 2085: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2086: }
2087: else {
2088: $onlybranchpoint = $onlyonbranch;
2089: }
2090: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2091: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
2092: }
2093: }
2094:
2095: undef @revisions;
2096:
2097: foreach (@allrevisions) {
2098: ($br = $_) =~ s/\.\d+$//;
2099: ($brp = $br) =~ s/\.\d+$//;
2100: next if ($onlyonbranch && $br ne $onlyonbranch &&
2101: $_ ne $onlybranchpoint);
2102: unshift(@revisions,$_);
2103: }
2104:
2105: if ($logsort eq "date") {
2106: # Sort the revisions in commit order an secondary sort on revision
2107: # (secondary sort needed for imported sources, or the first main
2108: # revision gets before the same revision on the 1.1.1 branch)
2109: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
2110: }
2111: elsif ($logsort eq "rev") {
2112: # Sort the revisions in revision order, highest first
2113: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
2114: }
2115: else {
2116: # No sorting. Present in the same order as rlog / cvs log
2117: @revdisplayorder = @revisions;
2118: }
2119:
2120: }
2121:
1.1.1.11 knu 2122: sub printDiffLinks($$) {
2123: my($text, $url) = @_;
2124: my @extra;
2125:
2126: local $_;
2127: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2128: my $f = $_ eq $defaultDiffType ? '' : $_;
2129:
2130: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2131: }
2132:
2133: print &link($text, $url), ' (', join(', ', @extra), ')';
2134: }
2135:
1.1.1.1 knu 2136: sub printLog($;$) {
2137: my ($link, $br, $brp);
2138: ($_,$link) = @_;
2139: ($br = $_) =~ s/\.\d+$//;
2140: ($brp = $br) =~ s/\.?\d+$//;
2141: my ($isDead, $prev);
2142:
2143: $link = 1 if (!defined($link));
2144: $isDead = ($state{$_} eq "dead");
2145:
2146: if ($link && !$isDead) {
2147: my ($filename);
2148: ($filename = $where) =~ s/^.*\///;
2149: my ($fileurl) = urlencode($filename);
2150: print "<a NAME=\"rev$_\"></a>";
2151: if (defined($revsym{$_})) {
2152: foreach my $sym (split(", ", $revsym{$_})) {
2153: print "<a NAME=\"$sym\"></a>";
2154: }
2155: }
2156: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
2157: foreach my $sym (split(", ", $revsym{$br})) {
2158: print "<a NAME=\"$sym\"></a>";
2159: }
2160: $nameprinted{$br} = 1;
2161: }
2162: print "\n Revision ";
2163: &download_link($fileurl, $_, $_,
1.1.1.11 knu 2164: $defaultViewable ? "text/x-cvsweb-markup" : undef);
1.1.1.1 knu 2165: if ($defaultViewable) {
1.1.1.11 knu 2166: print " / (";
2167: &download_link($fileurl, $_, "download", $mimetype);
2168: print ")";
1.1.1.1 knu 2169: }
2170: if (not $defaultTextPlain) {
1.1.1.11 knu 2171: print " / (";
2172: &download_link($fileurl, $_, "as text", "text/plain");
2173: print ")";
1.1.1.1 knu 2174: }
2175: if (!$defaultViewable) {
1.1.1.11 knu 2176: print " / (";
2177: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2178: print ")";
1.1.1.1 knu 2179: }
2180: if ($allow_annotate) {
1.1.1.11 knu 2181: print " - ";
2182: print &link('annotate',
2183: sprintf('%s/%s?annotate=%s%s',
2184: $scriptname,
2185: urlencode($where),
2186: $_,
2187: $barequery));
1.1.1.1 knu 2188: }
2189: # Plus a select link if enabled, and this version isn't selected
2190: if ($allow_version_select) {
2191: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
1.1.1.11 knu 2192: print " - ";
2193: print &link('[select for diffs]',
2194: sprintf('%s?r1=%s%s',
2195: $scriptwhere,
2196: $_,
2197: $barequery));
1.1.1.1 knu 2198: }
2199: else {
2200: print " - <b>[selected]</b>";
2201: }
2202: }
2203: }
2204: else {
2205: print "Revision <B>$_</B>";
2206: }
2207: if (/^1\.1\.1\.\d+$/) {
2208: print " <i>(vendor branch)</i>";
2209: }
2210: if (defined @mytz) {
2211: my ($est) = $mytz[(localtime($date{$_}))[8]];
1.1.1.11 knu 2212: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
1.1.1.1 knu 2213: } else {
1.1.1.11 knu 2214: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
1.1.1.1 knu 2215: }
1.1.1.11 knu 2216: print readableTime(time() - $date{$_},1), " ago)";
1.1.1.1 knu 2217: print " by ";
1.1.1.11 knu 2218: print "<i>", $author{$_}, "</i>\n";
1.1.1.1 knu 2219: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
2220: if ($revsym{$br});
2221: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
2222: if ($revsym{$_});
2223: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
2224: if ($branchpoint{$_});
2225: # Find the previous revision
2226: my @prevrev = split(/\./, $_);
2227: do {
2228: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 2229: # If it was X.Y.Z.1, just make it X.Y
1.1.1.1 knu 2230: pop(@prevrev);
2231: pop(@prevrev);
2232: }
2233: $prev = join(".", @prevrev);
2234: } until (defined($date{$prev}) || $prev eq "");
2235: if ($prev ne "") {
2236: if ($difflines{$_}) {
2237: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
2238: }
2239: }
2240: if ($isDead) {
2241: print "<BR><B><I>FILE REMOVED</I></B>\n";
2242: }
2243: elsif ($link) {
2244: my %diffrev = ();
2245: $diffrev{$_} = 1;
2246: $diffrev{""} = 1;
2247: print "<BR>Diff";
2248: #
2249: # Offer diff to previous revision
2250: if ($prev) {
2251: $diffrev{$prev} = 1;
1.1.1.11 knu 2252:
2253: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2254: $scriptwhere,
2255: $prev,
2256: $_,
2257: $barequery);
2258:
2259: print " to previous ";
2260: printDiffLinks($prev, $url);
1.1 jfieber 2261: }
1.1.1.1 knu 2262: #
2263: # Plus, if it's on a branch, and it's not a vendor branch,
2264: # offer a diff with the branch point.
2265: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
1.1.1.11 knu 2266: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2267: $scriptwhere,
2268: $brp,
2269: $_,
2270: $barequery);
2271:
2272: print " to branchpoint ";
2273: printDiffLinks($brp, $url);
1.1.1.1 knu 2274: }
2275: #
2276: # Plus, if it's on a branch, and it's not a vendor branch,
2277: # offer to diff with the next revision of the higher branch.
2278: # (e.g. change gets committed and then brought
2279: # over to -stable)
2280: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2281: my ($i,$nextmain);
2282: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
2283: my (@tmp2) = split(/\./, $_);
2284: for ($nextmain = ""; $i > 0; $i--) {
2285: my ($next) = $revorder[$i-1];
2286: my (@tmp1) = split(/\./, $next);
1.1 jfieber 2287: if ($#tmp1 < $#tmp2) {
1.1.1.1 knu 2288: $nextmain = $next;
2289: last;
1.1 jfieber 2290: }
1.1.1.1 knu 2291: # Only the highest version on a branch should have
2292: # a diff for the "next main".
2293: last if (join(".",@tmp1[0..$#tmp1-1])
2294: eq join(".",@tmp2[0..$#tmp1-1]));
2295: }
2296: if (!defined($diffrev{$nextmain})) {
2297: $diffrev{$nextmain} = 1;
1.1.1.11 knu 2298:
2299: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2300: $scriptwhere,
2301: $nextmain,
2302: $_,
2303: $barequery);
2304:
2305: print " next main ";
2306: printDiffLinks($nextmain, $url);
1.1.1.1 knu 2307: }
2308: }
2309: # Plus if user has selected only r1, then present a link
2310: # to make a diff to that revision
2311: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2312: $diffrev{$input{"r1"}} = 1;
2313:
1.1.1.11 knu 2314: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2315: $scriptwhere,
2316: $input{'r1'},
2317: $_,
2318: $barequery);
2319:
2320: print " to selected ";
2321: printDiffLinks($input{'r1'}, $url);
1.1 jfieber 2322: }
2323: }
1.1.1.1 knu 2324: print "<PRE>\n";
2325: print &htmlify($log{$_}, 1);
2326: print "</PRE>\n";
2327: }
2328:
1.1.1.2 knu 2329: sub doLog($) {
1.1.1.1 knu 2330: my($fullname) = @_;
2331: my ($diffrev, $upwhere, $filename, $backurl);
1.1.1.2 knu 2332:
1.1.1.1 knu 2333: readLog($fullname);
2334:
2335: html_header("CVS log for $where");
2336: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2337: ($filename = $where) =~ s|^.*/||;
2338: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2339: print &link($backicon, "$backurl#$filename"),
1.1.1.11 knu 2340: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
2341: print &link('Request diff between arbitrary revisions', '#diff');
2342: print '<HR NOSHADE>';
2343:
1.1.1.1 knu 2344: if ($curbranch) {
2345: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
2346: }
2347: else {
2348: print "No default branch";
2349: }
2350: print "<BR>\n";
2351: if ($input{only_with_tag}) {
2352: print "Current tag: $input{only_with_tag}<BR>\n";
2353: }
2354:
2355: undef %nameprinted;
2356:
2357: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2358: print "<HR size=1 NOSHADE>";
2359: printLog($revdisplayorder[$i]);
2360: }
2361:
2362: print "<HR NOSHADE>";
1.1 jfieber 2363: print "<A NAME=diff>\n";
2364: print "This form allows you to request diff's between any two\n";
2365: print "revisions of a file. You may select a symbolic revision\n";
2366: print "name using the selection box or you may type in a numeric\n";
2367: print "name using the type-in text box.\n";
2368: print "</A><P>\n";
1.1.1.1 knu 2369: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2370: foreach (@stickyvars) {
1.1.1.11 knu 2371: printf('<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">', $_, $input{$_})
1.1.1.1 knu 2372: if (defined($input{$_})
1.1.1.6 knu 2373: && ((!defined($DEFAULTVALUE{$_})
2374: || $input{$_} ne $DEFAULTVALUE{$_})
2375: && $input{$_} ne ""));
1.1.1.1 knu 2376: }
1.1.1.6 knu 2377: print "<TABLE><TR>\n";
2378: print "<TD align=right>Diffs between \n";
1.1 jfieber 2379: print "<SELECT NAME=\"r1\">\n";
2380: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2381: print $sel;
2382: print "</SELECT>\n";
1.1.1.1 knu 2383: $diffrev = $revdisplayorder[$#revdisplayorder];
2384: $diffrev = $input{"r1"} if (defined($input{"r1"}));
1.1.1.6 knu 2385: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
2386: print "<TD><BR></TD></TR>\n";
2387: print "<TR><TD align=right>and \n";
1.1 jfieber 2388: print "<SELECT NAME=\"r2\">\n";
2389: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2390: print $sel;
2391: print "</SELECT>\n";
1.1.1.1 knu 2392: $diffrev = $revdisplayorder[0];
2393: $diffrev = $input{"r2"} if (defined($input{"r2"}));
1.1.1.6 knu 2394: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
2395: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Get Diffs \"></TD>\n";
1.1.1.1 knu 2396: print "</FORM>\n";
1.1.1.6 knu 2397: print "</TR></TABLE>\n";
1.1.1.1 knu 2398: print "<HR noshade>\n";
1.1.1.6 knu 2399: print "<TABLE>";
2400: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
1.1.1.11 knu 2401: print "<TR><TD align=right>Preferred Diff type:</TD>";
2402: print "<TD>";
1.1.1.6 knu 2403: printDiffSelect($use_java_script);
2404: print "</TD><TD></TD></TR>\n";
1.1.1.1 knu 2405: if (@branchnames) {
1.1.1.6 knu 2406: print "<TR><TD align=right>View only Branch:</TD>";
2407: print "<TD>";
1.1.1.1 knu 2408: print "<A name=branch></A>\n";
2409: print "<SELECT NAME=\"only_with_tag\"";
2410: print " onchange=\"submit()\"" if ($use_java_script);
2411: print ">\n";
2412: print "<OPTION VALUE=\"\"";
2413: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2414: $input{"only_with_tag"} eq "");
2415: print ">Show all branches\n";
2416: foreach (reverse sort @branchnames) {
2417: print "<OPTION";
2418: print " SELECTED" if (defined($input{"only_with_tag"})
2419: && $input{"only_with_tag"} eq $_);
2420: print ">${_}\n";
2421: }
1.1.1.6 knu 2422: print "</SELECT></TD><TD></TD></TR>\n";
1.1.1.1 knu 2423: }
2424: foreach (@stickyvars) {
1.1.1.6 knu 2425: next if ($_ eq "f");
1.1.1.1 knu 2426: next if ($_ eq "only_with_tag");
2427: next if ($_ eq "logsort");
2428: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
1.1.1.6 knu 2429: if (defined($input{$_})
2430: && (!defined($DEFAULTVALUE{$_})
2431: || $input{$_} ne $DEFAULTVALUE{$_})
1.1.1.1 knu 2432: && $input{$_} ne "");
2433: }
1.1.1.6 knu 2434: print "<TR><TD align=right>";
2435: print "<A name=logsort></A>\n";
2436: print "Sort log by:</TD>";
1.1.1.11 knu 2437: print "<TD>";
2438: printLogSortSelect($use_java_script);
2439: print "</TD>";
1.1.1.6 knu 2440: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Set \"></TD>";
1.1 jfieber 2441: print "</FORM>\n";
1.1.1.6 knu 2442: print "</TR></TABLE>";
1.1.1.1 knu 2443: print &html_footer;
1.1 jfieber 2444: print "</BODY></HTML>\n";
2445: }
2446:
1.1.1.2 knu 2447: sub flush_diff_rows($$$$) {
1.1.1.1 knu 2448: my $j;
2449: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2450: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2451: for ($j = 0 ; $j < $leftRow; $j++) {
2452: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2453: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2454: }
2455: }
2456: elsif ($state eq "PreChange") { # state eq "PreChange"
2457: # we got removes with subsequent adds
2458: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2459: print "<tr>";
2460: if ($j < $leftRow) {
2461: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2462: }
2463: else {
2464: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2465: }
2466: if ($j < $rightRow) {
2467: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2468: }
2469: else {
2470: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2471: }
2472: print "</tr>\n";
2473: }
2474: }
2475: }
1.1 jfieber 2476:
1.1.1.1 knu 2477: ##
2478: # Function to generate Human readable diff-files
2479: # human_readable_diff(String revision_to_return_to);
2480: ##
2481: sub human_readable_diff($){
1.1.1.6 knu 2482: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
1.1.1.1 knu 2483: my ($fh, $rev) = @_;
2484: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2485: my (@rightCol, @leftCol);
2486:
2487: ($where_nd = $where) =~ s/.diff$//;
2488: ($filename = $where_nd) =~ s/^.*\///;
2489: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2490: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2491:
1.1.1.2 knu 2492: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
1.1 jfieber 2493:
1.1.1.1 knu 2494: # Read header to pick up read revision and date, if possible
2495: while (<$fh>) {
2496: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2497: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2498: last if (/^\+\+\+ /);
2499: }
2500: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2501: $rev1 = $r1r;
2502: $date1 = $r1d;
2503: }
2504: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2505: $rev2 = $r2r;
2506: $date2 = $r2d;
2507: }
1.1.1.2 knu 2508:
1.1.1.11 knu 2509: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
2510: "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n",
2511: "<tr bgcolor=\"#ffffff\">\n",
2512: "<th width=\"50%\" valign=TOP>",
2513: "version $rev1";
1.1.1.1 knu 2514: print ", $date1" if (defined($date1));
2515: print "<br>Tag: $sym1\n" if ($sym1);
1.1.1.11 knu 2516: print "</th>\n",
2517: "<th width=\"50%\" valign=TOP>",
2518: "version $rev2";
1.1.1.1 knu 2519: print ", $date2" if (defined($date2));
2520: print "<br>Tag: $sym2\n" if ($sym1);
2521: print "</th>\n";
2522:
2523: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\">";
2524: my $fe = "</font>";
2525:
2526: my $leftRow = 0;
2527: my $rightRow = 0;
2528: my ($oldline, $newline, $funname, $diffcode, $rest);
2529:
2530: # Process diff text
2531: # The diffrows are could make excellent use of
2532: # cascading style sheets because we've to set the
2533: # font and color for each row. anyone ...?
2534: ####
1.1.1.6 knu 2535:
2536: # prefetch several lines
2537: my @buf = head($fh);
2538:
2539: my %d = scan_directives(@buf);
2540:
2541: while (@buf || !eof($fh)) {
2542: $difftxt = @buf ? shift @buf : <$fh>;
1.1.1.2 knu 2543:
1.1.1.1 knu 2544: if ($difftxt =~ /^@@/) {
2545: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2546: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2547: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2548: print " <font size=-1>$funname</font></td></tr></table>";
2549: print "</td><td width=\"50%\">";
2550: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2551: print " <font size=-1>$funname</font></td></tr></table>";
2552: print "</td>\n";
2553: $state = "dump";
2554: $leftRow = 0;
2555: $rightRow = 0;
2556: }
2557: else {
2558: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
1.1.1.6 knu 2559: $_ = spacedHtmlText($rest, $d{'tabstop'});
1.1.1.1 knu 2560:
2561: # Add fontface, size
2562: $_ = "$fs $_$fe";
1.1.1.2 knu 2563:
1.1.1.1 knu 2564: #########
2565: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2566: # in order to get some nice 'ediff'-mode output
2567: # states:
2568: # "dump" - just dump the value
2569: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2570: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2571: ##########
2572:
2573: if ($diffcode eq '+') {
2574: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2575: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2576: }
2577: else { # we got minus before
2578: $state = "PreChange";
2579: $rightCol[$rightRow++] = $_;
2580: }
1.1.1.2 knu 2581: }
1.1.1.1 knu 2582: elsif ($diffcode eq '-') {
2583: $state = "PreChangeRemove";
2584: $leftCol[$leftRow++] = $_;
2585: }
2586: else { # empty diffcode
2587: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2588: print "<tr><td>$_</td><td>$_</td></tr>\n";
2589: $state = "dump";
2590: $leftRow = 0;
2591: $rightRow = 0;
2592: }
2593: }
2594: }
2595: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2596:
2597: # state is empty if we didn't have any change
2598: if (!$state) {
2599: print "<tr><td colspan=2> </td></tr>";
2600: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2601: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2602: }
2603: print "</table>";
2604: close($fh);
2605:
2606: print "<br><hr noshade width=\"100%\">\n";
2607:
2608: print "<table border=0>";
2609:
2610: print "<tr><td>";
2611: # print legend
2612: print "<table border=1><tr><td>";
2613: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2614: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2615: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2616: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2617: print "</table></td></tr></table>\n";
2618:
2619: print "<td>";
2620: # Print format selector
2621: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2622: foreach my $var (keys %input) {
2623: next if ($var eq "f");
2624: next if (defined($DEFAULTVALUE{$var})
2625: && $DEFAULTVALUE{$var} eq $input{$var});
2626: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2627: urlencode($input{$var}),"\">\n";
2628: }
2629: printDiffSelect($use_java_script);
2630: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2631: print "</FORM>\n";
2632: print "</td>";
2633:
2634: print "</tr></table>";
1.1 jfieber 2635: }
2636:
1.1.1.2 knu 2637: sub navigateHeader($$$$$) {
1.1.1.1 knu 2638: my ($swhere,$path,$filename,$rev,$title) = @_;
2639: $swhere = "" if ($swhere eq $scriptwhere);
2640: $swhere = urlencode($filename) if ($swhere eq "");
2641: print "<\!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
2642: print "<HTML>\n<HEAD>\n";
1.1.1.12! knu 2643: print '<!-- CVSweb $zRevision: 1.104 $ $kRevision: 1.39 $ -->';
1.1.1.1 knu 2644: print "\n<TITLE>$path$filename - $title - $rev</TITLE></HEAD>\n";
1.1.1.7 knu 2645: print "$body_tag_for_src\n";
1.1.1.1 knu 2646: print "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$navigationHeaderColor\">";
2647: print "<tr valign=bottom><td>";
1.1.1.11 knu 2648: print &link($backicon, "$swhere$query#rev$rev");
1.1.1.1 knu 2649: print "</a> <b>Return to ", &link("$filename","$swhere$query#rev$rev")," CVS log";
2650: print "</b> $fileicon</td>";
1.1.1.2 knu 2651:
1.1.1.1 knu 2652: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2653: print "</tr></table>";
2654: }
1.1 jfieber 2655:
1.1.1.2 knu 2656: sub plural_write($$) {
1.1.1.1 knu 2657: my ($num,$text) = @_;
2658: if ($num != 1) {
1.1.1.11 knu 2659: $text .= "s";
1.1.1.1 knu 2660: }
2661: if ($num > 0) {
1.1.1.11 knu 2662: return join(' ', $num, $text);
1.1.1.1 knu 2663: }
2664: else {
2665: return "";
2666: }
1.1 jfieber 2667: }
2668:
1.1.1.1 knu 2669: ##
2670: # print readable timestamp in terms of
2671: # '..time ago'
2672: # H. Zeller <zeller@think.de>
2673: ##
1.1.1.2 knu 2674: sub readableTime($$) {
1.1.1.1 knu 2675: my ($i, $break, $retval);
2676: my ($secs,$long) = @_;
1.1 jfieber 2677:
1.1.1.1 knu 2678: # this function works correct for time >= 2 seconds
2679: if ($secs < 2) {
2680: return "very little time";
2681: }
2682:
2683: my %desc = (1 , 'second',
2684: 60, 'minute',
2685: 3600, 'hour',
2686: 86400, 'day',
2687: 604800, 'week',
2688: 2628000, 'month',
2689: 31536000, 'year');
2690: my @breaks = sort {$a <=> $b} keys %desc;
2691: $i = 0;
1.1.1.2 knu 2692: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
1.1.1.1 knu 2693: $i++;
2694: }
2695: $i--;
2696: $break = $breaks[$i];
2697: $retval = plural_write(int ($secs / $break), $desc{$break});
2698:
2699: if ($long == 1 && $i > 0) {
2700: my $rest = $secs % $break;
2701: $i--;
2702: $break = $breaks[$i];
1.1.1.2 knu 2703: my $resttime = plural_write(int ($rest / $break),
1.1.1.1 knu 2704: $desc{$break});
2705: if ($resttime) {
1.1.1.11 knu 2706: $retval .= ", $resttime";
1.1.1.1 knu 2707: }
2708: }
2709:
2710: return $retval;
2711: }
2712:
2713: ##
2714: # clickablePath(String pathname, boolean last_item_clickable)
2715: #
2716: # returns a html-ified path whereas each directory is a link for
2717: # faster navigation. last_item_clickable controls whether the
2718: # basename (last directory/file) is a link as well
2719: ##
2720: sub clickablePath($$) {
1.1.1.2 knu 2721: my ($pathname,$clickLast) = @_;
1.1.1.1 knu 2722: my $retval = '';
1.1.1.2 knu 2723:
1.1.1.1 knu 2724: if ($pathname eq '/') {
2725: # this should never happen - chooseCVSRoot() is
2726: # intended to do this
2727: $retval = "[$cvstree]";
2728: }
2729: else {
1.1.1.11 knu 2730: $retval .= ' ' . &link("[$cvstree]", sprintf('%s/%s#dirlist',
2731: $scriptname,
2732: $query));
1.1.1.1 knu 2733: my $wherepath = '';
2734: my ($lastslash) = $pathname =~ m|/$|;
2735: foreach (split(/\//, $pathname)) {
1.1.1.11 knu 2736: $retval .= " / ";
2737: $wherepath .= "/$_";
1.1.1.1 knu 2738: my ($last) = "$wherepath/" eq "/$pathname"
2739: || $wherepath eq "/$pathname";
2740: if ($clickLast || !$last) {
1.1.1.11 knu 2741: $retval .= &link($_, join('',
2742: $scriptname,
2743: urlencode($wherepath),
2744: (!$last || $lastslash ? '/' : ''),
2745: $query,
2746: (!$last || $lastslash ? "#dirlist" : "")));
1.1.1.1 knu 2747: }
2748: else { # do not make a link to the current dir
1.1.1.11 knu 2749: $retval .= $_;
1.1 jfieber 2750: }
2751: }
1.1.1.1 knu 2752: }
2753: return $retval;
1.1 jfieber 2754: }
2755:
1.1.1.1 knu 2756: sub chooseCVSRoot() {
2757: my @foo;
2758: foreach (sort keys %CVSROOT) {
2759: if (-d $CVSROOT{$_}) {
2760: push(@foo, $_);
2761: }
2762: }
2763: if (@foo > 1) {
2764: my ($k);
2765: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2766: foreach $k (keys %input) {
1.1.1.2 knu 2767: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
1.1.1.1 knu 2768: if ($input{$k}) && ($k ne "cvsroot");
2769: }
2770: # Form-Elements look wierd in Netscape if the background
2771: # isn't gray and the form elements are not placed
2772: # within a table ...
2773: print "<table><tr>";
2774: print "<td>CVS Root:</td>";
2775: print "<td>\n<select name=\"cvsroot\"";
2776: print " onchange=\"submit()\"" if ($use_java_script);
2777: print ">\n";
2778: foreach $k (@foo) {
2779: print "<option value=\"$k\"";
2780: print " selected" if ($k eq $cvstree);
1.1.1.11 knu 2781: print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k), "</option>\n";
1.1.1.1 knu 2782: }
2783: print "</select>\n</td>";
2784: print "<td><input type=submit value=\"Go\"></td>";
2785: print "</tr></table></form>";
2786: }
2787: else {
2788: # no choice ..
2789: print "CVS Root: <b>[$cvstree]</b>";
2790: }
2791: }
2792:
2793: sub chooseMirror() {
2794: my ($mirror,$moremirrors);
2795: $moremirrors = 0;
2796: # This code comes from the original BSD-cvsweb
2797: # and may not be useful for your site; If you don't
2798: # set %MIRRORS this won't show up, anyway
2799: #
1.1.1.2 knu 2800: # Should perhaps exlude the current site somehow..
1.1.1.1 knu 2801: if (keys %MIRRORS) {
2802: print "\nThis cvsweb is mirrored in:\n";
2803: foreach $mirror (keys %MIRRORS) {
2804: print ", " if ($moremirrors);
1.1.1.11 knu 2805: print &link(htmlquote($mirror),$MIRRORS{$mirror});
1.1.1.1 knu 2806: $moremirrors = 1;
2807: }
2808: print "<p>\n";
2809: }
2810: }
2811:
1.1.1.2 knu 2812: sub fileSortCmp() {
1.1.1.1 knu 2813: my ($comp) = 0;
2814: my ($c,$d,$af,$bf);
2815:
2816: ($af = $a) =~ s/,v$//;
2817: ($bf = $b) =~ s/,v$//;
2818: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2819: if (defined($fileinfo{$af}));
2820: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2821: if (defined($fileinfo{$bf}));
2822:
2823: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2824: # Two files
2825: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2826: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2827: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2828: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2829: }
2830: if ($comp == 0) {
2831: # Directories first, then sorted on name if no other sort critera
2832: # available.
2833: my $ad = ((-d "$fullname/$a")?"D":"F");
2834: my $bd = ((-d "$fullname/$b")?"D":"F");
2835: ($c=$a) =~ s|.*/||;
2836: ($d=$b) =~ s|.*/||;
2837: $comp = ("$ad$c" cmp "$bd$d");
2838: }
2839: return $comp;
2840: }
2841:
2842: # make A url for downloading
1.1.1.2 knu 2843: sub download_url($$;$) {
1.1.1.1 knu 2844: my ($url,$revision,$mimetype) = @_;
2845:
1.1.1.12! knu 2846: $revision =~ s/\.0\././;
1.1.1.1 knu 2847:
1.1.1.11 knu 2848: if (defined($checkoutMagic)
1.1.1.1 knu 2849: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
1.1.1.11 knu 2850: my $path = $where;
2851: $path =~ s|/[^/]*$|/|;
1.1.1.1 knu 2852: $url = "$scriptname/$checkoutMagic/${path}$url";
2853: }
2854: $url .= "?rev=$revision";
1.1.1.11 knu 2855: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
1.1.1.1 knu 2856:
1.1.1.11 knu 2857: $url;
1.1.1.1 knu 2858: }
2859:
1.1.1.2 knu 2860: # Presents a link to download the
1.1.1.1 knu 2861: # selected revision
1.1.1.2 knu 2862: sub download_link($$$;$) {
1.1.1.11 knu 2863: my ($url, $revision, $textlink, $mimetype) = @_;
2864: my ($fullurl) = download_url($url, $revision, $mimetype);
2865:
2866: printf '<A HREF="%s"', htmlquote("$fullurl$barequery");
2867:
1.1.1.1 knu 2868: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
1.1.1.11 knu 2869: print ' target="cvs_checkout"';
1.1.1.1 knu 2870: # we should have
2871: # 'if (document.cvswin==null) document.cvswin=window.open(...'
2872: # in order to allow the user to resize the window; otherwise
2873: # the user may resize the window, but on next checkout - zap -
2874: # its original (configured s. cvsweb.conf) size is back again
2875: # .. annoying (if $extern_window_(width|height) is defined)
2876: # but this if (..) solution is far from perfect
2877: # what we need to do as well is
2878: # 1) save cvswin in an invisible frame that always exists
2879: # (document.cvswin will be void on next load)
2880: # 2) on close of the cvs_checkout - window set the cvswin
2881: # variable to 'null' again - so that it will be
2882: # reopenend with the configured size
2883: # anyone a JavaScript programmer ?
2884: # .. so here without if (..):
2885: # currently, the best way is to comment out the size parameters
2886: # ($extern_window...) in cvsweb.conf.
2887: if ($use_java_script) {
1.1.1.11 knu 2888: my @attr = qw(resizeable scrollbars);
2889:
2890: push @attr, qw(status toolbar)
2891: if (defined($mimetype) && $mimetype eq "text/html");
2892:
2893: push @attr, "width=$extern_window_width"
2894: if (defined($extern_window_width));
2895:
2896: push @attr, "height=$extern_window_height"
2897: if (defined($extern_window_height));
2898:
2899: printf q` onClick="window.open('%s','cvs_checkout','%s');"`,
2900: htmlquote($fullurl), join(',', @attr);
1.1.1.1 knu 2901: }
2902: }
2903: print "><b>$textlink</b></A>";
2904: }
2905:
2906: # Returns a Query string with the
2907: # specified parameter toggled
2908: sub toggleQuery($$) {
2909: my ($toggle,$value) = @_;
2910: my ($newquery,$var);
2911: my (%vars);
2912: %vars = %input;
2913: if (defined($value)) {
2914: $vars{$toggle} = $value;
2915: }
2916: else {
2917: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
2918: }
2919: # Build a new query of non-default paramenters
2920: $newquery = "";
2921: foreach $var (@stickyvars) {
2922: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
2923: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
2924: if ($value ne $default) {
1.1.1.11 knu 2925: $newquery .= "&" if ($newquery ne "");
1.1.1.1 knu 2926: $newquery .= urlencode($var) . "=" . urlencode($value);
2927: }
2928: }
2929: if ($newquery) {
2930: return '?' . $newquery;
2931: }
2932: return "";
2933: }
2934:
1.1.1.2 knu 2935: sub urlencode($) {
1.1.1.11 knu 2936: local($_) = @_;
2937:
2938: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
2939:
2940:
2941: $_;
2942: }
2943:
2944: sub htmlquote($) {
2945: local($_) = @_;
2946:
2947: # Special Characters; RFC 1866
2948: s/&/&/g;
2949: s/\"/"/g;
2950: s/</</g;
2951: s/>/>/g;
2952:
2953: $_;
2954: }
2955:
2956: sub htmlunquote($) {
2957: local($_) = @_;
2958:
2959: # Special Characters; RFC 1866
2960: s/"/\"/g;
2961: s/</</g;
2962: s/>/>/g;
2963: s/&/&/g;
2964:
2965: $_;
1.1.1.1 knu 2966: }
2967:
1.1.1.2 knu 2968: sub http_header(;$) {
1.1.1.1 knu 2969: my $content_type = shift || "text/html";
2970: if (defined($moddate)) {
2971: if ($is_mod_perl) {
1.1.1.6 knu 2972: Apache->request->header_out("Last-Modified" => scalar gmtime($moddate) . " GMT");
1.1.1.1 knu 2973: }
2974: else {
1.1.1.11 knu 2975: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
1.1.1.1 knu 2976: }
2977: }
2978: if ($is_mod_perl) {
2979: Apache->request->content_type($content_type);
2980: }
2981: else {
2982: print "Content-type: $content_type\r\n";
2983: }
2984: if ($allow_compress && $maycompress) {
1.1.1.6 knu 2985: if ($has_zlib || (defined($GZIPBIN) && open(GZIP, "|$GZIPBIN -1 -c"))) {
1.1.1.1 knu 2986: if ($is_mod_perl) {
2987: Apache->request->content_encoding("x-gzip");
2988: Apache->request->header_out(Vary => "Accept-Encoding");
2989: Apache->request->send_http_header;
2990: }
2991: else {
2992: print "Content-encoding: x-gzip\r\n";
2993: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
2994: print "\r\n"; # Close headers
2995: }
2996: $| = 1; $| = 0; # Flush header output
1.1.1.6 knu 2997: if ($has_zlib) {
2998: tie *GZIP, __PACKAGE__, \*STDOUT;
2999: }
3000: select(GZIP);
3001: $gzip_open = 1;
1.1.1.1 knu 3002: # print "<!-- gzipped -->" if ($content_type eq "text/html");
3003: }
3004: else {
3005: if ($is_mod_perl) {
3006: Apache->request->send_http_header;
3007: }
3008: else {
3009: print "\r\n"; # Close headers
3010: }
3011: print "<font size=-1>Unable to find gzip binary in the \$PATH to compress output</font><br>";
3012: }
3013: }
3014: else {
3015: if ($is_mod_perl) {
3016: Apache->request->send_http_header;
3017: }
3018: else {
3019: print "\r\n"; # Close headers
3020: }
3021: }
3022: }
3023:
3024: sub html_header($) {
3025: my ($title) = @_;
1.1.1.12! knu 3026: my $version = '$zRevision: 1.104 $ $kRevision: 1.39 $'; #'
1.1.1.1 knu 3027: http_header();
3028: print <<EOH;
3029: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
3030: "http://www.w3.org/TR/REC-html40/loose.dtd">
3031: <html>
3032: <title>$title</title>
3033: <!-- CVSweb $version -->
3034: </head>
3035: $body_tag
3036: $logo <h1 align="center">$title</h1>
3037: EOH
3038: }
3039:
1.1.1.2 knu 3040: sub html_footer() {
1.1.1.1 knu 3041: return "<hr noshade><address>$address</address>\n";
3042: }
3043:
1.1.1.2 knu 3044: sub link_tags($) {
1.1.1.1 knu 3045: my ($tags) = @_;
3046: my ($ret) = "";
3047: my ($fileurl,$filename);
3048:
3049: ($filename = $where) =~ s/^.*\///;
3050: $fileurl = urlencode($filename);
3051:
3052: foreach my $sym (split(", ", $tags)) {
3053: $ret .= ",\n" if ($ret ne "");
1.1.1.11 knu 3054: $ret .= &link($sym, $fileurl . toggleQuery('only_with_tag',$sym));
1.1.1.1 knu 3055: }
1.1.1.11 knu 3056: return "$ret\n";
1.1.1.1 knu 3057: }
3058:
3059: #
3060: # See if a module is listed in the config file's @HideModule list.
3061: #
1.1.1.2 knu 3062: sub forbidden_module($) {
1.1.1.1 knu 3063: my($module) = @_;
1.1.1.2 knu 3064:
1.1.1.1 knu 3065: for (my $i=0; $i < @HideModules; $i++) {
3066: return 1 if $module eq $HideModules[$i];
3067: }
3068:
3069: return 0;
1.1.1.7 knu 3070: }
3071:
3072: # Close the GZIP handle remove the tie.
3073:
3074: sub gzipclose {
3075: if ($gzip_open) {
3076: select(STDOUT);
3077: close(GZIP);
3078: untie *GZIP;
3079: $gzip_open = 0;
3080: }
1.1.1.6 knu 3081: }
3082:
3083: # implement a gzipped file handle via the Compress:Zlib compression
3084: # library.
3085:
3086: sub MAGIC1() { 0x1f }
3087: sub MAGIC2() { 0x8b }
3088: sub OSCODE() { 3 }
3089:
3090: sub TIEHANDLE {
3091: my ($class, $out) = @_;
3092: my ($d) = Compress::Zlib::deflateInit(-Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3093: -WindowBits => -Compress::Zlib::MAX_WBITS()) or return undef;
3094: my ($o) = {
3095: handle => $out,
3096: dh => $d,
3097: crc => 0,
3098: len => 0,
3099: };
3100: my ($header) = pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0,0,0,0,0,0, OSCODE);
3101: print {$o->{handle}} $header;
3102: return bless($o, $class);
3103: }
3104:
3105: sub PRINT {
3106: my ($o) = shift;
3107: my ($buf) = join(defined $, ? $, : "",@_);
3108: my ($len) = length($buf);
3109: my ($compressed, $status) = $o->{dh}->deflate($buf);
3110: print {$o->{handle}} $compressed if defined($compressed);
3111: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3112: $o->{len} += $len;
3113: return $len;
3114: }
3115:
3116: sub PRINTF {
3117: my ($o) = shift;
3118: my ($fmt) = shift;
3119: my ($buf) = sprintf($fmt, @_);
3120: my ($len) = length($buf);
3121: my ($compressed, $status) = $o->{dh}->deflate($buf);
3122: print {$o->{handle}} $compressed if defined($compressed);
3123: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3124: $o->{len} += $len;
3125: return $len;
3126: }
3127:
3128: sub WRITE {
3129: my ($o, $buf, $len, $off) = @_;
3130: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3131: print {$o->{handle}} $compressed if defined($compressed);
3132: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3133: $o->{len} += $len;
3134: return $len;
3135: }
3136:
3137: sub CLOSE {
3138: my ($o) = @_;
3139: return if !defined( $o->{dh});
3140: my ($buf) = $o->{dh}->flush();
3141: $buf .= pack("V V", $o->{crc}, $o->{len});
3142: print {$o->{handle}} $buf;
3143: undef $o->{dh};
3144: }
3145:
3146: sub DESTROY {
3147: my ($o) = @_;
3148: CLOSE($o);
1.1 jfieber 3149: }
CVSweb