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