Annotation of cvsweb/cvsweb.cgi, Revision 3.174
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.120 scop 1245: sub printDiffSelect($)
1246: {
1247: my ($use_java_script) = @_;
1248: my $f = $input{'f'};
1249:
1250: print '<select id="f" name="f"';
1251: print ' onchange="this.form.submit()"' if $use_java_script;
1252: print ">\n";
1253:
1254: local $_;
1255: for (@DIFFTYPES) {
1256: printf("<option value=\"%s\"%s>%s</option>\n",
1257: $_, $f eq $_ ? ' selected' : '',
1258: "\u$DIFFTYPES{$_}{'descr'}");
1259: }
1260:
1261: print "</select>";
1262: }
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.120 scop 1274: sub printLogSortSelect($)
1275: {
1276: my ($use_java_script) = @_;
1277:
1278: print '<select id="logsort" name="logsort"';
1279: print ' onchange="this.form.submit()"' if $use_java_script;
1280: print ">\n";
1281:
1282: local $_;
1283: for (@LOGSORTKEYS) {
1284: printf("<option value=\"%s\"%s>%s</option>\n",
1285: $_, $logsort eq $_ ? ' selected' : '',
1286: "\u$LOGSORTKEYS{$_}{'descr'}");
1287: }
1288:
1289: print "</select>";
1290: }
1291:
1292: sub findLastModifiedSubdirs(@)
1293: {
1294: my (@dirs) = @_;
1295: my ($dirname, @files);
1296:
1297: foreach $dirname (@dirs) {
1298: next if ($dirname eq ".");
1299: next if ($dirname eq "..");
1300: my ($dir) = "$fullname/$dirname";
1301: next if (!-d $dir);
1302:
1303: my ($lastmod) = undef;
1304: my ($lastmodtime) = undef;
1305: my $dh = do { local (*DH); };
1306:
1307: opendir($dh, $dir) or next;
1308: my (@filenames) = readdir($dh);
1309: closedir($dh);
1310:
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: }
1328: push (@files, $lastmod) if (defined($lastmod));
1329: }
1330: return @files;
1331: }
1332:
1333: sub htmlify_sub(&$)
1334: {
1335: (my $proc, local $_) = @_;
1336: my @a = split (m`(<a [^>]+>[^<]*</a>)`i);
1337: my $linked;
1338: my $result = '';
1339:
1340: while (($_, $linked) = splice(@a, 0, 2)) {
1341: &$proc();
1342: $result .= $_ if defined($_);
1343: $result .= $linked if defined($linked);
1344: }
1345:
1346: $result;
1347: }
1348:
1349: sub htmlify($;$)
1350: {
1351: (local $_, my $extra) = @_;
1352:
1353: $_ = htmlquote($_);
1354:
1355: # get URL's as link
1356: s{
3.130 scop 1357: ((https?|ftp)://.+?)([\s\']|&(quot|[lg]t);)
3.120 scop 1358: }{
3.130 scop 1359: &link($1, htmlunquote($1)) . $3
3.120 scop 1360: }egx;
1361:
1362: # get e-mails as link
1363: $_ = htmlify_sub {
1364: s<
1365: [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
1366: ><
1367: &link($&, "mailto:$&")
1368: >egix;
1369: } $_;
1370:
1371: if ($extra) {
1372:
1373: # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
1374: if (defined($prcgi) && defined($re_prkeyword)) {
1375: my $prev;
1376:
1377: do {
1378: $prev = $_;
1379:
1380: $_ = htmlify_sub {
1381: s{
1382: (\b$re_prkeyword[:\#]?\s*
1383: (?:
1384: \#?
1385: \d+[,\s]\s*
1386: )*
1387: \#?)
1388: (\d+)\b
1389: }{
1390: $1 . &link($2, sprintf($prcgi, $2))
1391: }egix;
1392: } $_;
1393: } while ($_ ne $prev);
1394:
1395: if (defined($re_prcategories)) {
1396: $_ = htmlify_sub {
1397: s{
1398: (\b$re_prcategories/(\d+)\b)
1399: }{
1400: &link($1, sprintf($prcgi, $2))
1401: }egox;
1402: } $_;
1403: }
1404: }
1405:
1406: # get manpage specs as link: "foo.1" "foo(1)"
1407: if (defined($mancgi)) {
1408: $_ = htmlify_sub {
1409: s{
3.143 knu 1410: (
1411: \b ( \w[\w+\-.]* (?: ::\w[\w+\-.]*)* )
3.120 scop 1412: (?:
3.143 knu 1413: \( ([0-9n]) \) \B
3.120 scop 1414: |
3.143 knu 1415: \. ([0-9n]) \b
3.120 scop 1416: )
1417: )
1418: }{
3.149 scop 1419: my($text, $name, $section) = ($1, $2, defined($3) ? $3 : $4);
1420: ($name =~ /[A-Za-z]/ && $name !~ /\.(:|$)/)
1421: ? &link($text, sprintf($mancgi, $section, $name))
1422: : $text;
3.120 scop 1423: }egx;
1424: } $_;
1425: }
1426: }
1427:
1428: $_;
1429: }
1430:
1431: sub spacedHtmlText($;$)
1432: {
1433: local $_ = $_[0];
1434: my $ts = $_[1] || $tabstop;
1435:
1436: # Cut trailing spaces and tabs
1437: s/[ \t]+$//;
1438:
1439: if (defined($ts)) {
1440:
1441: # Expand tabs
1442: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e;
1443: }
1444:
1445: # replace <tab> and <space> (\001 is to protect us from htmlify)
1446: # gzip can make excellent use of this repeating pattern :-)
1447: if ($hr_breakable) {
1448:
1449: # make every other space 'breakable'
1450: s/ / \001nbsp;/g; # 2 * <space>
1451: # leave single space as it is
1452: } else {
1453: s/ /\001nbsp;/g;
1454: }
1455:
1456: $_ = htmlify($_, $allow_source_extra);
1457:
1458: # unescape
1459: y/\001/&/;
1460:
1461: return $_;
1462: }
1463:
1464: # Note that this doesn't htmlquote the first argument...
1465: sub link($$)
1466: {
1467: my ($name, $url) = @_;
1468:
1469: $url =~ s/:/sprintf("%%%02x", ord($&))/eg
1470: if $url =~ /^[^a-z]/; # relative
1471:
1472: sprintf '<a href="%s">%s</a>', hrefquote($url), $name;
1473: }
1474:
1475: sub revcmp($$)
1476: {
1477: my ($rev1, $rev2) = @_;
1478:
1479: # make no comparison for a tag or a branch
1480: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1481:
1482: my (@r1) = split (/\./, $rev1);
1483: my (@r2) = split (/\./, $rev2);
1484: my ($a, $b);
1485:
1486: while (($a = shift (@r1)) && ($b = shift (@r2))) {
1487: if ($a != $b) {
1488: return $a <=> $b;
1489: }
1490: }
1491: if (@r1) { return 1; }
1492: if (@r2) { return -1; }
1493: return 0;
1494: }
1495:
1496: sub fatal($$@)
1497: {
1498: my ($errcode, $format, @args) = @_;
1499: if ($is_mod_perl) {
1500: Apache->request->status((split (/ /, $errcode))[0]);
1501: } else {
1502: print "Status: $errcode\r\n";
1503: }
3.131 scop 1504: html_header('Error');
3.120 scop 1505: print "<p>Error: ", sprintf($format, map(htmlquote($_), @args)), "</p>\n";
1506: html_footer();
1507: exit(1);
1508: }
1509:
1510: sub redirect($)
1511: {
1512: my ($url) = @_;
1513: if ($is_mod_perl) {
1514: Apache->request->status(301);
1515: Apache->request->header_out(Location => $url);
1516: } else {
1517: print "Status: 301 Moved\r\n";
1518: print "Location: $url\r\n";
1519: }
3.131 scop 1520: html_header('Moved');
3.120 scop 1521: print "<p>This document is located ", &link('here', $url), "</p>\n";
1522: html_footer();
1523: exit(1);
1524: }
1525:
1526: sub safeglob($)
1527: {
1528: my ($filename) = @_;
1529: my ($dirname);
1530: my (@results);
1531: my $dh = do { local (*DH); };
1532:
1533: ($dirname = $filename) =~ s|/[^/]+$||;
1534: $filename =~ s|.*/||;
1535:
1536: if (opendir($dh, $dirname)) {
1537: my $glob = $filename;
1538: my $t;
1539:
3.149 scop 1540: # transform filename from glob to regex. Deal with:
1541: # [, {, ?, * as glob chars
1542: # make sure to escape all other regex chars
3.120 scop 1543: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1544: $glob =~ s/\*/.*/g;
1545: $glob =~ s/\?/./g;
1546: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1547: foreach (readdir($dh)) {
1548:
1549: if (/^${glob}$/) {
1550: push (@results, "$dirname/" . $_);
1551: }
1552: }
1553: closedir($dh);
1554: }
1555:
1556: @results;
1557: }
1558:
3.160 scop 1559:
3.120 scop 1560: sub search_path($)
1561: {
1562: my ($command) = @_;
3.160 scop 1563: for my $d (split (/:/, $command_path)) {
3.120 scop 1564: return "$d/$command" if -x "$d/$command";
1565: }
1566: return '';
1567: }
1568:
3.156 scop 1569:
1570: sub getMimeType($;$)
3.120 scop 1571: {
3.156 scop 1572: my ($fullname, $binary) = @_;
1573: $binary = ($keywordsubstitution && $keywordsubstitution =~ /b/)
1574: unless defined($binary);
1575:
1576: (my $suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1577:
1578: my $mimetype = $MTYPES{$suffix};
1579: $mimetype ||= $MimeTypes->mimeTypeOf($fullname) if defined($MimeTypes);
1580:
1581: if (!$mimetype && $suffix ne '*' && -f $mime_types && -r _) {
1582: my $fh = do { local (*FH); };
1583: if (open($fh, $mime_types)) {
1584: my $re = sprintf('^\s*(\S+\/\S+)\s.+\b%s\b', quotemeta($suffix));
1585: while (my $line = <$fh>) {
1586: if ($line =~ $re) {
1587: $mimetype = $1;
1588: $MTYPES{$suffix} = $mimetype;
1589: last;
1590: }
3.120 scop 1591: }
3.156 scop 1592: close($fh);
1593: } else {
1594: warn("Can't open MIME types file $mime_types for reading: $!");
3.120 scop 1595: }
1596: }
1597:
3.156 scop 1598: $mimetype ||= $MTYPES{'*'};
1599: $mimetype ||= $binary ? 'application/octet-stream' : 'text/plain';
3.120 scop 1600: return $mimetype;
3.1 knu 1601: }
1602:
3.156 scop 1603:
3.1 knu 1604: ###############################
3.24 knu 1605: # read first lines like head(1)
1606: ###############################
3.120 scop 1607: sub head($;$)
1608: {
1609: my $fh = $_[0];
1610: my $linecount = $_[1] || 10;
3.24 knu 1611:
3.120 scop 1612: my @buf;
1613:
1614: if ($linecount > 0) {
1615: my $i;
1616: for ($i = 0; !eof($fh) && $i < $linecount; $i++) {
1617: push @buf, scalar <$fh>;
1618: }
1619: } else {
1620: @buf = <$fh>;
1621: }
1622:
1623: @buf;
3.24 knu 1624: }
1625:
1626: ###############################
1627: # scan vim and Emacs directives
1628: ###############################
3.120 scop 1629: sub scan_directives(@)
1630: {
1631: my $ts = undef;
3.24 knu 1632:
3.120 scop 1633: for (@_) {
1634: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1635: }
3.24 knu 1636:
3.120 scop 1637: ('tabstop' => $ts);
3.24 knu 1638: }
1639:
3.120 scop 1640: sub openOutputFilter()
1641: {
1642: return if !defined($output_filter) || $output_filter eq '';
3.86 knu 1643:
3.120 scop 1644: open(STDOUT, "|-") and return;
3.86 knu 1645:
3.120 scop 1646: # child of child
3.165 scop 1647: open(STDERR, '>', devnull());
3.120 scop 1648: exec($output_filter) or exit -1;
3.86 knu 1649: }
1650:
3.24 knu 1651: ###############################
3.1 knu 1652: # show Annotation
1653: ###############################
3.133 scop 1654: sub doAnnotate($)
3.120 scop 1655: {
1656: my ($rev) = @_;
1657:
1658: # make sure the revisions are wellformed, for security
1659: # reasons ..
1660: if ($rev =~ /[^\w.]/) {
1661: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1662: }
1663:
3.174 ! scop 1664: (my $pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
! 1665: (my $filename = $where) =~ s/^.*\///;
3.126 scop 1666:
3.174 ! scop 1667: # This annotate version is based on the cvs annotate-demo Perl script by
! 1668: # Cyclic Software. It was written by Cyclic Software,
! 1669: # http://www.cyclic.com/, and is in the public domain.
! 1670: # We could abandon the use of rlog, rcsdiff and co using
! 1671: # the cvs server in a similiar way one day (..after rewrite).
! 1672:
! 1673: local (*CVS_IN, *CVS_OUT);
! 1674: my ($h, $err) =
! 1675: startproc([ $CMD{cvs}, @annotate_options, 'server' ],
! 1676: '<pipe', \*CVS_IN, '>pipe', \*CVS_OUT, timeout(30));
! 1677: fatal('500 Internal Error', $err) unless $h;
3.120 scop 1678:
1679: # OK, first send the request to the server. A simplified example is:
1680: # Root /home/kingdon/zwork/cvsroot
1681: # Argument foo/xx
1682: # Directory foo
1683: # /home/kingdon/zwork/cvsroot/foo
1684: # Directory .
1685: # /home/kingdon/zwork/cvsroot
1686: # annotate
1687: # although as you can see there are a few more details.
1688:
3.174 ! scop 1689: print CVS_IN "Root $cvsroot\n";
! 1690: print CVS_IN
3.120 scop 1691: "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1692:
1693: # Don't worry about sending valid-requests, the server just needs to
1694: # support "annotate" and if it doesn't, there isn't anything to be done.
3.174 ! scop 1695: print CVS_IN "UseUnchanged\n";
! 1696: print CVS_IN "Argument -r\n";
! 1697: print CVS_IN "Argument $rev\n";
! 1698: print CVS_IN "Argument $where\n";
3.120 scop 1699:
1700: # The protocol requires us to fully fake a working directory (at
1701: # least to the point of including the directories down to the one
1702: # containing the file in question).
3.123 scop 1703: # So if $where is "dir/sdir/file", then dirs will be ("dir","sdir","file")
1704: my $path = '';
1705: foreach my $dir (split('/', $where)) {
3.120 scop 1706:
1707: if ($path eq "") {
3.123 scop 1708: # In our example, $dir is "dir".
1709: $path = $dir;
3.120 scop 1710: } else {
3.174 ! scop 1711: print CVS_IN "Directory $path\n";
! 1712: print CVS_IN "$cvsroot/$path\n";
3.120 scop 1713:
1714: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1715: # And the next time, "file" and "dir/sdir/file" (which then gets
1716: # ignored, because we don't need to send Directory for the file).
3.123 scop 1717: $path .= "/$dir";
3.120 scop 1718: }
1719: }
3.123 scop 1720: undef $path;
3.120 scop 1721:
1722: # And the last "Directory" before "annotate" is the top level.
3.174 ! scop 1723: print CVS_IN "Directory .\n";
! 1724: print CVS_IN "$cvsroot\n";
3.120 scop 1725:
3.174 ! scop 1726: print CVS_IN "annotate\n";
3.120 scop 1727:
1728: # OK, we've sent our command to the server. Thing to do is to
1729: # close the writer side and get all the responses. If "cvs server"
1730: # were nicer about buffering, then we could just leave it open, I think.
3.174 ! scop 1731: close(CVS_IN) or die "cannot close: $!";
3.120 scop 1732:
3.133 scop 1733: navigateHeader($scriptwhere, $pathname, $filename, $rev, 'annotate');
3.120 scop 1734:
3.136 scop 1735: print '<h3 style="text-align: center">Annotation of ',
1736: htmlquote("$pathname$filename"), ", revision $rev</h3>\n";
3.120 scop 1737:
1738: # Ready to get the responses from the server.
1739: # For example:
1740: # E Annotations for foo/xx
1741: # E ***************
1742: # M 1.3 (kingdon 06-Sep-97): hello
1743: # ok
1744: my ($lineNr) = 0;
1745: my ($oldLrev, $oldLusr) = ("", "");
1746: my ($revprint, $usrprint);
1747:
1748: if ($annTable) {
1749: print
1750: "<table style=\"border: none\" cellspacing=\"0\" cellpadding=\"0\">\n";
1751: } else {
1752: print "<pre>";
1753: }
1754:
1755: # prefetch several lines
3.174 ! scop 1756: my @buf = head(*CVS_OUT);
3.120 scop 1757:
1758: my %d = scan_directives(@buf);
1759:
3.174 ! scop 1760: while (@buf || !eof(*CVS_OUT)) {
! 1761: $_ = @buf ? shift @buf : <CVS_OUT>;
3.120 scop 1762:
1763: my @words = split;
1764:
1765: # Adding one is for the (single) space which follows $words[0].
1766: my $rest = substr($_, length($words[0]) + 1);
1767: if ($words[0] eq "E") {
1768: next;
1769: } elsif ($words[0] eq "M") {
1770: $lineNr++;
1771: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1772: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1773: my $line = substr($_, 36);
1774: my $isCurrentRev = ($rev eq $lrev);
1775:
1776: # we should parse the date here ..
1777: if ($lrev eq $oldLrev) {
1778: $revprint = sprintf('%-8s', '');
1779: } else {
1780: $revprint = sprintf('%-8s', $lrev);
1781: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
1782: $oldLusr = '';
1783: }
1784:
1785: if ($lusr eq $oldLusr) {
1786: $usrprint = '';
1787: } else {
1788: $usrprint = $lusr;
1789: }
1790: $oldLrev = $lrev;
1791: $oldLusr = $lusr;
1792:
1793: # Set bold for text-based browsers only - graphical
1794: # browsers show bold fonts a bit wider than regular fonts,
1795: # so it looks irregular.
1796: print "<b>" if ($isCurrentRev && $is_textbased);
1797:
3.136 scop 1798: $usrprint = sprintf('%-8s', $usrprint);
1799: printf '%s%s %s %4d:', $revprint, $isCurrentRev ? '!' : ' ',
1800: htmlquote($usrprint), $lineNr;
3.120 scop 1801: print spacedHtmlText($line, $d{'tabstop'});
1802:
1803: print "</b>" if ($isCurrentRev && $is_textbased);
1804: } elsif ($words[0] eq "ok") {
1805:
1806: # We could complain about any text received after this, like the
1807: # CVS command line client. But for simplicity, we don't.
1808: } elsif ($words[0] eq "error") {
1809: fatal("500 Internal Error",
1810: 'Error occured during annotate: <b>%s</b>', $_);
1811: }
1812: }
1813:
1814: if ($annTable) {
1815: print "</table>";
1816: } else {
1817: print "</pre>";
1818: }
3.124 scop 1819: html_footer();
1820:
3.174 ! scop 1821: finish($h);
3.1 knu 1822: }
1823:
1824: ###############################
1825: # make Checkout
1826: ###############################
3.120 scop 1827: sub doCheckout($$)
1828: {
1829: my ($fullname, $rev) = @_;
3.156 scop 1830: my ($revopt);
3.120 scop 1831:
1832: if ($rev eq 'HEAD' || $rev eq '.') {
1833: $rev = undef;
1834: }
1835:
1836: # make sure the revisions a wellformed, for security
1837: # reasons ..
1838: if (defined($rev) && $rev =~ /[^\w.]/) {
1839: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
1840: }
1841:
1842: # get mimetype
3.156 scop 1843: my $mimetype;
3.120 scop 1844: if (defined($input{"content-type"})
1845: && ($input{"content-type"} =~ /\S\/\S/))
1846: {
1847: $mimetype = $input{"content-type"};
1848: } else {
3.156 scop 1849: $mimetype = getMimeType($fullname);
3.120 scop 1850: }
1851:
3.163 scop 1852: my $moddate = undef;
3.120 scop 1853: if (defined($rev)) {
1854: $revopt = "-r$rev";
1855: if ($use_moddate) {
1856: readLog($fullname, $rev);
1857: $moddate = $date{$rev};
1858: }
1859: } else {
1860: $revopt = "-rHEAD";
1861: if ($use_moddate) {
1862: readLog($fullname);
1863: $moddate = $date{$symrev{HEAD}};
1864: }
1865: }
1866:
3.174 ! scop 1867: # Change to temporary directory first to avoid non-readable cgi-bin dirs.
! 1868: chdir(tmpdir());
! 1869: # Use abs_path to work around a bug of cvs -p; expand symlinks.
! 1870: my @cmd = ($CMD{cvs}, @cvs_options,
! 1871: '-d', abs_path($cvsroot), 'co', '-p', $revopt, $where);
! 1872: local $^W = 0; # IPC::Run is noisy w/perl 5.8. Also prevents weird hangs.
! 1873: local (*CVS_OUT, *CVS_ERR);
! 1874: my ($h, $err) =
! 1875: startproc(\@cmd, \"", '>pipe', \*CVS_OUT, '2>pipe', \*CVS_ERR,timeout(30));
! 1876: fatal('500 Internal Error', $err) unless $h;
3.120 scop 1877:
3.174 ! scop 1878: if (eof(CVS_ERR)) {
! 1879: finish($h);
3.120 scop 1880: fatal("404 Not Found", '%s is not (any longer) pertinent', $where);
1881: }
1882:
1883: #===================================================================
1884: #Checking out squid/src/ftp.c
1885: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1886: #VERS: 1.1.1.28.6.2
1887: #***************
1888:
1889: # Parse CVS header
1890: my ($revision, $filename, $cvsheader);
1891: $filename = "";
3.174 ! scop 1892: while (<CVS_ERR>) {
3.120 scop 1893: last if (/^\*\*\*\*/);
1894: $revision = $1 if (/^VERS: (.*)$/);
1895:
1896: if (/^Checking out (.*)$/) {
1897: $filename = $1;
1898: $filename =~ s/^\.\/*//;
1899: }
1900: $cvsheader .= $_;
1901: }
1902:
1903: if ($filename ne $where) {
3.174 ! scop 1904: finish($h);
3.120 scop 1905: fatal("500 Internal Error",
1906: 'Unexpected output from cvs co: %s', $cvsheader);
1907: }
1908:
3.146 scop 1909: if ($mimetype =~ $CvsWebMarkupRE) {
3.163 scop 1910: # Here we know the last modified date, but don't know if tags have been
1911: # added since: no last-modified (for now).
3.174 ! scop 1912: cvswebMarkup(\*CVS_OUT, $fullname, $revision);
3.120 scop 1913: } else {
3.163 scop 1914: http_header($mimetype, $moddate);
3.174 ! scop 1915: local $/ = undef;
! 1916: print <CVS_OUT>;
3.120 scop 1917: }
3.174 ! scop 1918: finish($h);
1.12 fenner 1919: }
1920:
3.174 ! scop 1921:
3.163 scop 1922: sub cvswebMarkup($$$;$)
3.120 scop 1923: {
3.163 scop 1924: my ($filehandle, $fullname, $revision, $mod) = @_;
3.120 scop 1925: my ($pathname, $filename);
3.1 knu 1926:
3.120 scop 1927: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1928: ($filename = $where) =~ s/^.*\///;
3.156 scop 1929: my $fileurl = urlencode($filename);
1930: my $mimetype = getMimeType($filename);
3.120 scop 1931:
3.163 scop 1932: navigateHeader($scriptwhere, $pathname, $filename, $revision, 'view', $mod);
3.120 scop 1933:
3.144 scop 1934: print <<EOF;
1935: <hr noshade>
1936: <table width="100%">
1937: <tr>
1938: <td class="log-markup">File:
1939: EOF
3.159 scop 1940: print &clickablePath($where, 1), ' - (';
3.144 scop 1941: &download_link($fileurl, $revision, 'download');
3.156 scop 1942: if ($mimetype ne 'text/plain') {
3.159 scop 1943: print ' / ';
3.120 scop 1944: &download_link($fileurl, $revision, "as text", "text/plain");
1945: }
3.159 scop 1946: print ')';
3.170 scop 1947: print ' - ', &graph_link('', 'graph') if $allow_cvsgraph;
3.120 scop 1948: print "<br>\n";
1949:
1950: if ($show_log_in_markup) {
1951: readLog($fullname); #,$revision);
1952: printLog($revision, 0);
1953: } else {
1954: print "Version: <b>$revision</b><br>\n";
1955: print "Tag: <b>", $input{only_with_tag}, "</b><br>\n"
1956: if $input{only_with_tag};
1957: }
1958: print "</td>\n</tr>\n</table>";
1959: my $url = download_url($fileurl, $revision, $mimetype);
1960: print "<hr noshade>";
1961:
1962: if ($mimetype =~ /^image/) {
3.160 scop 1963: printf '<img src="%s" alt="%s"><br>',
1964: hrefquote("$url$barequery"), htmlquote($filename);
3.120 scop 1965: } elsif ($mimetype =~ m%^application/pdf%) {
3.157 scop 1966: printf '<embed src="%s" width="100%%" height="100%%"><br>',
1967: hrefquote("$url$barequery");
3.120 scop 1968: } elsif ($preformat_in_markup) {
1969: print "<pre>";
1970:
1971: # prefetch several lines
1972: my @buf = head($filehandle);
1973:
1974: my %d = scan_directives(@buf);
1975:
1976: while (@buf || !eof($filehandle)) {
1977: $_ = @buf ? shift @buf : <$filehandle>;
1978:
1979: print spacedHtmlText($_, $d{'tabstop'});
1980: }
1981: print "</pre>";
1982: } else {
1983:
3.148 scop 1984: my $enscript_hl = undef;
1985:
1986: if ($allow_enscript) {
1987: while (my ($hl, $regex) = each %enscript_types) {
3.149 scop 1988: if ($filename =~ $regex) {
1989: $enscript_hl = $hl;
1990: last;
1991: }
3.148 scop 1992: }
1993: }
1994:
3.149 scop 1995: print '<pre>';
3.167 scop 1996: my $linenumbers = $input{ln} || 0;
3.149 scop 1997:
3.148 scop 1998: if ($enscript_hl) {
3.167 scop 1999: doEnscript($filehandle, $enscript_hl, $linenumbers);
3.148 scop 2000:
2001: } else {
3.167 scop 2002: my $ln = 0;
3.148 scop 2003: while (<$filehandle>) {
3.167 scop 2004: if ($linenumbers) {
2005: $ln++;
2006: printf '<a id="l%d" class="src">%5d: </a>', ($ln) x 2;
3.149 scop 2007: }
2008: print htmlquote($_);
3.148 scop 2009: }
3.120 scop 2010: }
3.149 scop 2011:
2012: print "</pre>\n";
3.120 scop 2013: }
3.131 scop 2014: html_footer();
3.120 scop 2015: }
2016:
3.156 scop 2017:
3.120 scop 2018: sub viewable($)
2019: {
3.156 scop 2020: my $mimetype = shift || '';
2021: return ($allow_markup && $mimetype =~ m%^((text|image)/|application/pdf)%);
2022: }
3.120 scop 2023:
3.1 knu 2024:
2025: ###############################
2026: # Show Colored Diff
2027: ###############################
3.120 scop 2028: sub doDiff($$$$$$)
2029: {
2030: my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
2031: my $fh = do { local (*FH); };
2032: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
2033:
2034: if (&forbidden_file($fullname)) {
2035: fatal("403 Forbidden",
2036: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
2037: }
2038:
2039: if ($r1 =~ /([^:]+)(:(.+))?/) {
2040: $rev1 = $1;
2041: $sym1 = $3;
2042: }
2043: if ($r1 eq 'text') {
2044: $rev1 = $tr1;
2045: $sym1 = "";
2046: }
2047:
2048: if ($r2 =~ /([^:]+)(:(.+))?/) {
2049: $rev2 = $1;
2050: $sym2 = $3;
2051: }
2052: if ($r2 eq 'text') {
2053: $rev2 = $tr2;
2054: $sym2 = "";
2055: }
2056:
2057: # make sure the revisions a wellformed, for security
2058: # reasons ..
2059: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
2060: fatal("404 Not Found", 'Malformed query "%s"', $ENV{QUERY_STRING});
2061: }
2062:
2063: #
2064: # rev1 and rev2 are now both numeric revisions.
2065: # Thus we do a DWIM here and swap them if rev1 is after rev2.
2066: # XXX should we warn about the fact that we do this?
2067: if (&revcmp($rev1, $rev2) > 0) {
2068: my ($tmp1, $tmp2) = ($rev1, $sym1);
2069: ($rev1, $sym1) = ($rev2, $sym2);
2070: ($rev2, $sym2) = ($tmp1, $tmp2);
2071: }
2072: my $difftype = $DIFFTYPES{$f};
2073:
2074: if (!$difftype) {
2075: fatal("400 Bad arguments", 'Diff format %s not understood', $f);
2076: }
2077:
2078: my @difftype = @{$difftype->{'opts'}};
2079: my $human_readable = $difftype->{'colored'};
2080:
2081: # apply special options
2082: if ($showfunc) {
2083: push @difftype, '-p' if $f ne 's';
2084:
2085: my ($re1, $re2);
2086:
2087: while (($re1, $re2) = each %funcline_regexp) {
2088: if ($fullname =~ /$re1/) {
2089: push @difftype, '-F', $re2;
2090: last;
2091: }
2092: }
2093: }
2094:
2095: if ($human_readable) {
2096: if ($hr_ignwhite) {
2097: push @difftype, '-w';
2098: }
2099: if ($hr_ignkeysubst) {
2100: push @difftype, '-kk';
2101: }
2102: }
2103:
2104: if (!open($fh, "-|")) { # child
2105: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
2106: openOutputFilter();
3.166 scop 2107: exec($CMD{rcsdiff}, @rcsdiff_options, @difftype, "-r$rev1", "-r$rev2",
2108: $fullname) or exit -1;
3.120 scop 2109: }
3.166 scop 2110:
3.120 scop 2111: if ($human_readable) {
3.168 scop 2112: #
2113: # Human readable diff.
2114: #
2115: human_readable_diff($fh, $rev2);
2116: html_footer();
2117: gzipclose();
2118: exit;
2119:
2120: } elsif ($f =~ /^([ucs])c$/) {
2121: #
2122: # Enscript colored diff.
2123: #
2124: my $hl = 'diff';
2125: $hl .= $1 if ($1 eq 'u' || $1 eq 's');
2126: (my $where_nd = $where) =~ s/\.diff$//;
2127: (my $pathname = $where_nd) =~ s|(Attic\/)?[^/]*$||;
2128: (my $filename = $where_nd) =~ s|^.*/||;
2129: (my $swhere = $scriptwhere) =~ s|\.diff$||;
2130: navigateHeader($swhere, $pathname, $filename, $rev2, 'diff');
2131: printf(<<EOF, $where_nd, $rev1, $rev2);
2132: <h3 style="text-align: center">Diff for /%s between versions %s and %s</h3>
2133: <pre>
2134: EOF
3.174 ! scop 2135: doEnscript(\$fh, $hl, 0);
3.168 scop 2136: print <<EOF;
2137: </pre>
2138: <hr style="width: 100%" noshade>
2139: <form method="get" action="$scriptwhere">
2140: EOF
2141: printDiffSelectStickyVars();
2142: print 'Diff format: ';
2143: printDiffSelect($use_java_script);
2144: print "<input type=\"submit\" value=\"Show\">\n</form>\n";
3.120 scop 2145: html_footer();
2146: gzipclose();
2147: exit;
3.168 scop 2148:
3.120 scop 2149: } else {
3.168 scop 2150: #
2151: # Plain diff.
2152: #
3.120 scop 2153: http_header("text/plain");
2154: }
2155:
2156: #
2157: #===================================================================
2158: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
2159: #retrieving revision 1.16
2160: #retrieving revision 1.17
2161: #diff -c -r1.16 -r1.17
2162: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2163: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
2164: #
2165: # Ideas:
2166: # - nuke the stderr output if it's what we expect it to be
2167: # - Add "no differences found" if the diff command supplied no output.
2168: #
2169: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2170: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
2171: # (bogus example, but...)
2172: #
2173: if (grep { $_ eq '-u' } @difftype) {
2174: $f1 = '---';
2175: $f2 = '\+\+\+';
2176: } else {
2177: $f1 = '\*\*\*';
2178: $f2 = '---';
2179: }
2180:
2181: while (<$fh>) {
2182: if (m|^$f1 $cvsroot|o) {
2183: s|$cvsroot/||o;
2184: if ($sym1) {
2185: chop;
2186: $_ .= " $sym1\n";
2187: }
2188: } elsif (m|^$f2 $cvsroot|o) {
2189: s|$cvsroot/||o;
2190:
2191: if ($sym2) {
2192: chop;
2193: $_ .= " $sym2\n";
2194: }
2195: }
2196: print $_;
2197: }
2198: close($fh);
1.12 fenner 2199: }
2200:
3.1 knu 2201: ###############################
2202: # Show Logs ..
2203: ###############################
3.120 scop 2204: sub getDirLogs($$@)
2205: {
2206: my ($cvsroot, $dirname, @otherFiles) = @_;
3.139 scop 2207: my $tag = $input{only_with_tag};
2208: my $DirName = "$cvsroot/$where";
3.120 scop 2209:
3.139 scop 2210: my @files = &safeglob("$DirName/*,v");
2211: push (@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
3.120 scop 2212: foreach my $file (@otherFiles) {
2213: push (@files, "$DirName/$file");
2214: }
2215:
3.150 scop 2216: # Weed out unreadable files.
2217: my $i = 0;
2218: my @unreadable = ();
2219: while ($i < scalar(@files)) {
2220: if (-r $files[$i]) {
2221: $i++;
2222: } else {
2223: push(@unreadable, splice(@files, $i, 1));
2224: }
2225: }
2226:
3.139 scop 2227: # If there are no files, we're done.
3.150 scop 2228: return @unreadable unless @files;
3.120 scop 2229:
3.139 scop 2230: my @cmd = ($CMD{rlog});
2231: # Can't use -r<tag> as '-' is allowed in tagnames,
2232: # but misinterpreted by rlog.
2233: push(@cmd, '-r') unless defined($tag);
3.120 scop 2234:
3.139 scop 2235: my $fh = do { local (*FH); };
2236: if (!open($fh, '-|')) { # Child
3.165 scop 2237: open(STDERR, '>', devnull()); # Ignore rlog's complaints.
3.139 scop 2238: openOutputFilter();
2239: if ($file_list_len && $file_list_len > 1) {
2240: while (scalar(@files) > $file_list_len) { # Process files in chunks.
2241: system(@cmd, splice(@files, 0, $file_list_len)) == 0 or exit -1;
2242: }
3.120 scop 2243: }
3.139 scop 2244: exec(@cmd, @files) or exit -1;
2245: }
2246: undef @cmd;
3.120 scop 2247:
3.139 scop 2248: my $state = 'start';
2249: my ($date, $branchpoint, $branch, $log, @filetags);
3.152 scop 2250: my ($rev, $revision, $revwanted, $filename, $head, $author, $keywordsubst);
3.120 scop 2251:
2252: while (<$fh>) {
2253: if ($state eq "start") {
2254:
2255: #Next file. Initialize file variables
2256: $rev = '';
2257: $revwanted = '';
2258: $branch = '';
2259: $branchpoint = '';
2260: $filename = '';
2261: $log = '';
2262: $revision = '';
2263: %symrev = ();
2264: @filetags = ();
3.152 scop 2265: $keywordsubst= '';
3.120 scop 2266:
2267: #jump to head state
2268: $state = "head";
2269: }
3.144 scop 2270:
3.120 scop 2271: again:
2272:
2273: if ($state eq "head") {
2274:
2275: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
2276:
2277: if (/^Working file: (.+)$/) {
2278: $filename = $1;
2279: } elsif (/^head: (.+)$/) {
2280: $head = $1;
2281: } elsif (/^branch: (.+)$/) {
2282: $branch = $1;
3.152 scop 2283: } elsif (/^keyword substitution: (.+)$/) {
2284: $keywordsubst = $1;
3.120 scop 2285: } elsif (/^symbolic names:/) {
2286: $state = "tags";
2287: ($branch = $head) =~ s/\.\d+$//
2288: if $branch eq '';
2289: $branch =~ s/(\d+)$/0.$1/;
2290: $symrev{MAIN} = $branch;
2291: $symrev{HEAD} = $branch;
2292: $alltags{MAIN} = 1;
2293: $alltags{HEAD} = 1;
2294: push (@filetags, "MAIN", "HEAD");
2295: } elsif (/$LOG_REVSEPARATOR/o) {
2296: $state = "log";
2297: $rev = '';
2298: $date = '';
2299: $log = '';
2300:
2301: # Try to reconstruct the relative filename if RCS spits out a full path
2302: $filename =~ s%^\Q$DirName\E/%%;
2303: }
2304: next;
2305: }
2306:
2307: if ($state eq "tags") {
2308: if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
2309: push (@filetags, $1);
2310: $symrev{$1} = $2;
2311: $alltags{$1} = 1;
2312: next;
2313: } elsif (/^\S/) {
2314:
2315: if (defined($tag)) {
2316: if (defined($symrev{$tag}) || $tag eq "HEAD") {
2317: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
2318: ($branch = $revwanted) =~ s/\b0\.//;
2319: ($branchpoint = $branch) =~ s/\.?\d+$//;
2320: $revwanted = '' if ($revwanted ne $branch);
2321: } elsif ($tag ne "HEAD") {
2322: $state = "skip";
2323: next;
2324: }
2325: }
2326:
2327: foreach my $tagfound (@filetags) {
2328: $tags{$tagfound} = 1;
2329: }
2330: $state = "head";
2331: goto again;
2332: }
2333: }
2334:
2335: if ($state eq "log") {
2336: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
2337:
2338: # End of a log entry.
2339: my $revbranch = $rev;
2340: $revbranch =~ s/\.\d+$//;
2341:
2342: if ($revwanted eq '' && $branch ne '' && $branch eq $revbranch
2343: || !defined($tag))
2344: {
2345: $revwanted = $rev;
2346: }
2347:
2348: if ($revwanted ne ''
2349: ? $rev eq $revwanted
2350: : $branchpoint ne ''
2351: ? $rev eq $branchpoint
2352: : 0
2353: && ($rev eq $head))
2354: { # Don't think head is needed here..
3.152 scop 2355: my @finfo = ($rev, $date, $log, $author, $filename, $keywordsubst);
2356: (my $name = $filename) =~ s%/.*%%;
3.120 scop 2357: $fileinfo{$name} = [@finfo];
2358: $state = "done" if ($rev eq $revwanted);
2359: }
2360: $rev = '';
2361: $date = '';
2362: $log = '';
2363: } elsif ($date eq ''
2364: && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|)
2365: {
3.172 scop 2366: my $yr = $1;
2367: $yr -= 1900 if ($yr > 100); # Damn 2-digit year routines :-)
2368: $date = timegm($6, $5, $4, $3, $2 - 1, $yr);
3.120 scop 2369: ($author) = /author: ([^;]+)/;
3.172 scop 2370: $state = 'log';
2371: $log = '';
3.120 scop 2372: next;
2373: } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
2374: $rev = $1; # .*$ eats up the locker(lockers?) info, if any
2375: next;
2376: } else {
2377: $log .= $_;
2378: }
2379: }
2380:
2381: if (/$LOG_FILESEPARATOR/o) {
2382: $state = "start";
2383: next;
2384: }
2385: }
2386:
3.139 scop 2387: my $linesread = $. || 0;
2388: close($fh);
2389:
2390: if ($linesread == 0) {
3.137 scop 2391: fatal('500 Internal Error',
2392: '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 2393: htmlquote(join(', ', @files)), $command_path);
3.120 scop 2394: }
3.150 scop 2395:
2396: return @unreadable;
3.120 scop 2397: }
2398:
2399: sub readLog($;$)
2400: {
2401: my ($fullname, $revision) = @_;
2402: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2403: my $fh = do { local (*FH); };
2404:
3.144 scop 2405: $revision = defined($revision) ? "-r$revision" : '';
3.120 scop 2406:
2407: undef %symrev;
2408: undef %revsym;
2409: undef @allrevisions;
2410: undef %date;
2411: undef %author;
2412: undef %state;
2413: undef %difflines;
2414: undef %log;
3.152 scop 2415: $keywordsubstitution = '';
3.120 scop 2416:
2417: if (!open($fh, "-|")) { # child
2418: if ($revision ne '') {
2419: openOutputFilter();
2420: exec($CMD{rlog}, $revision, $fullname) or exit -1;
2421: } else {
2422: openOutputFilter();
2423: exec($CMD{rlog}, $fullname) or exit -1;
2424: }
2425: }
2426:
2427: while (<$fh>) {
2428: if ($symnames) {
2429: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2430: $symrev{$1} = $2;
3.152 scop 2431: next;
3.120 scop 2432: } else {
2433: $symnames = 0;
2434: }
3.152 scop 2435: }
2436: if (/^head:\s+([\d\.]+)/) {
3.120 scop 2437: $head = $1;
2438: } elsif (/^branch:\s+([\d\.]+)/) {
2439: $curbranch = $1;
2440: } elsif (/^symbolic names/) {
2441: $symnames = 1;
3.152 scop 2442: } elsif (/^keyword substitution: (.+)$/) {
2443: $keywordsubstitution = $1;
3.120 scop 2444: } elsif (/^-----/) {
2445: last;
2446: }
2447: }
2448: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
2449:
2450: # each log entry is of the form:
2451: # ----------------------------
2452: # revision 3.7.1.1
2453: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2454: # log info
2455: # ----------------------------
2456:
2457: # For a locked revision, the first line after the separator
2458: # becomes smth like
3.149 scop 2459: # revision 9.19 locked by: vassilii;
3.120 scop 2460:
2461: logentry:
2462:
2463: while (!/$LOG_FILESEPARATOR/o) {
2464: $_ = <$fh>;
2465: last logentry if (!defined($_)); # EOF
2466: if (/^revision (\d+(?:\.\d+)+)/) {
2467: $rev = $1;
2468: unshift (@allrevisions, $rev);
2469: } elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
2470: next logentry;
2471: } else {
2472:
2473: # The rlog output is syntactically ambiguous. We must
2474: # have guessed wrong about where the end of the last log
2475: # message was.
2476: # Since this is likely to happen when people put rlog output
2477: # in their commit messages, don't even bother keeping
2478: # these lines since we don't know what revision they go with
2479: # any more.
2480: next logentry;
2481: }
2482: $_ = <$fh>;
2483: if (
2484: m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
2485: )
2486: {
3.172 scop 2487: my $yr = $1;
2488: $yr -= 1900 if ($yr > 100); # Damn 2-digit year routines :-)
2489: $date{$rev} = timegm($6, $5, $4, $3, $2 - 1, $yr);
3.120 scop 2490: $author{$rev} = $7;
2491: $state{$rev} = $8;
2492: $difflines{$rev} = $10;
2493: } else {
2494: fatal("500 Internal Error", 'Error parsing RCS output: %s', $_);
2495: }
2496:
2497: line:
2498: while (<$fh>) {
2499: next line if (/^branches:\s/);
2500: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
2501: $log{$rev} .= $_;
2502: }
2503: }
2504: close($fh);
2505:
2506: @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
2507:
2508: #
2509: # HEAD is an artificial tag which is simply the highest tag number on the main
2510: # branch, unless there is a branch tag in the RCS file in which case it's the
2511: # highest revision on that branch. Find it by looking through @revorder; it
2512: # is the first commit listed on the appropriate branch.
2513: # This is not neccesary the same revision as marked as head in the RCS file.
2514: my $headrev = $curbranch || "1";
2515: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
2516:
2517: foreach $rev (@revorder) {
2518: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2519: $symrev{"HEAD"} = $rev;
2520: last;
2521: }
2522: }
2523: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2524: if (!defined($symrev{"HEAD"}));
2525:
2526: #
2527: # Now that we know all of the revision numbers, we can associate
2528: # absolute revision numbers with all of the symbolic names, and
2529: # pass them to the form so that the same association doesn't have
2530: # to be built then.
2531: #
2532: undef @branchnames;
2533: undef %branchpoint;
2534: undef $sel;
2535:
2536: foreach (reverse sort keys %symrev) {
2537: $rev = $symrev{$_};
2538: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
2539: push (@branchnames, $_);
2540:
2541: #
2542: # A revision number of A.B.0.D really translates into
2543: # "the highest current revision on branch A.B.D".
2544: #
2545: # If there is no branch A.B.D, then it translates into
2546: # the head A.B .
2547: #
2548: # This reasoning also applies to the main branch A.B,
2549: # with the branch number 0.A, with the exception that
2550: # it has no head to translate to if there is nothing on
2551: # the branch, but I guess this can never happen?
2552: #
2553: # (the code below gracefully forgets about the branch
2554: # if it should happen)
2555: #
2556: $head = defined($2) ? $2 : "";
2557: $branch = $3;
2558: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2559: my $regex;
2560: $regex = quotemeta $branchrev;
2561: $rev = $head;
2562:
2563: foreach my $r (@revorder) {
2564: if ($r =~ /^${regex}\b/) {
2565: $rev = $branchrev;
2566: last;
2567: }
2568: }
2569: next if ($rev eq "");
2570:
2571: if ($rev ne $head && $head ne "") {
3.131 scop 2572: $branchpoint{$head} .= ', ' if ($branchpoint{$head});
3.120 scop 2573: $branchpoint{$head} .= $_;
2574: }
2575: }
2576: $revsym{$rev} .= ", " if ($revsym{$rev});
2577: $revsym{$rev} .= $_;
3.136 scop 2578: $sel .= sprintf("<option value=\"%s:%s\">%s</option>\n",
2579: htmlquote($rev), (htmlquote($_)) x 2);
3.120 scop 2580: }
2581:
2582: my ($onlyonbranch, $onlybranchpoint);
2583: if ($onlyonbranch = $input{'only_with_tag'}) {
2584: $onlyonbranch = $symrev{$onlyonbranch};
2585: if ($onlyonbranch =~ s/\b0\.//) {
2586: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2587: } else {
2588: $onlybranchpoint = $onlyonbranch;
2589: }
2590:
2591: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2592: fatal("404 Tag not found", 'Tag %s not defined',
3.131 scop 2593: $input{'only_with_tag'});
3.120 scop 2594: }
2595: }
2596:
2597: undef @revisions;
2598:
2599: foreach (@allrevisions) {
2600: ($br = $_) =~ s/\.\d+$//;
2601: ($brp = $br) =~ s/\.\d+$//;
2602: next if ($onlyonbranch
2603: && $br ne $onlyonbranch
2604: && $_ ne $onlybranchpoint);
2605: unshift (@revisions, $_);
2606: }
2607:
2608: if ($logsort eq "date") {
2609:
2610: # Sort the revisions in commit order an secondary sort on revision
2611: # (secondary sort needed for imported sources, or the first main
2612: # revision gets before the same revision on the 1.1.1 branch)
2613: @revdisplayorder =
2614: sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) } @revisions;
2615: } elsif ($logsort eq "rev") {
2616:
2617: # Sort the revisions in revision order, highest first
2618: @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
2619: } else {
2620:
2621: # No sorting. Present in the same order as rlog / cvs log
2622: @revdisplayorder = @revisions;
2623: }
2624:
2625: }
2626:
2627: sub printDiffLinks($$)
2628: {
2629: my ($text, $url) = @_;
2630: my @extra;
2631:
2632: local $_;
2633: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2634: my $f = $_ eq $defaultDiffType ? '' : $_;
2635:
2636: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2637: }
2638:
2639: print &link($text, $url), ' (', join (', ', @extra), ')';
2640: }
2641:
2642: sub printLog($;$)
2643: {
2644: my ($link, $br, $brp);
2645: ($_, $link) = @_;
2646: ($br = $_) =~ s/\.\d+$//;
2647: ($brp = $br) =~ s/\.?\d+$//;
3.131 scop 2648: my $prev;
3.120 scop 2649:
2650: $link = 1 if (!defined($link));
3.131 scop 2651: my $isDead = ($state{$_} eq 'dead');
2652: my $isSelected = (defined($input{'r1'}) && $input{'r1'} eq $_);
3.120 scop 2653:
3.131 scop 2654: print "<div class=\"diff-selected\">\n" if $isSelected;
3.120 scop 2655: print "<p>\n";
3.131 scop 2656:
3.120 scop 2657: if ($link && !$isDead) {
3.156 scop 2658: (my $filename = $where) =~ s/^.*\///;
2659: my $fileurl = urlencode($filename);
2660: my $mimetype = getMimeType($filename);
2661: my $viewable = viewable($mimetype);
2662:
3.120 scop 2663: print "<a name=\"rev$_\"></a>";
2664:
2665: if (defined($revsym{$_})) {
2666: foreach my $sym (split (", ", $revsym{$_})) {
3.136 scop 2667: print '<a name="', hrefquote($sym), '"></a>';
3.120 scop 2668: }
2669: }
2670:
2671: if (defined($revsym{$br})
2672: && $revsym{$br}
2673: && !defined($nameprinted{$br}))
2674: {
2675: foreach my $sym (split (", ", $revsym{$br})) {
3.136 scop 2676: print '<a name="', hrefquote($sym), '"></a>';
3.120 scop 2677: }
2678: $nameprinted{$br} = 1;
2679: }
2680: print "\n Revision ";
2681: &download_link($fileurl, $_, $_,
3.156 scop 2682: $viewable ? 'text/x-cvsweb-markup' : undef);
3.120 scop 2683:
3.161 scop 2684: print ' / (';
2685:
3.156 scop 2686: if ($viewable) {
3.120 scop 2687: &download_link($fileurl, $_, "download", $mimetype);
2688: }
2689:
3.156 scop 2690: if ($mimetype ne 'text/plain') {
3.161 scop 2691: print ' / ' if $viewable;
3.120 scop 2692: &download_link($fileurl, $_, "as text", "text/plain");
2693: }
2694:
3.156 scop 2695: if (!$viewable) {
3.161 scop 2696: print ' / ' if ($mimetype ne 'text/plain');
3.120 scop 2697: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2698: }
3.161 scop 2699:
2700: print ')';
3.120 scop 2701:
2702: if ($allow_annotate) {
2703: print " - ";
2704: print &link('annotate',
2705: sprintf('%s/%s?annotate=%s%s',
2706: $scriptname, urlencode($where), $_, $barequery));
2707: }
2708:
2709: # Plus a select link if enabled, and this version isn't selected
2710: if ($allow_version_select) {
3.131 scop 2711: print ' - ';
2712: if ($isSelected) {
2713: print '<b>[selected]</b>';
3.120 scop 2714: } else {
3.159 scop 2715: print &link('select for diffs',
3.131 scop 2716: sprintf('%s?r1=%s%s#rev%s',
2717: $scriptwhere, $_, $barequery, $_));
3.120 scop 2718: }
2719: }
2720: } else {
2721: print "Revision <b>$_</b>";
2722: }
2723:
2724: if (/^1\.1\.1\.\d+$/) {
2725: print " <i>(vendor branch)</i>";
2726: }
2727: if (defined @mytz) {
2728: my ($est) = $mytz[(localtime($date{$_}))[8]];
2729: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
2730: } else {
2731: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
2732: }
3.136 scop 2733: print readableTime(time() - $date{$_}, 1), ' ago)';
2734: print ' by <i>', htmlquote($author{$_}), "</i>\n";
2735:
2736: if ($revsym{$br}) {
2737: printf "<br>Branch: <b>%s</b>\n",
2738: $link ? link_tags($revsym{$br}) : htmlquote($revsym{$br});
2739: }
2740: if ($revsym{$_}) {
2741: printf "<br>CVS Tags: <b>%s</b>\n",
2742: $link ? link_tags($revsym{$_}) : htmlquote($revsym{$_});
2743: }
2744: if ($branchpoint{$_}) {
2745: printf "<br>Branch point for: <b>%s</b>\n",
2746: $link ? link_tags($branchpoint{$_}) : htmlquote($branchpoint{$_});
2747: }
3.120 scop 2748:
2749: # Find the previous revision
2750: my @prevrev = split (/\./, $_);
2751: do {
2752: if (--$prevrev[$#prevrev] <= 0) {
2753:
2754: # If it was X.Y.Z.1, just make it X.Y
2755: pop (@prevrev);
2756: pop (@prevrev);
2757: }
2758: $prev = join (".", @prevrev);
2759: } until (defined($date{$prev}) || $prev eq "");
2760:
2761: if ($prev ne "") {
2762: if ($difflines{$_}) {
2763: print "<br>Changes since <b>$prev: $difflines{$_} lines</b>";
2764: }
2765: }
2766:
2767: if ($isDead) {
2768: print "<br><b><i>FILE REMOVED</i></b>\n";
2769: } elsif ($link) {
2770: my %diffrev = ();
2771: $diffrev{$_} = 1;
2772: $diffrev{""} = 1;
2773: print '<br>';
2774: my $diff = 'Diff';
2775:
2776: #
2777: # Offer diff to previous revision
2778: if ($prev) {
2779: $diffrev{$prev} = 1;
2780:
2781: my $url =
2782: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $prev, $_, $barequery);
2783:
2784: print $diff, " to previous ";
2785: $diff = '';
2786: printDiffLinks($prev, $url);
2787: }
2788:
2789: #
2790: # Plus, if it's on a branch, and it's not a vendor branch,
2791: # offer a diff with the branch point.
2792: if ($revsym{$brp}
2793: && !/^1\.1\.1\.\d+$/
2794: && !defined($diffrev{$brp}))
2795: {
2796: my $url =
2797: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $brp, $_, $barequery);
2798:
2799: print $diff, " to branchpoint ";
2800: $diff = '';
2801: printDiffLinks($brp, $url);
2802: }
2803:
2804: #
2805: # Plus, if it's on a branch, and it's not a vendor branch,
2806: # offer to diff with the next revision of the higher branch.
2807: # (e.g. change gets committed and then brought
2808: # over to -stable)
2809: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2810: my ($i, $nextmain);
2811:
2812: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++) {
2813: }
2814: my @tmp2 = split (/\./, $_);
2815: for ($nextmain = ""; $i > 0; $i--) {
2816: my $next = $revorder[$i - 1];
2817: my @tmp1 = split (/\./, $next);
2818:
2819: if (@tmp1 < @tmp2) {
2820: $nextmain = $next;
2821: last;
2822: }
2823:
2824: # Only the highest version on a branch should have
2825: # a diff for the "next main".
2826: last
2827: if (@tmp1 - 1 <= @tmp2
2828: && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
2829: join (".", @tmp2[0 .. $#tmp1 - 1]));
2830: }
2831:
2832: if (!defined($diffrev{$nextmain})) {
2833: $diffrev{$nextmain} = 1;
2834:
2835: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2836: $scriptwhere, $nextmain, $_, $barequery);
2837:
2838: print $diff, " next main ";
2839: $diff = '';
2840: printDiffLinks($nextmain, $url);
2841: }
2842: }
2843:
2844: # Plus if user has selected only r1, then present a link
2845: # to make a diff to that revision
2846: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2847: $diffrev{$input{"r1"}} = 1;
2848:
2849: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2850: $scriptwhere, $input{'r1'}, $_, $barequery);
2851:
2852: print $diff, " to selected ";
2853: $diff = '';
2854: printDiffLinks($input{'r1'}, $url);
2855: }
2856:
2857: }
3.173 scop 2858: print "\n</p>\n<pre class=\"log\">\n";
3.120 scop 2859: print &htmlify($log{$_}, $allow_log_extra);
2860: print "</pre>\n";
3.131 scop 2861: print "</div>\n" if $isSelected;
3.120 scop 2862: }
2863:
3.132 scop 2864: #
2865: # Generates the HTML view for CvsGraph.
2866: #
3.170 scop 2867: sub doGraphView()
3.132 scop 2868: {
2869: (my $pathname = $where) =~ s|[^/]*$||;
2870: (my $filename = $where) =~ s|^.*/||;
2871:
3.170 scop 2872: navigateHeader($scriptwhere, $pathname, $filename, undef, 'graph');
3.132 scop 2873:
3.146 scop 2874: my $title = 'Revision graph of ' . htmlquote($pathname . $filename);
3.132 scop 2875: my $mapname = 'CvsGraphMap';
3.156 scop 2876: my $ctype = viewable(getMimeType($filename)) ?
2877: '&content-type=text/x-cvsweb-markup' : '';
3.132 scop 2878:
3.170 scop 2879: printf(<<EOF, $title, $mapname, $cvstree, $title);
3.146 scop 2880: <h3 style="text-align: center">%s</h3>
3.170 scop 2881: <div align="center"><img border="0" usemap="#%s" src="?cvsroot=%s&graph=1&makeimage=1" alt="%s"></div>
3.146 scop 2882: EOF
3.132 scop 2883:
3.135 scop 2884: my @graph_cmd =
2885: ($CMD{cvsgraph},
2886: '-r', $cvsroot,
2887: '-i',
2888: '-M', $mapname,
3.146 scop 2889: '-x', 4,
2890: "-Omap_branch_href=\"href=\\\"./?only_with_tag=%(%t%)$barequery\\\"\"",
2891: "-Omap_rev_href=\"href=\\\"?rev=%(%R%)$barequery$ctype\\\"\"",
2892: "-Omap_diff_href=\"href=\\\"%(%F%).diff" .
2893: "?r1=%(%P%)&r2=%(%R%)$barequery\\\"\"",
3.135 scop 2894: );
3.132 scop 2895: push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
3.174 ! scop 2896: push(@graph_cmd, catfile($pathname, $filename . ',v'));
3.132 scop 2897:
3.174 ! scop 2898: local *CVSGRAPH_OUT;
! 2899: local $^W = 0; # IPC::Run is noisy w/perl 5.8. Also prevents weird hangs.
! 2900: my ($h, $err) =
! 2901: startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT, timeout(30));
! 2902: fatal('500 Internal Error', $err) unless $h;
! 2903: {
! 2904: local $/ = undef;
! 2905: print <CVSGRAPH_OUT>;
3.132 scop 2906: }
3.174 ! scop 2907: finish($h);
3.132 scop 2908:
2909: html_footer();
2910: }
2911:
2912: #
2913: # Generates a graph using CvsGraph.
2914: #
3.170 scop 2915: sub doGraph()
3.132 scop 2916: {
2917: (my $pathname = $where) =~ s|[^/]*$||;
2918: (my $filename = $where) =~ s|^.*/||;
2919:
2920: http_header('image/png');
2921:
2922: my @graph_cmd = ($CMD{cvsgraph}, '-r', $cvsroot);
2923: push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
3.174 ! scop 2924: push(@graph_cmd, catfile($pathname, $filename . ',v'));
3.132 scop 2925:
3.174 ! scop 2926: local *CVSGRAPH_OUT;
! 2927: local $^W = 0; # IPC::Run is noisy w/perl 5.8. Also prevents weird hangs.
! 2928: my ($h, $err) =
! 2929: startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT, timeout(30));
! 2930: fatal('500 Internal Error', $err) unless $h;
3.132 scop 2931: {
2932: local $/ = undef;
2933: binmode(\*STDOUT);
3.174 ! scop 2934: print <CVSGRAPH_OUT>;
3.132 scop 2935: }
3.174 ! scop 2936: finish($h);
3.132 scop 2937: }
2938:
2939:
3.120 scop 2940: sub doLog($)
2941: {
2942: my ($fullname) = @_;
2943:
2944: readLog($fullname);
2945:
2946: html_header("CVS log for $where");
3.144 scop 2947:
2948: (my $upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2949: (my $filename = $where) =~ s|^.*/||;
2950: my $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2951:
3.120 scop 2952: print "<p>\n ";
2953: print &link($backicon, "$backurl#$filename"), " <b>Up to ",
2954: &clickablePath($upwhere, 1), "</b>\n</p>\n";
2955: print "<p>\n ";
2956: print &link('Request diff between arbitrary revisions', '#diff');
3.132 scop 2957: if ($allow_cvsgraph) {
3.170 scop 2958: print ' / ', &graph_link('', 'Display revisions graphically');
3.132 scop 2959: }
3.120 scop 2960: print "\n</p>\n<hr noshade>\n";
2961:
2962: print "<p>\n";
3.152 scop 2963:
2964: my $explain = $keywordsubstitution =~ /b/ ?
2965: ' (i.e.: CVS considers this a binary file)' : '';
2966: print "Keyword substitution: $keywordsubstitution$explain<br>\n";
3.144 scop 2967: print $curbranch
2968: ? ("Default branch: ", ($revsym{$curbranch} || $curbranch))
2969: : "No default branch";
3.120 scop 2970: print "<br>\n";
2971:
3.153 scop 2972: print 'Current tag: ', htmlquote($input{only_with_tag}), "<br>\n"
2973: if $input{only_with_tag};
3.120 scop 2974: print "</p>\n";
2975:
2976: undef %nameprinted;
2977:
2978: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2979: print "<hr size=\"1\" noshade>\n";
2980: printLog($revdisplayorder[$i]);
2981: }
2982:
3.144 scop 2983: printf(<<EOF, $scriptwhere);
2984: <hr noshade>
2985: <p>
2986: <a name="diff">
2987: This form allows you to request diff's between any two revisions of a file.
2988: You may select a symbolic revision name using the selection box or you may
2989: type in a numeric name using the type-in text box.
2990: </a>
2991: </p>
2992: <form method="get" action="%s.diff" name="diff_select">
2993: EOF
3.120 scop 2994:
2995: foreach (@stickyvars) {
3.154 scop 2996: printf("<input type=\"hidden\" name=\"%s\" value=\"%s\">\n",
2997: $_, htmlquote($input{$_}))
3.120 scop 2998: if (defined($input{$_})
2999: && ((!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_})
3000: && $input{$_} ne ""));
3001: }
3.144 scop 3002:
3003: print <<EOF;
3004: <table style="border: none">
3005: <tr>
3006: <td align="right">
3007: <label for="r1" accesskey="1">Diffs between </label>
3008: <select id="r1" name="r1">
3009: <option value="text" selected>Use Text Field</option>
3010: EOF
3011: print $sel, "</select>\n";
3012:
3013: my $diffrev = defined($input{r1}) ?
3014: $input{r1} : $revdisplayorder[$#revdisplayorder];
3015:
3016: printf(<<EOF, $inputTextSize, $diffrev);
3.147 scop 3017: <input type="text" size="%s" name="tr1" value="%s" onchange="this.form.r1.selectedIndex=0">
3.144 scop 3018: </td>
3019: <td><br></td>
3020: </tr><tr>
3021: <td align="right">
3022: <label for="r2" accesskey="2">and </label>
3023: <select id="r2" name="r2">
3024: <option value="text" selected>Use Text Field</option>
3025: EOF
3026: print $sel, "</select>\n";
3027:
3028: $diffrev = defined($input{r2}) ? $input{r2} : $revdisplayorder[0];
3029:
3030: printf(<<EOF, $inputTextSize, $diffrev, $scriptwhere);
3031: <input type="text" size="%s" name="tr2" value="%s" onchange="this.form.r2.selectedIndex=0">
3032: </td>
3033: <td><input type="submit" value=" Get Diffs " accesskey="G"></td>
3034: </tr>
3035: </table>
3036: </form>
3037: <hr noshade>
3038: <form method="get" action="%s">
3039: <table style="border: none">
3040: <tr>
3041: <td align="right">
3042: <label for="f" accesskey="D">Preferred Diff type:</label>
3043: </td><td>
3044: EOF
3045:
3.120 scop 3046: printDiffSelect($use_java_script);
3.144 scop 3047:
3048: print <<EOF;
3049: </td>
3050: <td></td>
3051: </tr>
3052: EOF
3.120 scop 3053:
3054: if (@branchnames) {
3.144 scop 3055:
3056: printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3057: <tr>
3058: <td align="right">
3059: <label for="only_with_tag" accesskey="B">View only Branch:</label>
3060: </td><td>
3061: <a name="branch"></a>
3062: <select id="only_with_tag" name="only_with_tag"%s>
3063: EOF
3064: print '<option value=""';
3065: print ' selected'
3066: if (defined($input{"only_with_tag"}) && $input{"only_with_tag"} eq '');
3.120 scop 3067: print ">Show all branches</option>\n";
3068:
3069: foreach (reverse sort @branchnames) {
3.136 scop 3070: my $selected =
3071: (defined($input{"only_with_tag"}) && $input{"only_with_tag"} eq $_);
3072: printf("<option%s>%s</option>\n",
3073: $selected ? ' selected' : '',
3074: htmlquote($_));
3.120 scop 3075: }
3.144 scop 3076: print <<EOF
3077: </select>
3078: </td>
3079: <td></td>
3080: </tr>
3081: EOF
3.120 scop 3082: }
3083:
3.144 scop 3084: print <<EOF;
3085: <tr>
3086: <td align="right">
3087: <a name="logsort"></a>
3088: <label for="logsort" accesskey="L">Sort log by:</label>
3089: </td><td>
3090: EOF
3.120 scop 3091: printLogSortSelect($use_java_script);
3.144 scop 3092: print <<EOF;
3093: </td>
3094: <td><input type="submit" value=" Set " accesskey="S"></td>
3095: </tr>
3096: </table>
3097: EOF
3.154 scop 3098: foreach (@stickyvars) {
3099: next if ($_ eq "f");
3100: next if ($_ eq "only_with_tag");
3101: next if ($_ eq "logsort");
3102: printf("<input type=\"hidden\" name=\"$_\" value=\"%s\">\n",
3103: htmlquote($input{$_}))
3104: if (defined($input{$_})
3105: && (!defined($DEFAULTVALUE{$_})
3106: || $input{$_} ne $DEFAULTVALUE{$_})
3107: && $input{$_} ne "");
3108: }
3109: print "</form>\n";
3.120 scop 3110: html_footer();
3111: }
3112:
3113: sub flush_diff_rows($$$$)
3114: {
3115: my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
3116:
3117: if (!defined($state)) {
3118: return;
3119: }
3120:
3121: if ($state eq "PreChangeRemove") { # we just got remove-lines before
3.133 scop 3122: for (my $j = 0; $j < $leftRow; $j++) {
3.144 scop 3123: printf(<<EOF, scalar(@$leftColRef[$j]));
3124: <tr>
3125: <td class="diff-removed"> %s</td>
3126: <td class="diff-empty"> </td>
3127: </tr>
3128: EOF
3.120 scop 3129: }
3130: } elsif ($state eq "PreChange") { # state eq "PreChange"
3131: # we got removes with subsequent adds
3132:
3.133 scop 3133: for (my $j = 0; $j < $leftRow || $j < $rightRow; $j++) { # dump both cols
3.120 scop 3134: print "<tr>\n";
3135: if ($j < $leftRow) {
3136: print "<td class=\"diff-changed\"> @$leftColRef[$j]</td>";
3137: } else {
3138: print "<td class=\"diff-changed-missing\"> </td>";
3139: }
3140: print "\n";
3141:
3142: if ($j < $rightRow) {
3143: print "<td class=\"diff-changed\"> @$rightColRef[$j]</td>";
3144: } else {
3145: print "<td class=\"diff-changed-missing\"> </td>";
3146: }
3147: print "\n</tr>\n";
3148: }
3149: }
3.1 knu 3150: }
3151:
3152: ##
3153: # Function to generate Human readable diff-files
3154: # human_readable_diff(String revision_to_return_to);
3155: ##
3.144 scop 3156: sub human_readable_diff($$)
3.120 scop 3157: {
3158: my ($fh, $rev) = @_;
3.144 scop 3159:
3.120 scop 3160: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
3161:
3.169 scop 3162: (my $where_nd = $where) =~ s|\.diff$||;
3163: (my $filename = $where_nd) =~ s|^.*/||;
3164: (my $pathname = $where_nd) =~ s|(Attic/)?[^/]*$||;
3165: (my $scriptwhere_nd = $scriptwhere) =~ s|\.diff$||;
3.120 scop 3166:
3.133 scop 3167: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, 'diff');
3.120 scop 3168:
3169: # Read header to pick up read revision and date, if possible
3170: while (<$fh>) {
3171: ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
3172: ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
3173: last if (/^\+\+\+ /);
3174: }
3175:
3176: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
3177: $rev1 = $r1r;
3178: $date1 = $r1d;
3179: }
3180: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
3181: $rev2 = $r2r;
3182: $date2 = $r2d;
3183: }
3184:
3.144 scop 3185: # Using <table style=\"border: none\" here breaks NS 4.x badly...
3186: printf(<<EOF, $where_nd, $rev1, $rev2, $rev1);
3187: <h3 style="text-align: center">Diff for /%s between versions %s and %s</h3>
3.147 scop 3188: <table border="0" cellspacing="0" cellpadding="0" width="100%%">
3.144 scop 3189: <tr style="background-color: #ffffff">
3.147 scop 3190: <th style="text-align: center; vertical-align: top" width="50%%">version %s
3.144 scop 3191: EOF
3192: print ', ', $date1 if defined($date1);
3193: print "<br>Tag: $sym1\n" if $sym1;
3194: printf(<<EOF, $rev2);
3195: </th>
3.147 scop 3196: <th style="text-align: center; vertical-align: top" width="50%%">version %s
3.144 scop 3197: EOF
3198: print ', ', $date2 if defined($date2);
3199: print "<br>Tag: $sym2\n" if $sym2;
3.120 scop 3200: print "</th>\n";
3201:
3202: # Process diff text
3203: # prefetch several lines
3204: my @buf = head($fh);
3.144 scop 3205: my %d = scan_directives(@buf);
3.120 scop 3206:
3.144 scop 3207: my $leftRow = 0;
3208: my $rightRow = 0;
3209: my ($difftxt, @rightCol, @leftCol, $oldline, $newline, $funname);
3210: my ($diffcode, $rest);
3.120 scop 3211:
3212: while (@buf || !eof($fh)) {
3213: $difftxt = @buf ? shift @buf : <$fh>;
3214:
3215: if ($difftxt =~ /^@@/) {
3216: ($oldline, $newline, $funname) =
3217: $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
3218: $funname = htmlquote($funname);
3219: $funname =~ s/\s/ /go;
3.144 scop 3220:
3221: printf(<<EOF, $oldline, $funname, $newline, $funname);
3222: <tr class="diff-heading">
3.147 scop 3223: <td width="50%%">
3224: <table width="100%%" border="1" cellpadding="5">
3.144 scop 3225: <tr>
3226: <td><b>Line %s</b> <span style="font-size: smaller">%s</span></td>
3227: </tr>
3228: </table>
3.147 scop 3229: </td><td width="50%%">
3230: <table width="100%%" border="1" cellpadding="5">
3.144 scop 3231: <tr>
3232: <td><b>Line %s</b> <span style="font-size: smaller">%s</span></td>
3233: </tr>
3234: </table>
3235: </td>
3236: EOF
3237:
3.120 scop 3238: $state = "dump";
3239: $leftRow = 0;
3240: $rightRow = 0;
3241: } else {
3242: ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
3243: $_ = spacedHtmlText($rest, $d{'tabstop'});
3244:
3245: #########
3246: # little state machine to parse unified-diff output (Hen, zeller@think.de)
3247: # in order to get some nice 'ediff'-mode output
3248: # states:
3249: # "dump" - just dump the value
3250: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
3251: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
3252: ##########
3253:
3254: if ($diffcode eq '+') {
3255: if ($state eq "dump")
3256: { # 'change' never begins with '+': just dump out value
3.144 scop 3257: printf(<<EOF, $_);
3258: <tr>
3259: <td class="diff-empty"> </td>
3260: <td class="diff-added"> %s</td>
3261: </tr>
3262: EOF
3.120 scop 3263: } else { # we got minus before
3264: $state = "PreChange";
3265: $rightCol[$rightRow++] = $_;
3266: }
3267: } elsif ($diffcode eq '-') {
3268: $state = "PreChangeRemove";
3269: $leftCol[$leftRow++] = $_;
3270: } else { # empty diffcode
3271: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3.147 scop 3272: printf(<<EOF, $_, $_);
3.144 scop 3273: <tr>
3274: <td class="diff-same"> %s</td>
3275: <td class="diff-same"> %s</td>
3276: </tr>
3277: EOF
3.120 scop 3278: $state = "dump";
3279: $leftRow = 0;
3280: $rightRow = 0;
3281: }
3282: }
3283: }
3284: close($fh);
3285:
3286: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3287:
3288: # state is empty if we didn't have any change
3289: if (!$state) {
3.144 scop 3290: print <<EOF;
3291: <tr>
3292: <td colspan="2"> </td>
3293: </tr>
3294: <tr class="diff-empty">
3295: <td colspan="2" align="center"><b>- No viewable change -</b></td>
3296: </tr>
3297: EOF
3.120 scop 3298: }
3299:
3.144 scop 3300: printf(<<EOF, $scriptwhere, $rev1, $rev2);
3301: </table>
3.147 scop 3302: <hr style="width: 100%%" noshade>
3.144 scop 3303: <form method="get" action="%s">
3304: <table style="border: none">
3305: <tr>
3306: <td>
3307: <table border="1">
3308: <tr>
3309: <td>
3310: Legend:<br>
3311: <table style="border: none" cellspacing="0" cellpadding="1">
3312: <tr>
3313: <td align="center" class="diff-removed">Removed from v.%s</td>
3314: <td class="diff-empty"> </td>
3315: </tr><tr class="diff-changed">
3316: <td align="center" colspan="2">changed lines</td>
3317: </tr><tr>
3318: <td class="diff-empty"> </td>
3319: <td align="center" class="diff-added">Added in v.%s</td>
3320: </tr>
3321: </table>
3322: </td>
3323: </tr>
3324: </table>
3325: </td>
3326: <td>
3327: EOF
3.168 scop 3328: printDiffSelectStickyVars();
3.120 scop 3329: printDiffSelect($use_java_script);
3.144 scop 3330: print <<EOF;
3331: <input type="submit" value="Show">
3332: </td>
3333: </tr>
3334: </table>
3335: </form>
3336: EOF
3.120 scop 3337: }
3.167 scop 3338:
3339:
3340: sub doEnscript($$$)
3341: {
3342: my ($filehandle, $highlight, $linenumbers) = @_;
3343:
3.174 ! scop 3344: my @cmd = ($CMD{enscript},
! 3345: @enscript_options,
! 3346: qw(-q --language=cvsweb -o -),
! 3347: "--highlight=$highlight");
! 3348:
! 3349: local $^W = 0; # IPC::Run is noisy w/ perl 5.8.
! 3350: local *ENSCRIPT_OUT;
! 3351: my ($h, $err) =
! 3352: startproc(\@cmd, $filehandle, '>pipe', \*ENSCRIPT_OUT, timeout(30));
! 3353: fatal('500 Internal Error', $err) unless $h;
! 3354:
! 3355: # We could short-circuit and have enscript output directly to STDOUT above,
! 3356: # but that doesn't work with mod_perl (at least some 1.99 versions).
! 3357: if ($linenumbers) {
! 3358: my $ln = 0;
! 3359: while (<ENSCRIPT_OUT>) {
! 3360: printf '<a id="l%d" class="src">%5d: </a>', (++$ln) x 2;
! 3361: print $_;
3.167 scop 3362: }
3.174 ! scop 3363: } else {
! 3364: local $/ = undef;
! 3365: print <ENSCRIPT_OUT>;
3.167 scop 3366: }
3.174 ! scop 3367: finish($h);
3.167 scop 3368: }
3369:
3.120 scop 3370:
3.163 scop 3371: sub navigateHeader($$$$$;$)
3.120 scop 3372: {
3.163 scop 3373: my ($swhere, $path, $filename, $rev, $title, $moddate) = @_;
3.120 scop 3374: $swhere = "" if ($swhere eq $scriptwhere);
3375: $swhere = './' . urlencode($filename) if ($swhere eq "");
3376:
3.136 scop 3377: my $qfile = htmlquote($filename);
3378: my $qpath = htmlquote($path);
3.170 scop 3379: my $trev = $rev ? " - $rev" : '';
3.100 knu 3380:
3.163 scop 3381: http_header('', $moddate);
3.133 scop 3382:
3.120 scop 3383: print <<EOF;
3.100 knu 3384: $HTML_DOCTYPE
3.89 knu 3385: <html>
3386: <head>
3.170 scop 3387: <title>$qpath$qfile - $title$trev</title>
3.144 scop 3388: $HTML_META$CSS</head>
3.129 scop 3389: <body class="src">
3390: <table width="100%" class="navigate-header" style="border: none" cellspacing="0" cellpadding="1">
3.144 scop 3391: <tr valign="bottom">
3392: <td>
3.64 knu 3393: EOF
3394:
3.170 scop 3395: print &link($backicon, "$swhere$query" . ($rev ? "#rev$rev" : ''));
3.136 scop 3396: printf '<b>Return to %s CVS log',
3.170 scop 3397: &link(htmlquote($filename), "$swhere$query" . ($rev ? "#rev$rev" : ''));
3.120 scop 3398: print "</b> $fileicon</td>";
3399:
3.144 scop 3400: printf(<<EOF, $diricon, &clickablePath($path, 1));
3401: <td align="right">%s <b>Up to %s</b></td>
3402: </tr>
3403: </table>
3404: EOF
3.120 scop 3405: }
3406:
3407: sub plural_write($$)
3408: {
3409: my ($num, $text) = @_;
3410: if ($num != 1) {
3411: $text .= "s";
3412: }
3413:
3414: if ($num > 0) {
3415: return join (' ', $num, $text);
3416: } else {
3417: return "";
3418: }
3.1 knu 3419: }
3420:
3421: ##
3422: # print readable timestamp in terms of
3423: # '..time ago'
3424: # H. Zeller <zeller@think.de>
3425: ##
3.120 scop 3426: sub readableTime($$)
3427: {
3428: my ($secs, $long) = @_;
3429:
3430: # this function works correct for time >= 2 seconds
3431: if ($secs < 2) {
3432: return "very little time";
3433: }
3434:
3435: my %desc = (
3.133 scop 3436: 1 => 'second',
3437: 60 => 'minute',
3438: 3600 => 'hour',
3439: 86400 => 'day',
3440: 604800 => 'week',
3441: 2628000 => 'month',
3442: 31536000 => 'year'
3443: );
3444:
3.120 scop 3445: my @breaks = sort { $a <=> $b } keys %desc;
3.133 scop 3446: my $i = 0;
3.120 scop 3447:
3448: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3449: $i++;
3450: }
3451: $i--;
3.133 scop 3452: my $break = $breaks[$i];
3453: my $retval = plural_write(int($secs / $break), $desc{$break});
3.120 scop 3454:
3455: if ($long == 1 && $i > 0) {
3456: my $rest = $secs % $break;
3457: $i--;
3458: $break = $breaks[$i];
3459: my $resttime = plural_write(int($rest / $break), $desc{$break});
3460: if ($resttime) {
3461: $retval .= ", $resttime";
3462: }
3463: }
3.1 knu 3464:
3.120 scop 3465: return $retval;
3.1 knu 3466: }
3467:
3468: ##
3469: # clickablePath(String pathname, boolean last_item_clickable)
3470: #
3471: # returns a html-ified path whereas each directory is a link for
3472: # faster navigation. last_item_clickable controls whether the
3473: # basename (last directory/file) is a link as well
3474: ##
3.120 scop 3475: sub clickablePath($$)
3476: {
3477: my ($pathname, $clickLast) = @_;
3478:
3.154 scop 3479: my $root = '[' . htmlquote($CVSROOTdescr{$cvstree} || $cvstree) . ']';
3480:
3.144 scop 3481: # This should never happen (see chooseCVSRoot()), but let's be sure...
3.154 scop 3482: return $root if ($pathname eq '/');
3.120 scop 3483:
3.144 scop 3484: my $retval =
3.154 scop 3485: ' ' . &link($root, sprintf('%s/%s#dirlist', $scriptname, $query));
3.144 scop 3486: my $wherepath = '';
3487: my ($lastslash) = $pathname =~ m|/$|;
3488:
3489: foreach (split (/\//, $pathname)) {
3490: $retval .= ' / ';
3491: $wherepath .= "/$_";
3492: my $last = "$wherepath/" eq "/$pathname" || $wherepath eq "/$pathname";
3493:
3494: if ($clickLast || !$last) {
3495: $retval .= &link(htmlquote($_),
3496: join ('',
3497: $scriptname, urlencode($wherepath),
3498: (!$last || $lastslash ? '/' : ''), $query,
3499: (!$last || $lastslash ? "#dirlist" : "")));
3500: } else { # do not make a link to the current dir
3501: $retval .= htmlquote($_);
3.120 scop 3502: }
3503: }
3504: return $retval;
3505: }
3506:
3.144 scop 3507:
3.120 scop 3508: sub chooseCVSRoot()
3509: {
3510:
3511: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3512: if (2 <= @CVSROOT) {
3.133 scop 3513: foreach my $k (keys %input) {
3.154 scop 3514: printf("<input type=\"hidden\" name=\"%s\" value=\"%s\">\n",
3515: htmlquote($k), htmlquote($input{$k}))
3516: if ($input{$k} && $k ne 'cvsroot');
3.120 scop 3517: }
3518:
3519: # Form-Elements look wierd in Netscape if the background
3520: # isn't gray and the form elements are not placed
3521: # within a table ...
3.144 scop 3522: printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3523: <table style="border: none">
3524: <tr>
3525: <td><label for="cvsroot" accesskey="C">CVS Root:</label></td>
3526: <td>
3527: <select id="cvsroot" name="cvsroot"%s>
3528: EOF
3.120 scop 3529:
3.133 scop 3530: foreach my $k (@CVSROOT) {
3.136 scop 3531: printf("<option value=\"%s\"%s>%s</option>\n",
3532: htmlquote($k),
3533: ($k eq $cvstree) ? ' selected' : '',
3534: htmlquote($CVSROOTdescr{$k} || $k));
3.120 scop 3535: }
3536: print "</select>\n</td>\n<td>";
3537: } else {
3538:
3539: # no choice -- but we need the form to select module/path,
3540: # at least for Netscape
3.154 scop 3541: printf "<p>\nCVS Root: <b>[%s]</b>",
3542: htmlquote($CVSROOTdescr{$cvstree} || $cvstree);
3.120 scop 3543: }
3544:
3.144 scop 3545: print <<EOF;
3546: <label for="mpath" accesskey="M">
3547: Module path or alias:
3548: <input type="text" id="mpath" name="path" value="" size="15">
3549: </label>
3550: <input type="submit" value="Go" accesskey="O">
3551: EOF
3.120 scop 3552:
3.144 scop 3553: print 2 <= @CVSROOT ? "</td>\n</tr>\n</table>" : '</p>';
3.120 scop 3554: print "\n</form>";
3555: }
3556:
3557: sub chooseMirror()
3558: {
3559:
3560: # This code comes from the original BSD-cvsweb
3561: # and may not be useful for your site; If you don't
3562: # set %MIRRORS this won't show up, anyway.
3563: scalar(%MIRRORS) or return;
3564:
3565: # Should perhaps exclude the current site somehow...
3566: print "\n<p>\nThis CVSweb is mirrored in\n";
3567:
3568: my @tmp = map(&link(htmlquote($_), $MIRRORS{$_}), sort keys %MIRRORS);
3569: my $tmp = pop (@tmp);
3570:
3571: if (scalar(@tmp)) {
3572: print join (', ', @tmp), ' and ';
3573: }
3574:
3575: print "$tmp.\n</p>\n";
3576: }
3577:
3578: sub fileSortCmp()
3579: {
3580: my ($comp) = 0;
3581: my ($c, $d, $af, $bf);
3582:
3583: ($af = $a) =~ s/,v$//;
3584: ($bf = $b) =~ s/,v$//;
3585: my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
3586: if (defined($fileinfo{$af}));
3587: my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
3588: if (defined($fileinfo{$bf}));
3589:
3.140 scop 3590: if (defined($filename1) && defined($filename2) &&
3591: $af eq $filename1 && $bf eq $filename2)
3.120 scop 3592: {
3593:
3594: # Two files
3.140 scop 3595: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
3596: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
3597: if ($input{ignorecase}) {
3598: $comp = (uc($log1) cmp uc($log2)) if ($bylog && $log1 && $log2);
3599: $comp = (uc($author1) cmp uc($author2)) if ($byauthor &&
3600: $author1 && $author2);
3601: } else {
3602: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
3603: $comp = ($author1 cmp $author2) if ($byauthor &&
3604: $author1 && $author2);
3605: }
3.120 scop 3606: }
3607:
3608: if ($comp == 0) {
3609:
3610: # Directories first, then files under version control,
3611: # then other, "rogue" files.
3612: # Sort by filename if no other criteria available.
3613:
3614: my $ad = (
3615: (-d "$fullname/$a")
3616: ? 'D'
3617: : (defined($fileinfo{$af}) ? 'F' : 'R')
3618: );
3619: my $bd = (
3620: (-d "$fullname/$b")
3621: ? 'D'
3622: : (defined($fileinfo{$bf}) ? 'F' : 'R')
3623: );
3624: ($c = $a) =~ s|.*/||;
3625: ($d = $b) =~ s|.*/||;
3.144 scop 3626:
3627: my ($l, $r) = ("$ad$c", "$bd$d");
3628: $comp = $input{ignorecase} ? (uc($l) cmp uc($r)) : ($l cmp $r);
3629:
3630: # Parent dir is always first, then Attic.
3631: if ($comp != 0) {
3632: if ($l eq 'D..') {
3.149 scop 3633: $comp = -1;
3.144 scop 3634: } elsif ($r eq 'D..') {
3.149 scop 3635: $comp = 1;
3.144 scop 3636: } elsif ($l eq 'DAttic') {
3.149 scop 3637: $comp = -1;
3.144 scop 3638: } elsif ($r eq 'DAttic') {
3.149 scop 3639: $comp = 1;
3.144 scop 3640: }
3641: }
3.120 scop 3642: }
3643: return $comp;
3.1 knu 3644: }
3645:
3646: # make A url for downloading
3.120 scop 3647: sub download_url($$;$)
3648: {
3649: my ($url, $revision, $mimetype) = @_;
3.1 knu 3650:
3.120 scop 3651: $revision =~ s/\b0\.//;
3.1 knu 3652:
3.146 scop 3653: if (defined($checkoutMagic) &&
3654: (!defined($mimetype) || $mimetype !~ $CvsWebMarkupRE))
3.120 scop 3655: {
3656: my $path = $where;
3657: $path =~ s|[^/]+$||;
3658: $url = "$scriptname/$checkoutMagic/${path}$url";
3659: }
3660: $url .= "?rev=$revision";
3661: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.67 knu 3662:
3.120 scop 3663: $url;
3.1 knu 3664: }
3665:
3.12 knu 3666: # Presents a link to download the
3.1 knu 3667: # selected revision
3.120 scop 3668: sub download_link($$$;$)
3669: {
3670: my ($url, $revision, $textlink, $mimetype) = @_;
3671: my ($fullurl) = download_url($url, $revision, $mimetype);
3672:
3673: $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
3674:
3.159 scop 3675: printf '<a href="%s" class="download-link"', hrefquote("$fullurl$barequery");
3.120 scop 3676:
3.146 scop 3677: if ($open_extern_window &&
3678: (!defined($mimetype) || $mimetype !~ $CvsWebMarkupRE))
3.120 scop 3679: {
3680: print ' target="cvs_checkout"';
3681:
3682: # we should have
3683: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3684: # in order to allow the user to resize the window; otherwise
3685: # the user may resize the window, but on next checkout - zap -
3686: # its original (configured s. cvsweb.conf) size is back again
3687: # .. annoying (if $extern_window_(width|height) is defined)
3688: # but this if (..) solution is far from perfect
3689: # what we need to do as well is
3690: # 1) save cvswin in an invisible frame that always exists
3691: # (document.cvswin will be void on next load)
3692: # 2) on close of the cvs_checkout - window set the cvswin
3693: # variable to 'null' again - so that it will be
3694: # reopenend with the configured size
3695: # anyone a JavaScript programmer ?
3696: # .. so here without if (..):
3697: # currently, the best way is to comment out the size parameters
3698: # ($extern_window...) in cvsweb.conf.
3699: if ($use_java_script) {
3.159 scop 3700: my @attr = qw(resizable scrollbars menubar);
3.120 scop 3701:
3702: push @attr, qw(status toolbar)
3703: if (defined($mimetype) && $mimetype eq "text/html");
3704:
3705: push @attr, "width=$extern_window_width"
3706: if (defined($extern_window_width));
3707:
3708: push @attr, "height=$extern_window_height"
3709: if (defined($extern_window_height));
3710:
3711: # We need the "return false" here to prevent browsers
3712: # from following the href after the onclick handler.
3713: # This would effectively load the same document in
3714: # the same window *twice*.
3715: printf q` onclick="window.open('%s','cvs_checkout','%s');return false"`,
3716: hrefquote("$fullurl$barequery"), join (',', @attr);
3717: }
3718: }
3.159 scop 3719: print ">$textlink</a>";
3.132 scop 3720: }
3721:
3.170 scop 3722: sub graph_link($;$)
3.132 scop 3723: {
3.170 scop 3724: my ($url, $text) = @_;
3.132 scop 3725: $text ||= $graphicon;
3.170 scop 3726: return sprintf('<a href="%s?graph=1%s">%s</a>',
3727: hrefquote($url), hrefquote($barequery), $text);
3.1 knu 3728: }
3729:
3730: # Returns a Query string with the
3731: # specified parameter toggled
3.140 scop 3732: sub toggleQuery($;$)
3.120 scop 3733: {
3734: my ($toggle, $value) = @_;
3.133 scop 3735:
3736: my %vars = %input;
3.120 scop 3737:
3738: if (defined($value)) {
3739: $vars{$toggle} = $value;
3740: } else {
3741: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3742: }
3743:
3744: # Build a new query of non-default paramenters
3.133 scop 3745: my $newquery = "";
3746: foreach my $var (@stickyvars) {
3.120 scop 3747: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3748: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3749:
3750: if ($value ne $default) {
3751: $newquery .= "&" if ($newquery ne "");
3752: $newquery .= urlencode($var) . "=" . urlencode($value);
3753: }
3754: }
3755:
3756: if ($newquery) {
3757: return '?' . $newquery;
3758: }
3759: return "";
3760: }
3761:
3762: sub urlencode($)
3763: {
3764: local ($_) = @_;
3765:
3766: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3767:
3768: $_;
3769: }
3770:
3771: sub htmlquote($)
3772: {
3773: local ($_) = @_;
3774:
3775: # Special Characters; RFC 1866
3776: s/&/&/g;
3777: s/\"/"/g;
3778: s/</</g;
3779: s/>/>/g;
3780:
3781: $_;
3782: }
3783:
3784: sub htmlunquote($)
3785: {
3786: local ($_) = @_;
3787:
3788: # Special Characters; RFC 1866
3789: s/"/\"/g;
3790: s/</</g;
3791: s/>/>/g;
3792: s/&/&/g;
3793:
3794: $_;
3795: }
3796:
3797: sub hrefquote($)
3798: {
3799: local ($_) = @_;
3800:
3801: y/ /+/;
3802:
3803: htmlquote($_);
3804: }
3805:
3.163 scop 3806: sub http_header(;$$)
3.120 scop 3807: {
3.163 scop 3808: my ($content_type, $moddate) = @_;
3809: $content_type ||= 'text/html';
3.120 scop 3810:
3811: $content_type .= "; charset=$charset"
3.163 scop 3812: if ($charset && $content_type =~ m,^text/,);
3.120 scop 3813:
3.163 scop 3814: if ($moddate) {
3.120 scop 3815: if ($is_mod_perl) {
3816: Apache->request->header_out(
3817: "Last-Modified" => scalar gmtime($moddate) . " GMT");
3818: } else {
3819: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
3820: }
3821: }
3822:
3823: if ($is_mod_perl) {
3824: Apache->request->content_type($content_type);
3825: } else {
3826: print "Content-Type: $content_type\r\n";
3827: }
3828:
3829: if ($allow_compress && $maycompress) {
3830: if ($has_zlib
3831: || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c")))
3832: {
3833:
3834: if ($is_mod_perl) {
3835: Apache->request->content_encoding("x-gzip");
3836: Apache->request->header_out(Vary => "Accept-Encoding");
3837: Apache->request->send_http_header;
3838: } else {
3839: print "Content-Encoding: x-gzip\r\n";
3840: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
3841: print "\r\n"; # Close headers
3842: }
3843: $| = 1;
3844: $| = 0; # Flush header output
3845:
3846: if ($has_zlib) {
3847: tie *GZIP, __PACKAGE__, \*STDOUT;
3848: }
3849: select(GZIP);
3850: $gzip_open = 1;
3851:
3.149 scop 3852: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
3.120 scop 3853: } else {
3854: if ($is_mod_perl) {
3855: Apache->request->send_http_header;
3856: } else {
3857: print "\r\n"; # Close headers
3858: }
3859: print
3860: "<span style=\"font-size: smaller\">Unable to find gzip binary in the <b>\$command_path</b> ($command_path) to compress output</span><br>";
3861: }
3862: } else {
3863:
3864: if ($is_mod_perl) {
3865: Apache->request->send_http_header;
3866: } else {
3867: print "\r\n"; # Close headers
3868: }
3869: }
3870: }
3871:
3.131 scop 3872:
3.163 scop 3873: sub html_header($;$)
3.120 scop 3874: {
3.163 scop 3875: my ($title, $moddate) = @_;
3876: $title = htmlquote($title);
3.162 scop 3877: my $l = $logo || '';
3.163 scop 3878: http_header('text/html', $moddate);
3.120 scop 3879: print <<EOH;
3.100 knu 3880: $HTML_DOCTYPE
3.1 knu 3881: <html>
3.40 knu 3882: <head>
3.134 scop 3883: <title>$title</title>
3.144 scop 3884: $HTML_META$CSS</head>
3.129 scop 3885: <body>
3.162 scop 3886: $l <h1 align="center">$title</h1>
3.1 knu 3887: EOH
3888: }
3889:
3.120 scop 3890: sub html_footer()
3891: {
3.127 scop 3892: print "<hr noshade>\n<address>$address</address>\n" if $address;
3893: print "</body>\n</html>\n";
3.1 knu 3894: }
3895:
3.120 scop 3896: sub link_tags($)
3897: {
3898: my ($tags) = @_;
3899: my ($ret) = "";
3900: my ($fileurl, $filename);
3901:
3902: ($filename = $where) =~ s/^.*\///;
3903: $fileurl = './' . urlencode($filename);
3904:
3905: foreach my $sym (split (", ", $tags)) {
3906: $ret .= ",\n" if ($ret ne "");
3.136 scop 3907: $ret .= &link(htmlquote($sym),
3908: $fileurl . toggleQuery('only_with_tag', $sym));
3.120 scop 3909: }
3910: return "$ret\n";
3.1 knu 3911: }
3912:
3913: #
3.81 knu 3914: # See if a module is listed in the config file's @HideModules list.
3.1 knu 3915: #
3.120 scop 3916: sub forbidden_module($)
3917: {
3918: my ($module) = @_;
3919: local $_;
3920:
3921: for (@HideModules) {
3922: return 1 if $module =~ $_;
3923: }
3924: return 0;
3925: }
3926:
3927: sub forbidden_file($)
3928: {
3929: my ($path) = @_;
3930: $path = substr($path, length($cvsroot) + 1);
3931: local $_;
3932: for (@ForbiddenFiles) {
3933: return 1 if $path =~ $_;
3934: }
3935: return 0;
3.174 ! scop 3936: }
! 3937:
! 3938:
! 3939: #
! 3940: # Starts a process using IPC::Run. All arguments are passed to
! 3941: # IPC::Run::start() as-is. Returns an array ($harness, $error) where
! 3942: # $harness is from IPC::Run if start() succeeds, undef otherwise. In case
! 3943: # of an error, $error contains message.
! 3944: #
! 3945: sub startproc($@)
! 3946: {
! 3947: my $h = undef;
! 3948: eval {
! 3949: local $^W = 0;
! 3950: local $SIG{__DIE__};
! 3951: $h = start(@_) or die("return code: $?");
! 3952: };
! 3953: my $err = $@ ? "Failed to run '@{$_[0]}': $@" : undef;
! 3954: return ($h, $err);
3.129 scop 3955: }
3956:
3.25 knu 3957:
3.173 scop 3958: # Close the GZIP handle, and remove the tie.
3.120 scop 3959: sub gzipclose
3960: {
3961: if ($gzip_open) {
3962: select(STDOUT);
3963: close(GZIP);
3964: untie *GZIP;
3965: $gzip_open = 0;
3966: }
3.23 knu 3967: }
3968:
3969: # implement a gzipped file handle via the Compress:Zlib compression
3970: # library.
3971:
3972: sub MAGIC1() { 0x1f }
3973: sub MAGIC2() { 0x8b }
3.80 knu 3974: sub OSCODE() { 3 }
3.23 knu 3975:
3.120 scop 3976: sub TIEHANDLE
3977: {
3978: my ($class, $out) = @_;
3979: my ($d) = Compress::Zlib::deflateInit(
3980: -Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3981: -WindowBits => -Compress::Zlib::MAX_WBITS()
3982: )
3983: or return undef;
3984: my ($o) = { handle => $out,
3985: dh => $d,
3986: crc => 0,
3987: len => 0,
3988: };
3989: my ($header) = pack("c10",
3990: MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(),
3991: 0, 0, 0, 0, 0, 0, OSCODE);
3992: print {$o->{handle}} $header;
3993: return bless($o, $class);
3994: }
3995:
3996: sub PRINT
3997: {
3998: my ($o) = shift;
3.164 scop 3999: my ($buf) = join (defined($,) ? $, : "", @_);
3.120 scop 4000: my ($len) = length($buf);
4001: my ($compressed, $status) = $o->{dh}->deflate($buf);
4002: print {$o->{handle}} $compressed if defined($compressed);
4003: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
4004: $o->{len} += $len;
4005: return $len;
4006: }
4007:
4008: sub PRINTF
4009: {
4010: my ($o) = shift;
4011: my ($fmt) = shift;
4012: my ($buf) = sprintf($fmt, @_);
4013: my ($len) = length($buf);
4014: my ($compressed, $status) = $o->{dh}->deflate($buf);
4015: print {$o->{handle}} $compressed if defined($compressed);
4016: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
4017: $o->{len} += $len;
4018: return $len;
4019: }
4020:
4021: sub WRITE
4022: {
4023: my ($o, $buf, $len, $off) = @_;
4024: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
4025: print {$o->{handle}} $compressed if defined($compressed);
4026: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
4027: $o->{len} += $len;
4028: return $len;
4029: }
4030:
4031: sub CLOSE
4032: {
4033: my ($o) = @_;
4034: return if !defined($o->{dh});
4035: my ($buf) = $o->{dh}->flush();
4036: $buf .= pack("V V", $o->{crc}, $o->{len});
4037: print {$o->{handle}} $buf;
4038: undef $o->{dh};
4039: }
4040:
4041: sub DESTROY
4042: {
4043: my ($o) = @_;
4044: CLOSE($o);
1.1 jfieber 4045: }
3.149 scop 4046:
4047: # Local variables:
4048: # indent-tabs-mode: nil
4049: # cperl-indent-level: 2
4050: # End:
CVSweb