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