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