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