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