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