Annotation of cvsweb/cvsweb.cgi, Revision 3.74
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.68 knu 45: # $Id: cvsweb.cgi,v 1.106 2001/03/10 01:16:27 hnordstrom Exp $
3.74 ! knu 46: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 3.73 2001/05/17 20:02:24 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.68 knu 142: $cvsweb_revision = '1.106' . '.' . (split(/ /,
3.74 ! knu 143: q$Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 3.73 2001/05/17 20:02:24 knu Exp $
3.68 knu 144: ))[2];
3.64 knu 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.74 ! knu 751: print " ", &link("Parent Directory", $url);
3.1 knu 752: }
753: else {
3.70 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($_);
3.70 knu 817: $url = './' . $fileurl . $query;
3.1 knu 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.
3.70 knu 915: "./$basefile.tar.gz$query".
3.46 knu 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 $_) = @_;
3.73 knu 1109: my @a = split(m`(<a [^>]+>[^<]*</a>)`i);
3.39 knu 1110: my $linked;
1111: my $result = '';
3.36 knu 1112:
3.73 knu 1113: while (($_, $linked) = splice(@a, 0, 2)) {
3.36 knu 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.70 knu 1229: $url =~ s/:/sprintf("%%%02x", ord($&))/eg if $url =~ /^[^a-z]/; # relative
3.67 knu 1230:
3.63 knu 1231: sprintf '<A HREF="%s">%s</A>', hrefquote($url), $name;
1.12 fenner 1232: }
1233:
3.12 knu 1234: sub revcmp($$) {
3.1 knu 1235: my($rev1, $rev2) = @_;
3.15 knu 1236:
1237: # make no comparison for a tag or a branch
1238: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1239:
3.1 knu 1240: my(@r1) = split(/\./, $rev1);
1241: my(@r2) = split(/\./, $rev2);
1242: my($a,$b);
1.12 fenner 1243:
1244: while (($a = shift(@r1)) && ($b = shift(@r2))) {
1245: if ($a != $b) {
1246: return $a <=> $b;
1247: }
1248: }
1249: if (@r1) { return 1; }
1250: if (@r2) { return -1; }
1251: return 0;
1252: }
1253:
3.12 knu 1254: sub fatal($$) {
3.1 knu 1255: my($errcode, $errmsg) = @_;
3.3 knu 1256: if ($is_mod_perl) {
3.1 knu 1257: Apache->request->status((split(/ /, $errcode))[0]);
1258: }
1259: else {
3.4 knu 1260: print "Status: $errcode\r\n";
3.1 knu 1261: }
1262: html_header("Error");
1.12 fenner 1263: print "Error: $errmsg\n";
1264: print &html_footer;
1265: exit(1);
1266: }
1267:
3.12 knu 1268: sub redirect($) {
3.1 knu 1269: my($url) = @_;
3.3 knu 1270: if ($is_mod_perl) {
3.1 knu 1271: Apache->request->status(301);
1272: Apache->request->header_out(Location => $url);
1273: }
1274: else {
3.4 knu 1275: print "Status: 301 Moved\r\n";
1276: print "Location: $url\r\n";
3.1 knu 1277: }
1278: html_header("Moved");
3.35 knu 1279: print "This document is located ", &link('here', $url), "\n";
1.12 fenner 1280: print &html_footer;
1281: exit(1);
1282: }
1283:
3.12 knu 1284: sub safeglob($) {
3.1 knu 1285: my ($filename) = @_;
1286: my ($dirname);
1287: my (@results);
1288: my $dh = do {local(*DH);};
1.12 fenner 1289:
1290: ($dirname = $filename) =~ s|/[^/]+$||;
1291: $filename =~ s|.*/||;
1292:
3.1 knu 1293: if (opendir($dh, $dirname)) {
1294: my $glob = $filename;
1295: my $t;
1.12 fenner 1296: # transform filename from glob to regex. Deal with:
1297: # [, {, ?, * as glob chars
1298: # make sure to escape all other regex chars
1299: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1300: $glob =~ s/\*/.*/g;
1301: $glob =~ s/\?/./g;
1302: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
3.1 knu 1303: foreach (readdir($dh)) {
1.12 fenner 1304: if (/^${glob}$/) {
3.36 knu 1305: push(@results, "$dirname/" .$_);
1.12 fenner 1306: }
1307: }
3.68 knu 1308: closedir($dh);
1.12 fenner 1309: }
1310:
1311: @results;
1312: }
1313:
3.58 knu 1314: sub search_path($) {
1315: my($command) = @_;
1316: my $d;
1317:
1318: for $d (split(/:/, $command_path)) {
1319: return "$d/$command" if -x "$d/$command";
1320: }
1321:
1322: $command;
1323: }
1324:
3.12 knu 1325: sub getMimeTypeFromSuffix($) {
3.1 knu 1326: my ($fullname) = @_;
1327: my ($mimetype, $suffix);
1328: my $fh = do {local(*FH);};
1329:
1330: ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1331: $mimetype = $MTYPES{$suffix};
1332: $mimetype = $MTYPES{'*'} if (!$mimetype);
3.12 knu 1333:
3.1 knu 1334: if (!$mimetype && -f $mime_types) {
1335: # okey, this is something special - search the
1336: # mime.types database
1337: open ($fh, "<$mime_types");
1338: while (<$fh>) {
1339: if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
1340: $mimetype = $1;
1341: last;
1342: }
1343: }
1344: close ($fh);
1345: }
3.12 knu 1346:
3.1 knu 1347: # okey, didn't find anything useful ..
1348: if (!($mimetype =~ /\S\/\S/)) {
1349: $mimetype = "text/plain";
1350: }
1351: return $mimetype;
1352: }
1353:
1354: ###############################
3.24 knu 1355: # read first lines like head(1)
1356: ###############################
1357: sub head($;$) {
1358: my $fh = $_[0];
1359: my $linecount = $_[1] || 10;
1360:
1361: my @buf;
1362:
1363: if ($linecount > 0) {
1364: my $i;
1365: for ($i = 0; !eof($fh) && $i < $linecount; $i++) {
1366: push @buf, scalar <$fh>;
1367: }
1368: } else {
1369: @buf = <$fh>;
1370: }
1371:
1372: @buf;
1373: }
1374:
1375: ###############################
1376: # scan vim and Emacs directives
1377: ###############################
1378: sub scan_directives(@) {
1379: my $ts = undef;
1380:
1381: for (@_) {
1382: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1383: }
1384:
1385: ('tabstop' => $ts);
1386: }
1387:
1388: ###############################
3.1 knu 1389: # show Annotation
1390: ###############################
3.12 knu 1391: sub doAnnotate($$) {
3.1 knu 1392: my ($rev) = @_;
1393: my ($pid);
1394: my ($pathname, $filename);
1395: my $reader = do {local(*FH);};
1396: my $writer = do {local(*FH);};
1397:
3.62 knu 1398: # make sure the revisions are wellformed, for security
3.1 knu 1399: # reasons ..
3.15 knu 1400: if ($rev =~ /[^\w.]/) {
3.1 knu 1401: &fatal("404 Not Found",
3.3 knu 1402: "Malformed query \"$ENV{QUERY_STRING}\"");
3.1 knu 1403: }
1.12 fenner 1404:
3.1 knu 1405: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1406: ($filename = $where) =~ s/^.*\///;
1407:
1408: # this seems to be necessary
1409: $| = 1; $| = 0; # Flush
1410:
1411: # this annotate version is based on the
1412: # cvs annotate-demo Perl script by Cyclic Software
1413: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1414: # the public domain.
1415: # we could abandon the use of rlog, rcsdiff and co using
1416: # the cvsserver in a similiar way one day (..after rewrite)
3.65 knu 1417: $pid = open2($reader, $writer, $CMD{cvs}, @cvs_options, "server")
3.55 knu 1418: || fatal ("500 Internal Error", "Fatal Error - unable to open cvs for annotation");
3.12 knu 1419:
3.1 knu 1420: # OK, first send the request to the server. A simplified example is:
1421: # Root /home/kingdon/zwork/cvsroot
1422: # Argument foo/xx
1423: # Directory foo
1424: # /home/kingdon/zwork/cvsroot/foo
1425: # Directory .
1426: # /home/kingdon/zwork/cvsroot
1427: # annotate
1428: # although as you can see there are a few more details.
3.12 knu 1429:
3.1 knu 1430: print $writer "Root $cvsroot\n";
1431: print $writer "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1432: # Don't worry about sending valid-requests, the server just needs to
1433: # support "annotate" and if it doesn't, there isn't anything to be done.
1434: print $writer "UseUnchanged\n";
1435: print $writer "Argument -r\n";
1436: print $writer "Argument $rev\n";
1437: print $writer "Argument $where\n";
1438:
1439: # The protocol requires us to fully fake a working directory (at
1440: # least to the point of including the directories down to the one
1441: # containing the file in question).
1442: # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
3.3 knu 1443: my @dirs = split('/', $where);
3.1 knu 1444: my $path = "";
1445: foreach (@dirs) {
1446: if ($path eq "") {
1447: # In our example, $_ is "dir".
1448: $path = $_;
3.12 knu 1449: }
3.1 knu 1450: else {
3.3 knu 1451: print $writer "Directory $path\n";
1452: print $writer "$cvsroot/$path\n";
3.1 knu 1453: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1454: # And the next time, "file" and "dir/sdir/file" (which then gets
1455: # ignored, because we don't need to send Directory for the file).
3.3 knu 1456: $path .= "/$_";
3.1 knu 1457: }
1458: }
1459: # And the last "Directory" before "annotate" is the top level.
1460: print $writer "Directory .\n";
1461: print $writer "$cvsroot\n";
3.12 knu 1462:
3.1 knu 1463: print $writer "annotate\n";
1464: # OK, we've sent our command to the server. Thing to do is to
1465: # close the writer side and get all the responses. If "cvs server"
1466: # were nicer about buffering, then we could just leave it open, I think.
1467: close ($writer) || die "cannot close: $!";
3.12 knu 1468:
3.30 knu 1469: http_header();
1470:
1471: navigateHeader($scriptwhere,$pathname,$filename,$rev, "annotate");
1472: print "<h3 align=center>Annotation of $pathname$filename, Revision $rev</h3>\n";
1473:
3.1 knu 1474: # Ready to get the responses from the server.
1475: # For example:
1476: # E Annotations for foo/xx
1477: # E ***************
3.12 knu 1478: # M 1.3 (kingdon 06-Sep-97): hello
3.1 knu 1479: # ok
1480: my ($lineNr) = 0;
1481: my ($oldLrev, $oldLusr) = ("", "");
1482: my ($revprint, $usrprint);
1483: if ($annTable) {
1484: print "<table border=0 cellspacing=0 cellpadding=0>\n";
1485: }
1486: else {
1487: print "<pre>";
1488: }
3.24 knu 1489:
1490: # prefetch several lines
1491: my @buf = head($reader);
1492:
1493: my %d = scan_directives(@buf);
1494:
1495: while (@buf || !eof($reader)) {
1496: $_ = @buf ? shift @buf : <$reader>;
1497:
3.1 knu 1498: my @words = split;
1499: # Adding one is for the (single) space which follows $words[0].
1500: my $rest = substr ($_, length ($words[0]) + 1);
1501: if ($words[0] eq "E") {
1502: next;
1503: }
1504: elsif ($words[0] eq "M") {
1505: $lineNr++;
3.30 knu 1506: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1507: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1508: my $line = substr($_, 36);
1509: my $isCurrentRev = ($rev eq $lrev);
3.1 knu 1510: # we should parse the date here ..
1511: if ($lrev eq $oldLrev) {
3.30 knu 1512: $revprint = sprintf('%-8s', '');
3.1 knu 1513: }
1514: else {
3.30 knu 1515: $revprint = sprintf('%-8s', $lrev);
3.36 knu 1516: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
3.30 knu 1517: $oldLusr = '';
3.1 knu 1518: }
1519: if ($lusr eq $oldLusr) {
3.30 knu 1520: $usrprint = '';
3.1 knu 1521: }
1522: else {
1523: $usrprint = $lusr;
1524: }
1525: $oldLrev = $lrev;
1526: $oldLusr = $lusr;
3.12 knu 1527:
3.30 knu 1528: # Set bold for text-based browsers only - graphical
1529: # browsers show bold fonts a bit wider than regular fonts,
1530: # so it looks irregular.
1531: print "<b>" if ($isCurrentRev && $is_textbased);
1532:
3.32 knu 1533: printf "%s%s %-8s %4d:",
3.30 knu 1534: $revprint,
1535: $isCurrentRev ? '!' : ' ',
1536: $usrprint,
3.32 knu 1537: $lineNr;
3.24 knu 1538: print spacedHtmlText($line, $d{'tabstop'});
3.30 knu 1539:
1540: print "</b>" if ($isCurrentRev && $is_textbased);
3.1 knu 1541: }
1542: elsif ($words[0] eq "ok") {
1543: # We could complain about any text received after this, like the
1544: # CVS command line client. But for simplicity, we don't.
1545: }
1546: elsif ($words[0] eq "error") {
3.36 knu 1547: fatal("500 Internal Error", "Error occured during annotate: <b>$_</b>");
3.1 knu 1548: }
1549: }
1550: if ($annTable) {
1551: print "</table>";
1552: }
1553: else {
1554: print "</pre>";
1555: }
1556: close ($reader) || warn "cannot close: $!";
1557: wait;
1558: }
1559:
1560: ###############################
1561: # make Checkout
1562: ###############################
3.12 knu 1563: sub doCheckout($$) {
3.1 knu 1564: my ($fullname, $rev) = @_;
1565: my ($mimetype,$revopt);
1566: my $fh = do {local(*FH);};
1567:
3.15 knu 1568: if ($rev eq 'HEAD' || $rev eq '.') {
1569: $rev = undef;
1570: }
1571:
3.1 knu 1572: # make sure the revisions a wellformed, for security
1573: # reasons ..
3.15 knu 1574: if (defined($rev) && $rev =~ /[^\w.]/) {
3.1 knu 1575: &fatal("404 Not Found",
3.3 knu 1576: "Malformed query \"$ENV{QUERY_STRING}\"");
3.1 knu 1577: }
1578:
1579: # get mimetype
1580: if (defined($input{"content-type"}) && ($input{"content-type"} =~ /\S\/\S/)) {
1581: $mimetype = $input{"content-type"}
1582: }
1583: else {
1584: $mimetype = &getMimeTypeFromSuffix($fullname);
1585: }
1586:
1587: if (defined($rev)) {
1588: $revopt = "-r$rev";
1589: if ($use_moddate) {
1590: readLog($fullname,$rev);
1591: $moddate=$date{$rev};
1592: }
1593: }
1594: else {
1595: $revopt = "-rHEAD";
1596: if ($use_moddate) {
1597: readLog($fullname);
1598: $moddate=$date{$symrev{HEAD}};
1599: }
1600: }
3.12 knu 1601:
3.1 knu 1602: ### just for the record:
1603: ### 'cvs co' seems to have a bug regarding single checkout of
1604: ### directories/files having spaces in it;
1605: ### this is an issue that should be resolved on cvs's side
1606: #
1607: # Safely for a child process to read from.
1608: if (! open($fh, "-|")) { # child
3.58 knu 1609: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1610: exec($CMD{cvs}, @cvs_options, '-d', $cvsroot, 'co', '-p', $revopt, $where);
3.12 knu 1611: }
3.41 knu 1612:
1613: if (eof($fh)) {
1614: &fatal("404 Not Found",
1615: "$where is not (any longer) pertinent");
1616: }
3.1 knu 1617: #===================================================================
1618: #Checking out squid/src/ftp.c
1619: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1620: #VERS: 1.1.1.28.6.2
1621: #***************
1622:
1623: # Parse CVS header
1624: my ($revision, $filename, $cvsheader);
1625: while(<$fh>) {
1626: last if (/^\*\*\*\*/);
1627: $revision = $1 if (/^VERS: (.*)$/);
1628: if (/^Checking out (.*)$/) {
1629: $filename = $1;
1630: $filename =~ s/^\.\/*//;
1.12 fenner 1631: }
3.1 knu 1632: $cvsheader .= $_;
1633: }
1634: if ($filename ne $where) {
1635: &fatal("500 Internal Error",
3.41 knu 1636: "Unexpected output from cvs co: $cvsheader");
3.1 knu 1637: }
1638: $| = 1;
1639:
1640: if ($mimetype eq "text/x-cvsweb-markup") {
1641: &cvswebMarkup($fh,$fullname,$revision);
1642: }
1643: else {
1644: http_header($mimetype);
1645: print <$fh>;
1646: }
1647: close($fh);
1648: }
1649:
3.12 knu 1650: sub cvswebMarkup($$$) {
3.1 knu 1651: my ($filehandle,$fullname,$revision) = @_;
1652: my ($pathname, $filename);
1653:
1654: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1655: ($filename = $where) =~ s/^.*\///;
1656: my ($fileurl) = urlencode($filename);
1657:
1658: http_header();
1659:
3.12 knu 1660: navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
3.1 knu 1661: print "<HR noshade>";
1662: print "<table width=\"100%\"><tr><td bgcolor=\"$markupLogColor\">";
1663: print "File: ", &clickablePath($where, 1);
3.35 knu 1664: print " (";
1665: &download_link($fileurl, $revision, "download");
1666: print ")";
3.1 knu 1667: if (!$defaultTextPlain) {
3.35 knu 1668: print " (";
1669: &download_link($fileurl, $revision, "as text",
3.1 knu 1670: "text/plain");
3.35 knu 1671: print ")";
3.1 knu 1672: }
1673: print "<BR>\n";
1674: if ($show_log_in_markup) {
1675: readLog($fullname); #,$revision);
1676: printLog($revision,0);
1677: }
1678: else {
1679: print "Version: <B>$revision</B><BR>\n";
1680: print "Tag: <B>", $input{only_with_tag}, "</b><br>\n" if
1681: $input{only_with_tag};
1682: }
1683: print "</td></tr></table>";
1684: my $url = download_url($fileurl, $revision, $mimetype);
1685: print "<HR noshade>";
1686: if ($mimetype =~ /^image/) {
3.46 knu 1687: printf '<IMG SRC="%s"><BR>', hrefquote("$url$barequery");
3.1 knu 1688: }
3.23 knu 1689: elsif ($mimetype =~ m%^application/pdf%) {
3.46 knu 1690: printf '<EMBED SRC="%s" WIDTH="100%"><BR>', hrefquote("$url$barequery");
3.23 knu 1691: }
3.51 knu 1692: elsif ($preformat_in_markup) {
3.1 knu 1693: print "<PRE>";
3.24 knu 1694:
1695: # prefetch several lines
1696: my @buf = head($filehandle);
1697:
1698: my %d = scan_directives(@buf);
1699:
1700: while (@buf || !eof($filehandle)) {
1701: $_ = @buf ? shift @buf : <$filehandle>;
1702:
1703: print spacedHtmlText($_, $d{'tabstop'});
1.12 fenner 1704: }
3.1 knu 1705: print "</PRE>";
1706: }
3.51 knu 1707: else {
3.69 knu 1708: print "<PRE>";
1709: while (<$filehandle>) {
1710: print htmlquote($_);
1711: }
1712: print "</PRE>";
3.51 knu 1713: }
1.12 fenner 1714: }
1715:
3.1 knu 1716: sub viewable($) {
1717: my ($mimetype) = @_;
1718:
3.23 knu 1719: $mimetype =~ m%^((text|image)/|application/pdf)% ;
3.1 knu 1720: }
1721:
1722: ###############################
1723: # Show Colored Diff
1724: ###############################
3.12 knu 1725: sub doDiff($$$$$$) {
3.1 knu 1726: my($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1727: my $fh = do {local(*FH);};
3.37 knu 1728: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1.12 fenner 1729:
1730: if ($r1 =~ /([^:]+)(:(.+))?/) {
1731: $rev1 = $1;
1732: $sym1 = $3;
1733: }
3.1 knu 1734: if ($r1 eq 'text') {
1.12 fenner 1735: $rev1 = $tr1;
3.1 knu 1736: $sym1 = "";
1.12 fenner 1737: }
1738: if ($r2 =~ /([^:]+)(:(.+))?/) {
1739: $rev2 = $1;
1740: $sym2 = $3;
1741: }
3.1 knu 1742: if ($r2 eq 'text') {
1.12 fenner 1743: $rev2 = $tr2;
3.1 knu 1744: $sym2 = "";
1.12 fenner 1745: }
3.15 knu 1746:
3.1 knu 1747: # make sure the revisions a wellformed, for security
1748: # reasons ..
3.15 knu 1749: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1.12 fenner 1750: &fatal("404 Not Found",
3.3 knu 1751: "Malformed query \"$ENV{QUERY_STRING}\"");
1.12 fenner 1752: }
1753: #
1754: # rev1 and rev2 are now both numeric revisions.
1755: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1756: # XXX should we warn about the fact that we do this?
1757: if (&revcmp($rev1,$rev2) > 0) {
3.1 knu 1758: my ($tmp1, $tmp2) = ($rev1, $sym1);
1.12 fenner 1759: ($rev1, $sym1) = ($rev2, $sym2);
1760: ($rev2, $sym2) = ($tmp1, $tmp2);
1761: }
3.37 knu 1762: my $difftype = $DIFFTYPES{$f};
1763:
1764: if (!$difftype) {
3.1 knu 1765: fatal ("400 Bad arguments", "Diff format $f not understood");
1766: }
1767:
3.37 knu 1768: my @difftype = @{$difftype->{'opts'}};
1769: my $human_readable = $difftype->{'colored'};
1770:
3.1 knu 1771: # apply special options
3.3 knu 1772: if ($showfunc) {
3.37 knu 1773: push @difftype, '-p' if $f ne 's';
3.1 knu 1774:
3.3 knu 1775: my($re1, $re2);
3.1 knu 1776:
3.3 knu 1777: while (($re1, $re2) = each %funcline_regexp) {
1778: if ($fullname =~ /$re1/) {
3.71 knu 1779: push @difftype, '-F', $re2;
3.3 knu 1780: last;
3.1 knu 1781: }
1782: }
3.3 knu 1783: }
1784: if ($human_readable) {
3.1 knu 1785: if ($hr_ignwhite) {
1786: push @difftype, '-w';
1787: }
1788: if ($hr_ignkeysubst) {
1789: push @difftype, '-kk';
1790: }
1791: }
1792: if (! open($fh, "-|")) { # child
3.3 knu 1793: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
3.58 knu 1794: exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname);
3.1 knu 1795: }
1796: if ($human_readable) {
1797: http_header();
1798: &human_readable_diff($fh, $rev2);
3.25 knu 1799: gzipclose();
3.1 knu 1800: exit;
1801: }
1802: else {
1803: http_header("text/plain");
1.44 knu 1804: }
1.12 fenner 1805: #
1806: #===================================================================
1807: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
1808: #retrieving revision 1.16
1809: #retrieving revision 1.17
1810: #diff -c -r1.16 -r1.17
1811: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1812: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
1813: #
1814: # Ideas:
1815: # - nuke the stderr output if it's what we expect it to be
1816: # - Add "no differences found" if the diff command supplied no output.
1817: #
1818: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1819: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
1820: # (bogus example, but...)
1821: #
3.1 knu 1822: if (grep { $_ eq '-u'} @difftype) {
1.12 fenner 1823: $f1 = '---';
1824: $f2 = '\+\+\+';
3.1 knu 1825: }
1826: else {
1.12 fenner 1827: $f1 = '\*\*\*';
1828: $f2 = '---';
1829: }
3.1 knu 1830: while (<$fh>) {
1.12 fenner 1831: if (m|^$f1 $cvsroot|o) {
1832: s|$cvsroot/||o;
1833: if ($sym1) {
1834: chop;
3.36 knu 1835: $_ .= " $sym1\n";
1.12 fenner 1836: }
3.1 knu 1837: }
1838: elsif (m|^$f2 $cvsroot|o) {
1.12 fenner 1839: s|$cvsroot/||o;
1840: if ($sym2) {
1841: chop;
3.36 knu 1842: $_ .= " $sym2\n";
1.12 fenner 1843: }
1844: }
1845: print $_;
1846: }
3.1 knu 1847: close($fh);
1.12 fenner 1848: }
1849:
3.1 knu 1850: ###############################
1851: # Show Logs ..
1852: ###############################
3.12 knu 1853: sub getDirLogs($$@) {
3.1 knu 1854: my ($cvsroot,$dirname,@otherFiles) = @_;
1855: my ($state,$otherFiles,$tag, $file, $date, $branchpoint, $branch, $log);
1856: my ($rev, $revision, $revwanted, $filename, $head, $author);
1857:
1858: $tag = $input{only_with_tag};
1859:
1860: my ($DirName) = "$cvsroot/$where";
1861: my (@files, @filetags);
1862: my $fh = do {local(*FH);};
1863:
1864: push(@files, &safeglob("$DirName/*,v"));
1865: push(@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
1866: foreach $file (@otherFiles) {
1867: push(@files, "$DirName/$file");
1868: }
1869:
1870: # just execute rlog if there are any files
3.12 knu 1871: if ($#files < 0) {
3.1 knu 1872: return;
1873: }
1874:
3.53 knu 1875: if (defined($tag)) {
3.1 knu 1876: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
1877: if (! open($fh, "-|")) {
3.58 knu 1878: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1879: exec($CMD{rlog}, @files);
3.1 knu 1880: }
1881: }
1882: else {
3.58 knu 1883: if (! open($fh, "-|")) {
1884: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1885: exec($CMD{rlog}, '-r', @files);
3.1 knu 1886: }
1887: }
1888: $state = "start";
1889: while (<$fh>) {
1890: if ($state eq "start") {
1891: #Next file. Initialize file variables
3.53 knu 1892: $rev = '';
1893: $revwanted = '';
1894: $branch = '';
1895: $branchpoint = '';
1896: $filename = '';
1897: $log = '';
1898: $revision = '';
3.1 knu 1899: %symrev = ();
1900: @filetags = ();
1901: #jump to head state
1902: $state = "head";
1903: }
1904: print "$state:$_" if ($verbose);
1905: again:
1906: if ($state eq "head") {
1907: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
3.41 knu 1908:
1909: if (/^Working file: (.+)$/) {
1910: $filename = $1;
1911: } elsif (/^head: (.+)$/) {
1912: $head = $1;
1913: } elsif (/^branch: (.+)$/) {
1914: $branch = $1
1915: } elsif (/^symbolic names:/) {
1916: $state = "tags";
3.53 knu 1917: ($branch = $head) =~ s/\.\d+$// if $branch eq '';
3.45 knu 1918: $branch =~ s/(\d+)$/0.$1/;
3.41 knu 1919: $symrev{MAIN} = $branch;
1920: $symrev{HEAD} = $branch;
1921: $alltags{MAIN} = 1;
1922: $alltags{HEAD} = 1;
1923: push (@filetags, "MAIN", "HEAD");
1924: } elsif (/$LOG_REVSEPARATOR/o) {
1925: $state = "log";
3.53 knu 1926: $rev = '';
1927: $date = '';
1928: $log = '';
3.41 knu 1929: # Try to reconstruct the relative filename if RCS spits out a full path
1930: $filename =~ s%^\Q$DirName\E/%%;
1931: }
3.1 knu 1932: next;
1933: }
3.41 knu 1934: if ($state eq "tags") {
1935: if (/^\s+(.+):\s+([\d\.]+)\s+$/) {
1936: push (@filetags, $1);
1937: $symrev{$1} = $2;
1938: $alltags{$1} = 1;
3.1 knu 1939: next;
3.41 knu 1940: } elsif (/^\S/) {
1941: if (defined($tag)) {
1942: if(defined($symrev{$tag}) || $tag eq "HEAD") {
1943: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
3.45 knu 1944: ($branch = $revwanted) =~ s/\b0\.//;
3.41 knu 1945: ($branchpoint = $branch) =~ s/\.?\d+$//;
3.53 knu 1946: $revwanted = '' if ($revwanted ne $branch);
3.41 knu 1947: } elsif ($tag ne "HEAD") {
1948: print "Tag not found, skip this file" if ($verbose);
1949: $state = "skip";
1950: next;
1951: }
1952: }
1953: foreach my $tagfound (@filetags) {
1954: $tags{$tagfound} = 1;
1955: }
1956: $state = "head";
1957: goto again;
3.1 knu 1958: }
1959: }
1960: if ($state eq "log") {
3.32 knu 1961: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
3.1 knu 1962: # End of a log entry.
3.53 knu 1963: my $revbranch = $rev;
1964: $revbranch =~ s/\.\d+$//;
3.36 knu 1965: print "$filename $rev Wanted: $revwanted ",
1966: "Revbranch: $revbranch Branch: $branch ",
1967: "Branchpoint: $branchpoint\n" if ($verbose);
3.53 knu 1968: if ($revwanted eq '' && $branch ne ''
3.1 knu 1969: && $branch eq $revbranch || !defined($tag)) {
1970: print "File revision $rev found for branch $branch\n"
1971: if ($verbose);
1972: $revwanted = $rev;
1973: }
3.53 knu 1974: if ($revwanted ne '' ? $rev eq $revwanted :
1975: $branchpoint ne '' ? $rev eq $branchpoint :
3.1 knu 1976: 0 && ($rev eq $head)) { # Don't think head is needed here..
1977: print "File info $rev found for $filename\n" if ($verbose);
1978: my @finfo = ($rev,$date,$log,$author,$filename);
1979: my ($name);
1980: ($name = $filename) =~ s%/.*%%;
1981: $fileinfo{$name} = [ @finfo ];
1982: $state = "done" if ($rev eq $revwanted);
1983: }
3.53 knu 1984: $rev = '';
1985: $date = '';
1986: $log = '';
3.1 knu 1987: }
3.53 knu 1988: elsif ($date eq '' && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
3.1 knu 1989: my $yr = $1;
1990: # damn 2-digit year routines :-)
1991: if ($yr > 100) {
1992: $yr -= 1900;
1993: }
1994: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1995: ($author) = /author: ([^;]+)/;
1996: $state = "log";
1997: $log = '';
1998: next;
1999: }
3.53 knu 2000: elsif ($rev eq '' && /^revision (.*)$/) {
3.1 knu 2001: $rev = $1;
2002: next;
2003: }
2004: else {
3.36 knu 2005: $log .= $_;
3.1 knu 2006: }
2007: }
3.32 knu 2008: if (/$LOG_FILESEPARATOR/o) {
3.1 knu 2009: $state = "start";
2010: next;
2011: }
2012: }
2013: if ($. == 0) {
3.12 knu 2014: fatal("500 Internal Error",
3.59 knu 2015: "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 2016: }
2017: close($fh);
2018: }
2019:
3.12 knu 2020: sub readLog($;$) {
3.1 knu 2021: my($fullname,$revision) = @_;
2022: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2023: my $fh = do {local(*FH);};
2024:
2025: if (defined($revision)) {
2026: $revision = "-r$revision";
2027: }
2028: else {
2029: $revision = "";
2030: }
2031:
2032: undef %symrev;
2033: undef %revsym;
2034: undef @allrevisions;
2035: undef %date;
2036: undef %author;
2037: undef %state;
2038: undef %difflines;
2039: undef %log;
1.12 fenner 2040:
2041: print("Going to rlog '$fullname'\n") if ($verbose);
3.1 knu 2042: if (! open($fh, "-|")) { # child
3.58 knu 2043: if ($revision ne '') {
2044: exec($CMD{rlog}, $revision, $fullname);
2045: }
2046: else {
2047: exec($CMD{rlog}, $fullname);
2048: }
1.44 knu 2049: }
3.1 knu 2050: while (<$fh>) {
1.1 jfieber 2051: print if ($verbose);
2052: if ($symnames) {
2053: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2054: $symrev{$1} = $2;
3.1 knu 2055: }
2056: else {
1.1 jfieber 2057: $symnames = 0;
2058: }
3.1 knu 2059: }
2060: elsif (/^head:\s+([\d\.]+)/) {
2061: $head = $1;
2062: }
2063: elsif (/^branch:\s+([\d\.]+)/) {
2064: $curbranch = $1;
2065: }
2066: elsif (/^symbolic names/) {
1.1 jfieber 2067: $symnames = 1;
3.1 knu 2068: }
2069: elsif (/^-----/) {
1.1 jfieber 2070: last;
2071: }
2072: }
3.1 knu 2073: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7 fenner 2074:
1.1 jfieber 2075: # each log entry is of the form:
2076: # ----------------------------
2077: # revision 3.7.1.1
2078: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2079: # log info
2080: # ----------------------------
2081: logentry:
3.32 knu 2082: while (!/$LOG_FILESEPARATOR/o) {
3.1 knu 2083: $_ = <$fh>;
1.12 fenner 2084: last logentry if (!defined($_)); # EOF
1.1 jfieber 2085: print "R:", $_ if ($verbose);
2086: if (/^revision ([\d\.]+)/) {
2087: $rev = $1;
3.1 knu 2088: unshift(@allrevisions,$rev);
2089: }
3.32 knu 2090: elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
1.1 jfieber 2091: next logentry;
3.1 knu 2092: }
2093: else {
1.12 fenner 2094: # The rlog output is syntactically ambiguous. We must
2095: # have guessed wrong about where the end of the last log
2096: # message was.
2097: # Since this is likely to happen when people put rlog output
2098: # in their commit messages, don't even bother keeping
2099: # these lines since we don't know what revision they go with
2100: # any more.
2101: next logentry;
2102: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 2103: }
3.1 knu 2104: $_ = <$fh>;
1.1 jfieber 2105: print "D:", $_ if ($verbose);
3.1 knu 2106: 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+-]+))?|) {
2107: my $yr = $1;
2108: # damn 2-digit year routines :-)
2109: if ($yr > 100) {
2110: $yr -= 1900;
2111: }
2112: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 2113: $author{$rev} = $7;
1.9 fenner 2114: $state{$rev} = $8;
3.1 knu 2115: $difflines{$rev} = $10;
2116: }
2117: else {
1.1 jfieber 2118: &fatal("500 Internal Error", "Error parsing RCS output: $_");
2119: }
2120: line:
3.1 knu 2121: while (<$fh>) {
1.1 jfieber 2122: print "L:", $_ if ($verbose);
2123: next line if (/^branches:\s/);
3.32 knu 2124: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
1.1 jfieber 2125: $log{$rev} .= $_;
2126: }
2127: print "E:", $_ if ($verbose);
2128: }
3.1 knu 2129: close($fh);
1.1 jfieber 2130: print "Done reading RCS file\n" if ($verbose);
3.1 knu 2131:
2132: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
2133: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
2134:
1.1 jfieber 2135: #
2136: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 2137: # branch, unless there is a branch tag in the RCS file in which case it's the
2138: # highest revision on that branch. Find it by looking through @revorder; it
2139: # is the first commit listed on the appropriate branch.
3.1 knu 2140: # This is not neccesary the same revision as marked as head in the RCS file.
2141: my $headrev = $curbranch || "1";
3.45 knu 2142: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
3.1 knu 2143: foreach $rev (@revorder) {
2144: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2145: $symrev{"HEAD"} = $rev;
3.41 knu 2146: last;
1.1 jfieber 2147: }
2148: }
3.1 knu 2149: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2150: if (!defined($symrev{"HEAD"}));
1.1 jfieber 2151: print "Done finding HEAD\n" if ($verbose);
2152: #
2153: # Now that we know all of the revision numbers, we can associate
2154: # absolute revision numbers with all of the symbolic names, and
2155: # pass them to the form so that the same association doesn't have
2156: # to be built then.
2157: #
3.1 knu 2158: undef @branchnames;
2159: undef %branchpoint;
2160: undef $sel;
2161:
2162: foreach (reverse sort keys %symrev) {
1.1 jfieber 2163: $rev = $symrev{$_};
3.45 knu 2164: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
1.7 fenner 2165: push(@branchnames, $_);
1.1 jfieber 2166: #
2167: # A revision number of A.B.0.D really translates into
2168: # "the highest current revision on branch A.B.D".
2169: #
2170: # If there is no branch A.B.D, then it translates into
2171: # the head A.B .
2172: #
3.1 knu 2173: # This reasoning also applies to the main branch A.B,
2174: # with the branch number 0.A, with the exception that
2175: # it has no head to translate to if there is nothing on
2176: # the branch, but I guess this can never happen?
3.38 knu 2177: #
3.45 knu 2178: # (the code below gracefully forgets about the branch
2179: # if it should happen)
3.1 knu 2180: #
2181: $head = defined($2) ? $2 : "";
1.1 jfieber 2182: $branch = $3;
3.1 knu 2183: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2184: my $regex;
3.41 knu 2185: $regex = quotemeta $branchrev;
1.1 jfieber 2186: $rev = $head;
2187:
3.1 knu 2188: foreach my $r (@revorder) {
2189: if ($r =~ /^${regex}\b/) {
2190: $rev = $branchrev;
3.41 knu 2191: last;
1.1 jfieber 2192: }
2193: }
3.1 knu 2194: next if ($rev eq "");
2195: if ($rev ne $head && $head ne "") {
1.8 fenner 2196: $branchpoint{$head} .= ", " if ($branchpoint{$head});
2197: $branchpoint{$head} .= $_;
2198: }
1.1 jfieber 2199: }
3.1 knu 2200: $revsym{$rev} .= ", " if ($revsym{$rev});
2201: $revsym{$rev} .= $_;
1.1 jfieber 2202: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
2203: }
2204: print "Done associating revisions with branches\n" if ($verbose);
3.1 knu 2205:
2206: my ($onlyonbranch, $onlybranchpoint);
2207: if ($onlyonbranch = $input{'only_with_tag'}) {
2208: $onlyonbranch = $symrev{$onlyonbranch};
3.45 knu 2209: if ($onlyonbranch =~ s/\b0\.//) {
3.1 knu 2210: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2211: }
2212: else {
2213: $onlybranchpoint = $onlyonbranch;
2214: }
2215: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2216: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
2217: }
1.8 fenner 2218: }
1.1 jfieber 2219:
3.1 knu 2220: undef @revisions;
2221:
2222: foreach (@allrevisions) {
1.7 fenner 2223: ($br = $_) =~ s/\.\d+$//;
3.1 knu 2224: ($brp = $br) =~ s/\.\d+$//;
1.7 fenner 2225: next if ($onlyonbranch && $br ne $onlyonbranch &&
3.1 knu 2226: $_ ne $onlybranchpoint);
2227: unshift(@revisions,$_);
2228: }
2229:
2230: if ($logsort eq "date") {
2231: # Sort the revisions in commit order an secondary sort on revision
2232: # (secondary sort needed for imported sources, or the first main
2233: # revision gets before the same revision on the 1.1.1 branch)
2234: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
2235: }
2236: elsif ($logsort eq "rev") {
2237: # Sort the revisions in revision order, highest first
2238: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
2239: }
2240: else {
2241: # No sorting. Present in the same order as rlog / cvs log
2242: @revdisplayorder = @revisions;
2243: }
2244:
2245: }
2246:
3.37 knu 2247: sub printDiffLinks($$) {
2248: my($text, $url) = @_;
2249: my @extra;
2250:
2251: local $_;
2252: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2253: my $f = $_ eq $defaultDiffType ? '' : $_;
2254:
2255: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2256: }
2257:
2258: print &link($text, $url), ' (', join(', ', @extra), ')';
2259: }
2260:
3.1 knu 2261: sub printLog($;$) {
2262: my ($link, $br, $brp);
2263: ($_,$link) = @_;
2264: ($br = $_) =~ s/\.\d+$//;
2265: ($brp = $br) =~ s/\.?\d+$//;
2266: my ($isDead, $prev);
2267:
2268: $link = 1 if (!defined($link));
2269: $isDead = ($state{$_} eq "dead");
2270:
2271: if ($link && !$isDead) {
2272: my ($filename);
2273: ($filename = $where) =~ s/^.*\///;
2274: my ($fileurl) = urlencode($filename);
1.4 fenner 2275: print "<a NAME=\"rev$_\"></a>";
3.1 knu 2276: if (defined($revsym{$_})) {
2277: foreach my $sym (split(", ", $revsym{$_})) {
2278: print "<a NAME=\"$sym\"></a>";
2279: }
1.4 fenner 2280: }
3.1 knu 2281: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
2282: foreach my $sym (split(", ", $revsym{$br})) {
1.4 fenner 2283: print "<a NAME=\"$sym\"></a>";
2284: }
3.1 knu 2285: $nameprinted{$br} = 1;
1.4 fenner 2286: }
3.1 knu 2287: print "\n Revision ";
2288: &download_link($fileurl, $_, $_,
3.35 knu 2289: $defaultViewable ? "text/x-cvsweb-markup" : undef);
3.1 knu 2290: if ($defaultViewable) {
3.35 knu 2291: print " / (";
2292: &download_link($fileurl, $_, "download", $mimetype);
2293: print ")";
3.1 knu 2294: }
2295: if (not $defaultTextPlain) {
3.35 knu 2296: print " / (";
2297: &download_link($fileurl, $_, "as text", "text/plain");
2298: print ")";
3.1 knu 2299: }
2300: if (!$defaultViewable) {
3.35 knu 2301: print " / (";
2302: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2303: print ")";
3.1 knu 2304: }
2305: if ($allow_annotate) {
3.35 knu 2306: print " - ";
2307: print &link('annotate',
2308: sprintf('%s/%s?annotate=%s%s',
2309: $scriptname,
2310: urlencode($where),
2311: $_,
2312: $barequery));
3.1 knu 2313: }
2314: # Plus a select link if enabled, and this version isn't selected
2315: if ($allow_version_select) {
2316: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
3.35 knu 2317: print " - ";
2318: print &link('[select for diffs]',
2319: sprintf('%s?r1=%s%s',
2320: $scriptwhere,
2321: $_,
2322: $barequery));
3.1 knu 2323: }
2324: else {
2325: print " - <b>[selected]</b>";
2326: }
2327: }
2328: }
2329: else {
2330: print "Revision <B>$_</B>";
2331: }
2332: if (/^1\.1\.1\.\d+$/) {
2333: print " <i>(vendor branch)</i>";
2334: }
2335: if (defined @mytz) {
2336: my ($est) = $mytz[(localtime($date{$_}))[8]];
3.36 knu 2337: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
3.1 knu 2338: } else {
3.36 knu 2339: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
3.1 knu 2340: }
3.36 knu 2341: print readableTime(time() - $date{$_},1), " ago)";
3.1 knu 2342: print " by ";
3.36 knu 2343: print "<i>", $author{$_}, "</i>\n";
3.1 knu 2344: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
2345: if ($revsym{$br});
2346: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
2347: if ($revsym{$_});
2348: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
2349: if ($branchpoint{$_});
2350: # Find the previous revision
2351: my @prevrev = split(/\./, $_);
2352: do {
2353: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 2354: # If it was X.Y.Z.1, just make it X.Y
3.1 knu 2355: pop(@prevrev);
2356: pop(@prevrev);
2357: }
2358: $prev = join(".", @prevrev);
2359: } until (defined($date{$prev}) || $prev eq "");
2360: if ($prev ne "") {
2361: if ($difflines{$_}) {
2362: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
2363: }
2364: }
2365: if ($isDead) {
2366: print "<BR><B><I>FILE REMOVED</I></B>\n";
2367: }
2368: elsif ($link) {
2369: my %diffrev = ();
2370: $diffrev{$_} = 1;
2371: $diffrev{""} = 1;
2372: print "<BR>Diff";
2373: #
2374: # Offer diff to previous revision
2375: if ($prev) {
2376: $diffrev{$prev} = 1;
3.35 knu 2377:
2378: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2379: $scriptwhere,
2380: $prev,
2381: $_,
2382: $barequery);
2383:
2384: print " to previous ";
3.37 knu 2385: printDiffLinks($prev, $url);
3.1 knu 2386: }
2387: #
2388: # Plus, if it's on a branch, and it's not a vendor branch,
2389: # offer a diff with the branch point.
2390: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
3.35 knu 2391: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2392: $scriptwhere,
2393: $brp,
2394: $_,
2395: $barequery);
2396:
2397: print " to branchpoint ";
3.37 knu 2398: printDiffLinks($brp, $url);
1.1 jfieber 2399: }
3.1 knu 2400: #
2401: # Plus, if it's on a branch, and it's not a vendor branch,
2402: # offer to diff with the next revision of the higher branch.
2403: # (e.g. change gets committed and then brought
2404: # over to -stable)
2405: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2406: my ($i,$nextmain);
2407: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
3.53 knu 2408: my @tmp2 = split(/\./, $_);
3.1 knu 2409: for ($nextmain = ""; $i > 0; $i--) {
3.53 knu 2410: my $next = $revorder[$i-1];
2411: my @tmp1 = split(/\./, $next);
2412: if (@tmp1 < @tmp2) {
3.1 knu 2413: $nextmain = $next;
2414: last;
2415: }
2416: # Only the highest version on a branch should have
2417: # a diff for the "next main".
3.53 knu 2418: last if (@tmp1 - 1 <= @tmp2 &&
2419: join(".",@tmp1[0..$#tmp1-1]) eq join(".",@tmp2[0..$#tmp1-1]));
3.1 knu 2420: }
2421: if (!defined($diffrev{$nextmain})) {
2422: $diffrev{$nextmain} = 1;
3.35 knu 2423:
2424: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2425: $scriptwhere,
2426: $nextmain,
2427: $_,
2428: $barequery);
2429:
2430: print " next main ";
3.37 knu 2431: printDiffLinks($nextmain, $url);
1.1 jfieber 2432: }
2433: }
3.1 knu 2434: # Plus if user has selected only r1, then present a link
2435: # to make a diff to that revision
2436: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2437: $diffrev{$input{"r1"}} = 1;
3.35 knu 2438:
2439: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2440: $scriptwhere,
2441: $input{'r1'},
2442: $_,
2443: $barequery);
2444:
2445: print " to selected ";
3.37 knu 2446: printDiffLinks($input{'r1'}, $url);
1.9 fenner 2447: }
1.1 jfieber 2448: }
3.1 knu 2449: print "<PRE>\n";
2450: print &htmlify($log{$_}, 1);
2451: print "</PRE>\n";
2452: }
2453:
3.12 knu 2454: sub doLog($) {
3.1 knu 2455: my($fullname) = @_;
2456: my ($diffrev, $upwhere, $filename, $backurl);
3.12 knu 2457:
3.1 knu 2458: readLog($fullname);
2459:
2460: html_header("CVS log for $where");
2461: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2462: ($filename = $where) =~ s|^.*/||;
2463: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2464: print &link($backicon, "$backurl#$filename"),
3.35 knu 2465: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
2466: print &link('Request diff between arbitrary revisions', '#diff');
2467: print '<HR NOSHADE>';
2468:
3.1 knu 2469: if ($curbranch) {
3.3 knu 2470: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
3.1 knu 2471: }
2472: else {
2473: print "No default branch";
2474: }
2475: print "<BR>\n";
2476: if ($input{only_with_tag}) {
2477: print "Current tag: $input{only_with_tag}<BR>\n";
2478: }
2479:
2480: undef %nameprinted;
2481:
2482: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2483: print "<HR size=1 NOSHADE>";
2484: printLog($revdisplayorder[$i]);
2485: }
2486:
2487: print "<HR NOSHADE>";
1.1 jfieber 2488: print "<A NAME=diff>\n";
2489: print "This form allows you to request diff's between any two\n";
2490: print "revisions of a file. You may select a symbolic revision\n";
2491: print "name using the selection box or you may type in a numeric\n";
2492: print "name using the type-in text box.\n";
2493: print "</A><P>\n";
3.1 knu 2494: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2495: foreach (@stickyvars) {
3.35 knu 2496: printf('<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">', $_, $input{$_})
3.1 knu 2497: if (defined($input{$_})
3.23 knu 2498: && ((!defined($DEFAULTVALUE{$_})
2499: || $input{$_} ne $DEFAULTVALUE{$_})
2500: && $input{$_} ne ""));
3.1 knu 2501: }
3.21 knu 2502: print "<TABLE><TR>\n";
2503: print "<TD align=right>Diffs between \n";
1.1 jfieber 2504: print "<SELECT NAME=\"r1\">\n";
2505: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2506: print $sel;
2507: print "</SELECT>\n";
3.1 knu 2508: $diffrev = $revdisplayorder[$#revdisplayorder];
2509: $diffrev = $input{"r1"} if (defined($input{"r1"}));
3.21 knu 2510: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
2511: print "<TD><BR></TD></TR>\n";
2512: print "<TR><TD align=right>and \n";
1.1 jfieber 2513: print "<SELECT NAME=\"r2\">\n";
2514: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2515: print $sel;
2516: print "</SELECT>\n";
3.1 knu 2517: $diffrev = $revdisplayorder[0];
2518: $diffrev = $input{"r2"} if (defined($input{"r2"}));
3.21 knu 2519: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
2520: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Get Diffs \"></TD>\n";
1.1 jfieber 2521: print "</FORM>\n";
3.21 knu 2522: print "</TR></TABLE>\n";
1.7 fenner 2523: print "<HR noshade>\n";
3.21 knu 2524: print "<TABLE>";
2525: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
3.37 knu 2526: print "<TR><TD align=right>Preferred Diff type:</TD>";
2527: print "<TD>";
3.21 knu 2528: printDiffSelect($use_java_script);
2529: print "</TD><TD></TD></TR>\n";
3.1 knu 2530: if (@branchnames) {
3.21 knu 2531: print "<TR><TD align=right>View only Branch:</TD>";
2532: print "<TD>";
3.1 knu 2533: print "<A name=branch></A>\n";
2534: print "<SELECT NAME=\"only_with_tag\"";
2535: print " onchange=\"submit()\"" if ($use_java_script);
2536: print ">\n";
2537: print "<OPTION VALUE=\"\"";
2538: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2539: $input{"only_with_tag"} eq "");
2540: print ">Show all branches\n";
2541: foreach (reverse sort @branchnames) {
1.9 fenner 2542: print "<OPTION";
3.1 knu 2543: print " SELECTED" if (defined($input{"only_with_tag"})
2544: && $input{"only_with_tag"} eq $_);
1.9 fenner 2545: print ">${_}\n";
3.1 knu 2546: }
3.21 knu 2547: print "</SELECT></TD><TD></TD></TR>\n";
1.7 fenner 2548: }
3.1 knu 2549: foreach (@stickyvars) {
3.21 knu 2550: next if ($_ eq "f");
3.1 knu 2551: next if ($_ eq "only_with_tag");
2552: next if ($_ eq "logsort");
2553: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
3.23 knu 2554: if (defined($input{$_})
2555: && (!defined($DEFAULTVALUE{$_})
2556: || $input{$_} ne $DEFAULTVALUE{$_})
3.1 knu 2557: && $input{$_} ne "");
2558: }
3.21 knu 2559: print "<TR><TD align=right>";
2560: print "<A name=logsort></A>\n";
2561: print "Sort log by:</TD>";
3.37 knu 2562: print "<TD>";
2563: printLogSortSelect($use_java_script);
2564: print "</TD>";
3.21 knu 2565: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Set \"></TD>";
1.7 fenner 2566: print "</FORM>\n";
3.21 knu 2567: print "</TR></TABLE>";
1.2 jfieber 2568: print &html_footer;
1.1 jfieber 2569: print "</BODY></HTML>\n";
1.10 wosch 2570: }
2571:
3.12 knu 2572: sub flush_diff_rows($$$$) {
3.1 knu 2573: my $j;
2574: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2575: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2576: for ($j = 0 ; $j < $leftRow; $j++) {
2577: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2578: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2579: }
2580: }
2581: elsif ($state eq "PreChange") { # state eq "PreChange"
2582: # we got removes with subsequent adds
2583: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2584: print "<tr>";
2585: if ($j < $leftRow) {
2586: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2587: }
2588: else {
2589: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2590: }
2591: if ($j < $rightRow) {
2592: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2593: }
2594: else {
2595: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2596: }
2597: print "</tr>\n";
2598: }
2599: }
2600: }
2601:
2602: ##
2603: # Function to generate Human readable diff-files
2604: # human_readable_diff(String revision_to_return_to);
2605: ##
2606: sub human_readable_diff($){
3.24 knu 2607: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
3.1 knu 2608: my ($fh, $rev) = @_;
2609: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2610: my (@rightCol, @leftCol);
2611:
2612: ($where_nd = $where) =~ s/.diff$//;
2613: ($filename = $where_nd) =~ s/^.*\///;
2614: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2615: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2616:
3.12 knu 2617: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
3.1 knu 2618:
2619: # Read header to pick up read revision and date, if possible
2620: while (<$fh>) {
2621: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2622: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2623: last if (/^\+\+\+ /);
2624: }
2625: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2626: $rev1 = $r1r;
2627: $date1 = $r1d;
2628: }
2629: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2630: $rev2 = $r2r;
2631: $date2 = $r2d;
2632: }
3.12 knu 2633:
3.36 knu 2634: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
2635: "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n",
2636: "<tr bgcolor=\"#ffffff\">\n",
2637: "<th width=\"50%\" valign=TOP>",
2638: "version $rev1";
3.1 knu 2639: print ", $date1" if (defined($date1));
2640: print "<br>Tag: $sym1\n" if ($sym1);
3.36 knu 2641: print "</th>\n",
2642: "<th width=\"50%\" valign=TOP>",
2643: "version $rev2";
3.1 knu 2644: print ", $date2" if (defined($date2));
2645: print "<br>Tag: $sym2\n" if ($sym1);
2646: print "</th>\n";
2647:
3.66 knu 2648: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\"><tt>";
2649: my $fe = "</tt></font>";
3.1 knu 2650:
2651: my $leftRow = 0;
2652: my $rightRow = 0;
2653: my ($oldline, $newline, $funname, $diffcode, $rest);
2654:
2655: # Process diff text
2656: # The diffrows are could make excellent use of
2657: # cascading style sheets because we've to set the
2658: # font and color for each row. anyone ...?
2659: ####
3.24 knu 2660:
2661: # prefetch several lines
2662: my @buf = head($fh);
2663:
2664: my %d = scan_directives(@buf);
2665:
2666: while (@buf || !eof($fh)) {
2667: $difftxt = @buf ? shift @buf : <$fh>;
3.12 knu 2668:
3.1 knu 2669: if ($difftxt =~ /^@@/) {
2670: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
3.74 ! knu 2671: $funname = htmlquote($funname);
3.1 knu 2672: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2673: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2674: print " <font size=-1>$funname</font></td></tr></table>";
2675: print "</td><td width=\"50%\">";
2676: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2677: print " <font size=-1>$funname</font></td></tr></table>";
2678: print "</td>\n";
2679: $state = "dump";
2680: $leftRow = 0;
2681: $rightRow = 0;
2682: }
2683: else {
2684: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
3.24 knu 2685: $_ = spacedHtmlText($rest, $d{'tabstop'});
3.1 knu 2686:
2687: # Add fontface, size
2688: $_ = "$fs $_$fe";
3.12 knu 2689:
3.1 knu 2690: #########
2691: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2692: # in order to get some nice 'ediff'-mode output
2693: # states:
2694: # "dump" - just dump the value
2695: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2696: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2697: ##########
2698:
2699: if ($diffcode eq '+') {
2700: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2701: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2702: }
2703: else { # we got minus before
2704: $state = "PreChange";
2705: $rightCol[$rightRow++] = $_;
2706: }
3.12 knu 2707: }
3.1 knu 2708: elsif ($diffcode eq '-') {
2709: $state = "PreChangeRemove";
2710: $leftCol[$leftRow++] = $_;
2711: }
2712: else { # empty diffcode
2713: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2714: print "<tr><td>$_</td><td>$_</td></tr>\n";
2715: $state = "dump";
2716: $leftRow = 0;
2717: $rightRow = 0;
2718: }
2719: }
2720: }
2721: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2722:
2723: # state is empty if we didn't have any change
2724: if (!$state) {
2725: print "<tr><td colspan=2> </td></tr>";
2726: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2727: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2728: }
2729: print "</table>";
2730: close($fh);
2731:
2732: print "<br><hr noshade width=\"100%\">\n";
2733:
2734: print "<table border=0>";
2735:
2736: print "<tr><td>";
2737: # print legend
2738: print "<table border=1><tr><td>";
2739: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2740: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2741: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2742: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2743: print "</table></td></tr></table>\n";
2744:
2745: print "<td>";
2746: # Print format selector
2747: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2748: foreach my $var (keys %input) {
2749: next if ($var eq "f");
2750: next if (defined($DEFAULTVALUE{$var})
2751: && $DEFAULTVALUE{$var} eq $input{$var});
2752: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2753: urlencode($input{$var}),"\">\n";
2754: }
2755: printDiffSelect($use_java_script);
2756: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2757: print "</FORM>\n";
2758: print "</td>";
2759:
2760: print "</tr></table>";
2761: }
2762:
3.12 knu 2763: sub navigateHeader($$$$$) {
3.1 knu 2764: my ($swhere,$path,$filename,$rev,$title) = @_;
2765: $swhere = "" if ($swhere eq $scriptwhere);
3.72 knu 2766: $swhere = './' . urlencode($filename) if ($swhere eq "");
3.64 knu 2767:
2768: print <<EOF;
2769: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2770: <HTML>
2771: <HEAD>
2772: <META name="robots" content="nofollow">
2773: <!-- knu-cvsweb $cvsweb_revision -->
2774: <TITLE>$path$filename - $title - $rev</TITLE></HEAD>
2775: $body_tag_for_src
2776: <table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="$navigationHeaderColor">
2777: <tr valign=bottom><td>
2778: EOF
2779:
3.35 knu 2780: print &link($backicon, "$swhere$query#rev$rev");
3.70 knu 2781: print "<b>Return to ", &link($filename,"$swhere$query#rev$rev")," CVS log";
3.1 knu 2782: print "</b> $fileicon</td>";
3.12 knu 2783:
3.1 knu 2784: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2785: print "</tr></table>";
2786: }
2787:
3.12 knu 2788: sub plural_write($$) {
3.1 knu 2789: my ($num,$text) = @_;
2790: if ($num != 1) {
3.36 knu 2791: $text .= "s";
3.1 knu 2792: }
2793: if ($num > 0) {
3.36 knu 2794: return join(' ', $num, $text);
3.1 knu 2795: }
2796: else {
2797: return "";
2798: }
2799: }
2800:
2801: ##
2802: # print readable timestamp in terms of
2803: # '..time ago'
2804: # H. Zeller <zeller@think.de>
2805: ##
3.12 knu 2806: sub readableTime($$) {
3.1 knu 2807: my ($i, $break, $retval);
2808: my ($secs,$long) = @_;
2809:
2810: # this function works correct for time >= 2 seconds
2811: if ($secs < 2) {
2812: return "very little time";
2813: }
2814:
2815: my %desc = (1 , 'second',
2816: 60, 'minute',
2817: 3600, 'hour',
2818: 86400, 'day',
2819: 604800, 'week',
2820: 2628000, 'month',
2821: 31536000, 'year');
2822: my @breaks = sort {$a <=> $b} keys %desc;
2823: $i = 0;
3.12 knu 2824: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3.1 knu 2825: $i++;
2826: }
2827: $i--;
2828: $break = $breaks[$i];
3.3 knu 2829: $retval = plural_write(int ($secs / $break), $desc{$break});
3.1 knu 2830:
2831: if ($long == 1 && $i > 0) {
2832: my $rest = $secs % $break;
2833: $i--;
2834: $break = $breaks[$i];
3.12 knu 2835: my $resttime = plural_write(int ($rest / $break),
3.3 knu 2836: $desc{$break});
3.1 knu 2837: if ($resttime) {
3.36 knu 2838: $retval .= ", $resttime";
3.1 knu 2839: }
2840: }
2841:
2842: return $retval;
2843: }
2844:
2845: ##
2846: # clickablePath(String pathname, boolean last_item_clickable)
2847: #
2848: # returns a html-ified path whereas each directory is a link for
2849: # faster navigation. last_item_clickable controls whether the
2850: # basename (last directory/file) is a link as well
2851: ##
2852: sub clickablePath($$) {
3.12 knu 2853: my ($pathname,$clickLast) = @_;
3.1 knu 2854: my $retval = '';
3.12 knu 2855:
3.1 knu 2856: if ($pathname eq '/') {
2857: # this should never happen - chooseCVSRoot() is
2858: # intended to do this
2859: $retval = "[$cvstree]";
2860: }
2861: else {
3.35 knu 2862: $retval .= ' ' . &link("[$cvstree]", sprintf('%s/%s#dirlist',
2863: $scriptname,
2864: $query));
3.1 knu 2865: my $wherepath = '';
2866: my ($lastslash) = $pathname =~ m|/$|;
2867: foreach (split(/\//, $pathname)) {
3.36 knu 2868: $retval .= " / ";
2869: $wherepath .= "/$_";
3.1 knu 2870: my ($last) = "$wherepath/" eq "/$pathname"
3.3 knu 2871: || $wherepath eq "/$pathname";
3.1 knu 2872: if ($clickLast || !$last) {
3.35 knu 2873: $retval .= &link($_, join('',
2874: $scriptname,
2875: urlencode($wherepath),
2876: (!$last || $lastslash ? '/' : ''),
2877: $query,
2878: (!$last || $lastslash ? "#dirlist" : "")));
3.1 knu 2879: }
2880: else { # do not make a link to the current dir
3.35 knu 2881: $retval .= $_;
3.1 knu 2882: }
2883: }
2884: }
2885: return $retval;
2886: }
2887:
2888: sub chooseCVSRoot() {
3.57 knu 2889: if (2 <= @CVSROOT) {
3.1 knu 2890: my ($k);
2891: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2892: foreach $k (keys %input) {
3.12 knu 2893: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
3.1 knu 2894: if ($input{$k}) && ($k ne "cvsroot");
2895: }
2896: # Form-Elements look wierd in Netscape if the background
2897: # isn't gray and the form elements are not placed
2898: # within a table ...
2899: print "<table><tr>";
2900: print "<td>CVS Root:</td>";
2901: print "<td>\n<select name=\"cvsroot\"";
2902: print " onchange=\"submit()\"" if ($use_java_script);
2903: print ">\n";
3.57 knu 2904: foreach $k (@CVSROOT) {
3.1 knu 2905: print "<option value=\"$k\"";
3.3 knu 2906: print " selected" if ($k eq $cvstree);
3.36 knu 2907: print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k), "</option>\n";
3.1 knu 2908: }
2909: print "</select>\n</td>";
3.57 knu 2910: print "<td>";
3.1 knu 2911: }
2912: else {
2913: # no choice ..
2914: print "CVS Root: <b>[$cvstree]</b>";
2915: }
3.57 knu 2916:
2917: print " Module path or alias:\n";
2918: print "<INPUT TYPE=TEXT NAME=\"path\" VALUE=\"\" SIZE=15>\n";
2919: print "<input type=submit value=\"Go\">";
2920:
2921: if (2 <= @CVSROOT) {
2922: print "</td></tr></table></form>";
2923: }
3.1 knu 2924: }
2925:
2926: sub chooseMirror() {
2927: my ($mirror,$moremirrors);
2928: $moremirrors = 0;
2929: # This code comes from the original BSD-cvsweb
2930: # and may not be useful for your site; If you don't
2931: # set %MIRRORS this won't show up, anyway
2932: #
3.12 knu 2933: # Should perhaps exlude the current site somehow..
3.1 knu 2934: if (keys %MIRRORS) {
2935: print "\nThis cvsweb is mirrored in:\n";
2936: foreach $mirror (keys %MIRRORS) {
2937: print ", " if ($moremirrors);
3.35 knu 2938: print &link(htmlquote($mirror),$MIRRORS{$mirror});
3.1 knu 2939: $moremirrors = 1;
2940: }
2941: print "<p>\n";
2942: }
2943: }
2944:
3.12 knu 2945: sub fileSortCmp() {
3.1 knu 2946: my ($comp) = 0;
2947: my ($c,$d,$af,$bf);
2948:
2949: ($af = $a) =~ s/,v$//;
2950: ($bf = $b) =~ s/,v$//;
2951: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2952: if (defined($fileinfo{$af}));
2953: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2954: if (defined($fileinfo{$bf}));
2955:
2956: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2957: # Two files
2958: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2959: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2960: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2961: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2962: }
2963: if ($comp == 0) {
2964: # Directories first, then sorted on name if no other sort critera
2965: # available.
2966: my $ad = ((-d "$fullname/$a")?"D":"F");
2967: my $bd = ((-d "$fullname/$b")?"D":"F");
2968: ($c=$a) =~ s|.*/||;
2969: ($d=$b) =~ s|.*/||;
2970: $comp = ("$ad$c" cmp "$bd$d");
2971: }
2972: return $comp;
2973: }
2974:
2975: # make A url for downloading
3.12 knu 2976: sub download_url($$;$) {
3.1 knu 2977: my ($url,$revision,$mimetype) = @_;
2978:
3.45 knu 2979: $revision =~ s/\b0\.//;
3.1 knu 2980:
3.35 knu 2981: if (defined($checkoutMagic)
3.1 knu 2982: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
3.35 knu 2983: my $path = $where;
2984: $path =~ s|/[^/]*$|/|;
3.1 knu 2985: $url = "$scriptname/$checkoutMagic/${path}$url";
2986: }
2987: $url .= "?rev=$revision";
3.35 knu 2988: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.67 knu 2989:
3.35 knu 2990: $url;
3.1 knu 2991: }
2992:
3.12 knu 2993: # Presents a link to download the
3.1 knu 2994: # selected revision
3.12 knu 2995: sub download_link($$$;$) {
3.35 knu 2996: my ($url, $revision, $textlink, $mimetype) = @_;
2997: my ($fullurl) = download_url($url, $revision, $mimetype);
2998:
3.70 knu 2999: $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
3000:
3.46 knu 3001: printf '<A HREF="%s"', hrefquote("$fullurl$barequery");
3.35 knu 3002:
3.1 knu 3003: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
3.35 knu 3004: print ' target="cvs_checkout"';
3.1 knu 3005: # we should have
3006: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3007: # in order to allow the user to resize the window; otherwise
3008: # the user may resize the window, but on next checkout - zap -
3009: # its original (configured s. cvsweb.conf) size is back again
3010: # .. annoying (if $extern_window_(width|height) is defined)
3011: # but this if (..) solution is far from perfect
3012: # what we need to do as well is
3013: # 1) save cvswin in an invisible frame that always exists
3014: # (document.cvswin will be void on next load)
3015: # 2) on close of the cvs_checkout - window set the cvswin
3016: # variable to 'null' again - so that it will be
3017: # reopenend with the configured size
3018: # anyone a JavaScript programmer ?
3019: # .. so here without if (..):
3020: # currently, the best way is to comment out the size parameters
3021: # ($extern_window...) in cvsweb.conf.
3022: if ($use_java_script) {
3.35 knu 3023: my @attr = qw(resizeable scrollbars);
3024:
3025: push @attr, qw(status toolbar)
3026: if (defined($mimetype) && $mimetype eq "text/html");
3027:
3028: push @attr, "width=$extern_window_width"
3029: if (defined($extern_window_width));
3030:
3031: push @attr, "height=$extern_window_height"
3032: if (defined($extern_window_height));
3033:
3034: printf q` onClick="window.open('%s','cvs_checkout','%s');"`,
3.46 knu 3035: hrefquote($fullurl), join(',', @attr);
3.1 knu 3036: }
3037: }
3038: print "><b>$textlink</b></A>";
3039: }
3040:
3041: # Returns a Query string with the
3042: # specified parameter toggled
3043: sub toggleQuery($$) {
3044: my ($toggle,$value) = @_;
3045: my ($newquery,$var);
3046: my (%vars);
3047: %vars = %input;
3048: if (defined($value)) {
3049: $vars{$toggle} = $value;
3050: }
3051: else {
3052: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3053: }
3054: # Build a new query of non-default paramenters
3055: $newquery = "";
3056: foreach $var (@stickyvars) {
3057: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3058: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3059: if ($value ne $default) {
3.35 knu 3060: $newquery .= "&" if ($newquery ne "");
3.1 knu 3061: $newquery .= urlencode($var) . "=" . urlencode($value);
3062: }
3063: }
3064: if ($newquery) {
3065: return '?' . $newquery;
3066: }
3067: return "";
3068: }
3069:
3.12 knu 3070: sub urlencode($) {
3.35 knu 3071: local($_) = @_;
3072:
3073: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3074:
3.46 knu 3075: $_;
3.35 knu 3076: }
3077:
3078: sub htmlquote($) {
3079: local($_) = @_;
3080:
3081: # Special Characters; RFC 1866
3082: s/&/&/g;
3083: s/\"/"/g;
3084: s/</</g;
3085: s/>/>/g;
3086:
3087: $_;
3.1 knu 3088: }
3089:
3.36 knu 3090: sub htmlunquote($) {
3091: local($_) = @_;
3092:
3093: # Special Characters; RFC 1866
3094: s/"/\"/g;
3095: s/</</g;
3096: s/>/>/g;
3097: s/&/&/g;
3098:
3099: $_;
3100: }
3101:
3.46 knu 3102: sub hrefquote($) {
3103: local($_) = @_;
3104:
3105: y/ /+/;
3106:
3107: htmlquote($_)
3108: }
3109:
3.12 knu 3110: sub http_header(;$) {
3.1 knu 3111: my $content_type = shift || "text/html";
3.50 knu 3112:
3113: $content_type .= "; charset=$charset"
3114: if $content_type =~ m,^text/, && defined($charset) && $charset;
3115:
3.1 knu 3116: if (defined($moddate)) {
3117: if ($is_mod_perl) {
3.23 knu 3118: Apache->request->header_out("Last-Modified" => scalar gmtime($moddate) . " GMT");
3.1 knu 3119: }
3120: else {
3.36 knu 3121: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
3.1 knu 3122: }
3123: }
3124: if ($is_mod_perl) {
3125: Apache->request->content_type($content_type);
3126: }
3127: else {
3.4 knu 3128: print "Content-type: $content_type\r\n";
3.1 knu 3129: }
3130: if ($allow_compress && $maycompress) {
3.60 knu 3131: if ($has_zlib || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c"))) {
3.1 knu 3132: if ($is_mod_perl) {
3133: Apache->request->content_encoding("x-gzip");
3134: Apache->request->header_out(Vary => "Accept-Encoding");
3135: Apache->request->send_http_header;
3136: }
3137: else {
3.4 knu 3138: print "Content-encoding: x-gzip\r\n";
3139: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
3140: print "\r\n"; # Close headers
3.1 knu 3141: }
3142: $| = 1; $| = 0; # Flush header output
3.23 knu 3143: if ($has_zlib) {
3144: tie *GZIP, __PACKAGE__, \*STDOUT;
3145: }
3146: select(GZIP);
3147: $gzip_open = 1;
3.40 knu 3148: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
3.1 knu 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: }
3.59 knu 3157: 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 3158: }
3159: }
3160: else {
3161: if ($is_mod_perl) {
3162: Apache->request->send_http_header;
3163: }
3164: else {
3.4 knu 3165: print "\r\n"; # Close headers
3.1 knu 3166: }
3167: }
3168: }
3169:
3170: sub html_header($) {
3171: my ($title) = @_;
3.50 knu 3172: http_header("text/html");
3.1 knu 3173: print <<EOH;
3174: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
3175: "http://www.w3.org/TR/REC-html40/loose.dtd">
3176: <html>
3.40 knu 3177: <head>
3.43 knu 3178: <meta name="robots" content="nofollow">
3.1 knu 3179: <title>$title</title>
3.64 knu 3180: <!-- knu-cvsweb $cvsweb_revision -->
3.1 knu 3181: </head>
3182: $body_tag
3183: $logo <h1 align="center">$title</h1>
3184: EOH
3185: }
3186:
3.12 knu 3187: sub html_footer() {
3.1 knu 3188: return "<hr noshade><address>$address</address>\n";
3189: }
3190:
3.12 knu 3191: sub link_tags($) {
3.1 knu 3192: my ($tags) = @_;
3193: my ($ret) = "";
3194: my ($fileurl,$filename);
3195:
3196: ($filename = $where) =~ s/^.*\///;
3.70 knu 3197: $fileurl = './' . urlencode($filename);
3.1 knu 3198:
3199: foreach my $sym (split(", ", $tags)) {
3200: $ret .= ",\n" if ($ret ne "");
3.35 knu 3201: $ret .= &link($sym, $fileurl . toggleQuery('only_with_tag',$sym));
3.1 knu 3202: }
3.35 knu 3203: return "$ret\n";
3.1 knu 3204: }
3205:
3206: #
3207: # See if a module is listed in the config file's @HideModule list.
3208: #
3.12 knu 3209: sub forbidden_module($) {
3.1 knu 3210: my($module) = @_;
3.12 knu 3211:
3.1 knu 3212: for (my $i=0; $i < @HideModules; $i++) {
3213: return 1 if $module eq $HideModules[$i];
3214: }
3215:
3216: return 0;
3.25 knu 3217: }
3218:
3219: # Close the GZIP handle remove the tie.
3220:
3221: sub gzipclose {
3222: if ($gzip_open) {
3223: select(STDOUT);
3224: close(GZIP);
3225: untie *GZIP;
3226: $gzip_open = 0;
3227: }
3.23 knu 3228: }
3229:
3230: # implement a gzipped file handle via the Compress:Zlib compression
3231: # library.
3232:
3233: sub MAGIC1() { 0x1f }
3234: sub MAGIC2() { 0x8b }
3235: sub OSCODE() { 3 }
3236:
3237: sub TIEHANDLE {
3238: my ($class, $out) = @_;
3239: my ($d) = Compress::Zlib::deflateInit(-Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3240: -WindowBits => -Compress::Zlib::MAX_WBITS()) or return undef;
3241: my ($o) = {
3242: handle => $out,
3243: dh => $d,
3244: crc => 0,
3245: len => 0,
3246: };
3247: my ($header) = pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0,0,0,0,0,0, OSCODE);
3248: print {$o->{handle}} $header;
3249: return bless($o, $class);
3250: }
3251:
3252: sub PRINT {
3253: my ($o) = shift;
3254: my ($buf) = join(defined $, ? $, : "",@_);
3255: my ($len) = length($buf);
3256: my ($compressed, $status) = $o->{dh}->deflate($buf);
3257: print {$o->{handle}} $compressed if defined($compressed);
3258: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3259: $o->{len} += $len;
3260: return $len;
3261: }
3262:
3263: sub PRINTF {
3264: my ($o) = shift;
3265: my ($fmt) = shift;
3266: my ($buf) = sprintf($fmt, @_);
3267: my ($len) = length($buf);
3268: my ($compressed, $status) = $o->{dh}->deflate($buf);
3269: print {$o->{handle}} $compressed if defined($compressed);
3270: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3271: $o->{len} += $len;
3272: return $len;
3273: }
3274:
3275: sub WRITE {
3276: my ($o, $buf, $len, $off) = @_;
3277: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3278: print {$o->{handle}} $compressed if defined($compressed);
3279: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3280: $o->{len} += $len;
3281: return $len;
3282: }
3283:
3284: sub CLOSE {
3285: my ($o) = @_;
3286: return if !defined( $o->{dh});
3287: my ($buf) = $o->{dh}->flush();
3288: $buf .= pack("V V", $o->{crc}, $o->{len});
3289: print {$o->{handle}} $buf;
3290: undef $o->{dh};
3291: }
3292:
3293: sub DESTROY {
3294: my ($o) = @_;
3295: CLOSE($o);
1.1 jfieber 3296: }
CVSweb