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