=================================================================== RCS file: /cvs/cvsweb/cvsweb.cgi,v retrieving revision 1.10 retrieving revision 1.31 diff -u -p -r1.10 -r1.31 --- cvsweb/cvsweb.cgi 1997/11/14 17:36:47 1.10 +++ cvsweb/cvsweb.cgi 1999/06/01 15:23:51 1.31 @@ -3,8 +3,35 @@ # cvsweb - a CGI interface to the CVS tree. # # Written by Bill Fenner on his own time. -# Insert BSD copyright here. # +# Copyright (c) 1996-1998 Bill Fenner +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $fId: cvsweb.cgi,v 1.30 1999/04/17 16:57:56 wosch Exp $ +# + + #HTTP_USER_AGENT: Mozilla/1.1N (X11; I; SunOS 4.1.3_U1 sun4m) via proxy gateway CERN-HTTPD/3.0 libwww/2.17 #SERVER_NAME: www.freebsd.org #QUERY_STRING: baz @@ -30,13 +57,25 @@ require 'ctime.pl'; $hsty_base = ""; require 'cgi-style.pl'; +#&get_the_source; %CVSROOT = ( 'freebsd', '/home/ncvs', - 'openbsd', '/home/OpenBSD/cvs', 'learn', '/c/learncvs', ); +%CVSROOTdescr = ( + 'freebsd', 'FreeBSD', + 'learn', 'Learn', + ); + +%mirrors = ( + 'Germany', 'http://www.de.freebsd.org/cgi/cvsweb.cgi', + 'Spain', 'http://www.es.freebsd.org/cgi/cvsweb.cgi', + 'California', 'http://www.freebsd.org/cgi/cvsweb.cgi', + 'Japan', 'http://www.jp.freebsd.org/cgi/cvsweb.cgi', + ); + $cvstreedefault = 'freebsd'; $cvstree = $cvstreedefault; $cvsroot = $CVSROOT{"$cvstree"} || "/home/ncvs"; @@ -56,7 +95,8 @@ display diffs between arbitrary revisions.

If you would like to use this CGI script on your own web server and CVS tree, see -the CVSWeb distribution site. +the CVSWeb distribution site or the current FreeBSD version.

Please send any suggestions, comments, etc. to Bill Fenner <fenner\@freebsd.org> @@ -75,7 +115,6 @@ $scriptname =~ s|/$||; $scriptwhere = $scriptname . '/' . $where; $scriptwhere =~ s|/$||; - if ($query = $ENV{'QUERY_STRING'}) { foreach (split(/&/, $query)) { s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted @@ -89,6 +128,8 @@ if ($query = $ENV{'QUERY_STRING'}) { } +$config = '/usr/local/etc/cvsweb'; +do "$config" if -f $config; if ($input{'cvsroot'}) { if ($CVSROOT{$input{'cvsroot'}}) { @@ -96,13 +137,49 @@ if ($input{'cvsroot'}) { $cvsroot = $CVSROOT{"$cvstree"}; } } +do "$config-$cvstree" if -f "$config-$cvstree"; $fullname = $cvsroot . '/' . $where; + if (!-d $cvsroot) { - &fatal("500 Internal Error",'$CVSROOT not found!'); + &fatal("500 Internal Error",'$CVSROOT not found!

The server on which the CVS tree lives is probably down. Please try again in a few minutes.'); } +{ + local(@foo, $i); + local($scriptname) = $ENV{'SCRIPT_NAME'}; + foreach (sort keys %CVSROOT) { + if (-d $CVSROOT{$_}) { + push(@foo, $_); + } + } + if ($#foo > 1) { + $intro .= "

\nThis script supports the following CVS trees:\n"; + for($i = 0; $i <= $#foo; $i++) { + $intro .= qq{} . + ($CVSROOTdescr{$foo[$i]} ? + $CVSROOTdescr{$foo[$i]} : $foo[$i]) . qq{} . + ($i == $#foo ? ".\n" : ",\n"); + } + } +} + + +{ + local(@mirrors) = sort keys %mirrors;; + if ($#mirrors >= 0) { + $intro .= "

\nThis script is mirrored in:\n"; + local($m); + for($m = 0; $m <= $#mirrors; $m++) { + $intro .= qq($mirrors[$m]); + $intro .= ',' if $m != $#mirrors; + $intro .= "\n"; + } + } +} + + if (-d $fullname) { opendir(DIR, $fullname) || &fatal("404 Not Found","$where: $!"); @dir = readdir(DIR); @@ -114,7 +191,11 @@ if (-d $fullname) { print &html_header("/$where"); print $shortinstr; } - print "

Current directory: /$where\n"; + print "

"; + print "Current CVS tree: ", + ($CVSROOTdescr{"$cvstree"} ? $CVSROOTdescr{"$cvstree"} : + $cvstree), "
\n"; + print "Current directory: /$where\n"; print "


\n"; # Using in this manner violates the HTML2.0 spec but # provides the results that I want in most browsers. Another @@ -126,6 +207,7 @@ if (-d $fullname) { last lookingforattic; } } + $haveattic = 1 if ($i <= $#dir); if (!$input{"showattic"} && ($i <= $#dir) && opendir(DIR, $fullname . "/Attic")) { splice(@dir, $i, 1, @@ -137,6 +219,9 @@ if (-d $fullname) { if ($_ eq '.') { next; } + # ignore CVS lock and stale NFS files + next if /^#cvs\.|^,|^\.nfs/; + if (s|^Attic/||) { $attic = " (in the Attic)"; } else { @@ -151,13 +236,14 @@ if (-d $fullname) { # &link("Directory-wide diffs", $scriptwhere . '/*'), "
"; } elsif (-d $fullname . "/" . $_) { print " ", - &link($_ . "/", $scriptwhere . '/' . $_ . '/' . $query), $attic, "
"; + &link($_ . "/", $scriptwhere . '/' . $_ . '/' . $query), + $attic, "
"; } elsif (s/,v$//) { # TODO: add date/time? How about sorting? print " ", &link($_, $scriptwhere . '/' . ($attic ? "Attic/" : "") . $_ . $query), - $attic, "
"; + $attic, "
"; } } print "
\n"; @@ -173,15 +259,17 @@ if (-d $fullname) { } $formwhere = $scriptwhere; $formwhere =~ s|Attic/?$|| if ($input{"showattic"}); - print "
\n"; - $input{"showattic"}=!$input{"showattic"}; - foreach $k (keys %input) { - print "\n" if $input{$k}; + if ($haveattic) { + print "
\n"; + $input{"showattic"}=!$input{"showattic"}; + foreach $k (keys %input) { + print "\n" if $input{$k}; + } + print "\n"; + print "
\n"; } - print "\n"; - print "\n"; print &html_footer; print "\n"; } elsif (-f $fullname . ',v') { @@ -194,6 +282,262 @@ if (-d $fullname) { $input{'r2'}, $input{'tr2'}, $input{'f'}); exit; } +print("going to dolog($fullname)\n") if ($verbose); + &dolog($fullname); +} elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" && + $input{'r1'} && $input{'r2'}) { + # Allow diffs using the ".diff" extension + # so that browsers that default to the URL + # for a save filename don't save diff's as + # e.g. foo.c + &dodiff($fullname, $input{'r1'}, $input{'tr1'}, + $input{'r2'}, $input{'tr2'}, $input{'f'}); + exit; +} elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| && + -f $newname . ",v") { + # The file has been removed and is in the Attic. + # Send a redirect pointing to the file in the Attic. + ($newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|; + &redirect($newplace); + exit; +} elsif (0 && (@files = &safeglob($fullname . ",v"))) { + print "Content-type: text/plain\n\n"; + print "You matched the following files:\n"; + print join("\n", @files); + # Find the tags from each file + # Display a form offering diffs between said tags +} else { + # Assume it's a module name with a potential path following it. + $xtra = $& if (($module = $where) =~ s|/.*||); + # Is there an indexed version of modules? + if (open(MODULES, "$cvsroot/CVSROOT/modules")) { + while () { + if (/^(\S+)\s+(\S+)/o && $module eq $1 + && -d "${cvsroot}/$2" && $module ne $2) { + &redirect($scriptname . '/' . $2 . $xtra); + } + } + } + &fatal("404 Not Found","$where: no such file or directory"); +} + +sub htmlify { + local($string, $pr) = @_; + + $string =~ s/&/&/g; + $string =~ s//>/g; + + if ($pr) { + $string =~ s!\b((pr[:#]?\s*#?)|((bin|conf|docs|gnu|i386|kern|misc|ports)\/))(\d+)\b!$&!ig; + } + + $string; +} + +sub link { + local($name, $where) = @_; + + "$name\n"; +} + +sub revcmp { + local($rev1, $rev2) = @_; + local(@r1) = split(/\./, $rev1); + local(@r2) = split(/\./, $rev2); + local($a,$b); + + while (($a = shift(@r1)) && ($b = shift(@r2))) { + if ($a != $b) { + return $a <=> $b; + } + } + if (@r1) { return 1; } + if (@r2) { return -1; } + return 0; +} + +sub fatal { + local($errcode, $errmsg) = @_; + print "Status: $errcode\n"; + print &html_header("Error"); +# print "Content-type: text/html\n"; +# print "\n"; +# print "Error\n"; +# print "Error: $errmsg\n"; + print "Error: $errmsg\n"; + print &html_footer; + exit(1); +} + +sub redirect { + local($url) = @_; + print "Status: 301 Moved\n"; + print "Location: $url\n"; + print &html_header("Moved"); +# print "Content-type: text/html\n"; +# print "\n"; +# print "Moved\n"; +# print "This document is located here.\n"; + print "This document is located here.\n"; + print &html_footer; + exit(1); +} + +sub safeglob { + local($filename) = @_; + local($dirname); + local(@results); + + ($dirname = $filename) =~ s|/[^/]+$||; + $filename =~ s|.*/||; + + if (opendir(DIR, $dirname)) { + $glob = $filename; + # transform filename from glob to regex. Deal with: + # [, {, ?, * as glob chars + # make sure to escape all other regex chars + $glob =~ s/([\.\(\)\|\+])/\\$1/g; + $glob =~ s/\*/.*/g; + $glob =~ s/\?/./g; + $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg; + foreach (readdir(DIR)) { + if (/^${glob}$/) { + push(@results, $dirname . "/" .$_); + } + } + } + + @results; +} + +sub checkout { + local($fullname, $rev) = @_; + + open(RCS, "co -p$rev '$fullname' 2>&1 |") || + &fail("500 Internal Error", "Couldn't co: $!"); +# /home/ncvs/src/sys/netinet/igmp.c,v --> standard output +# or +# /home/ncvs/src/sys/netinet/igmp.c,v --> stdout +# revision 1.1.1.2 +# /* + $_ = ; + if (/^(\S+),v\s+-->\s+st(andar)?d ?out(put)?\s*$/o && $1 eq $fullname) { + # As expected + } else { + &fatal("500 Internal Error", + "Unexpected output from co: $_"); + } + $_ = ; + if ($rev eq ".") { + # latest rev requested, don't check + } elsif (/^revision\s+$rev\s*$/) { + # As expected + } else { + &fatal("500 Internal Error", + "Unexpected output from co: $_"); + } + $| = 1; + print "Content-type: text/plain\n\n"; + print ; + close(RCS); +} + +sub dodiff { + local($fullname, $r1, $tr1, $r2, $tr2, $f) = @_; + + if ($r1 =~ /([^:]+)(:(.+))?/) { + $rev1 = $1; + $sym1 = $3; + } + if ($rev1 eq 'text') { + $rev1 = $tr1; + } + if ($r2 =~ /([^:]+)(:(.+))?/) { + $rev2 = $1; + $sym2 = $3; + } + if ($rev2 eq 'text') { + $rev2 = $tr2; + } + if (!($rev1 =~ /^[\d\.]+$/) || !($rev2 =~ /^[\d\.]+$/)) { + &fatal("404 Not Found", + "Malformed query \"$ENV{'QUERY_STRING'}\""); + } +# +# rev1 and rev2 are now both numeric revisions. +# Thus we do a DWIM here and swap them if rev1 is after rev2. +# XXX should we warn about the fact that we do this? + if (&revcmp($rev1,$rev2) > 0) { + ($tmp1, $tmp2) = ($rev1, $sym1); + ($rev1, $sym1) = ($rev2, $sym2); + ($rev2, $sym2) = ($tmp1, $tmp2); + } +# +# XXX Putting '-p' here is a personal preference + if ($f eq 'c') { + $difftype = '-p -c'; + $diffname = "Context diff"; + } elsif ($f eq 's') { + $difftype = '--side-by-side --width=164'; + $diffname = "Side by Side"; + } else { + $difftype = '-p -u'; + $diffname = "Unidiff"; + } +# XXX should this just be text/plain +# or should it have an HTML header and then a
+	print "Content-type: text/plain\n\n";
+	open(RCSDIFF, "rcsdiff $difftype -r$rev1 -r$rev2 '$fullname' 2>&1 |") ||
+	    &fail("500 Internal Error", "Couldn't rcsdiff: $!");
+#
+#===================================================================
+#RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
+#retrieving revision 1.16
+#retrieving revision 1.17
+#diff -c -r1.16 -r1.17
+#*** /home/ncvs/src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
+#--- /home/ncvs/src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17
+#
+# Ideas:
+# - nuke the stderr output if it's what we expect it to be
+# - Add "no differences found" if the diff command supplied no output.
+#
+#*** src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
+#--- src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17 RELENG_2_1_0
+# (bogus example, but...)
+#
+	if ($difftype eq '-u') {
+	    $f1 = '---';
+	    $f2 = '\+\+\+';
+	} else {
+	    $f1 = '\*\*\*';
+	    $f2 = '---';
+	}
+	while () {
+	    if (m|^$f1 $cvsroot|o) {
+		s|$cvsroot/||o;
+		if ($sym1) {
+		    chop;
+		    $_ .= " " . $sym1 . "\n";
+		}
+	    } elsif (m|^$f2 $cvsroot|o) {
+		s|$cvsroot/||o;
+		if ($sym2) {
+		    chop;
+		    $_ .= " " . $sym2 . "\n";
+		}
+	    }
+	    print $_;
+	}
+	close(RCSDIFF);
+}
+
+sub dolog {
+	local($fullname) = @_;
+	local($curbranch,$symnames);	#...
+
+	print("Going to rlog '$fullname'\n") if ($verbose);
 	open(RCS, "rlog '$fullname'|") || &fatal("500 Internal Error",
 						"Failed to spawn rlog");
 	while () {
@@ -232,13 +576,22 @@ if (-d $fullname) {
 	logentry:
 	while (!/^=========/) {
 	    $_ = ;
+	    last logentry if (!defined($_));	# EOF
 	    print "R:", $_ if ($verbose);
 	    if (/^revision ([\d\.]+)/) {
 		$rev = $1;
 	    } elsif (/^========/ || /^----------------------------$/) {
 		next logentry;
 	    } else {
-		&fatal("500 Internal Error","Error parsing RCS output: $_");
+		# The rlog output is syntactically ambiguous.  We must
+		# have guessed wrong about where the end of the last log
+		# message was.
+		# Since this is likely to happen when people put rlog output
+		# in their commit messages, don't even bother keeping
+		# these lines since we don't know what revision they go with
+		# any more.
+		next logentry;
+#		&fatal("500 Internal Error","Error parsing RCS output: $_");
 	    }
 	    $_ = ;
 	    print "D:", $_ if ($verbose);
@@ -367,12 +720,12 @@ if (-d $fullname) {
 	    }
 	    print "\n";
 	    print "$_};
+		&cvsroot . "\">$_";
 	    if (/^1\.1\.1\.\d+$/) {
 		print " (vendor branch)";
 	    }
-	    print " " . &ctime($date{$_}) . " by ";
-	    print "" . $author{$_} . "\n";
+	    print " " . &ctime($date{$_}) . " UTC by ";
+	    print "" . $author{$_} . "\n";
 	    if ($revsym{$_}) {
 		print "
CVS Tags: $revsym{$_}"; } @@ -410,7 +763,7 @@ if (-d $fullname) { if ($prevrev[$#prevrev] != 0) { $prev = join(".", @prevrev); print "
Diffs to $prev\n}; + print "&r2=$_" . &cvsroot . "\">Diffs to $prev\n"; # # Plus, if it's on a branch, and it's not a vendor branch, # offer to diff with the immediately-preceding commit if it @@ -425,7 +778,7 @@ if (-d $fullname) { if ($#tmp1 < $#tmp2) { print "; Diffs to $revorder[$i+1]\n}; + "\">Diffs to $revorder[$i+1]\n"; } } } @@ -443,7 +796,7 @@ if (-d $fullname) { print "name using the type-in text box.\n"; print "

\n"; print "

\n"; - print qq{\n} + print "\n" if &cvsroot; print "Diffs between \n"; print "