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