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