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