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