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