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