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