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