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