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