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