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