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