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