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