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