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