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