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