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