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