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