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