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