Annotation of cvsweb/cvsweb.cgi, Revision 3.223
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) = @_;
1597: $ts ||= $tabstop;
3.120 scop 1598:
1599: # Cut trailing spaces and tabs
1600: s/[ \t]+$//;
1601:
1602: if (defined($ts)) {
1603:
1604: # Expand tabs
1605: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e;
1606: }
1607:
1608: # replace <tab> and <space> (\001 is to protect us from htmlify)
1609: # gzip can make excellent use of this repeating pattern :-)
1610: if ($hr_breakable) {
1611:
1612: # make every other space 'breakable'
1613: s/ / \001nbsp;/g; # 2 * <space>
1614: # leave single space as it is
1615: } else {
1616: s/ /\001nbsp;/g;
1617: }
1618:
1619: $_ = htmlify($_, $allow_source_extra);
1620:
1621: # unescape
1622: y/\001/&/;
1623:
1624: return $_;
1625: }
1626:
3.175 scop 1627:
3.120 scop 1628: # Note that this doesn't htmlquote the first argument...
1629: sub link($$)
1630: {
1631: my ($name, $url) = @_;
1632:
1633: $url =~ s/:/sprintf("%%%02x", ord($&))/eg
1634: if $url =~ /^[^a-z]/; # relative
1635:
1636: sprintf '<a href="%s">%s</a>', hrefquote($url), $name;
1637: }
1638:
3.175 scop 1639:
3.120 scop 1640: sub revcmp($$)
1641: {
1642: my ($rev1, $rev2) = @_;
1643:
1644: # make no comparison for a tag or a branch
1645: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1646:
1647: my (@r1) = split (/\./, $rev1);
1648: my (@r2) = split (/\./, $rev2);
1649: my ($a, $b);
1650:
1651: while (($a = shift (@r1)) && ($b = shift (@r2))) {
1652: if ($a != $b) {
1653: return $a <=> $b;
1654: }
1655: }
1656: if (@r1) { return 1; }
1657: if (@r2) { return -1; }
1658: return 0;
1659: }
1660:
3.175 scop 1661:
3.120 scop 1662: sub fatal($$@)
1663: {
1664: my ($errcode, $format, @args) = @_;
3.185 scop 1665: print "Status: $errcode\r\n";
3.131 scop 1666: html_header('Error');
3.215 scop 1667: print '<div id="error">Error: ',
1668: sprintf($format, map(htmlquote($_), @args)), "</div>\n";
3.120 scop 1669: html_footer();
1670: exit(1);
1671: }
1672:
3.175 scop 1673:
3.120 scop 1674: sub redirect($)
1675: {
1676: my ($url) = @_;
3.185 scop 1677: print "Status: 301 Moved\r\n", "Location: $url\r\n";
3.131 scop 1678: html_header('Moved');
3.120 scop 1679: print "<p>This document is located ", &link('here', $url), "</p>\n";
1680: html_footer();
1681: exit(1);
1682: }
1683:
3.175 scop 1684:
3.120 scop 1685: sub safeglob($)
1686: {
1687: my ($filename) = @_;
1688:
3.175 scop 1689: (my $dirname = $filename) =~ s|/[^/]+$||;
3.120 scop 1690: $filename =~ s|.*/||;
1691:
3.175 scop 1692: my @results;
1693: my $dh = do { local (*DH); };
3.120 scop 1694: if (opendir($dh, $dirname)) {
1695: my $glob = $filename;
1696: my $t;
1697:
3.149 scop 1698: # transform filename from glob to regex. Deal with:
1699: # [, {, ?, * as glob chars
1700: # make sure to escape all other regex chars
3.120 scop 1701: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1702: $glob =~ s/\*/.*/g;
1703: $glob =~ s/\?/./g;
1704: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
3.222 scop 1705: $glob = qr/^$glob$/;
1706:
3.120 scop 1707: foreach (readdir($dh)) {
3.222 scop 1708: if ($_ =~ $glob && $_ =~ VALID_PATH) {
3.194 scop 1709: push(@results, catfile($dirname, $1)); # untaint
3.120 scop 1710: }
1711: }
1712: closedir($dh);
1713: }
1714:
3.175 scop 1715: return @results;
3.120 scop 1716: }
1717:
3.160 scop 1718:
3.120 scop 1719: sub search_path($)
1720: {
1721: my ($command) = @_;
3.160 scop 1722: for my $d (split (/:/, $command_path)) {
3.120 scop 1723: return "$d/$command" if -x "$d/$command";
1724: }
1725: return '';
1726: }
1727:
3.156 scop 1728:
3.219 scop 1729: #
1730: # Gets the enscript(1) highlight mode corresponding to the given filename,
1731: # or undef if unsupported.
1732: #
1733: sub getEnscriptHL($)
1734: {
1735: return undef unless $allow_enscript;
1736: my ($filename) = @_;
1737: while (my ($hl, $regex) = each %enscript_types) {
1738: return $hl if ($filename =~ $regex);
1739: }
1740: return undef;
1741: }
1742:
1743:
1744: #
1745: # Gets the MIME type for the given file name.
1746: #
3.156 scop 1747: sub getMimeType($;$)
3.120 scop 1748: {
3.156 scop 1749: my ($fullname, $binary) = @_;
1750: $binary = ($keywordsubstitution && $keywordsubstitution =~ /b/)
1751: unless defined($binary);
1752:
1753: (my $suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1754:
1755: my $mimetype = $MTYPES{$suffix};
1756: $mimetype ||= $MimeTypes->mimeTypeOf($fullname) if defined($MimeTypes);
1757:
1758: if (!$mimetype && $suffix ne '*' && -f $mime_types && -r _) {
1759: my $fh = do { local (*FH); };
1760: if (open($fh, $mime_types)) {
1761: my $re = sprintf('^\s*(\S+\/\S+)\s.+\b%s\b', quotemeta($suffix));
3.222 scop 1762: $re = qr/$re/;
3.156 scop 1763: while (my $line = <$fh>) {
1764: if ($line =~ $re) {
1765: $mimetype = $1;
1766: $MTYPES{$suffix} = $mimetype;
1767: last;
1768: }
3.120 scop 1769: }
3.156 scop 1770: close($fh);
1771: } else {
1772: warn("Can't open MIME types file $mime_types for reading: $!");
3.120 scop 1773: }
1774: }
1775:
3.156 scop 1776: $mimetype ||= $MTYPES{'*'};
1777: $mimetype ||= $binary ? 'application/octet-stream' : 'text/plain';
3.120 scop 1778: return $mimetype;
3.1 knu 1779: }
1780:
3.156 scop 1781:
3.1 knu 1782: ###############################
3.24 knu 1783: # read first lines like head(1)
1784: ###############################
3.120 scop 1785: sub head($;$)
1786: {
3.175 scop 1787: my ($fh, $linecount) = @_;
1788: $linecount ||= 10;
3.24 knu 1789:
3.120 scop 1790: my @buf;
1791: if ($linecount > 0) {
3.184 scop 1792: for (my $i = 0; !eof($fh) && $i < $linecount; $i++) {
3.120 scop 1793: push @buf, scalar <$fh>;
1794: }
1795: } else {
1796: @buf = <$fh>;
1797: }
3.175 scop 1798: return @buf;
1799: }
3.120 scop 1800:
3.24 knu 1801:
1802: ###############################
1803: # scan vim and Emacs directives
1804: ###############################
3.120 scop 1805: sub scan_directives(@)
1806: {
1807: my $ts = undef;
3.24 knu 1808:
3.120 scop 1809: for (@_) {
1810: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1811: }
3.24 knu 1812:
3.120 scop 1813: ('tabstop' => $ts);
3.24 knu 1814: }
1815:
3.175 scop 1816:
3.120 scop 1817: sub openOutputFilter()
1818: {
3.175 scop 1819: return unless $output_filter;
3.86 knu 1820:
3.120 scop 1821: open(STDOUT, "|-") and return;
3.86 knu 1822:
3.120 scop 1823: # child of child
3.165 scop 1824: open(STDERR, '>', devnull());
3.120 scop 1825: exec($output_filter) or exit -1;
3.86 knu 1826: }
1827:
3.175 scop 1828:
3.24 knu 1829: ###############################
3.1 knu 1830: # show Annotation
1831: ###############################
3.133 scop 1832: sub doAnnotate($)
3.120 scop 1833: {
1834: my ($rev) = @_;
3.174 scop 1835: (my $pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1836: (my $filename = $where) =~ s/^.*\///;
3.126 scop 1837:
3.174 scop 1838: # This annotate version is based on the cvs annotate-demo Perl script by
1839: # Cyclic Software. It was written by Cyclic Software,
1840: # http://www.cyclic.com/, and is in the public domain.
1841: # We could abandon the use of rlog, rcsdiff and co using
1842: # the cvs server in a similiar way one day (..after rewrite).
1843:
1844: local (*CVS_IN, *CVS_OUT);
3.215 scop 1845: my $annotate_err;
3.174 scop 1846: my ($h, $err) =
1847: startproc([ $CMD{cvs}, @annotate_options, 'server' ],
3.215 scop 1848: '<pipe', \*CVS_IN, '>pipe', \*CVS_OUT,
1849: '2>', \$annotate_err, timeout(30));
1850: fatal('500 Internal Error',
1851: 'Annotate failure (exit status %s), output: <pre>%s</pre>',
1852: $? >> 8 || -1, $err)
1853: unless $h;
3.120 scop 1854:
1855: # OK, first send the request to the server. A simplified example is:
1856: # Root /home/kingdon/zwork/cvsroot
1857: # Argument foo/xx
1858: # Directory foo
1859: # /home/kingdon/zwork/cvsroot/foo
1860: # Directory .
1861: # /home/kingdon/zwork/cvsroot
1862: # annotate
1863: # although as you can see there are a few more details.
1864:
3.174 scop 1865: print CVS_IN "Root $cvsroot\n";
1866: print CVS_IN
3.120 scop 1867: "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1868:
1869: # Don't worry about sending valid-requests, the server just needs to
1870: # support "annotate" and if it doesn't, there isn't anything to be done.
3.174 scop 1871: print CVS_IN "UseUnchanged\n";
1872: print CVS_IN "Argument -r\n";
1873: print CVS_IN "Argument $rev\n";
1874: print CVS_IN "Argument $where\n";
3.120 scop 1875:
1876: # The protocol requires us to fully fake a working directory (at
1877: # least to the point of including the directories down to the one
1878: # containing the file in question).
3.123 scop 1879: # So if $where is "dir/sdir/file", then dirs will be ("dir","sdir","file")
1880: my $path = '';
1881: foreach my $dir (split('/', $where)) {
3.120 scop 1882:
1883: if ($path eq "") {
3.123 scop 1884: # In our example, $dir is "dir".
1885: $path = $dir;
3.120 scop 1886: } else {
3.174 scop 1887: print CVS_IN "Directory $path\n";
1888: print CVS_IN "$cvsroot/$path\n";
3.120 scop 1889:
1890: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1891: # And the next time, "file" and "dir/sdir/file" (which then gets
1892: # ignored, because we don't need to send Directory for the file).
3.123 scop 1893: $path .= "/$dir";
3.120 scop 1894: }
1895: }
3.123 scop 1896: undef $path;
3.120 scop 1897:
1898: # And the last "Directory" before "annotate" is the top level.
3.174 scop 1899: print CVS_IN "Directory .\n";
1900: print CVS_IN "$cvsroot\n";
3.120 scop 1901:
3.174 scop 1902: print CVS_IN "annotate\n";
3.120 scop 1903:
1904: # OK, we've sent our command to the server. Thing to do is to
3.215 scop 1905: # close the writer side and get all the responses.
1906: if (!close(CVS_IN)) {
1907: finish($h);
1908: fatal('500 Internal Error',
1909: 'Annotate failure (exit status %s): <code>%s</code>, output: ' .
1910: '<pre>%s</pre>', $? >> 8, $!, $annotate_err);
1911: }
3.120 scop 1912:
3.133 scop 1913: navigateHeader($scriptwhere, $pathname, $filename, $rev, 'annotate');
3.120 scop 1914:
3.136 scop 1915: print '<h3 style="text-align: center">Annotation of ',
1916: htmlquote("$pathname$filename"), ", revision $rev</h3>\n";
3.120 scop 1917:
1918: # Ready to get the responses from the server.
1919: # For example:
1920: # E Annotations for foo/xx
1921: # E ***************
1922: # M 1.3 (kingdon 06-Sep-97): hello
1923: # ok
1924: my ($lineNr) = 0;
1925: my ($oldLrev, $oldLusr) = ("", "");
1926: my ($revprint, $usrprint);
1927:
1928: if ($annTable) {
3.179 scop 1929: print <<EOF;
1930: <table style="border: none" cellspacing="0" cellpadding="0" summary="Annotation">
1931: EOF
3.120 scop 1932: } else {
1933: print "<pre>";
1934: }
1935:
1936: # prefetch several lines
3.174 scop 1937: my @buf = head(*CVS_OUT);
3.120 scop 1938:
1939: my %d = scan_directives(@buf);
1940:
3.174 scop 1941: while (@buf || !eof(*CVS_OUT)) {
3.197 scop 1942:
3.174 scop 1943: $_ = @buf ? shift @buf : <CVS_OUT>;
3.120 scop 1944: my @words = split;
1945:
1946: # Adding one is for the (single) space which follows $words[0].
1947: my $rest = substr($_, length($words[0]) + 1);
1948: if ($words[0] eq "E") {
1949: next;
1950: } elsif ($words[0] eq "M") {
1951: $lineNr++;
1952: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1953: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1954: my $line = substr($_, 36);
1955: my $isCurrentRev = ($rev eq $lrev);
1956:
1957: # we should parse the date here ..
1958: if ($lrev eq $oldLrev) {
1959: $revprint = sprintf('%-8s', '');
1960: } else {
1961: $revprint = sprintf('%-8s', $lrev);
1962: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
1963: $oldLusr = '';
1964: }
1965:
1966: if ($lusr eq $oldLusr) {
1967: $usrprint = '';
1968: } else {
1969: $usrprint = $lusr;
1970: }
1971: $oldLrev = $lrev;
1972: $oldLusr = $lusr;
1973:
1974: # Set bold for text-based browsers only - graphical
1975: # browsers show bold fonts a bit wider than regular fonts,
1976: # so it looks irregular.
1977: print "<b>" if ($isCurrentRev && $is_textbased);
1978:
3.136 scop 1979: $usrprint = sprintf('%-8s', $usrprint);
1980: printf '%s%s %s %4d:', $revprint, $isCurrentRev ? '!' : ' ',
1981: htmlquote($usrprint), $lineNr;
3.120 scop 1982: print spacedHtmlText($line, $d{'tabstop'});
1983:
1984: print "</b>" if ($isCurrentRev && $is_textbased);
1985: } elsif ($words[0] eq "ok") {
1986:
1987: # We could complain about any text received after this, like the
1988: # CVS command line client. But for simplicity, we don't.
1989: } elsif ($words[0] eq "error") {
1990: fatal("500 Internal Error",
1991: 'Error occured during annotate: <b>%s</b>', $_);
1992: }
1993: }
1994:
1995: if ($annTable) {
1996: print "</table>";
1997: } else {
1998: print "</pre>";
1999: }
3.124 scop 2000: html_footer();
2001:
3.174 scop 2002: finish($h);
3.1 knu 2003: }
2004:
2005: ###############################
2006: # make Checkout
2007: ###############################
3.120 scop 2008: sub doCheckout($$)
2009: {
2010: my ($fullname, $rev) = @_;
3.194 scop 2011: $rev = undef if ($rev eq 'HEAD' || $rev eq '.');
3.120 scop 2012:
3.219 scop 2013: # Start resolving whether we will do a markup view or not.
2014: my $do_markup = undef;
2015: # No markup if markup disallowed.
2016: $do_markup = 0 unless $allow_markup;
2017: # No markup if checkout magic cookie in URL.
2018: $do_markup = 0 if (!defined($do_markup) && $doCheckout);
2019: # Do markup if explicitly asked using cvsweb-markup content type. If the
2020: # asked content type is anything else, no markup.
2021: if (!defined($do_markup) && $input{'content-type'}) {
3.222 scop 2022: $do_markup = ($input{'content-type'} =~ CVSWEBMARKUP) ? 1 : 0;
3.219 scop 2023: }
2024:
2025: # Ok, if $do_markup is still undefined, we know that a download has not been
2026: # explicitly asked. For the last check further down below we'll need to
2027: # know if the file is binary, and possibly run a log on it.
2028: my $needlog = $do_markup || $use_moddate;
3.120 scop 2029:
3.163 scop 2030: my $moddate = undef;
3.175 scop 2031: my $revopt;
3.120 scop 2032: if (defined($rev)) {
2033: $revopt = "-r$rev";
3.219 scop 2034: if ($needlog) {
3.120 scop 2035: readLog($fullname, $rev);
2036: $moddate = $date{$rev};
2037: }
2038: } else {
2039: $revopt = "-rHEAD";
3.219 scop 2040: if ($needlog) {
3.120 scop 2041: readLog($fullname);
2042: $moddate = $date{$symrev{HEAD}};
2043: }
2044: }
2045:
3.194 scop 2046: my $cr = abs_path($cvsroot) || $cvsroot;
2047: # abs_path() taints when run as a CGI...
2048: if ($cr =~ VALID_PATH) {
2049: $cr = $1;
2050: } else {
2051: fatal('500 Internal Error', 'Illegal CVS root: <code>%s</code>', $cr);
2052: }
3.183 scop 2053: # Use abs_path() to work around a bug of cvs -p; expand symlinks if we can.
3.194 scop 2054: my @cmd = ($CMD{cvs}, @cvs_options, '-d', $cr, 'co', '-p', $revopt, $where);
3.183 scop 2055:
3.174 scop 2056: local (*CVS_OUT, *CVS_ERR);
2057: my ($h, $err) =
2058: startproc(\@cmd, \"", '>pipe', \*CVS_OUT, '2>pipe', \*CVS_ERR,timeout(30));
3.215 scop 2059: fatal('500 Internal Error',
2060: 'Checkout failure (exit status %s), output: <pre>%s</pre>',
2061: $? >> 8 || -1, $err)
2062: unless $h;
3.120 scop 2063:
3.174 scop 2064: if (eof(CVS_ERR)) {
2065: finish($h);
3.120 scop 2066: fatal("404 Not Found", '%s is not (any longer) pertinent', $where);
2067: }
2068:
2069: #===================================================================
2070: #Checking out squid/src/ftp.c
2071: #RCS: /usr/src/CVS/squid/src/ftp.c,v
2072: #VERS: 1.1.1.28.6.2
2073: #***************
2074:
2075: # Parse CVS header
2076: my ($revision, $filename, $cvsheader);
2077: $filename = "";
3.174 scop 2078: while (<CVS_ERR>) {
3.120 scop 2079: last if (/^\*\*\*\*/);
2080: $revision = $1 if (/^VERS: (.*)$/);
2081:
2082: if (/^Checking out (.*)$/) {
3.214 scop 2083: ($filename = $1) =~ s|^\./+||;
3.120 scop 2084: }
2085: $cvsheader .= $_;
2086: }
3.219 scop 2087: close(CVS_ERR);
3.120 scop 2088:
2089: if ($filename ne $where) {
3.174 scop 2090: finish($h);
3.120 scop 2091: fatal("500 Internal Error",
3.214 scop 2092: 'Unexpected output from cvs co: <pre>%s</pre> ' .
2093: '(expected "<code>%s</code>" but got "<code>%s</code>")',
2094: $cvsheader, $where, $filename);
3.120 scop 2095: }
2096:
3.219 scop 2097: # Last checks whether we'll do markup or not.
2098: my $isbin = $keywordsubstitution && $keywordsubstitution =~ /b/;
2099: my $mimetype = getMimeType($fullname, $isbin);
2100:
2101: # If we still are not sure whether to do markup or not:
2102: # if the MIME type is "viewable" or this is not a binary file, do.
2103: $do_markup = !$isbin || viewable($mimetype) unless defined($do_markup);
2104:
2105: if ($do_markup) {
2106:
2107: # If this is something we'll be linking to in the markup view, we are
2108: # done with this particular output from "cvs co" and must discard it.
2109: my $linked = $mimetype =~ m{^image/|application/pdf$}i;
2110: if ($linked) {
2111: close(CVS_OUT);
2112: finish($h);
2113: }
2114:
3.163 scop 2115: # Here we know the last modified date, but don't know if tags have been
3.219 scop 2116: # added afterwards (those are shown in the markup view): no last-modified.
2117: cvswebMarkup(\*CVS_OUT, $fullname, $revision, $isbin, $mimetype, $needlog);
2118:
2119: finish($h) unless $linked;
2120:
3.120 scop 2121: } else {
3.163 scop 2122: http_header($mimetype, $moddate);
3.174 scop 2123: local $/ = undef;
2124: print <CVS_OUT>;
3.219 scop 2125: finish($h);
3.120 scop 2126: }
1.12 fenner 2127: }
2128:
3.174 scop 2129:
3.219 scop 2130: sub cvswebMarkup($$$$$$;$)
3.120 scop 2131: {
3.219 scop 2132: my ($filehandle, $fullname, $rev, $isbin, $mimetype, $logged, $mod) = @_;
3.1 knu 2133:
3.175 scop 2134: (my $pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
2135: (my $filename = $where) =~ s/^.*\///;
2136: my $fileurl = urlencode($filename);
3.120 scop 2137:
3.219 scop 2138: navigateHeader($scriptwhere, $pathname, $filename, $rev, 'view', $mod);
3.120 scop 2139:
3.144 scop 2140: print <<EOF;
3.208 scop 2141: <hr />
3.182 scop 2142: <div class="log-markup">
2143: File:
3.144 scop 2144: EOF
3.219 scop 2145: print &clickablePath($where, 1), "<br />\n";
3.120 scop 2146:
2147: if ($show_log_in_markup) {
3.219 scop 2148: readLog($fullname) unless $logged; #,$rev);
2149: printLog($rev, $mimetype, $isbin);
3.120 scop 2150: } else {
3.219 scop 2151: print "Version: <b>$rev</b><br />\n";
3.208 scop 2152: print "Tag: <b>", $input{only_with_tag}, "</b><br />\n"
3.120 scop 2153: if $input{only_with_tag};
2154: }
3.208 scop 2155: print "</div>\n<hr />";
3.219 scop 2156: my $url = download_url($fileurl, $rev, $mimetype);
3.120 scop 2157:
3.219 scop 2158: if ($mimetype =~ m|^image/|i) {
3.208 scop 2159: printf '<img src="%s" alt="%s" /><br />',
3.160 scop 2160: hrefquote("$url$barequery"), htmlquote($filename);
3.219 scop 2161: } elsif (lc($mimetype) eq 'application/pdf') {
3.208 scop 2162: printf '<embed src="%s" width="100%%" height="100%%" /><br />',
3.157 scop 2163: hrefquote("$url$barequery");
3.120 scop 2164: } else {
2165:
3.208 scop 2166: print "<pre>\n";
3.167 scop 2167: my $linenumbers = $input{ln} || 0;
3.149 scop 2168:
3.219 scop 2169: if (my $enscript_hl = getEnscriptHL($filename)) {
3.167 scop 2170: doEnscript($filehandle, $enscript_hl, $linenumbers);
3.148 scop 2171:
2172: } else {
3.200 scop 2173: my $ln = 0;
2174: my @buf = ();
2175: my $ts = undef;
2176:
2177: if ($preformat_in_markup) {
2178: # prefetch several lines
2179: @buf = head($filehandle);
2180: my %d = scan_directives(@buf);
2181: $ts = $d{tabstop};
2182: }
2183:
2184: while (@buf || !eof($filehandle)) {
2185: $_ = @buf ? shift @buf : <$filehandle>;
3.167 scop 2186: if ($linenumbers) {
2187: $ln++;
2188: printf '<a id="l%d" class="src">%5d: </a>', ($ln) x 2;
3.149 scop 2189: }
3.200 scop 2190: print $preformat_in_markup ? spacedHtmlText($_, $ts) : htmlquote($_);
3.148 scop 2191: }
3.120 scop 2192: }
3.149 scop 2193:
2194: print "</pre>\n";
3.120 scop 2195: }
3.131 scop 2196: html_footer();
3.120 scop 2197: }
2198:
3.156 scop 2199:
3.120 scop 2200: sub viewable($)
2201: {
3.219 scop 2202: return shift =~ m{^((text|image)/|application/pdf)}i;
3.156 scop 2203: }
3.120 scop 2204:
3.1 knu 2205:
2206: ###############################
2207: # Show Colored Diff
2208: ###############################
3.120 scop 2209: sub doDiff($$$$$$)
2210: {
2211: my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
2212:
2213: if (&forbidden_file($fullname)) {
2214: fatal("403 Forbidden",
2215: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
2216: }
2217:
3.175 scop 2218: my ($rev1, $sym1);
3.120 scop 2219: if ($r1 =~ /([^:]+)(:(.+))?/) {
2220: $rev1 = $1;
2221: $sym1 = $3;
2222: }
2223: if ($r1 eq 'text') {
2224: $rev1 = $tr1;
2225: $sym1 = "";
2226: }
2227:
3.175 scop 2228: my ($rev2, $sym2);
3.120 scop 2229: if ($r2 =~ /([^:]+)(:(.+))?/) {
2230: $rev2 = $1;
2231: $sym2 = $3;
2232: }
2233: if ($r2 eq 'text') {
2234: $rev2 = $tr2;
2235: $sym2 = "";
2236: }
2237:
2238: #
2239: # rev1 and rev2 are now both numeric revisions.
2240: # Thus we do a DWIM here and swap them if rev1 is after rev2.
2241: # XXX should we warn about the fact that we do this?
2242: if (&revcmp($rev1, $rev2) > 0) {
2243: my ($tmp1, $tmp2) = ($rev1, $sym1);
2244: ($rev1, $sym1) = ($rev2, $sym2);
2245: ($rev2, $sym2) = ($tmp1, $tmp2);
2246: }
2247: my $difftype = $DIFFTYPES{$f};
2248:
2249: if (!$difftype) {
2250: fatal("400 Bad arguments", 'Diff format %s not understood', $f);
2251: }
2252:
2253: my @difftype = @{$difftype->{'opts'}};
2254: my $human_readable = $difftype->{'colored'};
2255:
2256: # apply special options
2257: if ($showfunc) {
2258: push @difftype, '-p' if $f ne 's';
2259:
2260: my ($re1, $re2);
2261:
2262: while (($re1, $re2) = each %funcline_regexp) {
3.222 scop 2263: if ($fullname =~ $re1) {
3.120 scop 2264: push @difftype, '-F', $re2;
2265: last;
2266: }
2267: }
2268: }
2269:
2270: if ($human_readable) {
2271: if ($hr_ignwhite) {
2272: push @difftype, '-w';
2273: }
2274: if ($hr_ignkeysubst) {
2275: push @difftype, '-kk';
2276: }
2277: }
2278:
3.175 scop 2279: my $fh = do { local (*FH); };
3.120 scop 2280: if (!open($fh, "-|")) { # child
2281: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
2282: openOutputFilter();
3.166 scop 2283: exec($CMD{rcsdiff}, @rcsdiff_options, @difftype, "-r$rev1", "-r$rev2",
2284: $fullname) or exit -1;
3.120 scop 2285: }
3.166 scop 2286:
3.120 scop 2287: if ($human_readable) {
3.168 scop 2288: #
2289: # Human readable diff.
2290: #
2291: human_readable_diff($fh, $rev2);
2292: html_footer();
2293: gzipclose();
2294: exit;
2295:
2296: } elsif ($f =~ /^([ucs])c$/) {
2297: #
2298: # Enscript colored diff.
2299: #
2300: my $hl = 'diff';
2301: $hl .= $1 if ($1 eq 'u' || $1 eq 's');
2302: (my $where_nd = $where) =~ s/\.diff$//;
2303: (my $pathname = $where_nd) =~ s|(Attic\/)?[^/]*$||;
2304: (my $filename = $where_nd) =~ s|^.*/||;
2305: (my $swhere = $scriptwhere) =~ s|\.diff$||;
2306: navigateHeader($swhere, $pathname, $filename, $rev2, 'diff');
2307: printf(<<EOF, $where_nd, $rev1, $rev2);
2308: <h3 style="text-align: center">Diff for /%s between versions %s and %s</h3>
2309: <pre>
2310: EOF
3.174 scop 2311: doEnscript(\$fh, $hl, 0);
3.168 scop 2312: print <<EOF;
2313: </pre>
3.208 scop 2314: <hr style="width: 100%" />
3.168 scop 2315: <form method="get" action="$scriptwhere">
2316: EOF
2317: printDiffSelectStickyVars();
2318: print 'Diff format: ';
2319: printDiffSelect($use_java_script);
3.208 scop 2320: print "<input type=\"submit\" value=\"Show\" />\n</form>\n";
3.120 scop 2321: html_footer();
2322: gzipclose();
2323: exit;
3.168 scop 2324:
3.120 scop 2325: } else {
3.168 scop 2326: #
2327: # Plain diff.
2328: #
3.120 scop 2329: http_header("text/plain");
2330: }
2331:
2332: #
2333: #===================================================================
2334: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
2335: #retrieving revision 1.16
2336: #retrieving revision 1.17
2337: #diff -c -r1.16 -r1.17
2338: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2339: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
2340: #
2341: # Ideas:
2342: # - nuke the stderr output if it's what we expect it to be
2343: # - Add "no differences found" if the diff command supplied no output.
2344: #
2345: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2346: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
2347: # (bogus example, but...)
2348: #
3.175 scop 2349: my ($f1, $f2);
3.120 scop 2350: if (grep { $_ eq '-u' } @difftype) {
2351: $f1 = '---';
2352: $f2 = '\+\+\+';
2353: } else {
2354: $f1 = '\*\*\*';
2355: $f2 = '---';
2356: }
2357:
2358: while (<$fh>) {
2359: if (m|^$f1 $cvsroot|o) {
2360: s|$cvsroot/||o;
2361: if ($sym1) {
2362: chop;
2363: $_ .= " $sym1\n";
2364: }
2365: } elsif (m|^$f2 $cvsroot|o) {
2366: s|$cvsroot/||o;
2367:
2368: if ($sym2) {
2369: chop;
2370: $_ .= " $sym2\n";
2371: }
2372: }
2373: print $_;
2374: }
2375: close($fh);
1.12 fenner 2376: }
2377:
3.175 scop 2378:
3.1 knu 2379: ###############################
2380: # Show Logs ..
2381: ###############################
3.120 scop 2382: sub getDirLogs($$@)
2383: {
2384: my ($cvsroot, $dirname, @otherFiles) = @_;
3.139 scop 2385: my $tag = $input{only_with_tag};
3.196 scop 2386: my $DirName = catdir($cvsroot, $where);
3.120 scop 2387:
3.139 scop 2388: my @files = &safeglob("$DirName/*,v");
2389: push (@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
3.120 scop 2390: foreach my $file (@otherFiles) {
3.196 scop 2391: push(@files, catfile($DirName, $file));
3.120 scop 2392: }
2393:
3.150 scop 2394: # Weed out unreadable files.
2395: my $i = 0;
2396: my @unreadable = ();
2397: while ($i < scalar(@files)) {
3.197 scop 2398: # Note: last modified files from subdirs returned by
2399: # findLastModifiedSubdirs() come without the ,v suffix so they're not
2400: # found here, but have already been checked for readability. *cough*
2401: if (-r $files[$i] || !-e _) {
3.150 scop 2402: $i++;
2403: } else {
2404: push(@unreadable, splice(@files, $i, 1));
2405: }
2406: }
2407:
3.139 scop 2408: # If there are no files, we're done.
3.150 scop 2409: return @unreadable unless @files;
3.120 scop 2410:
3.139 scop 2411: my @cmd = ($CMD{rlog});
2412: # Can't use -r<tag> as '-' is allowed in tagnames,
2413: # but misinterpreted by rlog.
2414: push(@cmd, '-r') unless defined($tag);
3.120 scop 2415:
3.139 scop 2416: my $fh = do { local (*FH); };
2417: if (!open($fh, '-|')) { # Child
3.165 scop 2418: open(STDERR, '>', devnull()); # Ignore rlog's complaints.
3.139 scop 2419: openOutputFilter();
2420: if ($file_list_len && $file_list_len > 1) {
2421: while (scalar(@files) > $file_list_len) { # Process files in chunks.
2422: system(@cmd, splice(@files, 0, $file_list_len)) == 0 or exit -1;
2423: }
3.120 scop 2424: }
3.139 scop 2425: exec(@cmd, @files) or exit -1;
2426: }
2427: undef @cmd;
3.120 scop 2428:
3.139 scop 2429: my $state = 'start';
2430: my ($date, $branchpoint, $branch, $log, @filetags);
3.152 scop 2431: my ($rev, $revision, $revwanted, $filename, $head, $author, $keywordsubst);
3.120 scop 2432:
2433: while (<$fh>) {
2434: if ($state eq "start") {
2435:
2436: #Next file. Initialize file variables
2437: $rev = '';
2438: $revwanted = '';
2439: $branch = '';
2440: $branchpoint = '';
2441: $filename = '';
2442: $log = '';
2443: $revision = '';
2444: %symrev = ();
2445: @filetags = ();
3.152 scop 2446: $keywordsubst= '';
3.120 scop 2447:
2448: #jump to head state
2449: $state = "head";
2450: }
3.144 scop 2451:
3.120 scop 2452: again:
2453:
2454: if ($state eq "head") {
2455:
2456: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
2457:
2458: if (/^Working file: (.+)$/) {
2459: $filename = $1;
2460: } elsif (/^head: (.+)$/) {
2461: $head = $1;
2462: } elsif (/^branch: (.+)$/) {
2463: $branch = $1;
3.152 scop 2464: } elsif (/^keyword substitution: (.+)$/) {
2465: $keywordsubst = $1;
3.120 scop 2466: } elsif (/^symbolic names:/) {
2467: $state = "tags";
2468: ($branch = $head) =~ s/\.\d+$//
2469: if $branch eq '';
2470: $branch =~ s/(\d+)$/0.$1/;
2471: $symrev{MAIN} = $branch;
2472: $symrev{HEAD} = $branch;
2473: $alltags{MAIN} = 1;
2474: $alltags{HEAD} = 1;
2475: push (@filetags, "MAIN", "HEAD");
3.222 scop 2476: } elsif ($_ =~ LOG_REVSEPR) {
3.120 scop 2477: $state = "log";
2478: $rev = '';
2479: $date = '';
2480: $log = '';
2481:
2482: # Try to reconstruct the relative filename if RCS spits out a full path
2483: $filename =~ s%^\Q$DirName\E/%%;
2484: }
2485: next;
2486: }
2487:
2488: if ($state eq "tags") {
2489: if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
2490: push (@filetags, $1);
2491: $symrev{$1} = $2;
2492: $alltags{$1} = 1;
2493: next;
2494: } elsif (/^\S/) {
2495:
2496: if (defined($tag)) {
2497: if (defined($symrev{$tag}) || $tag eq "HEAD") {
2498: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
2499: ($branch = $revwanted) =~ s/\b0\.//;
2500: ($branchpoint = $branch) =~ s/\.?\d+$//;
2501: $revwanted = '' if ($revwanted ne $branch);
2502: } elsif ($tag ne "HEAD") {
2503: $state = "skip";
2504: next;
2505: }
2506: }
2507:
2508: foreach my $tagfound (@filetags) {
2509: $tags{$tagfound} = 1;
2510: }
2511: $state = "head";
2512: goto again;
2513: }
2514: }
2515:
2516: if ($state eq "log") {
3.222 scop 2517: if ($_ =~ LOG_REVSEPR || $_ =~ LOG_FILESEPR) {
3.120 scop 2518:
2519: # End of a log entry.
2520: my $revbranch = $rev;
2521: $revbranch =~ s/\.\d+$//;
2522:
2523: if ($revwanted eq '' && $branch ne '' && $branch eq $revbranch
2524: || !defined($tag))
2525: {
2526: $revwanted = $rev;
2527: }
2528:
2529: if ($revwanted ne ''
2530: ? $rev eq $revwanted
2531: : $branchpoint ne ''
2532: ? $rev eq $branchpoint
2533: : 0
2534: && ($rev eq $head))
2535: { # Don't think head is needed here..
3.152 scop 2536: my @finfo = ($rev, $date, $log, $author, $filename, $keywordsubst);
2537: (my $name = $filename) =~ s%/.*%%;
3.120 scop 2538: $fileinfo{$name} = [@finfo];
2539: $state = "done" if ($rev eq $revwanted);
2540: }
2541: $rev = '';
2542: $date = '';
2543: $log = '';
2544: } elsif ($date eq ''
2545: && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|)
2546: {
3.172 scop 2547: my $yr = $1;
2548: $yr -= 1900 if ($yr > 100); # Damn 2-digit year routines :-)
2549: $date = timegm($6, $5, $4, $3, $2 - 1, $yr);
3.120 scop 2550: ($author) = /author: ([^;]+)/;
3.172 scop 2551: $state = 'log';
2552: $log = '';
3.120 scop 2553: next;
2554: } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
2555: $rev = $1; # .*$ eats up the locker(lockers?) info, if any
2556: next;
2557: } else {
2558: $log .= $_;
2559: }
2560: }
2561:
3.222 scop 2562: if ($_ =~ LOG_FILESEPR) {
3.120 scop 2563: $state = "start";
2564: next;
2565: }
2566: }
2567:
3.139 scop 2568: my $linesread = $. || 0;
2569: close($fh);
2570:
2571: if ($linesread == 0) {
3.137 scop 2572: fatal('500 Internal Error',
3.208 scop 2573: '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 2574: htmlquote(join(', ', @files)), $command_path);
3.120 scop 2575: }
3.150 scop 2576:
2577: return @unreadable;
3.120 scop 2578: }
2579:
3.175 scop 2580:
3.120 scop 2581: sub readLog($;$)
2582: {
2583: my ($fullname, $revision) = @_;
2584: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2585:
3.144 scop 2586: $revision = defined($revision) ? "-r$revision" : '';
3.120 scop 2587:
2588: undef %symrev;
2589: undef %revsym;
2590: undef @allrevisions;
2591: undef %date;
2592: undef %author;
2593: undef %state;
2594: undef %difflines;
2595: undef %log;
3.152 scop 2596: $keywordsubstitution = '';
3.120 scop 2597:
3.175 scop 2598: my $fh = do { local (*FH); };
3.120 scop 2599: if (!open($fh, "-|")) { # child
2600: if ($revision ne '') {
2601: openOutputFilter();
2602: exec($CMD{rlog}, $revision, $fullname) or exit -1;
2603: } else {
2604: openOutputFilter();
2605: exec($CMD{rlog}, $fullname) or exit -1;
2606: }
2607: }
2608:
3.217 scop 2609: my $curbranch = undef;
3.120 scop 2610: while (<$fh>) {
2611: if ($symnames) {
2612: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2613: $symrev{$1} = $2;
3.152 scop 2614: next;
3.120 scop 2615: } else {
2616: $symnames = 0;
2617: }
3.152 scop 2618: }
2619: if (/^head:\s+([\d\.]+)/) {
3.120 scop 2620: $head = $1;
2621: } elsif (/^branch:\s+([\d\.]+)/) {
2622: $curbranch = $1;
2623: } elsif (/^symbolic names/) {
2624: $symnames = 1;
3.152 scop 2625: } elsif (/^keyword substitution: (.+)$/) {
2626: $keywordsubstitution = $1;
3.120 scop 2627: } elsif (/^-----/) {
2628: last;
2629: }
2630: }
2631: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
2632:
2633: # each log entry is of the form:
2634: # ----------------------------
2635: # revision 3.7.1.1
2636: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2637: # log info
2638: # ----------------------------
2639:
2640: # For a locked revision, the first line after the separator
2641: # becomes smth like
3.149 scop 2642: # revision 9.19 locked by: vassilii;
3.120 scop 2643:
2644: logentry:
2645:
3.222 scop 2646: while ($_ !~ LOG_FILESEPR) {
3.120 scop 2647: $_ = <$fh>;
2648: last logentry if (!defined($_)); # EOF
2649: if (/^revision (\d+(?:\.\d+)+)/) {
2650: $rev = $1;
2651: unshift (@allrevisions, $rev);
3.222 scop 2652: } elsif ($_ =~ LOG_FILESEPR || $_ =~ LOG_REVSEPR) {
3.120 scop 2653: next logentry;
2654: } else {
2655:
2656: # The rlog output is syntactically ambiguous. We must
2657: # have guessed wrong about where the end of the last log
2658: # message was.
2659: # Since this is likely to happen when people put rlog output
2660: # in their commit messages, don't even bother keeping
2661: # these lines since we don't know what revision they go with
2662: # any more.
2663: next logentry;
2664: }
2665: $_ = <$fh>;
2666: if (
2667: m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
2668: )
2669: {
3.172 scop 2670: my $yr = $1;
2671: $yr -= 1900 if ($yr > 100); # Damn 2-digit year routines :-)
2672: $date{$rev} = timegm($6, $5, $4, $3, $2 - 1, $yr);
3.120 scop 2673: $author{$rev} = $7;
2674: $state{$rev} = $8;
2675: $difflines{$rev} = $10;
2676: } else {
2677: fatal("500 Internal Error", 'Error parsing RCS output: %s', $_);
2678: }
2679:
2680: line:
2681: while (<$fh>) {
2682: next line if (/^branches:\s/);
3.222 scop 2683: last line if ($_ =~ LOG_FILESEPR || $_ =~ LOG_REVSEPR);
3.120 scop 2684: $log{$rev} .= $_;
2685: }
2686: }
2687: close($fh);
2688:
2689: @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
2690:
2691: #
2692: # HEAD is an artificial tag which is simply the highest tag number on the main
2693: # branch, unless there is a branch tag in the RCS file in which case it's the
2694: # highest revision on that branch. Find it by looking through @revorder; it
2695: # is the first commit listed on the appropriate branch.
2696: # This is not neccesary the same revision as marked as head in the RCS file.
2697: my $headrev = $curbranch || "1";
2698: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
2699:
2700: foreach $rev (@revorder) {
2701: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2702: $symrev{"HEAD"} = $rev;
2703: last;
2704: }
2705: }
2706: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2707: if (!defined($symrev{"HEAD"}));
2708:
2709: #
2710: # Now that we know all of the revision numbers, we can associate
2711: # absolute revision numbers with all of the symbolic names, and
2712: # pass them to the form so that the same association doesn't have
2713: # to be built then.
2714: #
2715: undef @branchnames;
2716: undef %branchpoint;
2717: undef $sel;
2718:
2719: foreach (reverse sort keys %symrev) {
2720: $rev = $symrev{$_};
2721: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
2722: push (@branchnames, $_);
2723:
2724: #
2725: # A revision number of A.B.0.D really translates into
2726: # "the highest current revision on branch A.B.D".
2727: #
2728: # If there is no branch A.B.D, then it translates into
2729: # the head A.B .
2730: #
2731: # This reasoning also applies to the main branch A.B,
2732: # with the branch number 0.A, with the exception that
2733: # it has no head to translate to if there is nothing on
2734: # the branch, but I guess this can never happen?
2735: #
2736: # (the code below gracefully forgets about the branch
2737: # if it should happen)
2738: #
2739: $head = defined($2) ? $2 : "";
2740: $branch = $3;
2741: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
3.222 scop 2742: $rev = $head;
2743:
2744: my $regex = '^' . quotemeta($branchrev) . '\b';
2745: $regex = qr/$regex/;
3.120 scop 2746:
2747: foreach my $r (@revorder) {
3.222 scop 2748: if ($r =~ $regex) {
3.120 scop 2749: $rev = $branchrev;
2750: last;
2751: }
2752: }
2753: next if ($rev eq "");
2754:
2755: if ($rev ne $head && $head ne "") {
3.131 scop 2756: $branchpoint{$head} .= ', ' if ($branchpoint{$head});
3.120 scop 2757: $branchpoint{$head} .= $_;
2758: }
2759: }
2760: $revsym{$rev} .= ", " if ($revsym{$rev});
2761: $revsym{$rev} .= $_;
3.136 scop 2762: $sel .= sprintf("<option value=\"%s:%s\">%s</option>\n",
2763: htmlquote($rev), (htmlquote($_)) x 2);
3.120 scop 2764: }
2765:
2766: my ($onlyonbranch, $onlybranchpoint);
2767: if ($onlyonbranch = $input{'only_with_tag'}) {
2768: $onlyonbranch = $symrev{$onlyonbranch};
2769: if ($onlyonbranch =~ s/\b0\.//) {
2770: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2771: } else {
2772: $onlybranchpoint = $onlyonbranch;
2773: }
2774:
2775: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2776: fatal("404 Tag not found", 'Tag %s not defined',
3.131 scop 2777: $input{'only_with_tag'});
3.120 scop 2778: }
2779: }
2780:
2781: undef @revisions;
2782:
2783: foreach (@allrevisions) {
2784: ($br = $_) =~ s/\.\d+$//;
2785: ($brp = $br) =~ s/\.\d+$//;
2786: next if ($onlyonbranch
2787: && $br ne $onlyonbranch
2788: && $_ ne $onlybranchpoint);
2789: unshift (@revisions, $_);
2790: }
2791:
2792: if ($logsort eq "date") {
2793:
2794: # Sort the revisions in commit order an secondary sort on revision
2795: # (secondary sort needed for imported sources, or the first main
2796: # revision gets before the same revision on the 1.1.1 branch)
2797: @revdisplayorder =
2798: sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) } @revisions;
2799: } elsif ($logsort eq "rev") {
2800:
2801: # Sort the revisions in revision order, highest first
2802: @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
2803: } else {
2804:
2805: # No sorting. Present in the same order as rlog / cvs log
2806: @revdisplayorder = @revisions;
2807: }
2808:
3.217 scop 2809: return $curbranch;
3.120 scop 2810: }
2811:
3.175 scop 2812:
3.120 scop 2813: sub printDiffLinks($$)
2814: {
2815: my ($text, $url) = @_;
2816: my @extra;
3.175 scop 2817: for my $difftype ($DIFFTYPES{$defaultDiffType}{colored} ? qw(u) : qw(h)) {
2818: my $f = $difftype eq $defaultDiffType ? '' : $difftype;
3.203 scop 2819: push(@extra, &link(lc($DIFFTYPES{$difftype}{descr}), "$url;f=$f"));
3.120 scop 2820: }
2821: print &link($text, $url), ' (', join (', ', @extra), ')';
2822: }
2823:
3.175 scop 2824:
3.219 scop 2825: sub printLog($$$;$$)
3.120 scop 2826: {
3.219 scop 2827: # inlogview: 1 if in log view, otherwise in markup view.
2828: ($_, my $mimetype, my $isbin, my $inlogview, my $isSelected) = @_;
3.175 scop 2829: (my $br = $_) =~ s/\.\d+$//;
2830: (my $brp = $br) =~ s/\.?\d+$//;
3.120 scop 2831:
3.131 scop 2832: my $isDead = ($state{$_} eq 'dead');
2833:
3.219 scop 2834: (my $filename = $where) =~ s/^.*\///;
2835: my $fileurl = urlencode($filename);
3.120 scop 2836:
3.219 scop 2837: print "<a name=\"rev$_\"></a>";
2838: if (defined($revsym{$_})) {
2839: foreach my $sym (split (", ", $revsym{$_})) {
2840: print '<a name="', hrefquote($sym), '"></a>';
3.120 scop 2841: }
3.219 scop 2842: }
2843: if ($revsym{$br} && !defined($nameprinted{$br})) {
2844: foreach my $sym (split (", ", $revsym{$br})) {
2845: print '<a name="', hrefquote($sym), '"></a>';
3.120 scop 2846: }
3.219 scop 2847: $nameprinted{$br} = 1;
2848: }
3.120 scop 2849:
3.219 scop 2850: printf "\n Revision <b>%s</b>", htmlquote($_);
2851: if (/^1\.1\.1\.\d+$/) {
2852: print " <i>(vendor branch)</i>";
2853: }
2854: if (!$isDead) {
3.220 scop 2855: print ': ', download_link($fileurl, $_, 'download', $mimetype);
3.219 scop 2856:
2857: my @vlinks = ();
2858: push(@vlinks, display_link($fileurl, $_, 'text', 'text/plain'))
2859: unless $isbin;
2860: push(@vlinks, display_link($fileurl, $_, 'markup', 'text/x-cvsweb-markup'))
2861: if ($allow_markup && $inlogview && (!$isbin || viewable($mimetype)));
2862: if (!$isbin) {
2863: push(@vlinks,
2864: &link('annotated',
2865: sprintf('%s/%s?annotate=%s%s',
2866: $scriptname, urlencode($where), $_, $barequery)))
2867: if $allow_annotate;
2868: }
2869: print ' - view: ', join(', ', @vlinks) if @vlinks;
2870: undef @vlinks;
2871:
2872: if (!$isbin) {
2873: if ($inlogview && $allow_version_select) {
2874: print ' - ';
2875: if ($isSelected) {
2876: print '<b>[selected for diffs]</b>';
2877: } else {
2878: print &link('select for diffs',
2879: sprintf('%s?r1=%s%s#rev%s',
2880: $scriptwhere, $_, $barequery, $_));
2881: }
2882: } elsif ($allow_cvsgraph) {
2883: print ' - ', &graph_link('', 'graph');
3.120 scop 2884: }
2885: }
2886: }
3.219 scop 2887: print "<br />\n";
3.120 scop 2888:
3.219 scop 2889: print '<i>';
3.120 scop 2890: if (defined @mytz) {
2891: my ($est) = $mytz[(localtime($date{$_}))[8]];
3.219 scop 2892: print scalar localtime($date{$_}), " $est</i> (";
3.120 scop 2893: } else {
3.219 scop 2894: print scalar gmtime($date{$_}), " UTC</i> (";
3.120 scop 2895: }
3.136 scop 2896: print readableTime(time() - $date{$_}, 1), ' ago)';
3.208 scop 2897: print ' by <i>', htmlquote($author{$_}), "</i><br />\n";
3.136 scop 2898:
2899: if ($revsym{$br}) {
3.219 scop 2900: printf "Branches: %s<br />\n",
2901: $inlogview ? link_tags($revsym{$br}) : htmlquote($revsym{$br});
3.136 scop 2902: }
2903: if ($revsym{$_}) {
3.219 scop 2904: printf "CVS tags: %s<br />\n",
2905: $inlogview ? link_tags($revsym{$_}) : htmlquote($revsym{$_});
3.136 scop 2906: }
2907: if ($branchpoint{$_}) {
3.219 scop 2908: printf "Branch point for: %s<br />\n",
2909: $inlogview ? link_tags($branchpoint{$_}) : htmlquote($branchpoint{$_});
3.136 scop 2910: }
3.120 scop 2911:
2912: # Find the previous revision
3.175 scop 2913: my $prev;
3.120 scop 2914: my @prevrev = split (/\./, $_);
2915: do {
2916: if (--$prevrev[$#prevrev] <= 0) {
2917:
2918: # If it was X.Y.Z.1, just make it X.Y
2919: pop (@prevrev);
2920: pop (@prevrev);
2921: }
2922: $prev = join (".", @prevrev);
2923: } until (defined($date{$prev}) || $prev eq "");
2924:
2925: if ($isDead) {
3.219 scop 2926: print "<b><i>FILE REMOVED</i></b><br />\n";
2927: } elsif ($inlogview) {
3.120 scop 2928: my %diffrev = ();
2929: $diffrev{$_} = 1;
2930: $diffrev{""} = 1;
2931: my $diff = 'Diff';
3.219 scop 2932: my $printed = 0;
3.120 scop 2933:
2934: #
2935: # Offer diff to previous revision
2936: if ($prev) {
2937: $diffrev{$prev} = 1;
2938:
2939: my $url =
3.203 scop 2940: sprintf('%s.diff?r1=%s;r2=%s%s', $scriptwhere, $prev, $_, $barequery);
3.120 scop 2941:
2942: print $diff, " to previous ";
3.219 scop 2943: $diff = ''; $printed = 1;
3.120 scop 2944: printDiffLinks($prev, $url);
2945: }
2946:
2947: #
2948: # Plus, if it's on a branch, and it's not a vendor branch,
2949: # offer a diff with the branch point.
2950: if ($revsym{$brp}
2951: && !/^1\.1\.1\.\d+$/
2952: && !defined($diffrev{$brp}))
2953: {
2954: my $url =
3.203 scop 2955: sprintf('%s.diff?r1=%s;r2=%s%s', $scriptwhere, $brp, $_, $barequery);
3.120 scop 2956:
2957: print $diff, " to branchpoint ";
3.219 scop 2958: $diff = ''; $printed = 1;
3.120 scop 2959: printDiffLinks($brp, $url);
2960: }
2961:
2962: #
2963: # Plus, if it's on a branch, and it's not a vendor branch,
2964: # offer to diff with the next revision of the higher branch.
2965: # (e.g. change gets committed and then brought
2966: # over to -stable)
2967: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2968: my ($i, $nextmain);
2969:
2970: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++) {
2971: }
2972: my @tmp2 = split (/\./, $_);
2973: for ($nextmain = ""; $i > 0; $i--) {
2974: my $next = $revorder[$i - 1];
2975: my @tmp1 = split (/\./, $next);
2976:
2977: if (@tmp1 < @tmp2) {
2978: $nextmain = $next;
2979: last;
2980: }
2981:
2982: # Only the highest version on a branch should have
2983: # a diff for the "next main".
2984: last
2985: if (@tmp1 - 1 <= @tmp2
2986: && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
2987: join (".", @tmp2[0 .. $#tmp1 - 1]));
2988: }
2989:
2990: if (!defined($diffrev{$nextmain})) {
2991: $diffrev{$nextmain} = 1;
2992:
3.203 scop 2993: my $url = sprintf('%s.diff?r1=%s;r2=%s%s',
3.120 scop 2994: $scriptwhere, $nextmain, $_, $barequery);
2995:
2996: print $diff, " next main ";
3.219 scop 2997: $diff = ''; $printed = 1;
3.120 scop 2998: printDiffLinks($nextmain, $url);
2999: }
3000: }
3001:
3002: # Plus if user has selected only r1, then present a link
3003: # to make a diff to that revision
3004: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
3005: $diffrev{$input{"r1"}} = 1;
3006:
3.203 scop 3007: my $url = sprintf('%s.diff?r1=%s;r2=%s%s',
3.120 scop 3008: $scriptwhere, $input{'r1'}, $_, $barequery);
3009:
3010: print $diff, " to selected ";
3.219 scop 3011: $diff = ''; $printed = 1;
3.120 scop 3012: printDiffLinks($input{'r1'}, $url);
3013: }
3014:
3.219 scop 3015: print "<br />\n" if $printed;
3016: }
3017:
3018: if ($prev ne "" && $difflines{$_}) {
3019: printf "Changes since revision %s: %s lines<br />\n",
3020: htmlquote($prev), htmlquote($difflines{$_});
3.120 scop 3021: }
3.189 scop 3022:
3.219 scop 3023: print "<pre class=\"log\">\n";
3.120 scop 3024: print &htmlify($log{$_}, $allow_log_extra);
3025: print "</pre>\n";
3026: }
3027:
3.175 scop 3028:
3.132 scop 3029: #
3030: # Generates the HTML view for CvsGraph.
3031: #
3.170 scop 3032: sub doGraphView()
3.132 scop 3033: {
3034: (my $pathname = $where) =~ s|[^/]*$||;
3035: (my $filename = $where) =~ s|^.*/||;
3036:
3.170 scop 3037: navigateHeader($scriptwhere, $pathname, $filename, undef, 'graph');
3.132 scop 3038:
3.146 scop 3039: my $title = 'Revision graph of ' . htmlquote($pathname . $filename);
3.132 scop 3040: my $mapname = 'CvsGraphMap';
3041:
3.170 scop 3042: printf(<<EOF, $title, $mapname, $cvstree, $title);
3.146 scop 3043: <h3 style="text-align: center">%s</h3>
3.219 scop 3044: <div style="text-align: center"><img border="0" usemap="#%s" src="?cvsroot=%s;graph=1;makeimage=1" alt="%s" />
3.146 scop 3045: EOF
3.132 scop 3046:
3.181 scop 3047: my $qquery = hrefquote($barequery);
3.135 scop 3048: my @graph_cmd =
3049: ($CMD{cvsgraph},
3050: '-r', $cvsroot,
3051: '-i',
3052: '-M', $mapname,
3.208 scop 3053: '-x', 'x',
3.181 scop 3054: "-Omap_branch_href=\"href=\\\"./?only_with_tag=%(%t%)$qquery\\\"\"",
3.219 scop 3055: "-Omap_rev_href=\"href=\\\"?rev=%(%R%)$qquery\\\"\"",
3.146 scop 3056: "-Omap_diff_href=\"href=\\\"%(%F%).diff" .
3.203 scop 3057: "?r1=%(%P%);r2=%(%R%)$qquery\\\"\"",
3.135 scop 3058: );
3.132 scop 3059: push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
3.174 scop 3060: push(@graph_cmd, catfile($pathname, $filename . ',v'));
3.132 scop 3061:
3.174 scop 3062: local *CVSGRAPH_OUT;
3063: my ($h, $err) =
3064: startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT, timeout(30));
3065: fatal('500 Internal Error', $err) unless $h;
3066: {
3067: local $/ = undef;
3068: print <CVSGRAPH_OUT>;
3.132 scop 3069: }
3.174 scop 3070: finish($h);
3.219 scop 3071: print "</div>\n";
3.132 scop 3072:
3073: html_footer();
3074: }
3075:
3.175 scop 3076:
3.132 scop 3077: #
3078: # Generates a graph using CvsGraph.
3079: #
3.170 scop 3080: sub doGraph()
3.132 scop 3081: {
3082: (my $pathname = $where) =~ s|[^/]*$||;
3083: (my $filename = $where) =~ s|^.*/||;
3084:
3085: http_header('image/png');
3086:
3087: my @graph_cmd = ($CMD{cvsgraph}, '-r', $cvsroot);
3088: push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
3.174 scop 3089: push(@graph_cmd, catfile($pathname, $filename . ',v'));
3.132 scop 3090:
3.174 scop 3091: local *CVSGRAPH_OUT;
3092: my ($h, $err) =
3093: startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT, timeout(30));
3094: fatal('500 Internal Error', $err) unless $h;
3.132 scop 3095: {
3096: local $/ = undef;
3097: binmode(\*STDOUT);
3.174 scop 3098: print <CVSGRAPH_OUT>;
3.132 scop 3099: }
3.174 scop 3100: finish($h);
3.132 scop 3101: }
3102:
3103:
3.120 scop 3104: sub doLog($)
3105: {
3106: my ($fullname) = @_;
3107:
3.217 scop 3108: my $curbranch = readLog($fullname);
3.120 scop 3109:
3110: html_header("CVS log for $where");
3.144 scop 3111:
3112: (my $upwhere = $where) =~ s|(Attic/)?[^/]+$||;
3113: (my $filename = $where) =~ s|^.*/||;
3114: my $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
3115:
3.219 scop 3116: my $isbin = $keywordsubstitution =~ /b/;
3117: my $mimetype = getMimeType($filename, $isbin);
3118:
3.120 scop 3119: print "<p>\n ";
3120: print &link($backicon, "$backurl#$filename"), " <b>Up to ",
3121: &clickablePath($upwhere, 1), "</b>\n</p>\n";
3122: print "<p>\n ";
3123: print &link('Request diff between arbitrary revisions', '#diff');
3.132 scop 3124: if ($allow_cvsgraph) {
3.219 scop 3125: print ' - ', &graph_link('', 'Display revisions graphically');
3.132 scop 3126: }
3.208 scop 3127: print "\n</p>\n<hr />\n";
3.120 scop 3128:
3129: print "<p>\n";
3.152 scop 3130:
3.219 scop 3131: my $explain = $isbin ? ' (i.e.: CVS considers this a binary file)' : '';
3.208 scop 3132: print "Keyword substitution: $keywordsubstitution$explain<br />\n";
3.217 scop 3133: if ($curbranch) {
3134: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
3135: } else {
3136: print "No default branch";
3137: }
3.208 scop 3138: print "<br />\n";
3.120 scop 3139:
3.208 scop 3140: print 'Current tag: ', htmlquote($input{only_with_tag}), "<br />\n"
3.153 scop 3141: if $input{only_with_tag};
3.120 scop 3142: print "</p>\n";
3143:
3144: undef %nameprinted;
3145:
3.182 scop 3146: for my $r (@revdisplayorder) {
3.208 scop 3147: print "<hr />\n";
3.182 scop 3148: my $sel = (defined($input{r1}) && $input{r1} eq $r);
3149: print "<div class=\"diff-selected\">\n" if $sel;
3.219 scop 3150: printLog($r, $mimetype, $isbin, 1, $sel);
3.182 scop 3151: print "</div>\n" if $sel;
3.120 scop 3152: }
3153:
3.144 scop 3154: printf(<<EOF, $scriptwhere);
3.208 scop 3155: <hr />
3156: <form method="get" action="%s.diff" id="diff_select">
3.189 scop 3157: <fieldset>
3158: <legend>Diff request</legend>
3.144 scop 3159: <p>
3160: <a name="diff">
3.189 scop 3161: This form allows you to request diffs between any two revisions of a file.
3.144 scop 3162: You may select a symbolic revision name using the selection box or you may
3163: type in a numeric name using the type-in text box.
3164: </a>
3165: </p>
3166: EOF
3.120 scop 3167:
3168: foreach (@stickyvars) {
3.208 scop 3169: printf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n",
3.154 scop 3170: $_, htmlquote($input{$_}))
3.194 scop 3171: if (defined($input{$_}) &&
3172: (!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_}));
3.120 scop 3173: }
3.144 scop 3174:
3175: print <<EOF;
3.189 scop 3176: <table summary="Diff between arbitrary revisions">
3.144 scop 3177: <tr>
3.189 scop 3178: <td class="opt-label">
3179: <label for="r1" accesskey="1">Diffs between</label>
3180: </td>
3181: <td class="opt-value">
3.144 scop 3182: <select id="r1" name="r1">
3.208 scop 3183: <option value="text" selected="selected">Use Text Field</option>
3.144 scop 3184: EOF
3185: print $sel, "</select>\n";
3186:
3187: my $diffrev = defined($input{r1}) ?
3188: $input{r1} : $revdisplayorder[$#revdisplayorder];
3189:
3190: printf(<<EOF, $inputTextSize, $diffrev);
3.208 scop 3191: <input type="text" size="%s" name="tr1" value="%s" onchange="this.form.r1.selectedIndex=0" />
3.144 scop 3192: </td>
3.189 scop 3193: <td></td>
3194: </tr>
3195: <tr>
3196: <td class="opt-label">
3197: <label for="r2" accesskey="2">and</label>
3198: </td>
3199: <td class="opt-value">
3.144 scop 3200: <select id="r2" name="r2">
3.208 scop 3201: <option value="text" selected="selected">Use Text Field</option>
3.144 scop 3202: EOF
3203: print $sel, "</select>\n";
3204:
3205: $diffrev = defined($input{r2}) ? $input{r2} : $revdisplayorder[0];
3206:
3207: printf(<<EOF, $inputTextSize, $diffrev, $scriptwhere);
3.208 scop 3208: <input type="text" size="%s" name="tr2" value="%s" onchange="this.form.r2.selectedIndex=0" />
3.144 scop 3209: </td>
3.208 scop 3210: <td><input type="submit" value="Get Diffs" accesskey="G" /></td>
3.144 scop 3211: </tr>
3212: </table>
3.189 scop 3213: </fieldset>
3.144 scop 3214: </form>
3215: <form method="get" action="%s">
3.189 scop 3216: <fieldset>
3217: <legend>Log view options</legend>
3218: <table summary="Log view options">
3.144 scop 3219: <tr>
3.189 scop 3220: <td class="opt-label">
3221: <label for="f" accesskey="D">Preferred diff type:</label>
3222: </td>
3223: <td class="opt-value">
3.144 scop 3224: EOF
3.120 scop 3225: printDiffSelect($use_java_script);
3.144 scop 3226: print <<EOF;
3.189 scop 3227: </td>
3228: <td></td>
3.144 scop 3229: </tr>
3230: EOF
3.120 scop 3231:
3232: if (@branchnames) {
3.144 scop 3233:
3234: printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3235: <tr>
3.189 scop 3236: <td class="opt-label">
3.188 scop 3237: <label for="only_with_tag" accesskey="B">View only branch:</label>
3.189 scop 3238: </td>
3239: <td class="opt-value">
3240: <a name="branch">
3.144 scop 3241: <select id="only_with_tag" name="only_with_tag"%s>
3242: EOF
3.120 scop 3243:
3.193 scop 3244: my @tmp = ();
3245: my $selfound = 0;
3.120 scop 3246: foreach (reverse sort @branchnames) {
3.136 scop 3247: my $selected =
3248: (defined($input{"only_with_tag"}) && $input{"only_with_tag"} eq $_);
3.193 scop 3249: $selfound ||= $selected;
3250: push(@tmp, sprintf('<option%s>%s</option>',
3.208 scop 3251: $selected ? ' selected="selected"' : '',
3.193 scop 3252: htmlquote($_)));
3.120 scop 3253: }
3.193 scop 3254: printf("<option value=\"\"%s>Show all branches</option>\n",
3.208 scop 3255: $selfound ? '' : ' selected="selected"');
3.193 scop 3256: print join("\n", @tmp);
3257:
3.144 scop 3258: print <<EOF
3259: </select>
3.189 scop 3260: </a>
3.144 scop 3261: </td>
3262: <td></td>
3263: </tr>
3264: EOF
3.120 scop 3265: }
3266:
3.144 scop 3267: print <<EOF;
3.189 scop 3268: <tr>
3269: <td class="opt-label">
3270: <label for="logsort" accesskey="L">Sort log by:</label>
3271: </td>
3272: <td>
3.144 scop 3273: EOF
3.120 scop 3274: printLogSortSelect($use_java_script);
3.144 scop 3275: print <<EOF;
3.189 scop 3276: </td>
3.208 scop 3277: <td><input type="submit" value="Set" accesskey="S" /></td>
3.189 scop 3278: </tr>
3.144 scop 3279: </table>
3280: EOF
3.154 scop 3281: foreach (@stickyvars) {
3282: next if ($_ eq "f");
3283: next if ($_ eq "only_with_tag");
3284: next if ($_ eq "logsort");
3.208 scop 3285: printf("<input type=\"hidden\" name=\"$_\" value=\"%s\" />\n",
3.154 scop 3286: htmlquote($input{$_}))
3287: if (defined($input{$_})
3.194 scop 3288: && (!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_}));
3.154 scop 3289: }
3.189 scop 3290: print "</fieldset>\n</form>\n";
3.120 scop 3291: html_footer();
3292: }
3293:
3.175 scop 3294:
3.120 scop 3295: sub flush_diff_rows($$$$)
3296: {
3297: my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
3298:
3.175 scop 3299: return unless defined($state);
3.120 scop 3300:
3301: if ($state eq "PreChangeRemove") { # we just got remove-lines before
3.133 scop 3302: for (my $j = 0; $j < $leftRow; $j++) {
3.144 scop 3303: printf(<<EOF, scalar(@$leftColRef[$j]));
3304: <tr>
3305: <td class="diff-removed"> %s</td>
3306: <td class="diff-empty"> </td>
3307: </tr>
3308: EOF
3.120 scop 3309: }
3310: } elsif ($state eq "PreChange") { # state eq "PreChange"
3311: # we got removes with subsequent adds
3.222 scop 3312: if (HAS_EDIFF) {
3.176 scop 3313: # construct the suffix tree
3314: my $left_diff = join("\n", @$leftColRef[0..$leftRow-1]);
3315: my $right_diff = join("\n", @$rightColRef[0..$rightRow-1]);
3316: my $diff_str = String::Ediff::ediff($left_diff, $right_diff);
3317:
3318: my @diff_str = split(/ /, $diff_str);
3319: my $INFINITY = 10000000;
3320: push(@diff_str, ($INFINITY) x 8);
3321: my ($idx, $b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3322: (0, @diff_str[0..7]);
3323: my ($l_cul, $r_cul) = (0, 0);
3324: my ($ldx, $rdx) = (0, 0);
3325: my (@left_html, @right_html);
3326: for (my $j = 0; $j < $leftRow; $j++) {
3327: my $line_len = length(@$leftColRef[$j]);
3328: my $line = @$leftColRef[$j];
3329: $l_cul += length($line) + 1; # includes "\n"
3330: my $l_culx = $l_cul - 1; # not includes "\n"
3331: if ($j < $lb1) {
3332: $line = spacedHtmlText($line);
3333: push(@left_html, "<td class=\"diff-changed\">$line</td>");
3334: } elsif ($lb1 == $j) {
3335: my $html_line;
3336: while ($lb1 == $j) {
3337: my $begin_char = $l_culx - $b1;
3338:
3339: $line =~ /^(.*)(.{$begin_char})$/;
3340: $html_line .= spacedHtmlText($1) .
3341: '</span><span class="diff-unchanged">';
3342: $line = $2;
3343: last if ($j != $le1);
3344:
3345: my $end_char = $l_culx - $e1;
3346: $line =~ /^(.*)(.{$end_char})$/;
3347: $html_line .= spacedHtmlText($1) .
3348: '</span><span class="diff-changed">';
3349: $line = $2;
3350:
3351: $idx++;
3352: my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
3353: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
3354: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3355: @diff_str[$idx*8..($idx+1)*8-1];
3356: $lb1 = $INFINITY if ($lb1 < 0);
3357: $lb2 = $INFINITY if ($lb2 < 0);
3358: $le1 = $INFINITY if ($le1 < 0);
3359: $le2 = $INFINITY if ($le2 < 0);
3360: if ($te1 > $b1) {
3361: ($b1, $lb1) = ($te1, $tle1);
3362: }
3363: if ($te2 > $b2) {
3364: ($b2, $lb2) = ($te2, $tle2);
3365: }
3366: }
3367: push(@left_html,
3368: sprintf('<td><span class="%s">%s%s</span></td>',
3369: 'diff-changed', $html_line, spacedHtmlText($line)));
3370: } elsif ($le1 == $j) {
3371: my $html_line;
3372: while ($le1 == $j) {
3373: my $end_char = $l_culx - $e1;
3374: $line =~ /^(.*)(.{$end_char})$/;
3375: $html_line .= spacedHtmlText($1) .
3376: '</span><span class="diff-changed">';
3377: $line = $2;
3378:
3379: $idx++;
3380: my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
3381: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
3382: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3383: @diff_str[$idx*8..($idx+1)*8-1];
3384: $lb1 = $INFINITY if ($lb1 < 0);
3385: $lb2 = $INFINITY if ($lb2 < 0);
3386: $le1 = $INFINITY if ($le1 < 0);
3387: $le2 = $INFINITY if ($le2 < 0);
3388: if ($te1 > $b1) {
3389: ($b1, $lb1) = ($te1, $tle1);
3390: }
3391: if ($te2 > $b2) {
3392: ($b2, $lb2) = ($te2, $tle2);
3393: }
3394:
3395: last if ($lb1 != $j);
3396:
3397: my $begin_char = $l_culx - $b1;
3398:
3399: $line =~ /^(.*)(.{$begin_char})$/;
3400: $html_line .= spacedHtmlText($1) .
3401: '</span><span class="diff-unchanged">';
3402: $line = $2;
3403: }
3404: push(@left_html,
3405: sprintf('<td><span class="%s">%s%s</span></td>',
3406: 'diff-unchanged', $html_line, spacedHtmlText($line)));
3407: } else {
3408: $line = spacedHtmlText($line);
3409: push(@left_html, "<td class=\"diff-unchanged\">$line</td>");
3410: }
3411: }
3412: ($idx, $b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3413: (0, @diff_str[0..7]);
3414: $lb1 = $INFINITY if ($lb1 < 0);
3415: $lb2 = $INFINITY if ($lb2 < 0);
3416: $le1 = $INFINITY if ($le1 < 0);
3417: $le2 = $INFINITY if ($le2 < 0);
3418: for (my $j = 0; $j < $rightRow; $j++) {
3419: my $line_len = length(@$rightColRef[$j]);
3420: my $line = @$rightColRef[$j];
3421: $r_cul += length($line) + 1; # includes "\n"
3422: my $r_culx = $r_cul - 1; # not includes "\n"
3423: if ($j < $lb2) {
3424: $line = spacedHtmlText($line);
3425: push(@right_html, "<td class=\"diff-changed\">$line</td>");
3426: } elsif ($lb2 == $j) {
3427: my $html_line;
3428: while ($lb2 == $j) {
3429: my $begin_char = $r_culx - $b2;
3430:
3431: $line =~ /^(.*)(.{$begin_char})$/;
3432: $html_line .= spacedHtmlText($1) .
3433: '</span><span class="diff-unchanged">';
3434: $line = $2;
3435:
3436: last if ($j != $le2);
3437:
3438: my $end_char = $r_culx - $e2;
3439: $line =~ /^(.*)(.{$end_char})$/;
3440: $html_line .= spacedHtmlText($1) .
3441: '</span><span class="diff-changed">';
3442: $line = $2;
3443:
3444: $idx++;
3445: my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
3446: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
3447: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3448: @diff_str[$idx*8..($idx+1)*8-1];
3449: $lb1 = $INFINITY if ($lb1 < 0);
3450: $lb2 = $INFINITY if ($lb2 < 0);
3451: $le1 = $INFINITY if ($le1 < 0);
3452: $le2 = $INFINITY if ($le2 < 0);
3453: if ($te1 > $b1) {
3454: ($b1, $lb1) = ($te1, $tle1);
3455: }
3456: if ($te2 > $b2) {
3457: ($b2, $lb2) = ($te2, $tle2);
3458: }
3459: }
3460: push(@right_html,
3461: sprintf('<td><span class="%s">%s%s</span></td>',
3462: 'diff-changed', $html_line, spacedHtmlText($line)));
3463: } elsif ($le2 == $j) {
3464: my $html_line;
3465: while ($le2 == $j) {
3466: my $end_char = $r_culx - $e2;
3467: $line =~ /^(.*)(.{$end_char})$/;
3468: $html_line .= spacedHtmlText($1) .
3469: '</span><span class="diff-changed">';
3470: $line = $2;
3471:
3472: $idx++;
3473: my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
3474: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
3475: ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
3476: @diff_str[$idx*8..($idx+1)*8-1];
3477: $lb1 = $INFINITY if ($lb1 < 0);
3478: $lb2 = $INFINITY if ($lb2 < 0);
3479: $le1 = $INFINITY if ($le1 < 0);
3480: $le2 = $INFINITY if ($le2 < 0);
3481: if ($te1 > $b1) {
3482: ($b1, $lb1) = ($te1, $tle1);
3483: }
3484: if ($te2 > $b2) {
3485: ($b2, $lb2) = ($te2, $tle2);
3486: }
3487:
3488: last if ($lb2 != $j);
3489:
3490: my $begin_char = $r_culx - $b2;
3491: $line =~ /^(.*)(.{$begin_char})$/;
3492: $html_line .= spacedHtmlText($1) .
3493: '</span><span class="diff-unchanged">';
3494: $line = $2;
3495: }
3496: push(@right_html,
3.208 scop 3497: sprintf('<td nowrap="nowrap"><span class="%s">%s%s</span></td>',
3.176 scop 3498: 'diff-unchanged', $html_line, spacedHtmlText($line)));
3499: } else {
3500: $line = spacedHtmlText ($line);
3501: push @right_html, "<td class=\"diff-unchanged\">$line</td>";
3502: }
3503: }
3504: for (my $j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
3505: print '<tr>';
3506: if ($j < $leftRow) {
3507: print $left_html[$j];
3508: } else {
3509: print '<td class="diff-changed-missing"> </td>';
3510: }
3511: if ($j < $rightRow) {
3512: print $right_html[$j];
3513: } else {
3514: print '<td class="diff-changed-missing"> </td>';
3515: }
3516: print "</tr>\n";
3.120 scop 3517: }
3.176 scop 3518: } else {
3519: for (my $j = 0; $j < $leftRow || $j < $rightRow; $j++) { # dump both cols
3520: print "<tr>\n";
3521: if ($j < $leftRow) {
3522: print '<td class="diff-changed"> ' .
3523: spacedHtmlText(@$leftColRef[$j]) . '</td>';
3524: } else {
3525: print '<td class="diff-changed-missing"> </td>';
3526: }
3527: print "\n";
3.120 scop 3528:
3.176 scop 3529: if ($j < $rightRow) {
3530: print '<td class="diff-changed"> ' .
3531: spacedHtmlText(@$rightColRef[$j]) . '</td>';
3532: } else {
3533: print '<td class="diff-changed-missing"> </td>';
3534: }
3535: print "\n</tr>\n";
3.120 scop 3536: }
3537: }
3538: }
3.1 knu 3539: }
3540:
3.175 scop 3541:
3.1 knu 3542: ##
3543: # Function to generate Human readable diff-files
3544: # human_readable_diff(String revision_to_return_to);
3545: ##
3.144 scop 3546: sub human_readable_diff($$)
3.120 scop 3547: {
3548: my ($fh, $rev) = @_;
3.144 scop 3549:
3.169 scop 3550: (my $where_nd = $where) =~ s|\.diff$||;
3551: (my $filename = $where_nd) =~ s|^.*/||;
3552: (my $pathname = $where_nd) =~ s|(Attic/)?[^/]*$||;
3553: (my $scriptwhere_nd = $scriptwhere) =~ s|\.diff$||;
3.120 scop 3554:
3.133 scop 3555: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, 'diff');
3.120 scop 3556:
3.178 scop 3557: # Read header to pick up read revision and date, if possible.
3558:
3559: my ($r1d, $r1r, $r2d, $r2r);
3.120 scop 3560: while (<$fh>) {
3561: ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
3562: ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
3563: last if (/^\+\+\+ /);
3564: }
3565:
3.178 scop 3566: my ($rev1, $date1);
3.120 scop 3567: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
3568: $rev1 = $r1r;
3569: $date1 = $r1d;
3570: }
3.178 scop 3571: my ($rev2, $date2);
3.120 scop 3572: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
3573: $rev2 = $r2r;
3574: $date2 = $r2d;
3575: }
3.178 scop 3576: $rev1 = 'unknown-left' unless defined($rev1);
3577: $rev2 = 'unknown-right' unless defined($rev2);
3578: $date1 = defined($date1) ? ', ' . htmlquote($date1) : '';
3579: $date2 = defined($date2) ? ', ' . htmlquote($date2) : '';
3.120 scop 3580:
3.219 scop 3581: my $link = uri_escape($filename) . $query;
3.210 scop 3582:
3.144 scop 3583: # Using <table style=\"border: none\" here breaks NS 4.x badly...
3.210 scop 3584: print <<EOF;
3585: <h3 style="text-align: center">Diff for /$where_nd between versions $rev1 and $rev2</h3>
3586: <table border="0" cellspacing="0" cellpadding="0" width="100%" summary="Diff output">
3.144 scop 3587: <tr style="background-color: #ffffff">
3.210 scop 3588: <th style="text-align: center; vertical-align: top" width="50%">
3589: <a href="$link;rev=$rev1">version $rev1</a>$date1
3.178 scop 3590: </th>
3.210 scop 3591: <th style="text-align: center; vertical-align: top" width="50%">
3592: <a href="$link;rev=$rev2">version $rev2</a>$date2
3.144 scop 3593: </th>
3.178 scop 3594: </tr>
3.144 scop 3595: EOF
3.120 scop 3596:
3597: # Process diff text
3598: # prefetch several lines
3599: my @buf = head($fh);
3.144 scop 3600: my %d = scan_directives(@buf);
3.120 scop 3601:
3.144 scop 3602: my $leftRow = 0;
3603: my $rightRow = 0;
3604: my ($difftxt, @rightCol, @leftCol, $oldline, $newline, $funname);
3605: my ($diffcode, $rest);
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 {
3637: ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
3.176 scop 3638: $_ = $rest;
3.120 scop 3639:
3640: #########
3641: # little state machine to parse unified-diff output (Hen, zeller@think.de)
3642: # in order to get some nice 'ediff'-mode output
3643: # states:
3644: # "dump" - just dump the value
3645: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
3646: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
3647: ##########
3648:
3649: if ($diffcode eq '+') {
3650: if ($state eq "dump")
3651: { # 'change' never begins with '+': just dump out value
3.176 scop 3652: $_ = spacedHtmlText($rest, $d{'tabstop'});
3.144 scop 3653: printf(<<EOF, $_);
3654: <tr>
3655: <td class="diff-empty"> </td>
3656: <td class="diff-added"> %s</td>
3657: </tr>
3658: EOF
3.120 scop 3659: } else { # we got minus before
3660: $state = "PreChange";
3661: $rightCol[$rightRow++] = $_;
3662: }
3663: } elsif ($diffcode eq '-') {
3664: $state = "PreChangeRemove";
3665: $leftCol[$leftRow++] = $_;
3666: } else { # empty diffcode
3667: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3.176 scop 3668: $_ = spacedHtmlText($rest, $d{'tabstop'});
3.147 scop 3669: printf(<<EOF, $_, $_);
3.144 scop 3670: <tr>
3671: <td class="diff-same"> %s</td>
3672: <td class="diff-same"> %s</td>
3673: </tr>
3674: EOF
3.120 scop 3675: $state = "dump";
3676: $leftRow = 0;
3677: $rightRow = 0;
3678: }
3679: }
3680: }
3681: close($fh);
3682:
3683: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3684:
3685: # state is empty if we didn't have any change
3686: if (!$state) {
3.144 scop 3687: print <<EOF;
3688: <tr>
3689: <td colspan="2"> </td>
3690: </tr>
3691: <tr class="diff-empty">
3692: <td colspan="2" align="center"><b>- No viewable change -</b></td>
3693: </tr>
3694: EOF
3.120 scop 3695: }
3696:
3.182 scop 3697: printf(<<EOF, $scriptwhere);
3.144 scop 3698: </table>
3.208 scop 3699: <hr style="width: 100%%" />
3.144 scop 3700: <form method="get" action="%s">
3.182 scop 3701: <div style="float: left">
3.208 scop 3702: <label for="f">Diff format:<br />
3.144 scop 3703: EOF
3.168 scop 3704: printDiffSelectStickyVars();
3.120 scop 3705: printDiffSelect($use_java_script);
3.182 scop 3706: printf(<<EOF, $rev1, $rev2);
3.179 scop 3707: </label>
3.208 scop 3708: <input type="submit" value="Show" />
3.182 scop 3709: </div>
3710: <table style="float: right; border: thin outset" cellspacing="0" cellpadding="1" title="Legend" summary="Legend">
3711: <tr>
3712: <td align="center" class="diff-removed">Removed from v.%s</td>
3713: <td class="diff-empty"> </td>
3714: </tr><tr class="diff-changed">
3715: <td align="center" colspan="2">changed lines</td>
3716: </tr><tr>
3717: <td class="diff-empty"> </td>
3718: <td align="center" class="diff-added">Added in v.%s</td>
3719: </tr>
3.144 scop 3720: </table>
3721: </form>
3.208 scop 3722: <br clear="all" />
3.144 scop 3723: EOF
3.120 scop 3724: }
3.167 scop 3725:
3726:
3727: sub doEnscript($$$)
3728: {
3729: my ($filehandle, $highlight, $linenumbers) = @_;
3730:
3.174 scop 3731: my @cmd = ($CMD{enscript},
3732: @enscript_options,
3733: qw(-q --language=cvsweb -o -),
3734: "--highlight=$highlight");
3735:
3736: local *ENSCRIPT_OUT;
3737: my ($h, $err) =
3738: startproc(\@cmd, $filehandle, '>pipe', \*ENSCRIPT_OUT, timeout(30));
3739: fatal('500 Internal Error', $err) unless $h;
3740:
3741: # We could short-circuit and have enscript output directly to STDOUT above,
3742: # but that doesn't work with mod_perl (at least some 1.99 versions).
3743: if ($linenumbers) {
3744: my $ln = 0;
3745: while (<ENSCRIPT_OUT>) {
3746: printf '<a id="l%d" class="src">%5d: </a>', (++$ln) x 2;
3747: print $_;
3.167 scop 3748: }
3.174 scop 3749: } else {
3750: local $/ = undef;
3751: print <ENSCRIPT_OUT>;
3.167 scop 3752: }
3.174 scop 3753: finish($h);
3.167 scop 3754: }
3755:
3.120 scop 3756:
3.163 scop 3757: sub navigateHeader($$$$$;$)
3.120 scop 3758: {
3.163 scop 3759: my ($swhere, $path, $filename, $rev, $title, $moddate) = @_;
3.120 scop 3760: $swhere = "" if ($swhere eq $scriptwhere);
3761: $swhere = './' . urlencode($filename) if ($swhere eq "");
3762:
3.136 scop 3763: my $qfile = htmlquote($filename);
3764: my $qpath = htmlquote($path);
3.170 scop 3765: my $trev = $rev ? " - $rev" : '';
3.100 knu 3766:
3.163 scop 3767: http_header('', $moddate);
3.133 scop 3768:
3.120 scop 3769: print <<EOF;
3.100 knu 3770: $HTML_DOCTYPE
3.89 knu 3771: <html>
3772: <head>
3.170 scop 3773: <title>$qpath$qfile - $title$trev</title>
3.144 scop 3774: $HTML_META$CSS</head>
3.129 scop 3775: <body class="src">
3.182 scop 3776: <table class="navigate-header" width="100%">
3.184 scop 3777: <tr>
3778: <td>
3.64 knu 3779: EOF
3780:
3.170 scop 3781: print &link($backicon, "$swhere$query" . ($rev ? "#rev$rev" : ''));
3.136 scop 3782: printf '<b>Return to %s CVS log',
3.205 scop 3783: &link($qfile, "$swhere$query" . ($rev ? "#rev$rev" : ''));
3.120 scop 3784: print "</b> $fileicon</td>";
3785:
3.144 scop 3786: printf(<<EOF, $diricon, &clickablePath($path, 1));
3.182 scop 3787: <td style="text-align: right">%s <b>Up to %s</b></td>
3.144 scop 3788: </tr>
3789: </table>
3790: EOF
3.120 scop 3791: }
3792:
3.175 scop 3793:
3.120 scop 3794: sub plural_write($$)
3795: {
3796: my ($num, $text) = @_;
3797: if ($num != 1) {
3798: $text .= "s";
3799: }
3800:
3801: if ($num > 0) {
3802: return join (' ', $num, $text);
3803: } else {
3804: return "";
3805: }
3.1 knu 3806: }
3807:
3.175 scop 3808:
3.1 knu 3809: ##
3810: # print readable timestamp in terms of
3811: # '..time ago'
3812: # H. Zeller <zeller@think.de>
3813: ##
3.120 scop 3814: sub readableTime($$)
3815: {
3816: my ($secs, $long) = @_;
3817:
3.175 scop 3818: # This function works correctly for time >= 2 seconds.
3819: return 'very little time' if ($secs < 2);
3.120 scop 3820:
3821: my %desc = (
3.133 scop 3822: 1 => 'second',
3823: 60 => 'minute',
3824: 3600 => 'hour',
3825: 86400 => 'day',
3826: 604800 => 'week',
3827: 2628000 => 'month',
3828: 31536000 => 'year'
3829: );
3830:
3.120 scop 3831: my @breaks = sort { $a <=> $b } keys %desc;
3.133 scop 3832: my $i = 0;
3.120 scop 3833:
3834: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3835: $i++;
3836: }
3837: $i--;
3.133 scop 3838: my $break = $breaks[$i];
3839: my $retval = plural_write(int($secs / $break), $desc{$break});
3.120 scop 3840:
3841: if ($long == 1 && $i > 0) {
3842: my $rest = $secs % $break;
3843: $i--;
3844: $break = $breaks[$i];
3845: my $resttime = plural_write(int($rest / $break), $desc{$break});
3846: if ($resttime) {
3847: $retval .= ", $resttime";
3848: }
3849: }
3.1 knu 3850:
3.120 scop 3851: return $retval;
3.1 knu 3852: }
3853:
3.175 scop 3854:
3.1 knu 3855: ##
3856: # clickablePath(String pathname, boolean last_item_clickable)
3857: #
3858: # returns a html-ified path whereas each directory is a link for
3859: # faster navigation. last_item_clickable controls whether the
3860: # basename (last directory/file) is a link as well
3861: ##
3.120 scop 3862: sub clickablePath($$)
3863: {
3864: my ($pathname, $clickLast) = @_;
3865:
3.154 scop 3866: my $root = '[' . htmlquote($CVSROOTdescr{$cvstree} || $cvstree) . ']';
3867:
3.144 scop 3868: # This should never happen (see chooseCVSRoot()), but let's be sure...
3.154 scop 3869: return $root if ($pathname eq '/');
3.120 scop 3870:
3.144 scop 3871: my $retval =
3.154 scop 3872: ' ' . &link($root, sprintf('%s/%s#dirlist', $scriptname, $query));
3.144 scop 3873: my $wherepath = '';
3874: my ($lastslash) = $pathname =~ m|/$|;
3875:
3876: foreach (split (/\//, $pathname)) {
3877: $retval .= ' / ';
3878: $wherepath .= "/$_";
3879: my $last = "$wherepath/" eq "/$pathname" || $wherepath eq "/$pathname";
3880:
3881: if ($clickLast || !$last) {
3882: $retval .= &link(htmlquote($_),
3883: join ('',
3884: $scriptname, urlencode($wherepath),
3885: (!$last || $lastslash ? '/' : ''), $query,
3886: (!$last || $lastslash ? "#dirlist" : "")));
3887: } else { # do not make a link to the current dir
3888: $retval .= htmlquote($_);
3.120 scop 3889: }
3890: }
3891: return $retval;
3892: }
3893:
3.144 scop 3894:
3.120 scop 3895: sub chooseCVSRoot()
3896: {
3.208 scop 3897: print "<form method=\"get\" action=\"${scriptwhere}\">\n<p>\n";
3.120 scop 3898: if (2 <= @CVSROOT) {
3.133 scop 3899: foreach my $k (keys %input) {
3.208 scop 3900: printf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n",
3.154 scop 3901: htmlquote($k), htmlquote($input{$k}))
3902: if ($input{$k} && $k ne 'cvsroot');
3.120 scop 3903: }
3904:
3.144 scop 3905: printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3.208 scop 3906: <label for="cvsroot" accesskey="C">CVS Root:
3.144 scop 3907: <select id="cvsroot" name="cvsroot"%s>
3908: EOF
3.120 scop 3909:
3.133 scop 3910: foreach my $k (@CVSROOT) {
3.136 scop 3911: printf("<option value=\"%s\"%s>%s</option>\n",
3912: htmlquote($k),
3.208 scop 3913: ($k eq $cvstree) ? ' selected="selected"' : '',
3.136 scop 3914: htmlquote($CVSROOTdescr{$k} || $k));
3.120 scop 3915: }
3.208 scop 3916: print '</select></label>';
3.120 scop 3917: } else {
3918:
3919: # no choice -- but we need the form to select module/path,
3920: # at least for Netscape
3.208 scop 3921: printf "CVS Root: <b>[%s]</b>",
3.154 scop 3922: htmlquote($CVSROOTdescr{$cvstree} || $cvstree);
3.120 scop 3923: }
3924:
3.144 scop 3925: print <<EOF;
3926: <label for="mpath" accesskey="M">
3927: Module path or alias:
3.208 scop 3928: <input type="text" id="mpath" name="path" value="" size="15" />
3.144 scop 3929: </label>
3.208 scop 3930: <input type="submit" value="Go" accesskey="O" />
3931: </p>
3932: </form>
3.144 scop 3933: EOF
3.120 scop 3934: }
3935:
3.175 scop 3936:
3.120 scop 3937: sub chooseMirror()
3938: {
3939: # This code comes from the original BSD-cvsweb
3940: # and may not be useful for your site; If you don't
3941: # set %MIRRORS this won't show up, anyway.
3942: scalar(%MIRRORS) or return;
3943:
3944: # Should perhaps exclude the current site somehow...
3945: print "\n<p>\nThis CVSweb is mirrored in\n";
3946:
3947: my @tmp = map(&link(htmlquote($_), $MIRRORS{$_}), sort keys %MIRRORS);
3948: my $tmp = pop (@tmp);
3949:
3950: if (scalar(@tmp)) {
3951: print join (', ', @tmp), ' and ';
3952: }
3953:
3954: print "$tmp.\n</p>\n";
3955: }
3956:
3.175 scop 3957:
3.120 scop 3958: sub fileSortCmp()
3959: {
3.175 scop 3960: (my $af = $a) =~ s/,v$//;
3961: (my $bf = $b) =~ s/,v$//;
3.120 scop 3962: my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
3963: if (defined($fileinfo{$af}));
3964: my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
3965: if (defined($fileinfo{$bf}));
3966:
3.175 scop 3967: my $comp = 0;
3.140 scop 3968: if (defined($filename1) && defined($filename2) &&
3969: $af eq $filename1 && $bf eq $filename2)
3.120 scop 3970: {
3971:
3972: # Two files
3.140 scop 3973: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
3974: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
3975: if ($input{ignorecase}) {
3976: $comp = (uc($log1) cmp uc($log2)) if ($bylog && $log1 && $log2);
3977: $comp = (uc($author1) cmp uc($author2)) if ($byauthor &&
3978: $author1 && $author2);
3979: } else {
3980: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
3981: $comp = ($author1 cmp $author2) if ($byauthor &&
3982: $author1 && $author2);
3983: }
3.120 scop 3984: }
3985:
3986: if ($comp == 0) {
3987:
3988: # Directories first, then files under version control,
3989: # then other, "rogue" files.
3990: # Sort by filename if no other criteria available.
3991:
3992: my $ad = (
3993: (-d "$fullname/$a")
3994: ? 'D'
3995: : (defined($fileinfo{$af}) ? 'F' : 'R')
3996: );
3997: my $bd = (
3998: (-d "$fullname/$b")
3999: ? 'D'
4000: : (defined($fileinfo{$bf}) ? 'F' : 'R')
4001: );
3.175 scop 4002: (my $c = $a) =~ s|.*/||;
4003: (my $d = $b) =~ s|.*/||;
3.144 scop 4004:
4005: my ($l, $r) = ("$ad$c", "$bd$d");
4006: $comp = $input{ignorecase} ? (uc($l) cmp uc($r)) : ($l cmp $r);
4007:
4008: # Parent dir is always first, then Attic.
4009: if ($comp != 0) {
4010: if ($l eq 'D..') {
3.149 scop 4011: $comp = -1;
3.144 scop 4012: } elsif ($r eq 'D..') {
3.149 scop 4013: $comp = 1;
3.144 scop 4014: } elsif ($l eq 'DAttic') {
3.149 scop 4015: $comp = -1;
3.144 scop 4016: } elsif ($r eq 'DAttic') {
3.149 scop 4017: $comp = 1;
3.144 scop 4018: }
4019: }
3.120 scop 4020: }
4021: return $comp;
3.1 knu 4022: }
4023:
3.220 scop 4024: #
4025: # Returns a URL to download the selected revision.
4026: #
3.120 scop 4027: sub download_url($$;$)
4028: {
4029: my ($url, $revision, $mimetype) = @_;
4030: $revision =~ s/\b0\.//;
3.1 knu 4031:
3.222 scop 4032: if (!defined($mimetype) || $mimetype !~ CVSWEBMARKUP) {
3.120 scop 4033: my $path = $where;
4034: $path =~ s|[^/]+$||;
3.222 scop 4035: $url = "$scriptname/$CheckoutMagic/${path}$url";
3.120 scop 4036: }
3.219 scop 4037: $url .= '?rev=' . uri_escape($revision);
4038: $url .= ';content-type=' . uri_escape($mimetype) if $mimetype;
3.67 knu 4039:
3.175 scop 4040: return $url;
3.1 knu 4041: }
4042:
3.175 scop 4043: #
3.220 scop 4044: # Returns a link to download the selected revision.
3.175 scop 4045: #
3.120 scop 4046: sub download_link($$$;$)
4047: {
4048: my ($url, $revision, $textlink, $mimetype) = @_;
3.175 scop 4049: my $fullurl = download_url($url, $revision, $mimetype);
3.220 scop 4050: return sprintf('<a href="%s" class="download-link">%s</a>',
4051: hrefquote("$fullurl$barequery"), htmlquote($textlink));
3.218 scop 4052: }
3.120 scop 4053:
3.219 scop 4054: #
4055: # Returns a URL to display the selected revision.
4056: #
4057: sub display_url($$;$)
4058: {
4059: my ($url, $revision, $mimetype) = @_;
4060: $url .= '?rev=' . uri_escape($revision);
4061: $url .= ';content-type=' . uri_escape($mimetype) if $mimetype;
4062: return $url;
4063: }
4064:
4065: #
4066: # Returns a link to display the selected revision.
4067: #
4068: sub display_link($$;$$)
4069: {
4070: my ($url, $revision, $textlink, $mtype) = @_;
4071: $textlink = $revision unless defined($textlink);
4072: return sprintf('<a href="%s" class="display-link">%s</a>',
4073: hrefquote(display_url($url, $revision, $mtype) . $barequery),
4074: htmlquote($textlink));
4075: }
3.132 scop 4076:
3.170 scop 4077: sub graph_link($;$)
3.132 scop 4078: {
3.170 scop 4079: my ($url, $text) = @_;
3.132 scop 4080: $text ||= $graphicon;
3.170 scop 4081: return sprintf('<a href="%s?graph=1%s">%s</a>',
4082: hrefquote($url), hrefquote($barequery), $text);
3.1 knu 4083: }
4084:
4085: # Returns a Query string with the
4086: # specified parameter toggled
3.140 scop 4087: sub toggleQuery($;$)
3.120 scop 4088: {
4089: my ($toggle, $value) = @_;
3.133 scop 4090:
4091: my %vars = %input;
3.120 scop 4092:
4093: if (defined($value)) {
4094: $vars{$toggle} = $value;
4095: } else {
4096: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
4097: }
4098:
4099: # Build a new query of non-default paramenters
3.133 scop 4100: my $newquery = "";
4101: foreach my $var (@stickyvars) {
3.120 scop 4102: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
4103: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
4104:
4105: if ($value ne $default) {
3.203 scop 4106: $newquery .= ';' if ($newquery ne "");
3.206 scop 4107: $newquery .= uri_escape($var) . '=' . uri_escape($value);
3.120 scop 4108: }
4109: }
4110:
4111: if ($newquery) {
4112: return '?' . $newquery;
4113: }
4114: return "";
4115: }
4116:
4117: sub urlencode($)
4118: {
4119: local ($_) = @_;
4120: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3.175 scop 4121: return $_;
3.120 scop 4122: }
4123:
4124: sub htmlquote($)
4125: {
4126: local ($_) = @_;
4127: # Special Characters; RFC 1866
4128: s/&/&/g;
4129: s/\"/"/g;
4130: s/</</g;
4131: s/>/>/g;
3.175 scop 4132: return $_;
3.120 scop 4133: }
4134:
4135: sub htmlunquote($)
4136: {
4137: local ($_) = @_;
4138: # Special Characters; RFC 1866
4139: s/"/\"/g;
4140: s/</</g;
4141: s/>/>/g;
4142: s/&/&/g;
3.175 scop 4143: return $_;
3.120 scop 4144: }
4145:
4146: sub hrefquote($)
4147: {
4148: local ($_) = @_;
4149:
4150: y/ /+/;
4151:
4152: htmlquote($_);
4153: }
4154:
3.163 scop 4155: sub http_header(;$$)
3.120 scop 4156: {
3.163 scop 4157: my ($content_type, $moddate) = @_;
4158: $content_type ||= 'text/html';
3.120 scop 4159:
4160: $content_type .= "; charset=$charset"
3.163 scop 4161: if ($charset && $content_type =~ m,^text/,);
3.120 scop 4162:
3.185 scop 4163: # Note that in the following, we explicitly join() and concatenate the
4164: # headers instead of printing them as an array. This is because some
4165: # systems, eg. early versions of mod_perl 2 don't quite get it if the
4166: # last \r\n\r\n isn't included in the last "payload" header print().
4167:
4168: my @headers = ();
4169: # TODO: ctime(3) from scalar gmtime() isn't HTTP compliant, see HTTP::Date.
4170: push(@headers, 'Last-Modified: ' . scalar gmtime($moddate) . ' GMT')
4171: if $moddate;
4172: push(@headers, 'Content-Type: ' . $content_type);
3.120 scop 4173:
4174: if ($allow_compress && $maycompress) {
3.222 scop 4175: if (HAS_ZLIB
3.120 scop 4176: || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c")))
4177: {
4178:
3.185 scop 4179: push(@headers, 'Content-Encoding: x-gzip');
4180: push(@headers, 'Vary: Accept-Encoding'); # RFC 2616, 14.44
4181: print join("\r\n", @headers) . "\r\n\r\n";
4182:
3.120 scop 4183: $| = 1;
3.185 scop 4184: $| = 0; # Flush header output.
3.120 scop 4185:
3.222 scop 4186: tie(*GZIP, __PACKAGE__, \*STDOUT) if HAS_ZLIB;
3.120 scop 4187: select(GZIP);
4188: $gzip_open = 1;
4189:
4190: } else {
3.185 scop 4191:
4192: print join("\r\n", @headers) . "\r\n\r\n";
3.120 scop 4193: print
3.208 scop 4194: "<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 4195: }
3.185 scop 4196:
3.120 scop 4197: } else {
3.185 scop 4198: print join("\r\n", @headers) . "\r\n\r\n";
3.120 scop 4199: }
4200: }
4201:
3.131 scop 4202:
3.163 scop 4203: sub html_header($;$)
3.120 scop 4204: {
3.163 scop 4205: my ($title, $moddate) = @_;
4206: $title = htmlquote($title);
3.162 scop 4207: my $l = $logo || '';
3.163 scop 4208: http_header('text/html', $moddate);
3.120 scop 4209: print <<EOH;
3.100 knu 4210: $HTML_DOCTYPE
3.1 knu 4211: <html>
3.40 knu 4212: <head>
3.134 scop 4213: <title>$title</title>
3.144 scop 4214: $HTML_META$CSS</head>
3.129 scop 4215: <body>
3.182 scop 4216: $l <h1>$title</h1>
3.1 knu 4217: EOH
4218: }
4219:
3.120 scop 4220: sub html_footer()
4221: {
3.208 scop 4222: print "<hr />\n<address>$address</address>\n" if $address;
3.127 scop 4223: print "</body>\n</html>\n";
3.1 knu 4224: }
4225:
3.120 scop 4226: sub link_tags($)
4227: {
4228: my ($tags) = @_;
4229: my ($ret) = "";
4230: my ($fileurl, $filename);
4231:
4232: ($filename = $where) =~ s/^.*\///;
4233: $fileurl = './' . urlencode($filename);
4234:
4235: foreach my $sym (split (", ", $tags)) {
4236: $ret .= ",\n" if ($ret ne "");
3.136 scop 4237: $ret .= &link(htmlquote($sym),
4238: $fileurl . toggleQuery('only_with_tag', $sym));
3.120 scop 4239: }
3.219 scop 4240: return $ret;
3.1 knu 4241: }
4242:
3.175 scop 4243:
3.1 knu 4244: #
3.221 scop 4245: # See if a module is listed in the config file's @HideModules list, ie. if
4246: # it should not be shown. Takes a path relative to the CVS root.
3.1 knu 4247: #
3.120 scop 4248: sub forbidden_module($)
4249: {
4250: my ($module) = @_;
3.175 scop 4251: for my $hidden_re (@HideModules) {
4252: return 1 if ($module =~ $hidden_re);
3.120 scop 4253: }
4254: return 0;
4255: }
4256:
3.175 scop 4257:
3.221 scop 4258: #
4259: # See if a file is listed in the config file's @ForbiddenFiles list, ie.
4260: # if it should not be shown. Takes a full file system path, without
4261: # the trailing ",v".
4262: #
3.120 scop 4263: sub forbidden_file($)
4264: {
4265: my ($path) = @_;
4266: $path = substr($path, length($cvsroot) + 1);
3.175 scop 4267: for my $forbidden_re (@ForbiddenFiles) {
4268: return 1 if ($path =~ $forbidden_re);
3.120 scop 4269: }
4270: return 0;
3.174 scop 4271: }
4272:
4273:
4274: #
4275: # Starts a process using IPC::Run. All arguments are passed to
4276: # IPC::Run::start() as-is. Returns an array ($harness, $error) where
4277: # $harness is from IPC::Run if start() succeeds, undef otherwise. In case
3.184 scop 4278: # of an error, $error contains the error message.
3.174 scop 4279: #
3.191 scop 4280: sub startproc(@)
3.174 scop 4281: {
3.215 scop 4282: my $h = my $err = undef;
3.174 scop 4283: eval {
4284: local $SIG{__DIE__};
3.215 scop 4285: $h = IPC::Run::start(@_) or die("return code: $?");
3.174 scop 4286: };
3.215 scop 4287: if ($@) {
4288: finish($h) if $h;
4289: $h = undef;
4290: $err = "'@{$_[0]}' failed: $@";
4291: }
3.174 scop 4292: return ($h, $err);
3.215 scop 4293: }
4294:
4295: #
4296: # Runs a process using IPC::Run. All arguments are passed to
4297: # IPC::Run::run() as-is. Returns an array ($exitcode, $errormsg).
4298: #
4299: sub runproc(@)
4300: {
4301: eval {
4302: local $SIG{__DIE__};
4303: IPC::Run::run(@_);
4304: };
4305: my $exitcode = $? >> 8;
4306: my $errormsg = undef;
4307: if ($@) {
4308: $exitcode ||= -1;
4309: $errormsg = "'@{$_[0]}' failed: $@";
4310: }
4311: return ($exitcode, $errormsg);
3.129 scop 4312: }
4313:
3.25 knu 4314:
3.173 scop 4315: # Close the GZIP handle, and remove the tie.
3.120 scop 4316: sub gzipclose
4317: {
4318: if ($gzip_open) {
4319: select(STDOUT);
4320: close(GZIP);
4321: untie *GZIP;
4322: $gzip_open = 0;
4323: }
3.23 knu 4324: }
4325:
4326: # implement a gzipped file handle via the Compress:Zlib compression
4327: # library.
4328:
4329: sub MAGIC1() { 0x1f }
4330: sub MAGIC2() { 0x8b }
3.80 knu 4331: sub OSCODE() { 3 }
3.23 knu 4332:
3.120 scop 4333: sub TIEHANDLE
4334: {
4335: my ($class, $out) = @_;
4336: my ($d) = Compress::Zlib::deflateInit(
4337: -Level => Compress::Zlib::Z_BEST_COMPRESSION(),
4338: -WindowBits => -Compress::Zlib::MAX_WBITS()
4339: )
4340: or return undef;
4341: my ($o) = { handle => $out,
4342: dh => $d,
4343: crc => 0,
4344: len => 0,
4345: };
4346: my ($header) = pack("c10",
4347: MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(),
4348: 0, 0, 0, 0, 0, 0, OSCODE);
4349: print {$o->{handle}} $header;
4350: return bless($o, $class);
4351: }
4352:
4353: sub PRINT
4354: {
4355: my ($o) = shift;
3.164 scop 4356: my ($buf) = join (defined($,) ? $, : "", @_);
3.120 scop 4357: my ($len) = length($buf);
4358: my ($compressed, $status) = $o->{dh}->deflate($buf);
4359: print {$o->{handle}} $compressed if defined($compressed);
4360: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
4361: $o->{len} += $len;
4362: return $len;
4363: }
4364:
4365: sub PRINTF
4366: {
4367: my ($o) = shift;
4368: my ($fmt) = shift;
4369: my ($buf) = sprintf($fmt, @_);
4370: my ($len) = length($buf);
4371: my ($compressed, $status) = $o->{dh}->deflate($buf);
4372: print {$o->{handle}} $compressed if defined($compressed);
4373: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
4374: $o->{len} += $len;
4375: return $len;
4376: }
4377:
4378: sub WRITE
4379: {
4380: my ($o, $buf, $len, $off) = @_;
4381: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
4382: print {$o->{handle}} $compressed if defined($compressed);
4383: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
4384: $o->{len} += $len;
4385: return $len;
4386: }
4387:
4388: sub CLOSE
4389: {
4390: my ($o) = @_;
4391: return if !defined($o->{dh});
4392: my ($buf) = $o->{dh}->flush();
4393: $buf .= pack("V V", $o->{crc}, $o->{len});
4394: print {$o->{handle}} $buf;
4395: undef $o->{dh};
4396: }
4397:
4398: sub DESTROY
4399: {
4400: my ($o) = @_;
4401: CLOSE($o);
1.1 jfieber 4402: }
3.149 scop 4403:
4404: # Local variables:
4405: # indent-tabs-mode: nil
4406: # cperl-indent-level: 2
4407: # End:
CVSweb