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