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