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