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