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