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