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