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