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