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