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