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