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