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