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