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