Annotation of cvsweb/cvsweb.cgi, Revision 3.189
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.113 scop 6: # Bill Fenner <fenner@FreeBSD.org> (original work)
7: # extended by Henner Zeller <zeller@think.de>,
8: # Henrik Nordstrom <hno@hem.passagen.se>
9: # Ken Coar <coar@Apache.Org>
10: # Dick Balaska <dick@buckosoft.com>
11: # Akinori MUSHA <knu@FreeBSD.org>
12: # Jens-Uwe Mager <jum@helios.de>
13: # Ville Skyttä <scop@FreeBSD.org>
14: # Vassilii Khachaturov <vassilii@tarunz.org>
3.1 knu 15: #
16: # Based on:
17: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
3.5 knu 18: # http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1 jfieber 19: #
1.21 wosch 20: # Copyright (c) 1996-1998 Bill Fenner
3.1 knu 21: # (c) 1998-1999 Henner Zeller
3.109 scop 22: # (c) 1999 Henrik Nordstrom
23: # (c) 2000-2002 Akinori MUSHA
3.148 scop 24: # (c) 2002-2003 Ville Skyttä
1.21 wosch 25: # All rights reserved.
26: #
27: # Redistribution and use in source and binary forms, with or without
28: # modification, are permitted provided that the following conditions
29: # are met:
30: # 1. Redistributions of source code must retain the above copyright
31: # notice, this list of conditions and the following disclaimer.
32: # 2. Redistributions in binary form must reproduce the above copyright
33: # notice, this list of conditions and the following disclaimer in the
34: # documentation and/or other materials provided with the distribution.
35: #
36: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
40: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46: # SUCH DAMAGE.
47: #
3.87 knu 48: # $FreeBSD$
3.82 knu 49: # $Id: cvsweb.cgi,v 1.112 2001/07/24 13:03:16 hzeller Exp $
3.85 knu 50: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 3.84 2001/10/07 20:50:10 knu Exp $
1.21 wosch 51: #
3.1 knu 52: ###
53:
3.138 scop 54: require 5.005_03;
3.55 knu 55:
3.1 knu 56: use strict;
1.21 wosch 57:
3.1 knu 58: use vars qw (
3.121 scop 59: $VERSION
3.144 scop 60: $config $allow_version_select
3.120 scop 61: @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr
62: %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
63: @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS
3.129 scop 64: %alltags %fileinfo %tags @branchnames %nameprinted
3.120 scop 65: %symrev %revsym @allrevisions %date %author @revdisplayorder
3.152 scop 66: @revisions %state %difflines %log %branchpoint @revorder $keywordsubstitution
3.120 scop 67: $prcgi @prcategories $re_prcategories $prkeyword $re_prkeyword $mancgi
68: $checkoutMagic $doCheckout $scriptname $scriptwhere
69: $where $pathinfo $Browser $nofilelinks $maycompress
3.185 scop 70: @stickyvars @unsafevars %funcline_regexp
3.120 scop 71: $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
72: %input $query $barequery $sortby $bydate $byrev $byauthor
73: $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot
3.156 scop 74: $charset $output_filter
3.132 scop 75: $command_path %CMD $allow_compress $backicon $diricon $fileicon $graphicon
3.152 scop 76: $fullname $newname $cvstreedefault $logo $defaulttitle $address $binfileicon
3.131 scop 77: $long_intro $short_instruction $shortLogLen $show_author
3.129 scop 78: $tablepadding $hr_breakable $showfunc $hr_ignwhite $hr_ignkeysubst
79: $inputTextSize $mime_types $allow_annotate $allow_markup
3.120 scop 80: $allow_log_extra $allow_dir_extra $allow_source_extra
3.132 scop 81: $allow_cvsgraph $cvsgraph_config $use_java_script $open_extern_window
3.120 scop 82: $extern_window_width $extern_window_height $edit_option_form
3.144 scop 83: $show_subdir_lastmod $show_log_in_markup $preformat_in_markup
3.120 scop 84: $tabstop $state $annTable $sel $curbranch @HideModules @ForbiddenFiles
3.163 scop 85: $module $use_descriptions %descriptions @mytz $dwhere
3.139 scop 86: $use_moddate $has_zlib $gzip_open $file_list_len
3.120 scop 87: $allow_tar @tar_options @gzip_options @zip_options @cvs_options
3.166 scop 88: @annotate_options @rcsdiff_options $LOG_FILESEPARATOR $LOG_REVSEPARATOR
3.165 scop 89: $HTML_DOCTYPE $HTML_META $cssurl $CSS
3.148 scop 90: $CvsWebMarkupRE $allow_enscript @enscript_options %enscript_types
3.176 scop 91: $MimeTypes $Have_Ediff
3.1 knu 92: );
93:
3.125 scop 94: # TODO:
95: # Maybe "use filetest 'access'" on perl >= 5.6 for better -X checks.
96: #($] >= 5.006) and eval "use filetest 'access'";
97:
3.183 scop 98: use Cwd qw(abs_path cwd);
3.172 scop 99: use File::Basename qw(dirname);
3.171 scop 100: use File::Path qw(rmtree);
3.183 scop 101: use File::Spec::Functions qw(catdir catfile devnull rootdir tmpdir);
3.165 scop 102: use File::Temp qw(tempdir);
3.174 scop 103: use IPC::Run qw(start finish timeout);
3.172 scop 104: use Time::Local qw(timegm);
3.122 scop 105:
106: # -----------------------------------------------------------------------------
107:
108: # All global initialization that can be done in compile time should go to
109: # the BEGIN block. Persistent environments, such as mod_perl, will benefit
110: # from this.
111:
112: BEGIN
113: {
114: $VERSION = '3.0-dev';
115:
116: $HTML_DOCTYPE =
117: '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
118:
119: $HTML_META = <<EOM;
120: <meta name="robots" content="nofollow">
121: <meta name="generator" content="FreeBSD-CVSweb $VERSION">
122: <meta http-equiv="Content-Script-Type" content="text/javascript">
123: <meta http-equiv="Content-Style-Type" content="text/css">
124: EOM
125:
126: # Check if the zlib C library interface is installed, and if yes,
127: # we can avoid using the extra gzip process.
128: eval { require Compress::Zlib; };
129: $has_zlib = !$@;
130:
3.156 scop 131: # Use MIME::Types for MIME type lookups if it's available.
132: eval {
133: require MIME::Types;
134: $MimeTypes = MIME::Types->new();
135: };
136: $MimeTypes = undef if $@;
137:
3.176 scop 138: # Use String::Ediff for enhanced human readable diffs if available.
139: eval { require String::Ediff; };
140: $Have_Ediff = !$@;
141:
3.122 scop 142: $LOG_FILESEPARATOR = qr/^={77}$/o;
143: $LOG_REVSEPARATOR = qr/^-{28}$/o;
3.146 scop 144:
145: $CvsWebMarkupRE = qr/^text\/(x-cvsweb|vnd\.viewcvs)-markup$/io;
3.172 scop 146:
3.122 scop 147: }
148:
149: # -----------------------------------------------------------------------------
150:
3.12 knu 151: sub printDiffSelect($);
3.168 scop 152: sub printDiffSelectStickyVars();
3.37 knu 153: sub printDiffLinks($$);
154: sub printLogSortSelect($);
3.12 knu 155: sub findLastModifiedSubdirs(@);
3.36 knu 156: sub htmlify_sub(&$);
3.12 knu 157: sub htmlify($;$);
3.20 knu 158: sub spacedHtmlText($;$);
3.12 knu 159: sub link($$);
160: sub revcmp($$);
3.103 knu 161: sub fatal($$@);
3.12 knu 162: sub redirect($);
163: sub safeglob($);
3.58 knu 164: sub search_path($);
3.156 scop 165: sub getMimeType($;$);
3.24 knu 166: sub head($;$);
167: sub scan_directives(@);
3.86 knu 168: sub openOutputFilter();
3.133 scop 169: sub doAnnotate($);
3.12 knu 170: sub doCheckout($$);
3.167 scop 171: sub doEnscript($$$);
3.170 scop 172: sub doGraph();
173: sub doGraphView();
3.163 scop 174: sub cvswebMarkup($$$;$);
3.12 knu 175: sub viewable($);
176: sub doDiff($$$$$$);
177: sub getDirLogs($$@);
178: sub readLog($;$);
3.182 scop 179: sub printLog($;$$);
3.12 knu 180: sub doLog($);
181: sub flush_diff_rows($$$$);
3.144 scop 182: sub human_readable_diff($$);
3.163 scop 183: sub navigateHeader($$$$$;$);
3.12 knu 184: sub plural_write($$);
185: sub readableTime($$);
186: sub clickablePath($$);
187: sub chooseCVSRoot();
188: sub chooseMirror();
189: sub fileSortCmp();
190: sub download_url($$;$);
191: sub download_link($$$;$);
3.170 scop 192: sub graph_link($;$);
3.140 scop 193: sub toggleQuery($;$);
3.12 knu 194: sub urlencode($);
3.35 knu 195: sub htmlquote($);
3.36 knu 196: sub htmlunquote($);
3.48 knu 197: sub hrefquote($);
3.163 scop 198: sub http_header(;$$);
199: sub html_header($;$);
3.12 knu 200: sub html_footer();
201: sub link_tags($);
3.81 knu 202: sub forbidden_file($);
3.12 knu 203: sub forbidden_module($);
3.174 scop 204: sub startproc($@);
3.12 knu 205:
3.1 knu 206: ##### Start of Configuration Area ########
3.122 scop 207:
3.142 scop 208: # Get rid of unsafe environment vars. Don't do this in BEGIN...
3.173 scop 209: # This will fail with mod_perl 1.99_X for X < 08.
210: # http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=103473352222344
3.142 scop 211: delete(@ENV{qw(PATH IFS CDPATH ENV BASH_ENV)});
3.59 knu 212:
3.172 scop 213: my ($mydir) = (dirname($0) =~ /(.*)/); # untaint
3.58 knu 214:
3.12 knu 215: # == EDIT this ==
3.28 knu 216: # Locations to search for user configuration, in order:
3.165 scop 217: for (catfile($mydir, 'cvsweb.conf'), '/usr/local/etc/cvsweb/cvsweb.conf') {
218: if (-r $_) {
3.120 scop 219: $config = $_;
220: last;
221: }
3.11 knu 222: }
3.122 scop 223: undef $mydir;
3.1 knu 224:
225: # == Configuration defaults ==
226: # Defaults for configuration variables that shouldn't need
227: # to be configured..
228: $allow_version_select = 1;
3.120 scop 229: $allow_log_extra = 1;
3.1 knu 230:
231: ##### End of Configuration Area ########
232:
233: ######## Configuration variables #########
234: # These are defined to allow checking with perl -cw
3.120 scop 235:
3.80 knu 236: @CVSrepositories = @CVSROOT = %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS =
3.129 scop 237: %MTYPES = %tags = %alltags = %fileinfo = ();
3.120 scop 238:
3.129 scop 239: $cvstreedefault = $logo = $defaulttitle =
3.120 scop 240: $address = $long_intro = $short_instruction = $shortLogLen = $show_author =
3.131 scop 241: $tablepadding = $hr_breakable = $showfunc = $hr_ignwhite =
3.129 scop 242: $hr_ignkeysubst = $inputTextSize = $mime_types = $allow_annotate =
3.120 scop 243: $allow_markup = $use_java_script = $open_extern_window =
244: $extern_window_width = $extern_window_height = $edit_option_form =
3.144 scop 245: $show_subdir_lastmod = $show_log_in_markup =
3.163 scop 246: $tabstop = $use_moddate = $gzip_open = undef;
3.32 knu 247:
3.37 knu 248: @DIFFTYPES = qw(h H u c s);
249: @DIFFTYPES{@DIFFTYPES} = (
3.120 scop 250: {
251: 'descr' => 'colored',
252: 'opts' => ['-u'],
253: 'colored' => 1,
254: },
255: {
256: 'descr' => 'long colored',
257: 'opts' => ['--unified=15'],
258: 'colored' => 1,
259: },
260: {
261: 'descr' => 'unified',
262: 'opts' => ['-u'],
263: 'colored' => 0,
264: },
265: {
266: 'descr' => 'context',
267: 'opts' => ['-c'],
268: 'colored' => 0,
269: },
270: {
271: 'descr' => 'side by side',
272: 'opts' => ['--side-by-side', '--width=164'],
273: 'colored' => 0,
274: },
3.80 knu 275: );
3.37 knu 276:
277: @LOGSORTKEYS = qw(cvs date rev);
278: @LOGSORTKEYS{@LOGSORTKEYS} = (
3.120 scop 279: {'descr' => 'Not sorted',},
280: {'descr' => 'Commit date',},
281: {'descr' => 'Revision',},
3.80 knu 282: );
3.37 knu 283:
3.1 knu 284: ##### End of configuration variables #####
285:
3.120 scop 286: $checkoutMagic = "~checkout~";
287: $pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
288: $where = $pathinfo;
289: $doCheckout = ($where =~ m|^/$checkoutMagic/|);
290: $where =~ s|^/$checkoutMagic/|/|;
291: $where =~ s|^/||;
292: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
293: $scriptname =~ s|^/*|/|;
3.63 knu 294:
3.64 knu 295: # Let's workaround thttpd's stupidity..
3.63 knu 296: if ($scriptname =~ m|/$|) {
3.120 scop 297: $pathinfo .= '/';
298: my $re = quotemeta $pathinfo;
299: $scriptname =~ s/$re$//;
3.63 knu 300: }
301:
3.120 scop 302: $scriptwhere = $scriptname;
3.63 knu 303: $scriptwhere .= '/' . urlencode($where);
304: $where = '/' if ($where eq '');
3.3 knu 305:
3.188 scop 306: # In text-based browsers, it's very annoying to have two links per file;
307: # skip linking the image for them.
308:
3.120 scop 309: $Browser = $ENV{HTTP_USER_AGENT} || '';
3.187 scop 310: $is_links = ($Browser =~ m`^E?Links `);
3.80 knu 311: $is_lynx = ($Browser =~ m`^Lynx/`i);
312: $is_w3m = ($Browser =~ m`^w3m/`i);
313: $is_msie = ($Browser =~ m`MSIE`);
3.5 knu 314: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
3.3 knu 315:
3.34 knu 316: $is_textbased = ($is_links || $is_lynx || $is_w3m);
3.5 knu 317:
318: $nofilelinks = $is_textbased;
3.1 knu 319:
320: # newer browsers accept gzip content encoding
321: # and state this in a header
322: # (netscape did always but didn't state it)
323: # It has been reported that these
324: # braindamaged MS-Internet Exploders claim that they
325: # accept gzip .. but don't in fact and
326: # display garbage then :-/
3.23 knu 327: # Turn off gzip if running under mod_perl and no zlib is available,
328: # piping does not work as expected inside the server.
3.120 scop 329: $maycompress = (
330: ((defined($ENV{HTTP_ACCEPT_ENCODING})
331: && $ENV{HTTP_ACCEPT_ENCODING} =~ /gzip/)
332: || $is_mozilla3)
333: && !$is_msie
3.185 scop 334: && !(defined($ENV{MOD_PERL}) && !$has_zlib)
3.120 scop 335: );
3.1 knu 336:
337: # put here the variables we need in order
338: # to hold our state - they will be added (with
3.12 knu 339: # their current value) to any link/query string
3.1 knu 340: # you construct
3.149 scop 341: @stickyvars = qw(cvsroot hideattic ignorecase sortby logsort f only_with_tag
342: ln);
3.97 knu 343: @unsafevars = qw(logsort only_with_tag r1 r2 rev sortby tr1 tr2);
1.1 jfieber 344:
3.1 knu 345: if (-f $config) {
3.120 scop 346: do "$config"
347: or fatal("500 Internal Error",
348: 'Error in loading configuration file: %s<br><br>%s<br>',
349: $config, $@);
3.27 knu 350: } else {
3.120 scop 351: fatal("500 Internal Error",
352: 'Configuration not found. Set the variable <code>$config</code> in cvsweb.cgi to your <b>cvsweb.conf</b> configuration file first.');
3.1 knu 353: }
354:
3.183 scop 355: # Try to find a readable dir where we can cd into. Some abs_path()
356: # implementations as well as various cvs operations require such a dir to
357: # work properly.
358: {
359: local $^W = 0;
360: for my $dir (cwd(), tmpdir(), rootdir()) {
361: last if (-r $dir && chdir($dir));
362: }
363: }
364:
3.144 scop 365: $CSS = $cssurl ?
366: sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">\n",
367: htmlquote($cssurl)) : '';
368:
3.1 knu 369: undef %input;
3.3 knu 370: $query = $ENV{QUERY_STRING};
371:
3.12 knu 372: if (defined($query) && $query ne '') {
3.120 scop 373: foreach (split (/&/, $query)) {
374: y/+/ /;
375: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
376: if (/(\S+)=(.*)/) {
377: $input{$1} = $2 if ($2 ne "");
378: } else {
379: $input{$_}++;
380: }
381: }
1.7 fenner 382: }
1.10 wosch 383:
3.12 knu 384: # For backwards compability, set only_with_tag to only_on_branch if set.
3.1 knu 385: $input{only_with_tag} = $input{only_on_branch}
3.120 scop 386: if (defined($input{only_on_branch}));
3.97 knu 387:
3.154 scop 388: # Prevent cross-site scripting, untaint.
3.97 knu 389: foreach (@unsafevars) {
3.154 scop 390: if (defined($input{$_})) {
391: # Colons are needed in diffs between tags.
3.155 scop 392: if ($input{$_} =~ /^([\w\-.:]*)$/) {
3.154 scop 393: $input{$_} = $1;
394: } else {
395: fatal("500 Internal Error", 'Malformed query (%s=%s)', $_, $input{$_});
396: }
3.120 scop 397: }
3.97 knu 398: }
399:
400: if (defined($input{"content-type"})) {
3.146 scop 401: fatal('500 Internal Error', 'Unsupported content-type')
402: if ($input{"content-type"} !~ /^[-0-9A-Za-z]+\/[-0-9A-Za-z\.]+$/);
3.97 knu 403: }
1.10 wosch 404:
3.158 scop 405: #
406: # CVS roots
407: #
408: my $rootfound = 0;
409: for (my $i = 0; $i < scalar(@CVSrepositories); $i += 2) {
410: my $key = $CVSrepositories[$i];
411: my ($descr, $cvsroot) = @{$CVSrepositories[$i+1]};
412: unless (-d $cvsroot) {
413: warn("Root '$cvsroot' defined in \@CVSrepositories is not a directory, " .
414: 'entry ignored');
415: next;
416: }
417: $rootfound ||= 1;
418: $cvstreedefault = $key unless defined($cvstreedefault);
419: $CVSROOTdescr{$key} = $descr;
420: $CVSROOT{$key} = $cvsroot;
421: push(@CVSROOT, $key);
422: }
423: unless ($rootfound) {
424: fatal('500 Internal Error',
425: 'No valid CVS roots found! See <code>@CVSrepositories</code> in ' .
426: 'your configuration file (<code>%s</code>).',
427: $config);
428: }
429: undef $rootfound;
430:
431: #
432: # Default CVS root
433: #
434: if (!defined($CVSROOT{$cvstreedefault})) {
435: fatal("500 Internal Error",
436: '<code>$cvstreedefault</code> points to a repository (%s) not ' .
437: 'defined in <code>@CVSrepositories</code> in your configuration ' .
438: 'file (<code>%s</code>).',
439: $cvstreedefault,
440: $config);
441: }
442:
3.1 knu 443: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
1.10 wosch 444:
3.120 scop 445: while (my ($key, $defval) = each %DEFAULTVALUE) {
3.80 knu 446:
3.120 scop 447: # Replace not given parameters with defaults.
448: next unless (defined($defval)
3.121 scop 449: && (!defined($input{$key}) || $input{$key} eq ''));
3.120 scop 450:
451: # Empty checkboxes in forms return nothing, so we define a helper variable
452: # in these forms (copt) which indicates that we just set parameters with a
453: # checkbox.
454: if (defined($input{'copt'})) {
455:
456: # 'copt' is defined -> the result of empty input checkbox
457: # -> set to zero (disable) if default is a boolean (0|1).
458: $input{$key} = 0 if ($defval eq '0' || $defval eq '1');
459:
460: } else {
461:
462: # 'copt' isn't defined --> empty input is not the result
463: # of empty input checkbox --> set default.
464: $input{$key} = $defval;
465: }
1.10 wosch 466: }
3.12 knu 467:
3.1 knu 468: $barequery = "";
3.31 knu 469: my @barequery;
3.1 knu 470: foreach (@stickyvars) {
3.80 knu 471:
3.120 scop 472: # construct a query string with the sticky non default parameters set
473: if (defined($input{$_})
474: && $input{$_} ne ''
475: && !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_}))
476: {
477: push @barequery, join ('=', urlencode($_), urlencode($input{$_}));
478: }
3.1 knu 479: }
3.80 knu 480:
3.168 scop 481: if ($allow_enscript) {
482: push(@DIFFTYPES, qw(uc cc sc));
483: @DIFFTYPES{qw(uc cc sc)} = (
484: {
485: 'descr' => 'unified, colored',
486: 'opts' => ['-u'],
487: 'colored' => 0,
488: },
489: {
490: 'descr' => 'context, colored',
491: 'opts' => ['-c'],
492: 'colored' => 0,
493: },
494: {
495: 'descr' => 'side by side, colored',
496: 'opts' => ['--side-by-side', '--width=164'],
497: 'colored' => 0,
498: },
499: );
500: } else {
501: # No Enscript -> respect difftype, but don't offer colorization.
502: if ($input{f} && $input{f} =~ /^([ucs])c$/) {
503: $input{f} = $1;
504: }
505: }
506:
3.1 knu 507: # is there any query ?
3.31 knu 508: if (@barequery) {
3.120 scop 509: $barequery = join ('&', @barequery);
510: $query = "?$barequery";
511: $barequery = "&$barequery";
3.80 knu 512: } else {
3.120 scop 513: $query = "";
3.1 knu 514: }
3.31 knu 515: undef @barequery;
3.1 knu 516:
3.120 scop 517: if (defined($input{'path'})) {
518: redirect("$scriptname/$input{path}$query");
3.57 knu 519: }
520:
3.1 knu 521: # get actual parameters
3.144 scop 522: {
523: my $sortby = $input{sortby} || 'file';
524: $bydate = 0;
525: $byrev = 0;
526: $byauthor = 0;
527: $bylog = 0;
528: $byfile = 0;
529: if ($sortby eq 'date') {
530: $bydate = 1;
531: } elsif ($sortby eq 'rev') {
532: $byrev = 1;
533: } elsif ($sortby eq 'author') {
534: $byauthor = 1;
535: } elsif ($sortby eq 'log') {
536: $bylog = 1;
537: } else {
538: $byfile = 1;
539: }
3.1 knu 540: }
541:
3.37 knu 542: $defaultDiffType = $input{'f'};
3.1 knu 543:
3.3 knu 544: $logsort = $input{'logsort'};
3.1 knu 545:
546: # alternate CVS-Tree, configured in cvsweb.conf
547: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
3.120 scop 548: $cvstree = $input{'cvsroot'};
3.1 knu 549: } else {
3.120 scop 550: $cvstree = $cvstreedefault;
1.10 wosch 551: }
552:
3.1 knu 553: $cvsroot = $CVSROOT{$cvstree};
1.10 wosch 554:
3.1 knu 555: # create icons out of description
3.120 scop 556: foreach my $k (keys %ICONS) {
557: my ($itxt, $ipath, $iwidth, $iheight) = @{$ICONS{$k}};
558: no strict 'refs';
559: if ($ipath) {
560: ${"${k}icon"} =
561: sprintf('<img src="%s" alt="%s" border="0" width="%d" height="%d">',
3.132 scop 562: hrefquote($ipath), htmlquote($itxt), $iwidth, $iheight);
3.120 scop 563: } else {
564: ${"${k}icon"} = $itxt;
565: }
1.24 wosch 566: }
567:
3.27 knu 568: my $config_cvstree = "$config-$cvstree";
569:
3.1 knu 570: # Do some special configuration for cvstrees
3.27 knu 571: if (-f $config_cvstree) {
3.120 scop 572: do "$config_cvstree"
573: or fatal("500 Internal Error",
574: 'Error in loading configuration file: %s<br><br>%s<br>',
575: $config_cvstree, $@);
3.27 knu 576: }
3.31 knu 577: undef $config_cvstree;
3.1 knu 578:
3.120 scop 579: $re_prcategories = '(?:' . join ('|', @prcategories) . ')' if @prcategories;
580: $re_prkeyword = quotemeta($prkeyword) if defined($prkeyword);
581: $prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.24 wosch 582:
3.80 knu 583: $fullname = "$cvsroot/$where";
3.1 knu 584:
3.63 knu 585: my $rewrite = 0;
586:
587: if ($pathinfo =~ m|//|) {
3.120 scop 588: $pathinfo =~ y|/|/|s;
589: $rewrite = 1;
3.63 knu 590: }
591:
3.120 scop 592: if (-d $fullname) {
593: if ($pathinfo !~ m|/$|) {
594: $pathinfo .= '/';
595: $rewrite = 1;
596: }
597: } else {
598: if ($pathinfo =~ m|/$|) {
599: chop $pathinfo;
600: $rewrite = 1;
601: }
3.63 knu 602: }
603:
604: if ($rewrite) {
3.120 scop 605: redirect($scriptname . urlencode($pathinfo) . $query);
3.1 knu 606: }
607:
3.63 knu 608: undef $rewrite;
609:
3.1 knu 610: if (!-d $cvsroot) {
3.120 scop 611: fatal("500 Internal Error",
612: '$CVSROOT not found!<p>The server on which the CVS tree lives is probably down. Please try again in a few minutes.');
3.1 knu 613: }
614:
615: #
616: # See if the module is in our forbidden list.
617: #
618: $where =~ m:([^/]*):;
619: $module = $1;
620: if ($module && &forbidden_module($module)) {
3.120 scop 621: fatal("403 Forbidden", 'Access to %s forbidden.', $where);
3.1 knu 622: }
3.46 knu 623:
624: #
625: # Handle tarball downloads before any headers are output.
626: #
627: if ($input{tarball}) {
3.120 scop 628: fatal('403 Forbidden', 'Downloading tarballs is prohibited.')
629: unless $allow_tar;
630: my ($module) = ($where =~ m,^/?(.*),); # untaint
631: $module =~ s,/([^/]*)$,,;
632: my ($ext) = ($1 =~ /(\.tar\.gz|\.zip)$/);
633: my ($basedir) = ($module =~ m,([^/]+)$,);
634:
635: if ($basedir eq '' || $module eq '') {
636: fatal('500 Internal Error',
637: 'You cannot download the top level directory.');
638: }
639:
3.138 scop 640: my $tmpexportdir;
641: eval {
642: local $SIG{__DIE__};
3.171 scop 643: # Don't use the CLEANUP argument to tempdir() here, since we might be under
644: # mod_perl (the process runs for a long time), unlink explicitly later.
645: $tmpexportdir = tempdir('.cvsweb.XXXXXXXX', TMPDIR => 1);
3.138 scop 646: };
647: if ($@) {
648: fatal('500 Internal Error', 'Unable to make temporary directory: %s', $@);
649: }
3.120 scop 650:
651: my @fatal;
652:
653: my $tag =
654: (exists $input{only_with_tag} && length $input{only_with_tag})
655: ? $input{only_with_tag}
656: : 'HEAD';
657:
658: $tag = 'HEAD' if $tag eq 'MAIN';
659:
660: if (system($CMD{cvs},
661: @cvs_options, '-Qd', $cvsroot, 'export', '-r', $tag, '-d',
3.165 scop 662: catdir($tmpexportdir, $basedir), $module))
3.120 scop 663: {
3.141 scop 664: @fatal = ('500 Internal Error', 'cvs export failure: %s: %s', $!, $module);
3.120 scop 665: } else {
666: $| = 1; # Essential to get the buffering right.
667:
668: if ($ext eq '.tar.gz') {
669: print "Content-Type: application/x-gzip\r\n\r\n";
670:
671: system("$CMD{tar} @tar_options -cf - -C $tmpexportdir $basedir | $CMD{gzip} @gzip_options -c")
672: and @fatal =
673: ('500 Internal Error', 'tar zc failure: %s: %s', $!, $basedir);
674: } elsif ($ext eq '.zip' && $CMD{zip}) {
675: print "Content-Type: application/zip\r\n\r\n";
676:
3.186 scop 677: if (!chdir($tmpexportdir) ||
678: system($CMD{zip}, @zip_options, '-r', '-', $basedir)) {
679: @fatal = ('500 Internal Error', 'zip failure: %s: %s', $!, $basedir);
680: }
3.120 scop 681: } else {
682: @fatal = ('500 Internal Error', 'unsupported file type');
683: }
684: }
3.46 knu 685:
3.171 scop 686: # Clean up.
687: rmtree($tmpexportdir);
3.46 knu 688:
3.120 scop 689: &fatal(@fatal) if @fatal;
3.46 knu 690:
3.120 scop 691: exit;
3.46 knu 692: }
693:
3.1 knu 694: ##############################
695: # View a directory
696: ###############################
3.46 knu 697: if (-d $fullname) {
3.120 scop 698: my $dh = do { local (*DH); };
699: opendir($dh, $fullname) or fatal("404 Not Found", '%s: %s', $where, $!);
700: my @dir = readdir($dh);
701: closedir($dh);
702: my @subLevelFiles = findLastModifiedSubdirs(@dir)
703: if ($show_subdir_lastmod);
3.150 scop 704: my @unreadable = getDirLogs($cvsroot, $where, @subLevelFiles);
3.120 scop 705:
706: if ($where eq '/') {
707: html_header($defaulttitle);
708: $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
709: print $long_intro;
710: } else {
711: html_header($where);
712: print $short_instruction;
713: }
714:
3.165 scop 715: if ($use_descriptions &&
716: open(DESC, '<', catfile($cvsroot, 'CVSROOT', 'descriptions'))) {
3.120 scop 717: while (<DESC>) {
718: chomp;
719: my ($dir, $description) = /(\S+)\s+(.*)/;
720: $descriptions{$dir} = $description;
721: }
722: close(DESC);
723: }
724:
725: print "<p><a name=\"dirlist\"></a></p>\n";
726:
727: # give direct access to dirs
728: if ($where eq '/') {
729: chooseMirror();
730: chooseCVSRoot();
731: } else {
732: print "<p>Current directory: <b>", &clickablePath($where, 0), "</b></p>\n";
733:
3.153 scop 734: print "<p>Current tag: <b>", htmlquote($input{only_with_tag}), "</b></p>\n"
3.120 scop 735: if $input{only_with_tag};
736:
737: }
738:
3.177 scop 739: print "<hr>\n";
3.120 scop 740:
3.179 scop 741: my $infocols = 1;
3.131 scop 742:
3.179 scop 743: printf(<<EOF, htmlquote("Index of $where"), ($byfile ? '-sorted' : ''));
3.182 scop 744: <table class="dir" width="100%%" cellspacing="0" cellpadding="$tablepadding" summary="%s">
3.179 scop 745: <tr>
746: <th class="dir-header%s" colspan="2">
747: EOF
3.131 scop 748:
749: if ($byfile) {
750: print 'File';
751: } else {
752: print &link('File',
753: sprintf('./%s#dirlist', toggleQuery('sortby', 'file')));
754: }
755: print "</th>\n";
3.120 scop 756:
3.131 scop 757: # Do not display the other column headers if we do not have any files
758: # with revision information.
759: if (scalar(%fileinfo)) {
3.120 scop 760: $infocols++;
3.131 scop 761: printf '<th class="dir-header%s">', $byrev ? '-sorted' : '';
3.120 scop 762:
3.131 scop 763: if ($byrev) {
764: print 'Rev.';
3.120 scop 765: } else {
3.131 scop 766: print &link('Rev.',
767: sprintf('./%s#dirlist', toggleQuery('sortby', 'rev')));
3.120 scop 768: }
769: print "</th>\n";
3.131 scop 770: $infocols++;
771: printf '<th class="dir-header%s">', $bydate ? '-sorted' : '';
3.120 scop 772:
3.131 scop 773: if ($bydate) {
774: print 'Age';
775: } else {
776: print &link('Age',
777: sprintf('./%s#dirlist', toggleQuery('sortby', 'date')));
778: }
779: print "</th>\n";
3.120 scop 780:
3.131 scop 781: if ($show_author) {
3.120 scop 782: $infocols++;
3.131 scop 783: printf '<th class="dir-header%s">', $byauthor ? '-sorted' : '';
3.120 scop 784:
3.131 scop 785: if ($byauthor) {
786: print 'Author';
3.120 scop 787: } else {
3.131 scop 788: print
789: &link('Author',
790: sprintf('./%s#dirlist', toggleQuery('sortby', 'author')));
3.120 scop 791: }
792: print "</th>\n";
3.131 scop 793: }
794: $infocols++;
795: printf '<th class="dir-header%s">', $bylog ? '-sorted' : '';
3.120 scop 796:
3.131 scop 797: if ($bylog) {
798: print 'Last log entry';
799: } else {
800: print &link('Last log entry',
801: sprintf('./%s#dirlist', toggleQuery('sortby', 'log')));
3.120 scop 802: }
3.131 scop 803: print "</th>\n";
804: } elsif ($use_descriptions) {
805: print "<th class=\"dir-header\">Description</th>\n";
806: $infocols++;
3.120 scop 807: }
3.131 scop 808: print "</tr>\n";
809:
3.120 scop 810: my $dirrow = 0;
811:
812: my $i;
813: lookingforattic:
814: for ($i = 0; $i <= $#dir; $i++) {
815: if ($dir[$i] eq "Attic") {
816: last lookingforattic;
817: }
818: }
819:
820: if (!$input{'hideattic'}
821: && ($i <= $#dir)
822: && opendir($dh, $fullname . '/Attic'))
823: {
824: splice(@dir, $i, 1, grep((s|^|Attic/|, !m|/\.|), readdir($dh)));
825: closedir($dh);
826: }
827:
828: my $hideAtticToggleLink =
829: $input{'hideattic'}
830: ? ''
831: : &link('[Hide]', sprintf('./%s#dirlist', &toggleQuery('hideattic')));
832:
833: # Sort without the Attic/ pathname.
834: # place directories first
835:
836: my $attic;
837: my $url;
838: my $fileurl;
839: my $filesexists;
840: my $filesfound;
841:
842: foreach my $file (sort { &fileSortCmp } @dir) {
843:
844: next if ($file eq '.');
845:
846: # ignore CVS lock and stale NFS files
847: next if ($file =~ /^\#cvs\.|^,|^\.nfs/); # \# for XEmacs cperl-mode...
848:
849: # Check whether to show the CVSROOT path
850: next if ($input{'hidecvsroot'} && $file eq 'CVSROOT');
851:
852: # Check whether the module is in the restricted list
853: next if ($file && &forbidden_module($file));
854:
3.150 scop 855: # Is it a directory?
856: my $isdir = -d "$fullname/$file";
857:
858: # Ignore non-readable files and directories?
859: next if ($input{'hidenonreadable'} && (! -r _ || ($isdir && ! -x _)));
3.120 scop 860:
861: if ($file =~ s|^Attic/||) {
3.131 scop 862: $attic = ' (in the Attic) ' . $hideAtticToggleLink;
3.120 scop 863: } else {
864: $attic = '';
865: }
866:
3.150 scop 867: if ($file eq '..' || $isdir) {
3.120 scop 868: next if ($file eq '..' && $where eq '/');
3.152 scop 869: my ($rev, $date, $log, $author, $filename, $keywordsubst) =
870: @{$fileinfo{$file}} if (defined($fileinfo{$file}));
3.132 scop 871: printf "<tr class=\"dir-row-%s\">\n<td colspan=\"2\">",
872: ($dirrow % 2) ? 'even' : 'odd';
3.120 scop 873:
874: if ($file eq '..') {
875: $url = "../$query";
876: if ($nofilelinks) {
877: print $backicon;
878: } else {
879: print &link($backicon, $url);
880: }
881: print ' ', &link("Parent Directory", $url);
882: } else {
883: $url = './' . urlencode($file) . "/$query";
3.136 scop 884: print '<a name="', hrefquote($file), '"></a>';
3.120 scop 885:
886: if ($nofilelinks) {
887: print $diricon;
888: } else {
889: print &link($diricon, $url);
890: }
3.136 scop 891: print ' ', &link(htmlquote("$file/"), $url), $attic;
3.120 scop 892:
893: if ($file eq "Attic") {
894: print " ";
895: print &link('[Don\'t hide]',
896: sprintf('./%s#dirlist', &toggleQuery('hideattic')));
897: }
898: }
899:
900: # Show last change in dir
901: if ($filename) {
3.131 scop 902: print "</td>\n<td> </td>\n<td> ";
903:
3.120 scop 904: if ($date) {
905: print " <i>", readableTime(time() - $date, 0), "</i>";
906: }
907:
908: if ($show_author) {
3.136 scop 909: print "</td>\n<td> ", htmlquote($author);
3.120 scop 910: }
3.131 scop 911: print "</td>\n<td> ";
3.120 scop 912: $filename =~ s%^[^/]+/%%;
3.136 scop 913: print htmlquote($filename), '/', $rev, '<br>';
3.120 scop 914:
915: if ($log) {
916: print ' <span style="font-size: smaller">',
917: &htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
918: print '...' if (length($log) > 80);
919: print '</span>';
920: }
921: } else {
922: my $dwhere = ($where ne '/' ? $where : '') . $file;
923:
924: if ($use_descriptions && defined $descriptions{$dwhere}) {
3.131 scop 925: print '<td colspan="', ($infocols - 1), '"> ';
3.120 scop 926: print $descriptions{$dwhere};
927:
3.131 scop 928: } elsif ($infocols > 1) {
3.120 scop 929:
930: # close the row with the appropriate number of
931: # columns, so that the vertical seperators are visible
932: my ($cols) = $infocols;
933: while ($cols > 1) {
934: print "</td>\n<td> ";
935: $cols--;
936: }
937: }
938: }
939:
3.131 scop 940: print "</td>\n</tr>\n";
3.120 scop 941: $dirrow++;
3.131 scop 942:
3.120 scop 943: } elsif ($file =~ s/,v$//) {
944:
945: # Skip forbidden files now so we'll give no hint
946: # about their existence. This should probably have
947: # been done earlier, but it's straightforward here.
948: next if forbidden_file("$fullname/$file");
949:
950: $fileurl = ($attic ? 'Attic/' : '') . urlencode($file);
951: $url = './' . $fileurl . $query;
952: $filesexists++;
953: next if (!defined($fileinfo{$file}));
3.152 scop 954: my ($rev, $date, $log, $author, $filename, $keywordsubst) =
955: @{$fileinfo{$file}};
3.156 scop 956: my $isbinary = $keywordsubst eq 'b' ? 1 : 0;
3.120 scop 957: $filesfound++;
3.156 scop 958:
3.132 scop 959: printf "<tr class=\"dir-row-%s\">\n", ($dirrow % 2) ? 'even' : 'odd';
960: printf '<td%s>', $allow_cvsgraph ? '' : ' colspan="2"';
3.120 scop 961:
3.156 scop 962: my $icon = $isbinary ? $binfileicon : $fileicon;
3.120 scop 963: if ($nofilelinks) {
3.152 scop 964: print $icon;
3.120 scop 965: } else {
3.152 scop 966: print &link($icon, $url);
3.120 scop 967: }
968: print ' ', &link(htmlquote($file), $url), $attic;
3.132 scop 969: if ($allow_cvsgraph) {
3.182 scop 970: print '</td><td style="width: 1%; text-align: center">',
971: graph_link($fileurl);
3.132 scop 972: }
973: print "</td>\n<td width=\"30\"> ";
3.120 scop 974: download_link($fileurl, $rev, $rev,
3.156 scop 975: viewable(getMimeType($file, $isbinary)) ?
976: 'text/x-cvsweb-markup' : undef);
3.131 scop 977: print "</td>\n<td> ";
3.120 scop 978:
979: if ($date) {
980: print " <i>", readableTime(time() - $date, 0), "</i>";
981: }
982: if ($show_author) {
3.136 scop 983: print "</td>\n<td> ", htmlquote($author);
3.120 scop 984: }
3.131 scop 985: print "</td>\n<td> ";
3.120 scop 986:
987: if ($log) {
988: print ' <span style="font-size: smaller">',
989: &htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
990: print '...' if (length $log > 80);
991: print '</span>';
992: }
3.131 scop 993: print "</td>\n</tr>";
3.120 scop 994: $dirrow++;
995: }
996: print "\n";
997: }
998:
3.131 scop 999: print "</table>\n";
3.120 scop 1000:
3.150 scop 1001: if ((my $num = scalar(@unreadable)) && ! $input{hidenonreadable}) {
1002: printf(<<EOF, $num, htmlquote(join(', ', @unreadable)));
1003: <p>
1004: <b>NOTE:</b> The following %d unreadable files were ignored:<br>
1005: <em>%s</em>
1006: </p>
1007: EOF
1008: }
1009:
3.120 scop 1010: if ($filesexists && !$filesfound) {
3.150 scop 1011: my $currtag = defined($input{only_with_tag}) ?
1012: sprintf(' (%s)', htmlquote($input{only_with_tag})) : '';
1013: printf(<<EOF, $filesexists, $currtag);
1014: <p>
1015: <b>NOTE:</b> There are %d files, but none matches the current tag%s.
1016: </p>
1017: EOF
3.120 scop 1018: }
1019:
1020: if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
1021: %tags = %alltags;
1022: }
1023:
1024: if (scalar %tags
1025: || $input{only_with_tag}
1026: || $edit_option_form
1027: || defined($input{"options"}))
1028: {
3.177 scop 1029: print "<hr>\n";
3.120 scop 1030: }
1031:
1032: if (scalar %tags || $input{only_with_tag}) {
1033: print "<form method=\"get\" action=\"./\">\n";
1034: foreach my $var (@stickyvars) {
3.154 scop 1035: printf("<input type=\"hidden\" name=\"$var\" value=\"%s\">\n",
1036: htmlquote($input{$var}))
3.120 scop 1037: if (defined($input{$var})
1038: && (!defined($DEFAULTVALUE{$var})
1039: || $input{$var} ne $DEFAULTVALUE{$var})
1040: && $input{$var} ne ""
1041: && $var ne 'only_with_tag');
1042: }
1043: print "<p><label for=\"only_with_tag\" accesskey=\"T\">";
1044: print "Show only files with tag:</label>\n";
1045: print "<select id=\"only_with_tag\" name=\"only_with_tag\"";
1046: print " onchange=\"this.form.submit()\"" if $use_java_script;
1047: print ">";
1048: print "<option value=\"\">All tags / default branch</option>\n";
1049:
1050: foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
3.136 scop 1051: my $selected =
1052: defined($input{only_with_tag}) && $input{only_with_tag} eq $tag;
1053: printf("<option%s>%s</option>\n",
1054: $selected ? ' selected' : '',
1055: htmlquote($tag));
3.120 scop 1056: }
1057: print "</select>\n";
3.189 ! scop 1058: print ' <label for="path" accesskey="P">';
3.120 scop 1059: print "Module path or alias:</label>\n";
1060: printf "<input type=\"text\" id=\"path\" name=\"path\" value=\"%s\" size=\"15\">\n", htmlquote($where);
1061: print "<input type=\"submit\" value=\"Go\" accesskey=\"G\"></p>\n";
1062: print "</form>\n";
1063: }
1064:
3.188 scop 1065: if ($allow_tar && $filesfound) {
3.120 scop 1066: my ($basefile) = ($where =~ m,(?:.*/)?([^/]+),);
1067:
1068: if (defined($basefile) && $basefile ne '') {
3.177 scop 1069: print "<hr>\n",
3.189 ! scop 1070: '<div style="text-align: center">Download this directory in ';
3.120 scop 1071:
1072: # Mangle the filename so browsers show a reasonable
1073: # filename to download.
1074: print
1075: &link("tarball",
1076: "./$basefile.tar.gz$query" . ($query ? "&" : "?") . "tarball=1");
1077: if ($CMD{zip}) {
1078: print " or ",
1079: &link("zip archive",
1080: "./$basefile.zip$query" . ($query ? "&" : "?") . "tarball=1");
1081: }
1082: print "</div>\n";
1083: }
1084: }
1085:
1086: if ($edit_option_form || defined($input{"options"})) {
1087:
1088: my $formwhere = $scriptwhere;
1089: $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
1090:
3.149 scop 1091: print <<EOF;
1092: <form method="get" action="${formwhere}">
3.189 ! scop 1093: <fieldset>
! 1094: <legend>General options</legend>
3.149 scop 1095: <input type="hidden" name="copt" value="1">
1096: EOF
3.120 scop 1097: if ($cvstree ne $cvstreedefault) {
1098: print "<input type=\"hidden\" name=\"cvsroot\" value=\"$cvstree\">\n";
1099: }
3.149 scop 1100: print <<EOF;
3.189 ! scop 1101: <table>
3.149 scop 1102: <tr>
3.189 ! scop 1103: <td class="opt-label">
! 1104: <label for="sortby" accesskey="F">Sort files by:</label>
! 1105: </td>
! 1106: <td class="opt-value">
3.149 scop 1107: <select id="sortby" name="sortby">
1108: <option value="">File</option>
1109: EOF
3.120 scop 1110: print "<option", $bydate ? " selected" : "",
1111: " value=\"date\">Age</option>\n";
1112: print "<option", $byauthor ? " selected" : "",
1113: " value=\"author\">Author</option>\n"
3.140 scop 1114: if $show_author;
3.120 scop 1115: print "<option", $byrev ? " selected" : "",
1116: " value=\"rev\">Revision</option>\n";
1117: print "<option", $bylog ? " selected" : "",
1118: " value=\"log\">Log message</option>\n";
3.189 ! scop 1119: print <<EOF;
! 1120: </select>,
! 1121: <label for="ignorecase" accesskey="I">case-insensitive:
! 1122: EOF
! 1123: print '<input id="ignorecase" name="ignorecase" type="checkbox"',
! 1124: $input{ignorecase} ? ' checked' : '', " value=\"1\"></label>\n";
! 1125: print <<EOF;
! 1126: </td>
! 1127: <td class="opt-label">
! 1128: <label for="hideattic" accesskey="A">Hide files in Attic:</label>
! 1129: </td>
! 1130: <td class="opt-value">
! 1131: EOF
! 1132: print '<input id="hideattic" name="hideattic" type="checkbox"',
! 1133: $input{hideattic} ? ' checked' : '', " value=\"1\"></td>\n";
! 1134: print <<EOF;
! 1135: </td>
! 1136: </tr>
! 1137: <tr>
! 1138: <td class="opt-label">
! 1139: <label for="logsort" accesskey="L">Sort log by:</label>
! 1140: </td>
! 1141: <td class="opt-value">
! 1142: EOF
3.120 scop 1143: printLogSortSelect(0);
3.189 ! scop 1144: print <<EOF;
! 1145: </td>
! 1146: <td class="opt-label">
! 1147: <label for="ln" accesskey="N">Show line numbers:</label>
! 1148: </td>
! 1149: <td class="opt-value">
! 1150: EOF
! 1151: print '<input id="ln" name="ln" type="checkbox"',
! 1152: $input{ln} ? ' checked' : '', " value=\"1\">\n";
! 1153: print <<EOF;
! 1154: </td>
! 1155: </tr>
! 1156: <tr>
! 1157: <td class="opt-label">
! 1158: <label for="f" accesskey="D">Diff format:</label>
! 1159: </td>
! 1160: <td>
! 1161: EOF
3.120 scop 1162: printDiffSelect(0);
3.149 scop 1163: print <<EOF;
3.189 ! scop 1164: </td>
! 1165: <td colspan="2" class="opt-label">
! 1166: <input type="submit" value="Change Options" accesskey="C">
! 1167: </td>
3.149 scop 1168: </tr>
1169: </table>
3.189 ! scop 1170: </fieldset>
3.149 scop 1171: </form>
1172: EOF
3.120 scop 1173: }
1174: html_footer();
3.80 knu 1175: }
3.1 knu 1176:
1177: ###############################
1178: # View Files
1179: ###############################
3.80 knu 1180: elsif (-f $fullname . ',v') {
3.114 scop 1181:
3.120 scop 1182: if (forbidden_file($fullname)) {
1183: fatal('403 Forbidden',
1184: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
1185: return;
1186: }
1187:
1188: if (defined($input{'rev'}) || $doCheckout) {
1189: &doCheckout($fullname, $input{'rev'});
1190: gzipclose();
1191: exit;
1192: }
1193:
1194: if (defined($input{'annotate'}) && $allow_annotate) {
1195: &doAnnotate($input{'annotate'});
1196: gzipclose();
1197: exit;
1198: }
1199:
1200: if (defined($input{'r1'}) && defined($input{'r2'})) {
1201: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1202: $input{'r2'}, $input{'tr2'}, $input{'f'});
1203: gzipclose();
1204: exit;
1205: }
3.132 scop 1206:
3.170 scop 1207: if ($allow_cvsgraph && $input{graph}) {
1208: if ($input{makeimage}) {
1209: doGraph();
3.132 scop 1210: } else {
3.170 scop 1211: doGraphView();
3.132 scop 1212: }
1213: gzipclose();
1214: exit;
1215: }
1216:
3.120 scop 1217: &doLog($fullname);
1218:
1219: ##############################
1220: # View Diff
1221: ##############################
1222: } elsif ($fullname =~ s/\.diff$//
1223: && -f $fullname . ",v"
1224: && $input{'r1'}
1225: && $input{'r2'})
1226: {
1227:
1228: # $where-diff-removal if 'cvs rdiff' is used
1229: # .. but 'cvs rdiff'doesn't support some options
1230: # rcsdiff does (-w and -p), so it is disabled
1231: # $where =~ s/\.diff$//;
1232:
3.189 ! scop 1233: # Allow diffs using the ".diff" extension so that browsers that default
! 1234: # to the filename in the URL when saving don't save diffs as eg. foo.c.
3.120 scop 1235: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1236: $input{'r2'}, $input{'tr2'}, $input{'f'});
1237: gzipclose();
1238: exit;
1239: } elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1|
1240: && -f $newname . ",v")
1241: {
1242:
1243: # The file has been removed and is in the Attic.
1244: # Send a redirect pointing to the file in the Attic.
1245: (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
1246: if ($ENV{QUERY_STRING} ne "") {
1247: redirect("${newplace}?$ENV{QUERY_STRING}");
1248: } else {
1249: redirect($newplace);
1250: }
1251: exit;
3.80 knu 1252: } elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
3.120 scop 1253: http_header("text/plain");
1254: print "You matched the following files:\n";
1255: print join ("\n", @files);
3.80 knu 1256:
3.120 scop 1257: # Find the tags from each file
1258: # Display a form offering diffs between said tags
3.80 knu 1259: } else {
3.120 scop 1260: my $fh = do { local (*FH); };
1261: my ($xtra, $module);
3.80 knu 1262:
3.120 scop 1263: # Assume it's a module name with a potential path following it.
1264: $xtra = (($module = $where) =~ s|/.*||) ? $& : '';
3.80 knu 1265:
3.120 scop 1266: # Is there an indexed version of modules?
1267: if (open($fh, "< $cvsroot/CVSROOT/modules")) {
1268: while (<$fh>) {
1269: if (/^(\S+)\s+(\S+)/o
1270: && $module eq $1
1271: && -d "$cvsroot/$2"
1272: && $module ne $2)
1273: {
1274: redirect("$scriptname/$2$xtra$query");
1275: }
1276: }
1277: }
1278: fatal("404 Not Found", '%s: no such file or directory', $where);
3.80 knu 1279: }
3.23 knu 1280:
3.25 knu 1281: gzipclose();
3.80 knu 1282:
3.1 knu 1283: ## End MAIN
1284:
3.175 scop 1285:
3.120 scop 1286: sub printDiffSelect($)
1287: {
1288: my ($use_java_script) = @_;
1289:
1290: print '<select id="f" name="f"';
1291: print ' onchange="this.form.submit()"' if $use_java_script;
1292: print ">\n";
1293:
3.175 scop 1294: for my $difftype (@DIFFTYPES) {
3.120 scop 1295: printf("<option value=\"%s\"%s>%s</option>\n",
3.175 scop 1296: $difftype, $input{f} eq $difftype ? ' selected' : '',
1297: "\u$DIFFTYPES{$difftype}{descr}");
3.120 scop 1298: }
1299:
1300: print "</select>";
1301: }
1302:
3.175 scop 1303:
3.168 scop 1304: sub printDiffSelectStickyVars()
1305: {
1306: while (my ($key, $val) = each %input) {
1307: next if ($key eq 'f');
1308: next if (defined($DEFAULTVALUE{$key}) && $DEFAULTVALUE{$key} eq $val);
1309: print "<input type=\"hidden\" name=\"", urlencode($key), "\" value=\"",
1310: urlencode($val), "\">\n";
1311: }
1312: }
1313:
3.175 scop 1314:
3.120 scop 1315: sub printLogSortSelect($)
1316: {
1317: my ($use_java_script) = @_;
1318:
1319: print '<select id="logsort" name="logsort"';
1320: print ' onchange="this.form.submit()"' if $use_java_script;
1321: print ">\n";
1322:
3.175 scop 1323: for my $sortkey (@LOGSORTKEYS) {
3.120 scop 1324: printf("<option value=\"%s\"%s>%s</option>\n",
3.175 scop 1325: $sortkey, $logsort eq $sortkey ? ' selected' : '',
1326: "\u$LOGSORTKEYS{$sortkey}{descr}");
3.120 scop 1327: }
1328:
1329: print "</select>";
1330: }
1331:
3.175 scop 1332:
3.120 scop 1333: sub findLastModifiedSubdirs(@)
1334: {
1335: my (@dirs) = @_;
1336:
3.175 scop 1337: my @files;
1338: foreach my $dirname (@dirs) {
3.120 scop 1339: next if ($dirname eq ".");
1340: next if ($dirname eq "..");
3.175 scop 1341: my $dir = "$fullname/$dirname";
3.120 scop 1342: next if (!-d $dir);
1343:
1344: my $dh = do { local (*DH); };
1345: opendir($dh, $dir) or next;
1346: my (@filenames) = readdir($dh);
1347: closedir($dh);
1348:
3.175 scop 1349: my $lastmod = undef;
1350: my $lastmodtime = undef;
3.120 scop 1351: foreach my $filename (@filenames) {
1352: $filename = "$dirname/$filename";
1353: my ($file) = "$fullname/$filename";
1354: next if ($filename !~ /,v$/ || !-f $file);
1355:
1356: # Skip forbidden files.
1357: (my $f = $file) =~ s/,v$//;
1358: next if forbidden_file($f);
1359:
1360: $filename =~ s/,v$//;
1361: my $modtime = -M $file;
1362:
1363: if (!defined($lastmod) || $modtime < $lastmodtime) {
1364: $lastmod = $filename;
1365: $lastmodtime = $modtime;
1366: }
1367: }
3.175 scop 1368: push(@files, $lastmod) if (defined($lastmod));
3.120 scop 1369: }
1370: return @files;
1371: }
1372:
3.175 scop 1373:
3.120 scop 1374: sub htmlify_sub(&$)
1375: {
1376: (my $proc, local $_) = @_;
1377: my @a = split (m`(<a [^>]+>[^<]*</a>)`i);
1378: my $linked;
1379: my $result = '';
1380:
1381: while (($_, $linked) = splice(@a, 0, 2)) {
1382: &$proc();
1383: $result .= $_ if defined($_);
1384: $result .= $linked if defined($linked);
1385: }
1386:
3.175 scop 1387: return $result;
3.120 scop 1388: }
1389:
3.175 scop 1390:
3.120 scop 1391: sub htmlify($;$)
1392: {
1393: (local $_, my $extra) = @_;
1394:
1395: $_ = htmlquote($_);
1396:
1397: # get URL's as link
1398: s{
3.130 scop 1399: ((https?|ftp)://.+?)([\s\']|&(quot|[lg]t);)
3.120 scop 1400: }{
3.130 scop 1401: &link($1, htmlunquote($1)) . $3
3.120 scop 1402: }egx;
1403:
1404: # get e-mails as link
1405: $_ = htmlify_sub {
1406: s<
1407: [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
1408: ><
1409: &link($&, "mailto:$&")
1410: >egix;
1411: } $_;
1412:
1413: if ($extra) {
1414:
1415: # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
1416: if (defined($prcgi) && defined($re_prkeyword)) {
1417: my $prev;
1418:
1419: do {
1420: $prev = $_;
1421:
1422: $_ = htmlify_sub {
1423: s{
1424: (\b$re_prkeyword[:\#]?\s*
1425: (?:
1426: \#?
1427: \d+[,\s]\s*
1428: )*
1429: \#?)
1430: (\d+)\b
1431: }{
1432: $1 . &link($2, sprintf($prcgi, $2))
1433: }egix;
1434: } $_;
1435: } while ($_ ne $prev);
1436:
1437: if (defined($re_prcategories)) {
1438: $_ = htmlify_sub {
1439: s{
1440: (\b$re_prcategories/(\d+)\b)
1441: }{
1442: &link($1, sprintf($prcgi, $2))
1443: }egox;
1444: } $_;
1445: }
1446: }
1447:
1448: # get manpage specs as link: "foo.1" "foo(1)"
1449: if (defined($mancgi)) {
1450: $_ = htmlify_sub {
1451: s{
3.143 knu 1452: (
1453: \b ( \w[\w+\-.]* (?: ::\w[\w+\-.]*)* )
3.120 scop 1454: (?:
3.143 knu 1455: \( ([0-9n]) \) \B
3.120 scop 1456: |
3.143 knu 1457: \. ([0-9n]) \b
3.120 scop 1458: )
1459: )
1460: }{
3.149 scop 1461: my($text, $name, $section) = ($1, $2, defined($3) ? $3 : $4);
1462: ($name =~ /[A-Za-z]/ && $name !~ /\.(:|$)/)
1463: ? &link($text, sprintf($mancgi, $section, $name))
1464: : $text;
3.120 scop 1465: }egx;
1466: } $_;
1467: }
1468: }
1469:
3.175 scop 1470: return $_;
3.120 scop 1471: }
1472:
3.175 scop 1473:
3.120 scop 1474: sub spacedHtmlText($;$)
1475: {
3.175 scop 1476: (local $_, my $ts) = @_;
1477: $ts ||= $tabstop;
3.120 scop 1478:
1479: # Cut trailing spaces and tabs
1480: s/[ \t]+$//;
1481:
1482: if (defined($ts)) {
1483:
1484: # Expand tabs
1485: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e;
1486: }
1487:
1488: # replace <tab> and <space> (\001 is to protect us from htmlify)
1489: # gzip can make excellent use of this repeating pattern :-)
1490: if ($hr_breakable) {
1491:
1492: # make every other space 'breakable'
1493: s/ / \001nbsp;/g; # 2 * <space>
1494: # leave single space as it is
1495: } else {
1496: s/ /\001nbsp;/g;
1497: }
1498:
1499: $_ = htmlify($_, $allow_source_extra);
1500:
1501: # unescape
1502: y/\001/&/;
1503:
1504: return $_;
1505: }
1506:
3.175 scop 1507:
3.120 scop 1508: # Note that this doesn't htmlquote the first argument...
1509: sub link($$)
1510: {
1511: my ($name, $url) = @_;
1512:
1513: $url =~ s/:/sprintf("%%%02x", ord($&))/eg
1514: if $url =~ /^[^a-z]/; # relative
1515:
1516: sprintf '<a href="%s">%s</a>', hrefquote($url), $name;
1517: }
1518:
3.175 scop 1519:
3.120 scop 1520: sub revcmp($$)
1521: {
1522: my ($rev1, $rev2) = @_;
1523:
1524: # make no comparison for a tag or a branch
1525: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1526:
1527: my (@r1) = split (/\./, $rev1);
1528: my (@r2) = split (/\./, $rev2);
1529: my ($a, $b);
1530:
1531: while (($a = shift (@r1)) && ($b = shift (@r2))) {
1532: if ($a != $b) {
1533: return $a <=> $b;
1534: }
1535: }
1536: if (@r1) { return 1; }
1537: if (@r2) { return -1; }
1538: return 0;
1539: }
1540:
3.175 scop 1541:
3.120 scop 1542: sub fatal($$@)
1543: {
1544: my ($errcode, $format, @args) = @_;
3.185 scop 1545: print "Status: $errcode\r\n";
3.131 scop 1546: html_header('Error');
3.120 scop 1547: print "<p>Error: ", sprintf($format, map(htmlquote($_), @args)), "</p>\n";
1548: html_footer();
1549: exit(1);
1550: }
1551:
3.175 scop 1552:
3.120 scop 1553: sub redirect($)
1554: {
1555: my ($url) = @_;
3.185 scop 1556: print "Status: 301 Moved\r\n", "Location: $url\r\n";
3.131 scop 1557: html_header('Moved');
3.120 scop 1558: print "<p>This document is located ", &link('here', $url), "</p>\n";
1559: html_footer();
1560: exit(1);
1561: }
1562:
3.175 scop 1563:
3.120 scop 1564: sub safeglob($)
1565: {
1566: my ($filename) = @_;
1567:
3.175 scop 1568: (my $dirname = $filename) =~ s|/[^/]+$||;
3.120 scop 1569: $filename =~ s|.*/||;
1570:
3.175 scop 1571: my @results;
1572: my $dh = do { local (*DH); };
3.120 scop 1573: if (opendir($dh, $dirname)) {
1574: my $glob = $filename;
1575: my $t;
1576:
3.149 scop 1577: # transform filename from glob to regex. Deal with:
1578: # [, {, ?, * as glob chars
1579: # make sure to escape all other regex chars
3.120 scop 1580: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1581: $glob =~ s/\*/.*/g;
1582: $glob =~ s/\?/./g;
1583: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1584: foreach (readdir($dh)) {
1585:
1586: if (/^${glob}$/) {
1587: push (@results, "$dirname/" . $_);
1588: }
1589: }
1590: closedir($dh);
1591: }
1592:
3.175 scop 1593: return @results;
3.120 scop 1594: }
1595:
3.160 scop 1596:
3.120 scop 1597: sub search_path($)
1598: {
1599: my ($command) = @_;
3.160 scop 1600: for my $d (split (/:/, $command_path)) {
3.120 scop 1601: return "$d/$command" if -x "$d/$command";
1602: }
1603: return '';
1604: }
1605:
3.156 scop 1606:
1607: sub getMimeType($;$)
3.120 scop 1608: {
3.156 scop 1609: my ($fullname, $binary) = @_;
1610: $binary = ($keywordsubstitution && $keywordsubstitution =~ /b/)
1611: unless defined($binary);
1612:
1613: (my $suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1614:
1615: my $mimetype = $MTYPES{$suffix};
1616: $mimetype ||= $MimeTypes->mimeTypeOf($fullname) if defined($MimeTypes);
1617:
1618: if (!$mimetype && $suffix ne '*' && -f $mime_types && -r _) {
1619: my $fh = do { local (*FH); };
1620: if (open($fh, $mime_types)) {
1621: my $re = sprintf('^\s*(\S+\/\S+)\s.+\b%s\b', quotemeta($suffix));
1622: while (my $line = <$fh>) {
1623: if ($line =~ $re) {
1624: $mimetype = $1;
1625: $MTYPES{$suffix} = $mimetype;
1626: last;
1627: }
3.120 scop 1628: }
3.156 scop 1629: close($fh);
1630: } else {
1631: warn("Can't open MIME types file $mime_types for reading: $!");
3.120 scop 1632: }
1633: }
1634:
3.156 scop 1635: $mimetype ||= $MTYPES{'*'};
1636: $mimetype ||= $binary ? 'application/octet-stream' : 'text/plain';
3.120 scop 1637: return $mimetype;
3.1 knu 1638: }
1639:
3.156 scop 1640:
3.1 knu 1641: ###############################
3.24 knu 1642: # read first lines like head(1)
1643: ###############################
3.120 scop 1644: sub head($;$)
1645: {
3.175 scop 1646: my ($fh, $linecount) = @_;
1647: $linecount ||= 10;
3.24 knu 1648:
3.120 scop 1649: my @buf;
1650: if ($linecount > 0) {
3.184 scop 1651: for (my $i = 0; !eof($fh) && $i < $linecount; $i++) {
3.120 scop 1652: push @buf, scalar <$fh>;
1653: }
1654: } else {
1655: @buf = <$fh>;
1656: }
3.175 scop 1657: return @buf;
1658: }
3.120 scop 1659:
3.24 knu 1660:
1661: ###############################
1662: # scan vim and Emacs directives
1663: ###############################
3.120 scop 1664: sub scan_directives(@)
1665: {
1666: my $ts = undef;
3.24 knu 1667:
3.120 scop 1668: for (@_) {
1669: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1670: }
3.24 knu 1671:
3.120 scop 1672: ('tabstop' => $ts);
3.24 knu 1673: }
1674:
3.175 scop 1675:
3.120 scop 1676: sub openOutputFilter()
1677: {
3.175 scop 1678: return unless $output_filter;
3.86 knu 1679:
3.120 scop 1680: open(STDOUT, "|-") and return;
3.86 knu 1681:
3.120 scop 1682: # child of child
3.165 scop 1683: open(STDERR, '>', devnull());
3.120 scop 1684: exec($output_filter) or exit -1;
3.86 knu 1685: }
1686:
3.175 scop 1687:
3.24 knu 1688: ###############################
3.1 knu 1689: # show Annotation
1690: ###############################
3.133 scop 1691: sub doAnnotate($)
3.120 scop 1692: {
1693: my ($rev) = @_;
1694:
1695: # make sure the revisions are wellformed, for security
1696: # reasons ..
1697: if ($rev =~ /[^\w.]/) {
1698: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1699: }
1700:
3.174 scop 1701: (my $pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1702: (my $filename = $where) =~ s/^.*\///;
3.126 scop 1703:
3.174 scop 1704: # This annotate version is based on the cvs annotate-demo Perl script by
1705: # Cyclic Software. It was written by Cyclic Software,
1706: # http://www.cyclic.com/, and is in the public domain.
1707: # We could abandon the use of rlog, rcsdiff and co using
1708: # the cvs server in a similiar way one day (..after rewrite).
1709:
1710: local (*CVS_IN, *CVS_OUT);
1711: my ($h, $err) =
1712: startproc([ $CMD{cvs}, @annotate_options, 'server' ],
1713: '<pipe', \*CVS_IN, '>pipe', \*CVS_OUT, timeout(30));
1714: fatal('500 Internal Error', $err) unless $h;
3.120 scop 1715:
1716: # OK, first send the request to the server. A simplified example is:
1717: # Root /home/kingdon/zwork/cvsroot
1718: # Argument foo/xx
1719: # Directory foo
1720: # /home/kingdon/zwork/cvsroot/foo
1721: # Directory .
1722: # /home/kingdon/zwork/cvsroot
1723: # annotate
1724: # although as you can see there are a few more details.
1725:
3.174 scop 1726: print CVS_IN "Root $cvsroot\n";
1727: print CVS_IN
3.120 scop 1728: "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1729:
1730: # Don't worry about sending valid-requests, the server just needs to
1731: # support "annotate" and if it doesn't, there isn't anything to be done.
3.174 scop 1732: print CVS_IN "UseUnchanged\n";
1733: print CVS_IN "Argument -r\n";
1734: print CVS_IN "Argument $rev\n";
1735: print CVS_IN "Argument $where\n";
3.120 scop 1736:
1737: # The protocol requires us to fully fake a working directory (at
1738: # least to the point of including the directories down to the one
1739: # containing the file in question).
3.123 scop 1740: # So if $where is "dir/sdir/file", then dirs will be ("dir","sdir","file")
1741: my $path = '';
1742: foreach my $dir (split('/', $where)) {
3.120 scop 1743:
1744: if ($path eq "") {
3.123 scop 1745: # In our example, $dir is "dir".
1746: $path = $dir;
3.120 scop 1747: } else {
3.174 scop 1748: print CVS_IN "Directory $path\n";
1749: print CVS_IN "$cvsroot/$path\n";
3.120 scop 1750:
1751: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1752: # And the next time, "file" and "dir/sdir/file" (which then gets
1753: # ignored, because we don't need to send Directory for the file).
3.123 scop 1754: $path .= "/$dir";
3.120 scop 1755: }
1756: }
3.123 scop 1757: undef $path;
3.120 scop 1758:
1759: # And the last "Directory" before "annotate" is the top level.
3.174 scop 1760: print CVS_IN "Directory .\n";
1761: print CVS_IN "$cvsroot\n";
3.120 scop 1762:
3.174 scop 1763: print CVS_IN "annotate\n";
3.120 scop 1764:
1765: # OK, we've sent our command to the server. Thing to do is to
1766: # close the writer side and get all the responses. If "cvs server"
1767: # were nicer about buffering, then we could just leave it open, I think.
3.174 scop 1768: close(CVS_IN) or die "cannot close: $!";
3.120 scop 1769:
3.133 scop 1770: navigateHeader($scriptwhere, $pathname, $filename, $rev, 'annotate');
3.120 scop 1771:
3.136 scop 1772: print '<h3 style="text-align: center">Annotation of ',
1773: htmlquote("$pathname$filename"), ", revision $rev</h3>\n";
3.120 scop 1774:
1775: # Ready to get the responses from the server.
1776: # For example:
1777: # E Annotations for foo/xx
1778: # E ***************
1779: # M 1.3 (kingdon 06-Sep-97): hello
1780: # ok
1781: my ($lineNr) = 0;
1782: my ($oldLrev, $oldLusr) = ("", "");
1783: my ($revprint, $usrprint);
1784:
1785: if ($annTable) {
3.179 scop 1786: print <<EOF;
1787: <table style="border: none" cellspacing="0" cellpadding="0" summary="Annotation">
1788: EOF
3.120 scop 1789: } else {
1790: print "<pre>";
1791: }
1792:
1793: # prefetch several lines
3.174 scop 1794: my @buf = head(*CVS_OUT);
3.120 scop 1795:
1796: my %d = scan_directives(@buf);
1797:
3.174 scop 1798: while (@buf || !eof(*CVS_OUT)) {
1799: $_ = @buf ? shift @buf : <CVS_OUT>;
3.120 scop 1800:
1801: my @words = split;
1802:
1803: # Adding one is for the (single) space which follows $words[0].
1804: my $rest = substr($_, length($words[0]) + 1);
1805: if ($words[0] eq "E") {
1806: next;
1807: } elsif ($words[0] eq "M") {
1808: $lineNr++;
1809: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1810: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1811: my $line = substr($_, 36);
1812: my $isCurrentRev = ($rev eq $lrev);
1813:
1814: # we should parse the date here ..
1815: if ($lrev eq $oldLrev) {
1816: $revprint = sprintf('%-8s', '');
1817: } else {
1818: $revprint = sprintf('%-8s', $lrev);
1819: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
1820: $oldLusr = '';
1821: }
1822:
1823: if ($lusr eq $oldLusr) {
1824: $usrprint = '';
1825: } else {
1826: $usrprint = $lusr;
1827: }
1828: $oldLrev = $lrev;
1829: $oldLusr = $lusr;
1830:
1831: # Set bold for text-based browsers only - graphical
1832: # browsers show bold fonts a bit wider than regular fonts,
1833: # so it looks irregular.
1834: print "<b>" if ($isCurrentRev && $is_textbased);
1835:
3.136 scop 1836: $usrprint = sprintf('%-8s', $usrprint);
1837: printf '%s%s %s %4d:', $revprint, $isCurrentRev ? '!' : ' ',
1838: htmlquote($usrprint), $lineNr;
3.120 scop 1839: print spacedHtmlText($line, $d{'tabstop'});
1840:
1841: print "</b>" if ($isCurrentRev && $is_textbased);
1842: } elsif ($words[0] eq "ok") {
1843:
1844: # We could complain about any text received after this, like the
1845: # CVS command line client. But for simplicity, we don't.
1846: } elsif ($words[0] eq "error") {
1847: fatal("500 Internal Error",
1848: 'Error occured during annotate: <b>%s</b>', $_);
1849: }
1850: }
1851:
1852: if ($annTable) {
1853: print "</table>";
1854: } else {
1855: print "</pre>";
1856: }
3.124 scop 1857: html_footer();
1858:
3.174 scop 1859: finish($h);
3.1 knu 1860: }
1861:
1862: ###############################
1863: # make Checkout
1864: ###############################
3.120 scop 1865: sub doCheckout($$)
1866: {
1867: my ($fullname, $rev) = @_;
1868:
1869: if ($rev eq 'HEAD' || $rev eq '.') {
1870: $rev = undef;
1871: }
1872:
1873: # make sure the revisions a wellformed, for security
1874: # reasons ..
1875: if (defined($rev) && $rev =~ /[^\w.]/) {
1876: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1877: }
1878:
1879: # get mimetype
3.156 scop 1880: my $mimetype;
3.175 scop 1881: if (defined($input{"content-type"}) &&
1882: ($input{"content-type"} =~ /\S\/\S/))
3.120 scop 1883: {
1884: $mimetype = $input{"content-type"};
1885: } else {
3.156 scop 1886: $mimetype = getMimeType($fullname);
3.120 scop 1887: }
1888:
3.163 scop 1889: my $moddate = undef;
3.175 scop 1890: my $revopt;
3.120 scop 1891: if (defined($rev)) {
1892: $revopt = "-r$rev";
1893: if ($use_moddate) {
1894: readLog($fullname, $rev);
1895: $moddate = $date{$rev};
1896: }
1897: } else {
1898: $revopt = "-rHEAD";
1899: if ($use_moddate) {
1900: readLog($fullname);
1901: $moddate = $date{$symrev{HEAD}};
1902: }
1903: }
1904:
3.183 scop 1905: # Use abs_path() to work around a bug of cvs -p; expand symlinks if we can.
1906: my @cmd = ($CMD{cvs}, @cvs_options, '-d', (abs_path($cvsroot) || $cvsroot),
1907: 'co', '-p', $revopt, $where);
1908:
3.174 scop 1909: local $^W = 0; # IPC::Run is noisy w/perl 5.8. Also prevents weird hangs.
1910: local (*CVS_OUT, *CVS_ERR);
1911: my ($h, $err) =
1912: startproc(\@cmd, \"", '>pipe', \*CVS_OUT, '2>pipe', \*CVS_ERR,timeout(30));
1913: fatal('500 Internal Error', $err) unless $h;
3.120 scop 1914:
3.174 scop 1915: if (eof(CVS_ERR)) {
1916: finish($h);
3.120 scop 1917: fatal("404 Not Found", '%s is not (any longer) pertinent', $where);
1918: }
1919:
1920: #===================================================================
1921: #Checking out squid/src/ftp.c
1922: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1923: #VERS: 1.1.1.28.6.2
1924: #***************
1925:
1926: # Parse CVS header
1927: my ($revision, $filename, $cvsheader);
1928: $filename = "";
3.174 scop 1929: while (<CVS_ERR>) {
3.120 scop 1930: last if (/^\*\*\*\*/);
1931: $revision = $1 if (/^VERS: (.*)$/);
1932:
1933: if (/^Checking out (.*)$/) {
1934: $filename = $1;
1935: $filename =~ s/^\.\/*//;
1936: }
1937: $cvsheader .= $_;
1938: }
1939:
1940: if ($filename ne $where) {
3.174 scop 1941: finish($h);
3.120 scop 1942: fatal("500 Internal Error",
1943: 'Unexpected output from cvs co: %s', $cvsheader);
1944: }
1945:
3.146 scop 1946: if ($mimetype =~ $CvsWebMarkupRE) {
3.163 scop 1947: # Here we know the last modified date, but don't know if tags have been
1948: # added since: no last-modified (for now).
3.174 scop 1949: cvswebMarkup(\*CVS_OUT, $fullname, $revision);
3.120 scop 1950: } else {
3.163 scop 1951: http_header($mimetype, $moddate);
3.174 scop 1952: local $/ = undef;
1953: print <CVS_OUT>;
3.120 scop 1954: }
3.174 scop 1955: finish($h);
1.12 fenner 1956: }
1957:
3.174 scop 1958:
3.163 scop 1959: sub cvswebMarkup($$$;$)
3.120 scop 1960: {
3.163 scop 1961: my ($filehandle, $fullname, $revision, $mod) = @_;
3.1 knu 1962:
3.175 scop 1963: (my $pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1964: (my $filename = $where) =~ s/^.*\///;
1965: my $fileurl = urlencode($filename);
1966: my $mimetype = getMimeType($filename);
3.120 scop 1967:
3.163 scop 1968: navigateHeader($scriptwhere, $pathname, $filename, $revision, 'view', $mod);
3.120 scop 1969:
3.144 scop 1970: print <<EOF;
3.177 scop 1971: <hr>
3.182 scop 1972: <div class="log-markup">
1973: File:
3.144 scop 1974: EOF
3.159 scop 1975: print &clickablePath($where, 1), ' - (';
3.144 scop 1976: &download_link($fileurl, $revision, 'download');
3.156 scop 1977: if ($mimetype ne 'text/plain') {
3.159 scop 1978: print ' / ';
3.120 scop 1979: &download_link($fileurl, $revision, "as text", "text/plain");
1980: }
3.159 scop 1981: print ')';
3.170 scop 1982: print ' - ', &graph_link('', 'graph') if $allow_cvsgraph;
3.120 scop 1983: print "<br>\n";
1984:
1985: if ($show_log_in_markup) {
1986: readLog($fullname); #,$revision);
1987: printLog($revision, 0);
1988: } else {
1989: print "Version: <b>$revision</b><br>\n";
1990: print "Tag: <b>", $input{only_with_tag}, "</b><br>\n"
1991: if $input{only_with_tag};
1992: }
3.182 scop 1993: print "</div>\n<hr>";
3.120 scop 1994: my $url = download_url($fileurl, $revision, $mimetype);
1995:
1996: if ($mimetype =~ /^image/) {
3.160 scop 1997: printf '<img src="%s" alt="%s"><br>',
1998: hrefquote("$url$barequery"), htmlquote($filename);
3.120 scop 1999: } elsif ($mimetype =~ m%^application/pdf%) {
3.157 scop 2000: printf '<embed src="%s" width="100%%" height="100%%"><br>',
2001: hrefquote("$url$barequery");
3.120 scop 2002: } elsif ($preformat_in_markup) {
2003: print "<pre>";
2004:
2005: # prefetch several lines
2006: my @buf = head($filehandle);
2007:
2008: my %d = scan_directives(@buf);
2009:
2010: while (@buf || !eof($filehandle)) {
2011: $_ = @buf ? shift @buf : <$filehandle>;
2012:
2013: print spacedHtmlText($_, $d{'tabstop'});
2014: }
2015: print "</pre>";
2016: } else {
2017:
3.148 scop 2018: my $enscript_hl = undef;
2019:
2020: if ($allow_enscript) {
2021: while (my ($hl, $regex) = each %enscript_types) {
3.149 scop 2022: if ($filename =~ $regex) {
2023: $enscript_hl = $hl;
2024: last;
2025: }
3.148 scop 2026: }
2027: }
2028:
3.149 scop 2029: print '<pre>';
3.167 scop 2030: my $linenumbers = $input{ln} || 0;
3.149 scop 2031:
3.148 scop 2032: if ($enscript_hl) {
3.167 scop 2033: doEnscript($filehandle, $enscript_hl, $linenumbers);
3.148 scop 2034:
2035: } else {
3.167 scop 2036: my $ln = 0;
3.148 scop 2037: while (<$filehandle>) {
3.167 scop 2038: if ($linenumbers) {
2039: $ln++;
2040: printf '<a id="l%d" class="src">%5d: </a>', ($ln) x 2;
3.149 scop 2041: }
2042: print htmlquote($_);
3.148 scop 2043: }
3.120 scop 2044: }
3.149 scop 2045:
2046: print "</pre>\n";
3.120 scop 2047: }
3.131 scop 2048: html_footer();
3.120 scop 2049: }
2050:
3.156 scop 2051:
3.120 scop 2052: sub viewable($)
2053: {
3.156 scop 2054: my $mimetype = shift || '';
2055: return ($allow_markup && $mimetype =~ m%^((text|image)/|application/pdf)%);
2056: }
3.120 scop 2057:
3.1 knu 2058:
2059: ###############################
2060: # Show Colored Diff
2061: ###############################
3.120 scop 2062: sub doDiff($$$$$$)
2063: {
2064: my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
2065:
2066: if (&forbidden_file($fullname)) {
2067: fatal("403 Forbidden",
2068: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
2069: }
2070:
3.175 scop 2071: my ($rev1, $sym1);
3.120 scop 2072: if ($r1 =~ /([^:]+)(:(.+))?/) {
2073: $rev1 = $1;
2074: $sym1 = $3;
2075: }
2076: if ($r1 eq 'text') {
2077: $rev1 = $tr1;
2078: $sym1 = "";
2079: }
2080:
3.175 scop 2081: my ($rev2, $sym2);
3.120 scop 2082: if ($r2 =~ /([^:]+)(:(.+))?/) {
2083: $rev2 = $1;
2084: $sym2 = $3;
2085: }
2086: if ($r2 eq 'text') {
2087: $rev2 = $tr2;
2088: $sym2 = "";
2089: }
2090:
2091: # make sure the revisions a wellformed, for security
2092: # reasons ..
2093: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
2094: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
2095: }
2096:
2097: #
2098: # rev1 and rev2 are now both numeric revisions.
2099: # Thus we do a DWIM here and swap them if rev1 is after rev2.
2100: # XXX should we warn about the fact that we do this?
2101: if (&revcmp($rev1, $rev2) > 0) {
2102: my ($tmp1, $tmp2) = ($rev1, $sym1);
2103: ($rev1, $sym1) = ($rev2, $sym2);
2104: ($rev2, $sym2) = ($tmp1, $tmp2);
2105: }
2106: my $difftype = $DIFFTYPES{$f};
2107:
2108: if (!$difftype) {
2109: fatal("400 Bad arguments", 'Diff format %s not understood', $f);
2110: }
2111:
2112: my @difftype = @{$difftype->{'opts'}};
2113: my $human_readable = $difftype->{'colored'};
2114:
2115: # apply special options
2116: if ($showfunc) {
2117: push @difftype, '-p' if $f ne 's';
2118:
2119: my ($re1, $re2);
2120:
2121: while (($re1, $re2) = each %funcline_regexp) {
2122: if ($fullname =~ /$re1/) {
2123: push @difftype, '-F', $re2;
2124: last;
2125: }
2126: }
2127: }
2128:
2129: if ($human_readable) {
2130: if ($hr_ignwhite) {
2131: push @difftype, '-w';
2132: }
2133: if ($hr_ignkeysubst) {
2134: push @difftype, '-kk';
2135: }
2136: }
2137:
3.175 scop 2138: my $fh = do { local (*FH); };
3.120 scop 2139: if (!open($fh, "-|")) { # child
2140: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
2141: openOutputFilter();
3.166 scop 2142: exec($CMD{rcsdiff}, @rcsdiff_options, @difftype, "-r$rev1", "-r$rev2",
2143: $fullname) or exit -1;
3.120 scop 2144: }
3.166 scop 2145:
3.120 scop 2146: if ($human_readable) {
3.168 scop 2147: #
2148: # Human readable diff.
2149: #
2150: human_readable_diff($fh, $rev2);
2151: html_footer();
2152: gzipclose();
2153: exit;
2154:
2155: } elsif ($f =~ /^([ucs])c$/) {
2156: #
2157: # Enscript colored diff.
2158: #
2159: my $hl = 'diff';
2160: $hl .= $1 if ($1 eq 'u' || $1 eq 's');
2161: (my $where_nd = $where) =~ s/\.diff$//;
2162: (my $pathname = $where_nd) =~ s|(Attic\/)?[^/]*$||;
2163: (my $filename = $where_nd) =~ s|^.*/||;
2164: (my $swhere = $scriptwhere) =~ s|\.diff$||;
2165: navigateHeader($swhere, $pathname, $filename, $rev2, 'diff');
2166: printf(<<EOF, $where_nd, $rev1, $rev2);
2167: <h3 style="text-align: center">Diff for /%s between versions %s and %s</h3>
2168: <pre>
2169: EOF
3.174 scop 2170: doEnscript(\$fh, $hl, 0);
3.168 scop 2171: print <<EOF;
2172: </pre>
3.177 scop 2173: <hr style="width: 100%">
3.168 scop 2174: <form method="get" action="$scriptwhere">
2175: EOF
2176: printDiffSelectStickyVars();
2177: print 'Diff format: ';
2178: printDiffSelect($use_java_script);
2179: print "<input type=\"submit\" value=\"Show\">\n</form>\n";
3.120 scop 2180: html_footer();
2181: gzipclose();
2182: exit;
3.168 scop 2183:
3.120 scop 2184: } else {
3.168 scop 2185: #
2186: # Plain diff.
2187: #
3.120 scop 2188: http_header("text/plain");
2189: }
2190:
2191: #
2192: #===================================================================
2193: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
2194: #retrieving revision 1.16
2195: #retrieving revision 1.17
2196: #diff -c -r1.16 -r1.17
2197: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2198: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
2199: #
2200: # Ideas:
2201: # - nuke the stderr output if it's what we expect it to be
2202: # - Add "no differences found" if the diff command supplied no output.
2203: #
2204: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2205: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
2206: # (bogus example, but...)
2207: #
3.175 scop 2208: my ($f1, $f2);
3.120 scop 2209: if (grep { $_ eq '-u' } @difftype) {
2210: $f1 = '---';
2211: $f2 = '\+\+\+';
2212: } else {
2213: $f1 = '\*\*\*';
2214: $f2 = '---';
2215: }
2216:
2217: while (<$fh>) {
2218: if (m|^$f1 $cvsroot|o) {
2219: s|$cvsroot/||o;
2220: if ($sym1) {
2221: chop;
2222: $_ .= " $sym1\n";
2223: }
2224: } elsif (m|^$f2 $cvsroot|o) {
2225: s|$cvsroot/||o;
2226:
2227: if ($sym2) {
2228: chop;
2229: $_ .= " $sym2\n";
2230: }
2231: }
2232: print $_;
2233: }
2234: close($fh);
1.12 fenner 2235: }
2236:
3.175 scop 2237:
3.1 knu 2238: ###############################
2239: # Show Logs ..
2240: ###############################
3.120 scop 2241: sub getDirLogs($$@)
2242: {
2243: my ($cvsroot, $dirname, @otherFiles) = @_;
3.139 scop 2244: my $tag = $input{only_with_tag};
2245: my $DirName = "$cvsroot/$where";
3.120 scop 2246:
3.139 scop 2247: my @files = &safeglob("$DirName/*,v");
2248: push (@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
3.120 scop 2249: foreach my $file (@otherFiles) {
2250: push (@files, "$DirName/$file");
2251: }
2252:
3.150 scop 2253: # Weed out unreadable files.
2254: my $i = 0;
2255: my @unreadable = ();
2256: while ($i < scalar(@files)) {
2257: if (-r $files[$i]) {
2258: $i++;
2259: } else {
2260: push(@unreadable, splice(@files, $i, 1));
2261: }
2262: }
2263:
3.139 scop 2264: # If there are no files, we're done.
3.150 scop 2265: return @unreadable unless @files;
3.120 scop 2266:
3.139 scop 2267: my @cmd = ($CMD{rlog});
2268: # Can't use -r<tag> as '-' is allowed in tagnames,
2269: # but misinterpreted by rlog.
2270: push(@cmd, '-r') unless defined($tag);
3.120 scop 2271:
3.139 scop 2272: my $fh = do { local (*FH); };
2273: if (!open($fh, '-|')) { # Child
3.165 scop 2274: open(STDERR, '>', devnull()); # Ignore rlog's complaints.
3.139 scop 2275: openOutputFilter();
2276: if ($file_list_len && $file_list_len > 1) {
2277: while (scalar(@files) > $file_list_len) { # Process files in chunks.
2278: system(@cmd, splice(@files, 0, $file_list_len)) == 0 or exit -1;
2279: }
3.120 scop 2280: }
3.139 scop 2281: exec(@cmd, @files) or exit -1;
2282: }
2283: undef @cmd;
3.120 scop 2284:
3.139 scop 2285: my $state = 'start';
2286: my ($date, $branchpoint, $branch, $log, @filetags);
3.152 scop 2287: my ($rev, $revision, $revwanted, $filename, $head, $author, $keywordsubst);
3.120 scop 2288:
2289: while (<$fh>) {
2290: if ($state eq "start") {
2291:
2292: #Next file. Initialize file variables
2293: $rev = '';
2294: $revwanted = '';
2295: $branch = '';
2296: $branchpoint = '';
2297: $filename = '';
2298: $log = '';
2299: $revision = '';
2300: %symrev = ();
2301: @filetags = ();
3.152 scop 2302: $keywordsubst= '';
3.120 scop 2303:
2304: #jump to head state
2305: $state = "head";
2306: }
3.144 scop 2307:
3.120 scop 2308: again:
2309:
2310: if ($state eq "head") {
2311:
2312: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
2313:
2314: if (/^Working file: (.+)$/) {
2315: $filename = $1;
2316: } elsif (/^head: (.+)$/) {
2317: $head = $1;
2318: } elsif (/^branch: (.+)$/) {
2319: $branch = $1;
3.152 scop 2320: } elsif (/^keyword substitution: (.+)$/) {
2321: $keywordsubst = $1;
3.120 scop 2322: } elsif (/^symbolic names:/) {
2323: $state = "tags";
2324: ($branch = $head) =~ s/\.\d+$//
2325: if $branch eq '';
2326: $branch =~ s/(\d+)$/0.$1/;
2327: $symrev{MAIN} = $branch;
2328: $symrev{HEAD} = $branch;
2329: $alltags{MAIN} = 1;
2330: $alltags{HEAD} = 1;
2331: push (@filetags, "MAIN", "HEAD");
2332: } elsif (/$LOG_REVSEPARATOR/o) {
2333: $state = "log";
2334: $rev = '';
2335: $date = '';
2336: $log = '';
2337:
2338: # Try to reconstruct the relative filename if RCS spits out a full path
2339: $filename =~ s%^\Q$DirName\E/%%;
2340: }
2341: next;
2342: }
2343:
2344: if ($state eq "tags") {
2345: if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
2346: push (@filetags, $1);
2347: $symrev{$1} = $2;
2348: $alltags{$1} = 1;
2349: next;
2350: } elsif (/^\S/) {
2351:
2352: if (defined($tag)) {
2353: if (defined($symrev{$tag}) || $tag eq "HEAD") {
2354: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
2355: ($branch = $revwanted) =~ s/\b0\.//;
2356: ($branchpoint = $branch) =~ s/\.?\d+$//;
2357: $revwanted = '' if ($revwanted ne $branch);
2358: } elsif ($tag ne "HEAD") {
2359: $state = "skip";
2360: next;
2361: }
2362: }
2363:
2364: foreach my $tagfound (@filetags) {
2365: $tags{$tagfound} = 1;
2366: }
2367: $state = "head";
2368: goto again;
2369: }
2370: }
2371:
2372: if ($state eq "log") {
2373: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
2374:
2375: # End of a log entry.
2376: my $revbranch = $rev;
2377: $revbranch =~ s/\.\d+$//;
2378:
2379: if ($revwanted eq '' && $branch ne '' && $branch eq $revbranch
2380: || !defined($tag))
2381: {
2382: $revwanted = $rev;
2383: }
2384:
2385: if ($revwanted ne ''
2386: ? $rev eq $revwanted
2387: : $branchpoint ne ''
2388: ? $rev eq $branchpoint
2389: : 0
2390: && ($rev eq $head))
2391: { # Don't think head is needed here..
3.152 scop 2392: my @finfo = ($rev, $date, $log, $author, $filename, $keywordsubst);
2393: (my $name = $filename) =~ s%/.*%%;
3.120 scop 2394: $fileinfo{$name} = [@finfo];
2395: $state = "done" if ($rev eq $revwanted);
2396: }
2397: $rev = '';
2398: $date = '';
2399: $log = '';
2400: } elsif ($date eq ''
2401: && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|)
2402: {
3.172 scop 2403: my $yr = $1;
2404: $yr -= 1900 if ($yr > 100); # Damn 2-digit year routines :-)
2405: $date = timegm($6, $5, $4, $3, $2 - 1, $yr);
3.120 scop 2406: ($author) = /author: ([^;]+)/;
3.172 scop 2407: $state = 'log';
2408: $log = '';
3.120 scop 2409: next;
2410: } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
2411: $rev = $1; # .*$ eats up the locker(lockers?) info, if any
2412: next;
2413: } else {
2414: $log .= $_;
2415: }
2416: }
2417:
2418: if (/$LOG_FILESEPARATOR/o) {
2419: $state = "start";
2420: next;
2421: }
2422: }
2423:
3.139 scop 2424: my $linesread = $. || 0;
2425: close($fh);
2426:
2427: if ($linesread == 0) {
3.137 scop 2428: fatal('500 Internal Error',
2429: 'Failed to spawn GNU rlog on <em>"%s"</em>.<br><br>Did you set the <b><code>$command_path</code></b> in your configuration file correctly? (Currently: "<code>%s</code>")',
3.150 scop 2430: htmlquote(join(', ', @files)), $command_path);
3.120 scop 2431: }
3.150 scop 2432:
2433: return @unreadable;
3.120 scop 2434: }
2435:
3.175 scop 2436:
3.120 scop 2437: sub readLog($;$)
2438: {
2439: my ($fullname, $revision) = @_;
2440: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2441:
3.144 scop 2442: $revision = defined($revision) ? "-r$revision" : '';
3.120 scop 2443:
2444: undef %symrev;
2445: undef %revsym;
2446: undef @allrevisions;
2447: undef %date;
2448: undef %author;
2449: undef %state;
2450: undef %difflines;
2451: undef %log;
3.152 scop 2452: $keywordsubstitution = '';
3.120 scop 2453:
3.175 scop 2454: my $fh = do { local (*FH); };
3.120 scop 2455: if (!open($fh, "-|")) { # child
2456: if ($revision ne '') {
2457: openOutputFilter();
2458: exec($CMD{rlog}, $revision, $fullname) or exit -1;
2459: } else {
2460: openOutputFilter();
2461: exec($CMD{rlog}, $fullname) or exit -1;
2462: }
2463: }
2464:
2465: while (<$fh>) {
2466: if ($symnames) {
2467: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2468: $symrev{$1} = $2;
3.152 scop 2469: next;
3.120 scop 2470: } else {
2471: $symnames = 0;
2472: }
3.152 scop 2473: }
2474: if (/^head:\s+([\d\.]+)/) {
3.120 scop 2475: $head = $1;
2476: } elsif (/^branch:\s+([\d\.]+)/) {
2477: $curbranch = $1;
2478: } elsif (/^symbolic names/) {
2479: $symnames = 1;
3.152 scop 2480: } elsif (/^keyword substitution: (.+)$/) {
2481: $keywordsubstitution = $1;
3.120 scop 2482: } elsif (/^-----/) {
2483: last;
2484: }
2485: }
2486: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
2487:
2488: # each log entry is of the form:
2489: # ----------------------------
2490: # revision 3.7.1.1
2491: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2492: # log info
2493: # ----------------------------
2494:
2495: # For a locked revision, the first line after the separator
2496: # becomes smth like
3.149 scop 2497: # revision 9.19 locked by: vassilii;
3.120 scop 2498:
2499: logentry:
2500:
2501: while (!/$LOG_FILESEPARATOR/o) {
2502: $_ = <$fh>;
2503: last logentry if (!defined($_)); # EOF
2504: if (/^revision (\d+(?:\.\d+)+)/) {
2505: $rev = $1;
2506: unshift (@allrevisions, $rev);
2507: } elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
2508: next logentry;
2509: } else {
2510:
2511: # The rlog output is syntactically ambiguous. We must
2512: # have guessed wrong about where the end of the last log
2513: # message was.
2514: # Since this is likely to happen when people put rlog output
2515: # in their commit messages, don't even bother keeping
2516: # these lines since we don't know what revision they go with
2517: # any more.
2518: next logentry;
2519: }
2520: $_ = <$fh>;
2521: if (
2522: m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
2523: )
2524: {
3.172 scop 2525: my $yr = $1;
2526: $yr -= 1900 if ($yr > 100); # Damn 2-digit year routines :-)
2527: $date{$rev} = timegm($6, $5, $4, $3, $2 - 1, $yr);
3.120 scop 2528: $author{$rev} = $7;
2529: $state{$rev} = $8;
2530: $difflines{$rev} = $10;
2531: } else {
2532: fatal("500 Internal Error", 'Error parsing RCS output: %s', $_);
2533: }
2534:
2535: line:
2536: while (<$fh>) {
2537: next line if (/^branches:\s/);
2538: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
2539: $log{$rev} .= $_;
2540: }
2541: }
2542: close($fh);
2543:
2544: @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
2545:
2546: #
2547: # HEAD is an artificial tag which is simply the highest tag number on the main
2548: # branch, unless there is a branch tag in the RCS file in which case it's the
2549: # highest revision on that branch. Find it by looking through @revorder; it
2550: # is the first commit listed on the appropriate branch.
2551: # This is not neccesary the same revision as marked as head in the RCS file.
2552: my $headrev = $curbranch || "1";
2553: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
2554:
2555: foreach $rev (@revorder) {
2556: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2557: $symrev{"HEAD"} = $rev;
2558: last;
2559: }
2560: }
2561: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2562: if (!defined($symrev{"HEAD"}));
2563:
2564: #
2565: # Now that we know all of the revision numbers, we can associate
2566: # absolute revision numbers with all of the symbolic names, and
2567: # pass them to the form so that the same association doesn't have
2568: # to be built then.
2569: #
2570: undef @branchnames;
2571: undef %branchpoint;
2572: undef $sel;
2573:
2574: foreach (reverse sort keys %symrev) {
2575: $rev = $symrev{$_};
2576: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
2577: push (@branchnames, $_);
2578:
2579: #
2580: # A revision number of A.B.0.D really translates into
2581: # "the highest current revision on branch A.B.D".
2582: #
2583: # If there is no branch A.B.D, then it translates into
2584: # the head A.B .
2585: #
2586: # This reasoning also applies to the main branch A.B,
2587: # with the branch number 0.A, with the exception that
2588: # it has no head to translate to if there is nothing on
2589: # the branch, but I guess this can never happen?
2590: #
2591: # (the code below gracefully forgets about the branch
2592: # if it should happen)
2593: #
2594: $head = defined($2) ? $2 : "";
2595: $branch = $3;
2596: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2597: my $regex;
2598: $regex = quotemeta $branchrev;
2599: $rev = $head;
2600:
2601: foreach my $r (@revorder) {
2602: if ($r =~ /^${regex}\b/) {
2603: $rev = $branchrev;
2604: last;
2605: }
2606: }
2607: next if ($rev eq "");
2608:
2609: if ($rev ne $head && $head ne "") {
3.131 scop 2610: $branchpoint{$head} .= ', ' if ($branchpoint{$head});
3.120 scop 2611: $branchpoint{$head} .= $_;
2612: }
2613: }
2614: $revsym{$rev} .= ", " if ($revsym{$rev});
2615: $revsym{$rev} .= $_;
3.136 scop 2616: $sel .= sprintf("<option value=\"%s:%s\">%s</option>\n",
2617: htmlquote($rev), (htmlquote($_)) x 2);
3.120 scop 2618: }
2619:
2620: my ($onlyonbranch, $onlybranchpoint);
2621: if ($onlyonbranch = $input{'only_with_tag'}) {
2622: $onlyonbranch = $symrev{$onlyonbranch};
2623: if ($onlyonbranch =~ s/\b0\.//) {
2624: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2625: } else {
2626: $onlybranchpoint = $onlyonbranch;
2627: }
2628:
2629: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2630: fatal("404 Tag not found", 'Tag %s not defined',
3.131 scop 2631: $input{'only_with_tag'});
3.120 scop 2632: }
2633: }
2634:
2635: undef @revisions;
2636:
2637: foreach (@allrevisions) {
2638: ($br = $_) =~ s/\.\d+$//;
2639: ($brp = $br) =~ s/\.\d+$//;
2640: next if ($onlyonbranch
2641: && $br ne $onlyonbranch
2642: && $_ ne $onlybranchpoint);
2643: unshift (@revisions, $_);
2644: }
2645:
2646: if ($logsort eq "date") {
2647:
2648: # Sort the revisions in commit order an secondary sort on revision
2649: # (secondary sort needed for imported sources, or the first main
2650: # revision gets before the same revision on the 1.1.1 branch)
2651: @revdisplayorder =
2652: sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) } @revisions;
2653: } elsif ($logsort eq "rev") {
2654:
2655: # Sort the revisions in revision order, highest first
2656: @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
2657: } else {
2658:
2659: # No sorting. Present in the same order as rlog / cvs log
2660: @revdisplayorder = @revisions;
2661: }
2662:
2663: }
2664:
3.175 scop 2665:
3.120 scop 2666: sub printDiffLinks($$)
2667: {
2668: my ($text, $url) = @_;
2669: my @extra;
3.175 scop 2670: for my $difftype ($DIFFTYPES{$defaultDiffType}{colored} ? qw(u) : qw(h)) {
2671: my $f = $difftype eq $defaultDiffType ? '' : $difftype;
2672: push(@extra, &link(lc($DIFFTYPES{$difftype}{descr}), "$url&f=$f"));
3.120 scop 2673: }
2674: print &link($text, $url), ' (', join (', ', @extra), ')';
2675: }
2676:
3.175 scop 2677:
3.182 scop 2678: sub printLog($;$$)
3.120 scop 2679: {
3.182 scop 2680: ($_, my $link, my $isSelected) = @_;
3.175 scop 2681: (my $br = $_) =~ s/\.\d+$//;
2682: (my $brp = $br) =~ s/\.?\d+$//;
3.120 scop 2683:
2684: $link = 1 if (!defined($link));
3.131 scop 2685: my $isDead = ($state{$_} eq 'dead');
2686:
3.120 scop 2687: if ($link && !$isDead) {
3.156 scop 2688: (my $filename = $where) =~ s/^.*\///;
2689: my $fileurl = urlencode($filename);
2690: my $mimetype = getMimeType($filename);
2691: my $viewable = viewable($mimetype);
2692:
3.120 scop 2693: print "<a name=\"rev$_\"></a>";
2694:
2695: if (defined($revsym{$_})) {
2696: foreach my $sym (split (", ", $revsym{$_})) {
3.136 scop 2697: print '<a name="', hrefquote($sym), '"></a>';
3.120 scop 2698: }
2699: }
2700:
2701: if (defined($revsym{$br})
2702: && $revsym{$br}
2703: && !defined($nameprinted{$br}))
2704: {
2705: foreach my $sym (split (", ", $revsym{$br})) {
3.136 scop 2706: print '<a name="', hrefquote($sym), '"></a>';
3.120 scop 2707: }
2708: $nameprinted{$br} = 1;
2709: }
2710: print "\n Revision ";
2711: &download_link($fileurl, $_, $_,
3.156 scop 2712: $viewable ? 'text/x-cvsweb-markup' : undef);
3.120 scop 2713:
3.161 scop 2714: print ' / (';
2715:
3.156 scop 2716: if ($viewable) {
3.120 scop 2717: &download_link($fileurl, $_, "download", $mimetype);
2718: }
2719:
3.156 scop 2720: if ($mimetype ne 'text/plain') {
3.161 scop 2721: print ' / ' if $viewable;
3.120 scop 2722: &download_link($fileurl, $_, "as text", "text/plain");
2723: }
2724:
3.156 scop 2725: if (!$viewable) {
3.161 scop 2726: print ' / ' if ($mimetype ne 'text/plain');
3.120 scop 2727: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2728: }
3.161 scop 2729:
2730: print ')';
3.120 scop 2731:
2732: if ($allow_annotate) {
2733: print " - ";
2734: print &link('annotate',
2735: sprintf('%s/%s?annotate=%s%s',
2736: $scriptname, urlencode($where), $_, $barequery));
2737: }
2738:
2739: # Plus a select link if enabled, and this version isn't selected
2740: if ($allow_version_select) {
3.131 scop 2741: print ' - ';
2742: if ($isSelected) {
2743: print '<b>[selected]</b>';
3.120 scop 2744: } else {
3.159 scop 2745: print &link('select for diffs',
3.131 scop 2746: sprintf('%s?r1=%s%s#rev%s',
2747: $scriptwhere, $_, $barequery, $_));
3.120 scop 2748: }
2749: }
2750: } else {
2751: print "Revision <b>$_</b>";
2752: }
2753:
2754: if (/^1\.1\.1\.\d+$/) {
2755: print " <i>(vendor branch)</i>";
2756: }
2757: if (defined @mytz) {
2758: my ($est) = $mytz[(localtime($date{$_}))[8]];
2759: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
2760: } else {
2761: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
2762: }
3.136 scop 2763: print readableTime(time() - $date{$_}, 1), ' ago)';
3.189 ! scop 2764: print ' by <i>', htmlquote($author{$_}), "</i><br>\n";
3.136 scop 2765:
2766: if ($revsym{$br}) {
3.189 ! scop 2767: printf "Branch: <b>%s</b><br>\n",
3.136 scop 2768: $link ? link_tags($revsym{$br}) : htmlquote($revsym{$br});
2769: }
2770: if ($revsym{$_}) {
3.189 ! scop 2771: printf "CVS Tags: <b>%s</b><br>\n",
3.136 scop 2772: $link ? link_tags($revsym{$_}) : htmlquote($revsym{$_});
2773: }
2774: if ($branchpoint{$_}) {
3.189 ! scop 2775: printf "Branch point for: <b>%s</b><br>\n",
3.136 scop 2776: $link ? link_tags($branchpoint{$_}) : htmlquote($branchpoint{$_});
2777: }
3.120 scop 2778:
2779: # Find the previous revision
3.175 scop 2780: my $prev;
3.120 scop 2781: my @prevrev = split (/\./, $_);
2782: do {
2783: if (--$prevrev[$#prevrev] <= 0) {
2784:
2785: # If it was X.Y.Z.1, just make it X.Y
2786: pop (@prevrev);
2787: pop (@prevrev);
2788: }
2789: $prev = join (".", @prevrev);
2790: } until (defined($date{$prev}) || $prev eq "");
2791:
2792: if ($prev ne "") {
2793: if ($difflines{$_}) {
3.189 ! scop 2794: print "Changes since <b>$prev: $difflines{$_} lines</b><br>";
3.120 scop 2795: }
2796: }
2797:
2798: if ($isDead) {
3.189 ! scop 2799: print "<b><i>FILE REMOVED</i></b>\n";
3.120 scop 2800: } elsif ($link) {
2801: my %diffrev = ();
2802: $diffrev{$_} = 1;
2803: $diffrev{""} = 1;
2804: my $diff = 'Diff';
2805:
2806: #
2807: # Offer diff to previous revision
2808: if ($prev) {
2809: $diffrev{$prev} = 1;
2810:
2811: my $url =
2812: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $prev, $_, $barequery);
2813:
2814: print $diff, " to previous ";
2815: $diff = '';
2816: printDiffLinks($prev, $url);
2817: }
2818:
2819: #
2820: # Plus, if it's on a branch, and it's not a vendor branch,
2821: # offer a diff with the branch point.
2822: if ($revsym{$brp}
2823: && !/^1\.1\.1\.\d+$/
2824: && !defined($diffrev{$brp}))
2825: {
2826: my $url =
2827: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $brp, $_, $barequery);
2828:
2829: print $diff, " to branchpoint ";
2830: $diff = '';
2831: printDiffLinks($brp, $url);
2832: }
2833:
2834: #
2835: # Plus, if it's on a branch, and it's not a vendor branch,
2836: # offer to diff with the next revision of the higher branch.
2837: # (e.g. change gets committed and then brought
2838: # over to -stable)
2839: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2840: my ($i, $nextmain);
2841:
2842: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++) {
2843: }
2844: my @tmp2 = split (/\./, $_);
2845: for ($nextmain = ""; $i > 0; $i--) {
2846: my $next = $revorder[$i - 1];
2847: my @tmp1 = split (/\./, $next);
2848:
2849: if (@tmp1 < @tmp2) {
2850: $nextmain = $next;
2851: last;
2852: }
2853:
2854: # Only the highest version on a branch should have
2855: # a diff for the "next main".
2856: last
2857: if (@tmp1 - 1 <= @tmp2
2858: && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
2859: join (".", @tmp2[0 .. $#tmp1 - 1]));
2860: }
2861:
2862: if (!defined($diffrev{$nextmain})) {
2863: $diffrev{$nextmain} = 1;
2864:
2865: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2866: $scriptwhere, $nextmain, $_, $barequery);
2867:
2868: print $diff, " next main ";
2869: $diff = '';
2870: printDiffLinks($nextmain, $url);
2871: }
2872: }
2873:
2874: # Plus if user has selected only r1, then present a link
2875: # to make a diff to that revision
2876: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2877: $diffrev{$input{"r1"}} = 1;
2878:
2879: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2880: $scriptwhere, $input{'r1'}, $_, $barequery);
2881:
2882: print $diff, " to selected ";
2883: $diff = '';
2884: printDiffLinks($input{'r1'}, $url);
2885: }
2886:
2887: }
3.189 ! scop 2888:
3.182 scop 2889: print "\n<pre class=\"log\">\n";
3.120 scop 2890: print &htmlify($log{$_}, $allow_log_extra);
2891: print "</pre>\n";
2892: }
2893:
3.175 scop 2894:
3.132 scop 2895: #
2896: # Generates the HTML view for CvsGraph.
2897: #
3.170 scop 2898: sub doGraphView()
3.132 scop 2899: {
2900: (my $pathname = $where) =~ s|[^/]*$||;
2901: (my $filename = $where) =~ s|^.*/||;
2902:
3.170 scop 2903: navigateHeader($scriptwhere, $pathname, $filename, undef, 'graph');
3.132 scop 2904:
3.146 scop 2905: my $title = 'Revision graph of ' . htmlquote($pathname . $filename);
3.132 scop 2906: my $mapname = 'CvsGraphMap';
3.156 scop 2907: my $ctype = viewable(getMimeType($filename)) ?
2908: '&content-type=text/x-cvsweb-markup' : '';
3.132 scop 2909:
3.170 scop 2910: printf(<<EOF, $title, $mapname, $cvstree, $title);
3.146 scop 2911: <h3 style="text-align: center">%s</h3>
3.170 scop 2912: <div align="center"><img border="0" usemap="#%s" src="?cvsroot=%s&graph=1&makeimage=1" alt="%s"></div>
3.146 scop 2913: EOF
3.132 scop 2914:
3.181 scop 2915: my $qquery = hrefquote($barequery);
3.135 scop 2916: my @graph_cmd =
2917: ($CMD{cvsgraph},
2918: '-r', $cvsroot,
2919: '-i',
2920: '-M', $mapname,
3.146 scop 2921: '-x', 4,
3.181 scop 2922: "-Omap_branch_href=\"href=\\\"./?only_with_tag=%(%t%)$qquery\\\"\"",
2923: "-Omap_rev_href=\"href=\\\"?rev=%(%R%)$qquery$ctype\\\"\"",
3.146 scop 2924: "-Omap_diff_href=\"href=\\\"%(%F%).diff" .
3.181 scop 2925: "?r1=%(%P%)&r2=%(%R%)$qquery\\\"\"",
3.135 scop 2926: );
3.132 scop 2927: push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
3.174 scop 2928: push(@graph_cmd, catfile($pathname, $filename . ',v'));
3.132 scop 2929:
3.174 scop 2930: local *CVSGRAPH_OUT;
2931: local $^W = 0; # IPC::Run is noisy w/perl 5.8. Also prevents weird hangs.
2932: my ($h, $err) =
2933: startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT, timeout(30));
2934: fatal('500 Internal Error', $err) unless $h;
2935: {
2936: local $/ = undef;
2937: print <CVSGRAPH_OUT>;
3.132 scop 2938: }
3.174 scop 2939: finish($h);
3.132 scop 2940:
2941: html_footer();
2942: }
2943:
3.175 scop 2944:
3.132 scop 2945: #
2946: # Generates a graph using CvsGraph.
2947: #
3.170 scop 2948: sub doGraph()
3.132 scop 2949: {
2950: (my $pathname = $where) =~ s|[^/]*$||;
2951: (my $filename = $where) =~ s|^.*/||;
2952:
2953: http_header('image/png');
2954:
2955: my @graph_cmd = ($CMD{cvsgraph}, '-r', $cvsroot);
2956: push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
3.174 scop 2957: push(@graph_cmd, catfile($pathname, $filename . ',v'));
3.132 scop 2958:
3.174 scop 2959: local *CVSGRAPH_OUT;
2960: local $^W = 0; # IPC::Run is noisy w/perl 5.8. Also prevents weird hangs.
2961: my ($h, $err) =
2962: startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT, timeout(30));
2963: fatal('500 Internal Error', $err) unless $h;
3.132 scop 2964: {
2965: local $/ = undef;
2966: binmode(\*STDOUT);
3.174 scop 2967: print <CVSGRAPH_OUT>;
3.132 scop 2968: }
3.174 scop 2969: finish($h);
3.132 scop 2970: }
2971:
2972:
3.120 scop 2973: sub doLog($)
2974: {
2975: my ($fullname) = @_;
2976:
2977: readLog($fullname);
2978:
2979: html_header("CVS log for $where");
3.144 scop 2980:
2981: (my $upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2982: (my $filename = $where) =~ s|^.*/||;
2983: my $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2984:
3.120 scop 2985: print "<p>\n ";
2986: print &link($backicon, "$backurl#$filename"), " <b>Up to ",
2987: &clickablePath($upwhere, 1), "</b>\n</p>\n";
2988: print "<p>\n ";
2989: print &link('Request diff between arbitrary revisions', '#diff');
3.132 scop 2990: if ($allow_cvsgraph) {
3.170 scop 2991: print ' / ', &graph_link('', 'Display revisions graphically');
3.132 scop 2992: }
3.177 scop 2993: print "\n</p>\n<hr>\n";
3.120 scop 2994:
2995: print "<p>\n";
3.152 scop 2996:
2997: my $explain = $keywordsubstitution =~ /b/ ?
2998: ' (i.e.: CVS considers this a binary file)' : '';
2999: print "Keyword substitution: $keywordsubstitution$explain<br>\n";
3.144 scop 3000: print $curbranch
3001: ? ("Default branch: ", ($revsym{$curbranch} || $curbranch))
3002: : "No default branch";
3.120 scop 3003: print "<br>\n";
3004:
3.153 scop 3005: print 'Current tag: ', htmlquote($input{only_with_tag}), "<br>\n"
3006: if $input{only_with_tag};
3.120 scop 3007: print "</p>\n";
3008:
3009: undef %nameprinted;
3010:
3.182 scop 3011: for my $r (@revdisplayorder) {
3.177 scop 3012: print "<hr>\n";
3.182 scop 3013: my $sel = (defined($input{r1}) && $input{r1} eq $r);
3014: print "<div class=\"diff-selected\">\n" if $sel;
3015: printLog($r, undef, $sel);
3016: print "</div>\n" if $sel;
3.120 scop 3017: }
3018:
3.144 scop 3019: printf(<<EOF, $scriptwhere);
3.177 scop 3020: <hr>
3.189 ! scop 3021: <form method="get" action="%s.diff" name="diff_select">
! 3022: <fieldset>
! 3023: <legend>Diff request</legend>
3.144 scop 3024: <p>
3025: <a name="diff">
3.189 ! scop 3026: This form allows you to request diffs between any two revisions of a file.
3.144 scop 3027: You may select a symbolic revision name using the selection box or you may
3028: type in a numeric name using the type-in text box.
3029: </a>
3030: </p>
3031: EOF
3.120 scop 3032:
3033: foreach (@stickyvars) {
3.154 scop 3034: printf("<input type=\"hidden\" name=\"%s\" value=\"%s\">\n",
3035: $_, htmlquote($input{$_}))
3.120 scop 3036: if (defined($input{$_})
3037: && ((!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_})
3038: && $input{$_} ne ""));
3039: }
3.144 scop 3040:
3041: print <<EOF;
3.189 ! scop 3042: <table summary="Diff between arbitrary revisions">
3.144 scop 3043: <tr>
3.189 ! scop 3044: <td class="opt-label">
! 3045: <label for="r1" accesskey="1">Diffs between</label>
! 3046: </td>
! 3047: <td class="opt-value">
3.144 scop 3048: <select id="r1" name="r1">
3049: <option value="text" selected>Use Text Field</option>
3050: EOF
3051: print $sel, "</select>\n";
3052:
3053: my $diffrev = defined($input{r1}) ?
3054: $input{r1} : $revdisplayorder[$#revdisplayorder];
3055:
3056: printf(<<EOF, $inputTextSize, $diffrev);
3.147 scop 3057: <input type="text" size="%s" name="tr1" value="%s" onchange="this.form.r1.selectedIndex=0">
3.144 scop 3058: </td>
3.189 ! scop 3059: <td></td>
! 3060: </tr>
! 3061: <tr>
! 3062: <td class="opt-label">
! 3063: <label for="r2" accesskey="2">and</label>
! 3064: </td>
! 3065: <td class="opt-value">
3.144 scop 3066: <select id="r2" name="r2">
3067: <option value="text" selected>Use Text Field</option>
3068: EOF
3069: print $sel, "</select>\n";
3070:
3071: $diffrev = defined($input{r2}) ? $input{r2} : $revdisplayorder[0];
3072:
3073: printf(<<EOF, $inputTextSize, $diffrev, $scriptwhere);
3074: <input type="text" size="%s" name="tr2" value="%s" onchange="this.form.r2.selectedIndex=0">
3075: </td>
3.189 ! scop 3076: <td><input type="submit" value="Get Diffs" accesskey="G"></td>
3.144 scop 3077: </tr>
3078: </table>
3.189 ! scop 3079: </fieldset>
3.144 scop 3080: </form>
3081: <form method="get" action="%s">
3.189 ! scop 3082: <fieldset>
! 3083: <legend>Log view options</legend>
! 3084: <table summary="Log view options">
3.144 scop 3085: <tr>
3.189 ! scop 3086: <td class="opt-label">
! 3087: <label for="f" accesskey="D">Preferred diff type:</label>
! 3088: </td>
! 3089: <td class="opt-value">
3.144 scop 3090: EOF
3.120 scop 3091: printDiffSelect($use_java_script);
3.144 scop 3092: print <<EOF;
3.189 ! scop 3093: </td>
! 3094: <td></td>
3.144 scop 3095: </tr>
3096: EOF
3.120 scop 3097:
3098: if (@branchnames) {
3.144 scop 3099:
3100: printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3101: <tr>
3.189 ! scop 3102: <td class="opt-label">
3.188 scop 3103: <label for="only_with_tag" accesskey="B">View only branch:</label>
3.189 ! scop 3104: </td>
! 3105: <td class="opt-value">
! 3106: <a name="branch">
3.144 scop 3107: <select id="only_with_tag" name="only_with_tag"%s>
3108: EOF
3109: print '<option value=""';
3110: print ' selected'
3111: if (defined($input{"only_with_tag"}) && $input{"only_with_tag"} eq '');
3.120 scop 3112: print ">Show all branches</option>\n";
3113:
3114: foreach (reverse sort @branchnames) {
3.136 scop 3115: my $selected =
3116: (defined($input{"only_with_tag"}) && $input{"only_with_tag"} eq $_);
3117: printf("<option%s>%s</option>\n",
3118: $selected ? ' selected' : '',
3119: htmlquote($_));
3.120 scop 3120: }
3.144 scop 3121: print <<EOF
3122: </select>
3.189 ! scop 3123: </a>
3.144 scop 3124: </td>
3125: <td></td>
3126: </tr>
3127: EOF
3.120 scop 3128: }
3129:
3.144 scop 3130: print <<EOF;
3.189 ! scop 3131: <tr>
! 3132: <td class="opt-label">
! 3133: <label for="logsort" accesskey="L">Sort log by:</label>
! 3134: </td>
! 3135: <td>
3.144 scop 3136: EOF
3.120 scop 3137: printLogSortSelect($use_java_script);
3.144 scop 3138: print <<EOF;
3.189 ! scop 3139: </td>
! 3140: <td><input type="submit" value="Set" accesskey="S"></td>
! 3141: </tr>
3.144 scop 3142: </table>
3143: EOF
3.154 scop 3144: foreach (@stickyvars) {
3145: next if ($_ eq "f");
3146: next if ($_ eq "only_with_tag");
3147: next if ($_ eq "logsort");
3148: printf("<input type=\"hidden\" name=\"$_\" value=\"%s\">\n",
3149: htmlquote($input{$_}))
3150: if (defined($input{$_})
3151: && (!defined($DEFAULTVALUE{$_})
3152: || $input{$_} ne $DEFAULTVALUE{$_})
3153: && $input{$_} ne "");
3154: }
3.189 ! scop 3155: print "</fieldset>\n</form>\n";
3.120 scop 3156: html_footer();
3157: }
3158:
3.175 scop 3159:
3.120 scop 3160: sub flush_diff_rows($$$$)
3161: {
3162: my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
3163:
3.175 scop 3164: return unless defined($state);
3.120 scop 3165:
3166: if ($state eq "PreChangeRemove") { # we just got remove-lines before
3.133 scop 3167: for (my $j = 0; $j < $leftRow; $j++) {
3.144 scop 3168: printf(<<EOF, scalar(@$leftColRef[$j]));
3169: <tr>
3170: <td class="diff-removed"> %s</td>
3171: <td class="diff-empty"> </td>
3172: </tr>
3173: EOF
3.120 scop 3174: }
3175: } elsif ($state eq "PreChange") { # state eq "PreChange"
3176: # we got removes with subsequent adds
3.176 scop 3177: if ($Have_Ediff) {
3178: # construct the suffix tree
3179: my $left_diff = join("\n", @$leftColRef[0..$leftRow-1]);
3180: my $right_diff = join("\n", @$rightColRef[0..$rightRow-1]);
3181: my $diff_str = String::Ediff::ediff($left_diff, $right_diff);
3182:
3183: my @diff_str = split(/ /, $diff_str);
3184: my $INFINITY = 10000000;
3185: push(@diff_str, ($INFINITY) x 8);
3186: my ($idx, $b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3187: (0, @diff_str[0..7]);
3188: my ($l_cul, $r_cul) = (0, 0);
3189: my ($ldx, $rdx) = (0, 0);
3190: my (@left_html, @right_html);
3191: for (my $j = 0; $j < $leftRow; $j++) {
3192: my $line_len = length(@$leftColRef[$j]);
3193: my $line = @$leftColRef[$j];
3194: $l_cul += length($line) + 1; # includes "\n"
3195: my $l_culx = $l_cul - 1; # not includes "\n"
3196: if ($j < $lb1) {
3197: $line = spacedHtmlText($line);
3198: push(@left_html, "<td class=\"diff-changed\">$line</td>");
3199: } elsif ($lb1 == $j) {
3200: my $html_line;
3201: while ($lb1 == $j) {
3202: my $begin_char = $l_culx - $b1;
3203:
3204: $line =~ /^(.*)(.{$begin_char})$/;
3205: $html_line .= spacedHtmlText($1) .
3206: '</span><span class="diff-unchanged">';
3207: $line = $2;
3208: last if ($j != $le1);
3209:
3210: my $end_char = $l_culx - $e1;
3211: $line =~ /^(.*)(.{$end_char})$/;
3212: $html_line .= spacedHtmlText($1) .
3213: '</span><span class="diff-changed">';
3214: $line = $2;
3215:
3216: $idx++;
3217: my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
3218: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
3219: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3220: @diff_str[$idx*8..($idx+1)*8-1];
3221: $lb1 = $INFINITY if ($lb1 < 0);
3222: $lb2 = $INFINITY if ($lb2 < 0);
3223: $le1 = $INFINITY if ($le1 < 0);
3224: $le2 = $INFINITY if ($le2 < 0);
3225: if ($te1 > $b1) {
3226: ($b1, $lb1) = ($te1, $tle1);
3227: }
3228: if ($te2 > $b2) {
3229: ($b2, $lb2) = ($te2, $tle2);
3230: }
3231: }
3232: push(@left_html,
3233: sprintf('<td><span class="%s">%s%s</span></td>',
3234: 'diff-changed', $html_line, spacedHtmlText($line)));
3235: } elsif ($le1 == $j) {
3236: my $html_line;
3237: while ($le1 == $j) {
3238: my $end_char = $l_culx - $e1;
3239: $line =~ /^(.*)(.{$end_char})$/;
3240: $html_line .= spacedHtmlText($1) .
3241: '</span><span class="diff-changed">';
3242: $line = $2;
3243:
3244: $idx++;
3245: my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
3246: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
3247: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3248: @diff_str[$idx*8..($idx+1)*8-1];
3249: $lb1 = $INFINITY if ($lb1 < 0);
3250: $lb2 = $INFINITY if ($lb2 < 0);
3251: $le1 = $INFINITY if ($le1 < 0);
3252: $le2 = $INFINITY if ($le2 < 0);
3253: if ($te1 > $b1) {
3254: ($b1, $lb1) = ($te1, $tle1);
3255: }
3256: if ($te2 > $b2) {
3257: ($b2, $lb2) = ($te2, $tle2);
3258: }
3259:
3260: last if ($lb1 != $j);
3261:
3262: my $begin_char = $l_culx - $b1;
3263:
3264: $line =~ /^(.*)(.{$begin_char})$/;
3265: $html_line .= spacedHtmlText($1) .
3266: '</span><span class="diff-unchanged">';
3267: $line = $2;
3268: }
3269: push(@left_html,
3270: sprintf('<td><span class="%s">%s%s</span></td>',
3271: 'diff-unchanged', $html_line, spacedHtmlText($line)));
3272: } else {
3273: $line = spacedHtmlText($line);
3274: push(@left_html, "<td class=\"diff-unchanged\">$line</td>");
3275: }
3276: }
3277: ($idx, $b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3278: (0, @diff_str[0..7]);
3279: $lb1 = $INFINITY if ($lb1 < 0);
3280: $lb2 = $INFINITY if ($lb2 < 0);
3281: $le1 = $INFINITY if ($le1 < 0);
3282: $le2 = $INFINITY if ($le2 < 0);
3283: for (my $j = 0; $j < $rightRow; $j++) {
3284: my $line_len = length(@$rightColRef[$j]);
3285: my $line = @$rightColRef[$j];
3286: $r_cul += length($line) + 1; # includes "\n"
3287: my $r_culx = $r_cul - 1; # not includes "\n"
3288: if ($j < $lb2) {
3289: $line = spacedHtmlText($line);
3290: push(@right_html, "<td class=\"diff-changed\">$line</td>");
3291: } elsif ($lb2 == $j) {
3292: my $html_line;
3293: while ($lb2 == $j) {
3294: my $begin_char = $r_culx - $b2;
3295:
3296: $line =~ /^(.*)(.{$begin_char})$/;
3297: $html_line .= spacedHtmlText($1) .
3298: '</span><span class="diff-unchanged">';
3299: $line = $2;
3300:
3301: last if ($j != $le2);
3302:
3303: my $end_char = $r_culx - $e2;
3304: $line =~ /^(.*)(.{$end_char})$/;
3305: $html_line .= spacedHtmlText($1) .
3306: '</span><span class="diff-changed">';
3307: $line = $2;
3308:
3309: $idx++;
3310: my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
3311: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
3312: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3313: @diff_str[$idx*8..($idx+1)*8-1];
3314: $lb1 = $INFINITY if ($lb1 < 0);
3315: $lb2 = $INFINITY if ($lb2 < 0);
3316: $le1 = $INFINITY if ($le1 < 0);
3317: $le2 = $INFINITY if ($le2 < 0);
3318: if ($te1 > $b1) {
3319: ($b1, $lb1) = ($te1, $tle1);
3320: }
3321: if ($te2 > $b2) {
3322: ($b2, $lb2) = ($te2, $tle2);
3323: }
3324: }
3325: push(@right_html,
3326: sprintf('<td><span class="%s">%s%s</span></td>',
3327: 'diff-changed', $html_line, spacedHtmlText($line)));
3328: } elsif ($le2 == $j) {
3329: my $html_line;
3330: while ($le2 == $j) {
3331: my $end_char = $r_culx - $e2;
3332: $line =~ /^(.*)(.{$end_char})$/;
3333: $html_line .= spacedHtmlText($1) .
3334: '</span><span class="diff-changed">';
3335: $line = $2;
3336:
3337: $idx++;
3338: my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
3339: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
3340: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3341: @diff_str[$idx*8..($idx+1)*8-1];
3342: $lb1 = $INFINITY if ($lb1 < 0);
3343: $lb2 = $INFINITY if ($lb2 < 0);
3344: $le1 = $INFINITY if ($le1 < 0);
3345: $le2 = $INFINITY if ($le2 < 0);
3346: if ($te1 > $b1) {
3347: ($b1, $lb1) = ($te1, $tle1);
3348: }
3349: if ($te2 > $b2) {
3350: ($b2, $lb2) = ($te2, $tle2);
3351: }
3352:
3353: last if ($lb2 != $j);
3354:
3355: my $begin_char = $r_culx - $b2;
3356: $line =~ /^(.*)(.{$begin_char})$/;
3357: $html_line .= spacedHtmlText($1) .
3358: '</span><span class="diff-unchanged">';
3359: $line = $2;
3360: }
3361: push(@right_html,
3362: sprintf('<td nowrap><span class="%s">%s%s</span></td>',
3363: 'diff-unchanged', $html_line, spacedHtmlText($line)));
3364: } else {
3365: $line = spacedHtmlText ($line);
3366: push @right_html, "<td class=\"diff-unchanged\">$line</td>";
3367: }
3368: }
3369: for (my $j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
3370: print '<tr>';
3371: if ($j < $leftRow) {
3372: print $left_html[$j];
3373: } else {
3374: print '<td class="diff-changed-missing"> </td>';
3375: }
3376: if ($j < $rightRow) {
3377: print $right_html[$j];
3378: } else {
3379: print '<td class="diff-changed-missing"> </td>';
3380: }
3381: print "</tr>\n";
3.120 scop 3382: }
3.176 scop 3383: } else {
3384: for (my $j = 0; $j < $leftRow || $j < $rightRow; $j++) { # dump both cols
3385: print "<tr>\n";
3386: if ($j < $leftRow) {
3387: print '<td class="diff-changed"> ' .
3388: spacedHtmlText(@$leftColRef[$j]) . '</td>';
3389: } else {
3390: print '<td class="diff-changed-missing"> </td>';
3391: }
3392: print "\n";
3.120 scop 3393:
3.176 scop 3394: if ($j < $rightRow) {
3395: print '<td class="diff-changed"> ' .
3396: spacedHtmlText(@$rightColRef[$j]) . '</td>';
3397: } else {
3398: print '<td class="diff-changed-missing"> </td>';
3399: }
3400: print "\n</tr>\n";
3.120 scop 3401: }
3402: }
3403: }
3.1 knu 3404: }
3405:
3.175 scop 3406:
3.1 knu 3407: ##
3408: # Function to generate Human readable diff-files
3409: # human_readable_diff(String revision_to_return_to);
3410: ##
3.144 scop 3411: sub human_readable_diff($$)
3.120 scop 3412: {
3413: my ($fh, $rev) = @_;
3.144 scop 3414:
3.169 scop 3415: (my $where_nd = $where) =~ s|\.diff$||;
3416: (my $filename = $where_nd) =~ s|^.*/||;
3417: (my $pathname = $where_nd) =~ s|(Attic/)?[^/]*$||;
3418: (my $scriptwhere_nd = $scriptwhere) =~ s|\.diff$||;
3.120 scop 3419:
3.133 scop 3420: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, 'diff');
3.120 scop 3421:
3.178 scop 3422: # Read header to pick up read revision and date, if possible.
3423:
3424: my ($r1d, $r1r, $r2d, $r2r);
3.120 scop 3425: while (<$fh>) {
3426: ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
3427: ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
3428: last if (/^\+\+\+ /);
3429: }
3430:
3.178 scop 3431: my ($rev1, $date1);
3.120 scop 3432: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
3433: $rev1 = $r1r;
3434: $date1 = $r1d;
3435: }
3.178 scop 3436: my ($rev2, $date2);
3.120 scop 3437: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
3438: $rev2 = $r2r;
3439: $date2 = $r2d;
3440: }
3.178 scop 3441: $rev1 = 'unknown-left' unless defined($rev1);
3442: $rev2 = 'unknown-right' unless defined($rev2);
3443: $date1 = defined($date1) ? ', ' . htmlquote($date1) : '';
3444: $date2 = defined($date2) ? ', ' . htmlquote($date2) : '';
3.120 scop 3445:
3.144 scop 3446: # Using <table style=\"border: none\" here breaks NS 4.x badly...
3.178 scop 3447: printf(<<EOF, $where_nd, $rev1, $rev2, $rev1, $date1, $rev2, $date2);
3.144 scop 3448: <h3 style="text-align: center">Diff for /%s between versions %s and %s</h3>
3.179 scop 3449: <table border="0" cellspacing="0" cellpadding="0" width="100%%" summary="Diff output">
3.144 scop 3450: <tr style="background-color: #ffffff">
3.178 scop 3451: <th style="text-align: center; vertical-align: top" width="50%%">
3452: version %s%s
3453: </th>
3454: <th style="text-align: center; vertical-align: top" width="50%%">
3455: version %s%s
3.144 scop 3456: </th>
3.178 scop 3457: </tr>
3.144 scop 3458: EOF
3.120 scop 3459:
3460: # Process diff text
3461: # prefetch several lines
3462: my @buf = head($fh);
3.144 scop 3463: my %d = scan_directives(@buf);
3.120 scop 3464:
3.144 scop 3465: my $leftRow = 0;
3466: my $rightRow = 0;
3467: my ($difftxt, @rightCol, @leftCol, $oldline, $newline, $funname);
3468: my ($diffcode, $rest);
3.120 scop 3469:
3470: while (@buf || !eof($fh)) {
3471: $difftxt = @buf ? shift @buf : <$fh>;
3472:
3473: if ($difftxt =~ /^@@/) {
3474: ($oldline, $newline, $funname) =
3475: $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
3476: $funname = htmlquote($funname);
3477: $funname =~ s/\s/ /go;
3.182 scop 3478: $funname &&= " <span style=\"font-size: smaller\">$funname</span>";
3.144 scop 3479:
3480: printf(<<EOF, $oldline, $funname, $newline, $funname);
3.182 scop 3481: <tr>
3482: <td width="50%%" class="diff-heading">
3483: <b>Line %s</b>%s
3484: </td>
3485: <td width="50%%" class="diff-heading">
3486: <b>Line %s</b>%s
3.144 scop 3487: </td>
3488: EOF
3489:
3.120 scop 3490: $state = "dump";
3491: $leftRow = 0;
3492: $rightRow = 0;
3493: } else {
3494: ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
3.176 scop 3495: $_ = $rest;
3.120 scop 3496:
3497: #########
3498: # little state machine to parse unified-diff output (Hen, zeller@think.de)
3499: # in order to get some nice 'ediff'-mode output
3500: # states:
3501: # "dump" - just dump the value
3502: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
3503: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
3504: ##########
3505:
3506: if ($diffcode eq '+') {
3507: if ($state eq "dump")
3508: { # 'change' never begins with '+': just dump out value
3.176 scop 3509: $_ = spacedHtmlText($rest, $d{'tabstop'});
3.144 scop 3510: printf(<<EOF, $_);
3511: <tr>
3512: <td class="diff-empty"> </td>
3513: <td class="diff-added"> %s</td>
3514: </tr>
3515: EOF
3.120 scop 3516: } else { # we got minus before
3517: $state = "PreChange";
3518: $rightCol[$rightRow++] = $_;
3519: }
3520: } elsif ($diffcode eq '-') {
3521: $state = "PreChangeRemove";
3522: $leftCol[$leftRow++] = $_;
3523: } else { # empty diffcode
3524: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3.176 scop 3525: $_ = spacedHtmlText($rest, $d{'tabstop'});
3.147 scop 3526: printf(<<EOF, $_, $_);
3.144 scop 3527: <tr>
3528: <td class="diff-same"> %s</td>
3529: <td class="diff-same"> %s</td>
3530: </tr>
3531: EOF
3.120 scop 3532: $state = "dump";
3533: $leftRow = 0;
3534: $rightRow = 0;
3535: }
3536: }
3537: }
3538: close($fh);
3539:
3540: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3541:
3542: # state is empty if we didn't have any change
3543: if (!$state) {
3.144 scop 3544: print <<EOF;
3545: <tr>
3546: <td colspan="2"> </td>
3547: </tr>
3548: <tr class="diff-empty">
3549: <td colspan="2" align="center"><b>- No viewable change -</b></td>
3550: </tr>
3551: EOF
3.120 scop 3552: }
3553:
3.182 scop 3554: printf(<<EOF, $scriptwhere);
3.144 scop 3555: </table>
3.177 scop 3556: <hr style="width: 100%%">
3.144 scop 3557: <form method="get" action="%s">
3.182 scop 3558: <div style="float: left">
3559: <label for="f">Diff format:<br>
3.144 scop 3560: EOF
3.168 scop 3561: printDiffSelectStickyVars();
3.120 scop 3562: printDiffSelect($use_java_script);
3.182 scop 3563: printf(<<EOF, $rev1, $rev2);
3.179 scop 3564: </label>
3.144 scop 3565: <input type="submit" value="Show">
3.182 scop 3566: </div>
3567: <table style="float: right; border: thin outset" cellspacing="0" cellpadding="1" title="Legend" summary="Legend">
3568: <tr>
3569: <td align="center" class="diff-removed">Removed from v.%s</td>
3570: <td class="diff-empty"> </td>
3571: </tr><tr class="diff-changed">
3572: <td align="center" colspan="2">changed lines</td>
3573: </tr><tr>
3574: <td class="diff-empty"> </td>
3575: <td align="center" class="diff-added">Added in v.%s</td>
3576: </tr>
3.144 scop 3577: </table>
3578: </form>
3.182 scop 3579: <br clear="all">
3.144 scop 3580: EOF
3.120 scop 3581: }
3.167 scop 3582:
3583:
3584: sub doEnscript($$$)
3585: {
3586: my ($filehandle, $highlight, $linenumbers) = @_;
3587:
3.174 scop 3588: my @cmd = ($CMD{enscript},
3589: @enscript_options,
3590: qw(-q --language=cvsweb -o -),
3591: "--highlight=$highlight");
3592:
3593: local $^W = 0; # IPC::Run is noisy w/ perl 5.8.
3594: local *ENSCRIPT_OUT;
3595: my ($h, $err) =
3596: startproc(\@cmd, $filehandle, '>pipe', \*ENSCRIPT_OUT, timeout(30));
3597: fatal('500 Internal Error', $err) unless $h;
3598:
3599: # We could short-circuit and have enscript output directly to STDOUT above,
3600: # but that doesn't work with mod_perl (at least some 1.99 versions).
3601: if ($linenumbers) {
3602: my $ln = 0;
3603: while (<ENSCRIPT_OUT>) {
3604: printf '<a id="l%d" class="src">%5d: </a>', (++$ln) x 2;
3605: print $_;
3.167 scop 3606: }
3.174 scop 3607: } else {
3608: local $/ = undef;
3609: print <ENSCRIPT_OUT>;
3.167 scop 3610: }
3.174 scop 3611: finish($h);
3.167 scop 3612: }
3613:
3.120 scop 3614:
3.163 scop 3615: sub navigateHeader($$$$$;$)
3.120 scop 3616: {
3.163 scop 3617: my ($swhere, $path, $filename, $rev, $title, $moddate) = @_;
3.120 scop 3618: $swhere = "" if ($swhere eq $scriptwhere);
3619: $swhere = './' . urlencode($filename) if ($swhere eq "");
3620:
3.136 scop 3621: my $qfile = htmlquote($filename);
3622: my $qpath = htmlquote($path);
3.170 scop 3623: my $trev = $rev ? " - $rev" : '';
3.100 knu 3624:
3.163 scop 3625: http_header('', $moddate);
3.133 scop 3626:
3.120 scop 3627: print <<EOF;
3.100 knu 3628: $HTML_DOCTYPE
3.89 knu 3629: <html>
3630: <head>
3.170 scop 3631: <title>$qpath$qfile - $title$trev</title>
3.144 scop 3632: $HTML_META$CSS</head>
3.129 scop 3633: <body class="src">
3.182 scop 3634: <table class="navigate-header" width="100%">
3.184 scop 3635: <tr>
3636: <td>
3.64 knu 3637: EOF
3638:
3.170 scop 3639: print &link($backicon, "$swhere$query" . ($rev ? "#rev$rev" : ''));
3.136 scop 3640: printf '<b>Return to %s CVS log',
3.170 scop 3641: &link(htmlquote($filename), "$swhere$query" . ($rev ? "#rev$rev" : ''));
3.120 scop 3642: print "</b> $fileicon</td>";
3643:
3.144 scop 3644: printf(<<EOF, $diricon, &clickablePath($path, 1));
3.182 scop 3645: <td style="text-align: right">%s <b>Up to %s</b></td>
3.144 scop 3646: </tr>
3647: </table>
3648: EOF
3.120 scop 3649: }
3650:
3.175 scop 3651:
3.120 scop 3652: sub plural_write($$)
3653: {
3654: my ($num, $text) = @_;
3655: if ($num != 1) {
3656: $text .= "s";
3657: }
3658:
3659: if ($num > 0) {
3660: return join (' ', $num, $text);
3661: } else {
3662: return "";
3663: }
3.1 knu 3664: }
3665:
3.175 scop 3666:
3.1 knu 3667: ##
3668: # print readable timestamp in terms of
3669: # '..time ago'
3670: # H. Zeller <zeller@think.de>
3671: ##
3.120 scop 3672: sub readableTime($$)
3673: {
3674: my ($secs, $long) = @_;
3675:
3.175 scop 3676: # This function works correctly for time >= 2 seconds.
3677: return 'very little time' if ($secs < 2);
3.120 scop 3678:
3679: my %desc = (
3.133 scop 3680: 1 => 'second',
3681: 60 => 'minute',
3682: 3600 => 'hour',
3683: 86400 => 'day',
3684: 604800 => 'week',
3685: 2628000 => 'month',
3686: 31536000 => 'year'
3687: );
3688:
3.120 scop 3689: my @breaks = sort { $a <=> $b } keys %desc;
3.133 scop 3690: my $i = 0;
3.120 scop 3691:
3692: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3693: $i++;
3694: }
3695: $i--;
3.133 scop 3696: my $break = $breaks[$i];
3697: my $retval = plural_write(int($secs / $break), $desc{$break});
3.120 scop 3698:
3699: if ($long == 1 && $i > 0) {
3700: my $rest = $secs % $break;
3701: $i--;
3702: $break = $breaks[$i];
3703: my $resttime = plural_write(int($rest / $break), $desc{$break});
3704: if ($resttime) {
3705: $retval .= ", $resttime";
3706: }
3707: }
3.1 knu 3708:
3.120 scop 3709: return $retval;
3.1 knu 3710: }
3711:
3.175 scop 3712:
3.1 knu 3713: ##
3714: # clickablePath(String pathname, boolean last_item_clickable)
3715: #
3716: # returns a html-ified path whereas each directory is a link for
3717: # faster navigation. last_item_clickable controls whether the
3718: # basename (last directory/file) is a link as well
3719: ##
3.120 scop 3720: sub clickablePath($$)
3721: {
3722: my ($pathname, $clickLast) = @_;
3723:
3.154 scop 3724: my $root = '[' . htmlquote($CVSROOTdescr{$cvstree} || $cvstree) . ']';
3725:
3.144 scop 3726: # This should never happen (see chooseCVSRoot()), but let's be sure...
3.154 scop 3727: return $root if ($pathname eq '/');
3.120 scop 3728:
3.144 scop 3729: my $retval =
3.154 scop 3730: ' ' . &link($root, sprintf('%s/%s#dirlist', $scriptname, $query));
3.144 scop 3731: my $wherepath = '';
3732: my ($lastslash) = $pathname =~ m|/$|;
3733:
3734: foreach (split (/\//, $pathname)) {
3735: $retval .= ' / ';
3736: $wherepath .= "/$_";
3737: my $last = "$wherepath/" eq "/$pathname" || $wherepath eq "/$pathname";
3738:
3739: if ($clickLast || !$last) {
3740: $retval .= &link(htmlquote($_),
3741: join ('',
3742: $scriptname, urlencode($wherepath),
3743: (!$last || $lastslash ? '/' : ''), $query,
3744: (!$last || $lastslash ? "#dirlist" : "")));
3745: } else { # do not make a link to the current dir
3746: $retval .= htmlquote($_);
3.120 scop 3747: }
3748: }
3749: return $retval;
3750: }
3751:
3.144 scop 3752:
3.120 scop 3753: sub chooseCVSRoot()
3754: {
3755: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3756: if (2 <= @CVSROOT) {
3.133 scop 3757: foreach my $k (keys %input) {
3.154 scop 3758: printf("<input type=\"hidden\" name=\"%s\" value=\"%s\">\n",
3759: htmlquote($k), htmlquote($input{$k}))
3760: if ($input{$k} && $k ne 'cvsroot');
3.120 scop 3761: }
3762:
3763: # Form-Elements look wierd in Netscape if the background
3764: # isn't gray and the form elements are not placed
3765: # within a table ...
3.144 scop 3766: printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3767: <table style="border: none">
3768: <tr>
3769: <td><label for="cvsroot" accesskey="C">CVS Root:</label></td>
3770: <td>
3771: <select id="cvsroot" name="cvsroot"%s>
3772: EOF
3.120 scop 3773:
3.133 scop 3774: foreach my $k (@CVSROOT) {
3.136 scop 3775: printf("<option value=\"%s\"%s>%s</option>\n",
3776: htmlquote($k),
3777: ($k eq $cvstree) ? ' selected' : '',
3778: htmlquote($CVSROOTdescr{$k} || $k));
3.120 scop 3779: }
3780: print "</select>\n</td>\n<td>";
3781: } else {
3782:
3783: # no choice -- but we need the form to select module/path,
3784: # at least for Netscape
3.154 scop 3785: printf "<p>\nCVS Root: <b>[%s]</b>",
3786: htmlquote($CVSROOTdescr{$cvstree} || $cvstree);
3.120 scop 3787: }
3788:
3.144 scop 3789: print <<EOF;
3790: <label for="mpath" accesskey="M">
3791: Module path or alias:
3792: <input type="text" id="mpath" name="path" value="" size="15">
3793: </label>
3794: <input type="submit" value="Go" accesskey="O">
3795: EOF
3.120 scop 3796:
3.144 scop 3797: print 2 <= @CVSROOT ? "</td>\n</tr>\n</table>" : '</p>';
3.120 scop 3798: print "\n</form>";
3799: }
3800:
3.175 scop 3801:
3.120 scop 3802: sub chooseMirror()
3803: {
3804: # This code comes from the original BSD-cvsweb
3805: # and may not be useful for your site; If you don't
3806: # set %MIRRORS this won't show up, anyway.
3807: scalar(%MIRRORS) or return;
3808:
3809: # Should perhaps exclude the current site somehow...
3810: print "\n<p>\nThis CVSweb is mirrored in\n";
3811:
3812: my @tmp = map(&link(htmlquote($_), $MIRRORS{$_}), sort keys %MIRRORS);
3813: my $tmp = pop (@tmp);
3814:
3815: if (scalar(@tmp)) {
3816: print join (', ', @tmp), ' and ';
3817: }
3818:
3819: print "$tmp.\n</p>\n";
3820: }
3821:
3.175 scop 3822:
3.120 scop 3823: sub fileSortCmp()
3824: {
3.175 scop 3825: (my $af = $a) =~ s/,v$//;
3826: (my $bf = $b) =~ s/,v$//;
3.120 scop 3827: my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
3828: if (defined($fileinfo{$af}));
3829: my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
3830: if (defined($fileinfo{$bf}));
3831:
3.175 scop 3832: my $comp = 0;
3.140 scop 3833: if (defined($filename1) && defined($filename2) &&
3834: $af eq $filename1 && $bf eq $filename2)
3.120 scop 3835: {
3836:
3837: # Two files
3.140 scop 3838: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
3839: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
3840: if ($input{ignorecase}) {
3841: $comp = (uc($log1) cmp uc($log2)) if ($bylog && $log1 && $log2);
3842: $comp = (uc($author1) cmp uc($author2)) if ($byauthor &&
3843: $author1 && $author2);
3844: } else {
3845: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
3846: $comp = ($author1 cmp $author2) if ($byauthor &&
3847: $author1 && $author2);
3848: }
3.120 scop 3849: }
3850:
3851: if ($comp == 0) {
3852:
3853: # Directories first, then files under version control,
3854: # then other, "rogue" files.
3855: # Sort by filename if no other criteria available.
3856:
3857: my $ad = (
3858: (-d "$fullname/$a")
3859: ? 'D'
3860: : (defined($fileinfo{$af}) ? 'F' : 'R')
3861: );
3862: my $bd = (
3863: (-d "$fullname/$b")
3864: ? 'D'
3865: : (defined($fileinfo{$bf}) ? 'F' : 'R')
3866: );
3.175 scop 3867: (my $c = $a) =~ s|.*/||;
3868: (my $d = $b) =~ s|.*/||;
3.144 scop 3869:
3870: my ($l, $r) = ("$ad$c", "$bd$d");
3871: $comp = $input{ignorecase} ? (uc($l) cmp uc($r)) : ($l cmp $r);
3872:
3873: # Parent dir is always first, then Attic.
3874: if ($comp != 0) {
3875: if ($l eq 'D..') {
3.149 scop 3876: $comp = -1;
3.144 scop 3877: } elsif ($r eq 'D..') {
3.149 scop 3878: $comp = 1;
3.144 scop 3879: } elsif ($l eq 'DAttic') {
3.149 scop 3880: $comp = -1;
3.144 scop 3881: } elsif ($r eq 'DAttic') {
3.149 scop 3882: $comp = 1;
3.144 scop 3883: }
3884: }
3.120 scop 3885: }
3886: return $comp;
3.1 knu 3887: }
3888:
3.175 scop 3889:
3.1 knu 3890: # make A url for downloading
3.120 scop 3891: sub download_url($$;$)
3892: {
3893: my ($url, $revision, $mimetype) = @_;
3894: $revision =~ s/\b0\.//;
3.1 knu 3895:
3.146 scop 3896: if (defined($checkoutMagic) &&
3897: (!defined($mimetype) || $mimetype !~ $CvsWebMarkupRE))
3.120 scop 3898: {
3899: my $path = $where;
3900: $path =~ s|[^/]+$||;
3901: $url = "$scriptname/$checkoutMagic/${path}$url";
3902: }
3903: $url .= "?rev=$revision";
3904: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.67 knu 3905:
3.175 scop 3906: return $url;
3.1 knu 3907: }
3908:
3.175 scop 3909:
3910: #
3911: # Presents a link to download the selected revision.
3912: #
3.120 scop 3913: sub download_link($$$;$)
3914: {
3915: my ($url, $revision, $textlink, $mimetype) = @_;
3916:
3.175 scop 3917: my $fullurl = download_url($url, $revision, $mimetype);
3.120 scop 3918: $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
3919:
3.159 scop 3920: printf '<a href="%s" class="download-link"', hrefquote("$fullurl$barequery");
3.120 scop 3921:
3.146 scop 3922: if ($open_extern_window &&
3923: (!defined($mimetype) || $mimetype !~ $CvsWebMarkupRE))
3.120 scop 3924: {
3925: print ' target="cvs_checkout"';
3926:
3927: # we should have
3928: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3929: # in order to allow the user to resize the window; otherwise
3930: # the user may resize the window, but on next checkout - zap -
3931: # its original (configured s. cvsweb.conf) size is back again
3932: # .. annoying (if $extern_window_(width|height) is defined)
3933: # but this if (..) solution is far from perfect
3934: # what we need to do as well is
3935: # 1) save cvswin in an invisible frame that always exists
3936: # (document.cvswin will be void on next load)
3937: # 2) on close of the cvs_checkout - window set the cvswin
3938: # variable to 'null' again - so that it will be
3939: # reopenend with the configured size
3940: # anyone a JavaScript programmer ?
3941: # .. so here without if (..):
3942: # currently, the best way is to comment out the size parameters
3943: # ($extern_window...) in cvsweb.conf.
3944: if ($use_java_script) {
3.159 scop 3945: my @attr = qw(resizable scrollbars menubar);
3.120 scop 3946:
3947: push @attr, qw(status toolbar)
3948: if (defined($mimetype) && $mimetype eq "text/html");
3949:
3950: push @attr, "width=$extern_window_width"
3951: if (defined($extern_window_width));
3952:
3953: push @attr, "height=$extern_window_height"
3954: if (defined($extern_window_height));
3955:
3956: # We need the "return false" here to prevent browsers
3957: # from following the href after the onclick handler.
3958: # This would effectively load the same document in
3959: # the same window *twice*.
3960: printf q` onclick="window.open('%s','cvs_checkout','%s');return false"`,
3961: hrefquote("$fullurl$barequery"), join (',', @attr);
3962: }
3963: }
3.159 scop 3964: print ">$textlink</a>";
3.132 scop 3965: }
3966:
3.170 scop 3967: sub graph_link($;$)
3.132 scop 3968: {
3.170 scop 3969: my ($url, $text) = @_;
3.132 scop 3970: $text ||= $graphicon;
3.170 scop 3971: return sprintf('<a href="%s?graph=1%s">%s</a>',
3972: hrefquote($url), hrefquote($barequery), $text);
3.1 knu 3973: }
3974:
3975: # Returns a Query string with the
3976: # specified parameter toggled
3.140 scop 3977: sub toggleQuery($;$)
3.120 scop 3978: {
3979: my ($toggle, $value) = @_;
3.133 scop 3980:
3981: my %vars = %input;
3.120 scop 3982:
3983: if (defined($value)) {
3984: $vars{$toggle} = $value;
3985: } else {
3986: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3987: }
3988:
3989: # Build a new query of non-default paramenters
3.133 scop 3990: my $newquery = "";
3991: foreach my $var (@stickyvars) {
3.120 scop 3992: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3993: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3994:
3995: if ($value ne $default) {
3996: $newquery .= "&" if ($newquery ne "");
3997: $newquery .= urlencode($var) . "=" . urlencode($value);
3998: }
3999: }
4000:
4001: if ($newquery) {
4002: return '?' . $newquery;
4003: }
4004: return "";
4005: }
4006:
4007: sub urlencode($)
4008: {
4009: local ($_) = @_;
4010: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3.175 scop 4011: return $_;
3.120 scop 4012: }
4013:
4014: sub htmlquote($)
4015: {
4016: local ($_) = @_;
4017: # Special Characters; RFC 1866
4018: s/&/&/g;
4019: s/\"/"/g;
4020: s/</</g;
4021: s/>/>/g;
3.175 scop 4022: return $_;
3.120 scop 4023: }
4024:
4025: sub htmlunquote($)
4026: {
4027: local ($_) = @_;
4028: # Special Characters; RFC 1866
4029: s/"/\"/g;
4030: s/</</g;
4031: s/>/>/g;
4032: s/&/&/g;
3.175 scop 4033: return $_;
3.120 scop 4034: }
4035:
4036: sub hrefquote($)
4037: {
4038: local ($_) = @_;
4039:
4040: y/ /+/;
4041:
4042: htmlquote($_);
4043: }
4044:
3.163 scop 4045: sub http_header(;$$)
3.120 scop 4046: {
3.163 scop 4047: my ($content_type, $moddate) = @_;
4048: $content_type ||= 'text/html';
3.120 scop 4049:
4050: $content_type .= "; charset=$charset"
3.163 scop 4051: if ($charset && $content_type =~ m,^text/,);
3.120 scop 4052:
3.185 scop 4053: # Note that in the following, we explicitly join() and concatenate the
4054: # headers instead of printing them as an array. This is because some
4055: # systems, eg. early versions of mod_perl 2 don't quite get it if the
4056: # last \r\n\r\n isn't included in the last "payload" header print().
4057:
4058: my @headers = ();
4059: # TODO: ctime(3) from scalar gmtime() isn't HTTP compliant, see HTTP::Date.
4060: push(@headers, 'Last-Modified: ' . scalar gmtime($moddate) . ' GMT')
4061: if $moddate;
4062: push(@headers, 'Content-Type: ' . $content_type);
3.120 scop 4063:
4064: if ($allow_compress && $maycompress) {
4065: if ($has_zlib
4066: || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c")))
4067: {
4068:
3.185 scop 4069: push(@headers, 'Content-Encoding: x-gzip');
4070: push(@headers, 'Vary: Accept-Encoding'); # RFC 2616, 14.44
4071: print join("\r\n", @headers) . "\r\n\r\n";
4072:
3.120 scop 4073: $| = 1;
3.185 scop 4074: $| = 0; # Flush header output.
3.120 scop 4075:
4076: if ($has_zlib) {
4077: tie *GZIP, __PACKAGE__, \*STDOUT;
4078: }
4079: select(GZIP);
4080: $gzip_open = 1;
4081:
4082: } else {
3.185 scop 4083:
4084: print join("\r\n", @headers) . "\r\n\r\n";
3.120 scop 4085: print
4086: "<span style=\"font-size: smaller\">Unable to find gzip binary in the <b>\$command_path</b> ($command_path) to compress output</span><br>";
4087: }
3.185 scop 4088:
3.120 scop 4089: } else {
3.185 scop 4090: print join("\r\n", @headers) . "\r\n\r\n";
3.120 scop 4091: }
4092: }
4093:
3.131 scop 4094:
3.163 scop 4095: sub html_header($;$)
3.120 scop 4096: {
3.163 scop 4097: my ($title, $moddate) = @_;
4098: $title = htmlquote($title);
3.162 scop 4099: my $l = $logo || '';
3.163 scop 4100: http_header('text/html', $moddate);
3.120 scop 4101: print <<EOH;
3.100 knu 4102: $HTML_DOCTYPE
3.1 knu 4103: <html>
3.40 knu 4104: <head>
3.134 scop 4105: <title>$title</title>
3.144 scop 4106: $HTML_META$CSS</head>
3.129 scop 4107: <body>
3.182 scop 4108: $l <h1>$title</h1>
3.1 knu 4109: EOH
4110: }
4111:
3.120 scop 4112: sub html_footer()
4113: {
3.177 scop 4114: print "<hr>\n<address>$address</address>\n" if $address;
3.127 scop 4115: print "</body>\n</html>\n";
3.1 knu 4116: }
4117:
3.120 scop 4118: sub link_tags($)
4119: {
4120: my ($tags) = @_;
4121: my ($ret) = "";
4122: my ($fileurl, $filename);
4123:
4124: ($filename = $where) =~ s/^.*\///;
4125: $fileurl = './' . urlencode($filename);
4126:
4127: foreach my $sym (split (", ", $tags)) {
4128: $ret .= ",\n" if ($ret ne "");
3.136 scop 4129: $ret .= &link(htmlquote($sym),
4130: $fileurl . toggleQuery('only_with_tag', $sym));
3.120 scop 4131: }
4132: return "$ret\n";
3.1 knu 4133: }
4134:
3.175 scop 4135:
3.1 knu 4136: #
3.81 knu 4137: # See if a module is listed in the config file's @HideModules list.
3.1 knu 4138: #
3.120 scop 4139: sub forbidden_module($)
4140: {
4141: my ($module) = @_;
3.175 scop 4142: for my $hidden_re (@HideModules) {
4143: return 1 if ($module =~ $hidden_re);
3.120 scop 4144: }
4145: return 0;
4146: }
4147:
3.175 scop 4148:
3.120 scop 4149: sub forbidden_file($)
4150: {
4151: my ($path) = @_;
4152: $path = substr($path, length($cvsroot) + 1);
3.175 scop 4153: for my $forbidden_re (@ForbiddenFiles) {
4154: return 1 if ($path =~ $forbidden_re);
3.120 scop 4155: }
4156: return 0;
3.174 scop 4157: }
4158:
4159:
4160: #
4161: # Starts a process using IPC::Run. All arguments are passed to
4162: # IPC::Run::start() as-is. Returns an array ($harness, $error) where
4163: # $harness is from IPC::Run if start() succeeds, undef otherwise. In case
3.184 scop 4164: # of an error, $error contains the error message.
3.174 scop 4165: #
4166: sub startproc($@)
4167: {
4168: my $h = undef;
4169: eval {
4170: local $^W = 0;
4171: local $SIG{__DIE__};
4172: $h = start(@_) or die("return code: $?");
4173: };
4174: my $err = $@ ? "Failed to run '@{$_[0]}': $@" : undef;
4175: return ($h, $err);
3.129 scop 4176: }
4177:
3.25 knu 4178:
3.173 scop 4179: # Close the GZIP handle, and remove the tie.
3.120 scop 4180: sub gzipclose
4181: {
4182: if ($gzip_open) {
4183: select(STDOUT);
4184: close(GZIP);
4185: untie *GZIP;
4186: $gzip_open = 0;
4187: }
3.23 knu 4188: }
4189:
4190: # implement a gzipped file handle via the Compress:Zlib compression
4191: # library.
4192:
4193: sub MAGIC1() { 0x1f }
4194: sub MAGIC2() { 0x8b }
3.80 knu 4195: sub OSCODE() { 3 }
3.23 knu 4196:
3.120 scop 4197: sub TIEHANDLE
4198: {
4199: my ($class, $out) = @_;
4200: my ($d) = Compress::Zlib::deflateInit(
4201: -Level => Compress::Zlib::Z_BEST_COMPRESSION(),
4202: -WindowBits => -Compress::Zlib::MAX_WBITS()
4203: )
4204: or return undef;
4205: my ($o) = { handle => $out,
4206: dh => $d,
4207: crc => 0,
4208: len => 0,
4209: };
4210: my ($header) = pack("c10",
4211: MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(),
4212: 0, 0, 0, 0, 0, 0, OSCODE);
4213: print {$o->{handle}} $header;
4214: return bless($o, $class);
4215: }
4216:
4217: sub PRINT
4218: {
4219: my ($o) = shift;
3.164 scop 4220: my ($buf) = join (defined($,) ? $, : "", @_);
3.120 scop 4221: my ($len) = length($buf);
4222: my ($compressed, $status) = $o->{dh}->deflate($buf);
4223: print {$o->{handle}} $compressed if defined($compressed);
4224: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
4225: $o->{len} += $len;
4226: return $len;
4227: }
4228:
4229: sub PRINTF
4230: {
4231: my ($o) = shift;
4232: my ($fmt) = shift;
4233: my ($buf) = sprintf($fmt, @_);
4234: my ($len) = length($buf);
4235: my ($compressed, $status) = $o->{dh}->deflate($buf);
4236: print {$o->{handle}} $compressed if defined($compressed);
4237: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
4238: $o->{len} += $len;
4239: return $len;
4240: }
4241:
4242: sub WRITE
4243: {
4244: my ($o, $buf, $len, $off) = @_;
4245: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
4246: print {$o->{handle}} $compressed if defined($compressed);
4247: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
4248: $o->{len} += $len;
4249: return $len;
4250: }
4251:
4252: sub CLOSE
4253: {
4254: my ($o) = @_;
4255: return if !defined($o->{dh});
4256: my ($buf) = $o->{dh}->flush();
4257: $buf .= pack("V V", $o->{crc}, $o->{len});
4258: print {$o->{handle}} $buf;
4259: undef $o->{dh};
4260: }
4261:
4262: sub DESTROY
4263: {
4264: my ($o) = @_;
4265: CLOSE($o);
1.1 jfieber 4266: }
3.149 scop 4267:
4268: # Local variables:
4269: # indent-tabs-mode: nil
4270: # cperl-indent-level: 2
4271: # End:
CVSweb