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