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