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