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