Annotation of cvsweb/cvsweb.cgi, Revision 1.45
1.1 jfieber 1: #!/usr/bin/perl -s
2: #
3: # cvsweb - a CGI interface to the CVS tree.
4: #
5: # Written by Bill Fenner <fenner@parc.xerox.com> on his own time.
6: #
1.21 wosch 7: # Copyright (c) 1996-1998 Bill Fenner
8: # All rights reserved.
9: #
10: # Redistribution and use in source and binary forms, with or without
11: # modification, are permitted provided that the following conditions
12: # are met:
13: # 1. Redistributions of source code must retain the above copyright
14: # notice, this list of conditions and the following disclaimer.
15: # 2. Redistributions in binary form must reproduce the above copyright
16: # notice, this list of conditions and the following disclaimer in the
17: # documentation and/or other materials provided with the distribution.
18: #
19: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: # SUCH DAMAGE.
30: #
1.45 ! knu 31: # $FreeBSD: www/en/cgi/cvsweb.cgi,v 1.44 2000/07/13 09:01:10 knu Exp $
1.21 wosch 32: #
33:
34:
1.1 jfieber 35: #HTTP_USER_AGENT: Mozilla/1.1N (X11; I; SunOS 4.1.3_U1 sun4m) via proxy gateway CERN-HTTPD/3.0 libwww/2.17
1.37 phantom 36: #SERVER_NAME: www.FreeBSD.org
1.1 jfieber 37: #QUERY_STRING: baz
38: #SCRIPT_FILENAME: /usr/local/www/cgi-bin/env.pl
39: #SERVER_PORT: 80
40: #HTTP_ACCEPT: */*, image/gif, image/x-xbitmap, image/jpeg
41: #SERVER_PROTOCOL: HTTP/1.0
42: #HTTP_COOKIE: s=beta26429821397802167
43: #PATH_INFO: /foo/bar
44: #REMOTE_ADDR: 13.1.64.94
45: #DOCUMENT_ROOT: /usr/local/www/data/
46: #PATH: /sbin:/bin:/usr/sbin:/usr/bin
47: #PATH_TRANSLATED: /usr/local/www/data//foo/bar
48: #GATEWAY_INTERFACE: CGI/1.1
49: #REQUEST_METHOD: GET
50: #SCRIPT_NAME: /cgi-bin/env.pl
51: #SERVER_SOFTWARE: Apache/1.0.0
52: #REMOTE_HOST: beta.xerox.com
1.37 phantom 53: #SERVER_ADMIN: webmaster@FreeBSD.org
1.1 jfieber 54: #
55: require 'timelocal.pl';
56: require 'ctime.pl';
57:
1.2 jfieber 58: $hsty_base = "";
59: require 'cgi-style.pl';
1.11 wosch 60: #&get_the_source;
1.2 jfieber 61:
1.10 wosch 62: %CVSROOT = (
63: 'freebsd', '/home/ncvs',
64: 'learn', '/c/learncvs',
65: );
66:
1.16 wosch 67: %CVSROOTdescr = (
68: 'freebsd', 'FreeBSD',
69: 'learn', 'Learn',
70: );
71:
1.24 wosch 72: %mirrors = (
1.37 phantom 73: 'Germany', 'http://www.de.FreeBSD.org/cgi/cvsweb.cgi',
1.42 jdp 74: 'Portugal', 'http://cvsup.pt.freebsd.org/cgi-bin/cvsweb/cvsweb.cgi',
1.43 jdp 75: 'Russia', 'http://www.FreeBSD.org.ua/cgi/cvsweb.cgi?cvsroot=freebsd',
1.37 phantom 76: 'Spain', 'http://www.es.FreeBSD.org/cgi/cvsweb.cgi',
77: 'USA, California', 'http://www.FreeBSD.org/cgi/cvsweb.cgi',
78: 'Japan', 'http://www.jp.FreeBSD.org/cgi/cvsweb.cgi',
1.24 wosch 79: );
80:
1.10 wosch 81: $cvstreedefault = 'freebsd';
82: $cvstree = $cvstreedefault;
83: $cvsroot = $CVSROOT{"$cvstree"} || "/home/ncvs";
84:
85:
1.1 jfieber 86: $intro = "
87: This is a WWW interface to the FreeBSD CVS tree.
88: You can browse the file hierarchy by picking directories
89: (which have slashes after them, e.g. <b>src/</b>).
90: If you pick a file, you will see the revision history
91: for that file.
92: Selecting a revision number will download that revision of
93: the file. There is a link at each revision to display
94: diffs between that revision and the previous one, and
95: a form at the bottom of the page that allows you to
96: display diffs between arbitrary revisions.
97: <p>
1.7 fenner 98: If you would like to use this CGI script on your own web server and
1.37 phantom 99: CVS tree, see <A HREF=\"http://www.FreeBSD.org/~fenner/cvsweb/\">
1.17 wosch 100: the CVSWeb distribution site</A> or the <a
1.39 wosch 101: href=\"http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi\">current</a> FreeBSD version.
1.7 fenner 102: <p>
1.1 jfieber 103: Please send any suggestions, comments, etc. to
1.37 phantom 104: <A HREF=\"mailto:fenner\@FreeBSD.org\">Bill Fenner <fenner\@FreeBSD.org></A>
1.1 jfieber 105: ";
106: $shortinstr = "
107: Click on a directory to enter that directory. Click on a file to display
108: its revision history and to get a
109: chance to display diffs between revisions.
110: ";
111:
112: $verbose = $v;
113: ($where = $ENV{'PATH_INFO'}) =~ s|^/||;
114: $where =~ s|/$||;
115: ($scriptname = $ENV{'SCRIPT_NAME'}) =~ s|^/?|/|;
116: $scriptname =~ s|/$||;
117: $scriptwhere = $scriptname . '/' . $where;
118: $scriptwhere =~ s|/$||;
119:
1.9 fenner 120: if ($query = $ENV{'QUERY_STRING'}) {
121: foreach (split(/&/, $query)) {
1.7 fenner 122: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
123: if (/(\S+)=(.*)/) {
124: $input{$1} = $2;
125: } else {
126: $input{$_}++;
127: }
128: }
1.9 fenner 129: $query = "?" . $query;
1.7 fenner 130: }
1.10 wosch 131:
132:
1.11 wosch 133: $config = '/usr/local/etc/cvsweb';
134: do "$config" if -f $config;
1.10 wosch 135:
136: if ($input{'cvsroot'}) {
137: if ($CVSROOT{$input{'cvsroot'}}) {
138: $cvstree = $input{'cvsroot'};
139: $cvsroot = $CVSROOT{"$cvstree"};
140: }
141: }
1.11 wosch 142: do "$config-$cvstree" if -f "$config-$cvstree";
1.10 wosch 143:
144: $fullname = $cvsroot . '/' . $where;
1.12 fenner 145:
1.10 wosch 146: if (!-d $cvsroot) {
1.12 fenner 147: &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.');
1.10 wosch 148: }
149:
150:
1.16 wosch 151: {
152: local(@foo, $i);
153: local($scriptname) = $ENV{'SCRIPT_NAME'};
1.23 wosch 154: foreach (sort keys %CVSROOT) {
1.16 wosch 155: if (-d $CVSROOT{$_}) {
156: push(@foo, $_);
157: }
158: }
1.38 wosch 159: if ($#foo >= 1) {
1.27 hoek 160: $intro .= "<p>\nThis script supports the following CVS trees:\n";
1.16 wosch 161: for($i = 0; $i <= $#foo; $i++) {
162: $intro .= qq{<a href="$scriptname?cvsroot=$foo[$i]">} .
163: ($CVSROOTdescr{$foo[$i]} ?
164: $CVSROOTdescr{$foo[$i]} : $foo[$i]) . qq{</a>} .
165: ($i == $#foo ? ".\n" : ",\n");
1.24 wosch 166: }
167: }
168: }
169:
170:
171: {
172: local(@mirrors) = sort keys %mirrors;;
173: if ($#mirrors >= 0) {
174: $intro .= "<p>\nThis script is mirrored in:\n";
175: local($m);
176: for($m = 0; $m <= $#mirrors; $m++) {
177: $intro .= qq(<a href="$mirrors{$mirrors[$m]}">$mirrors[$m]</a>);
178: $intro .= ',' if $m != $#mirrors;
179: $intro .= "\n";
1.16 wosch 180: }
181: }
182: }
183:
184:
1.1 jfieber 185: if (-d $fullname) {
186: opendir(DIR, $fullname) || &fatal("404 Not Found","$where: $!");
187: @dir = readdir(DIR);
188: closedir(DIR);
189: if ($where eq '') {
1.2 jfieber 190: print &html_header("FreeBSD CVS Repository");
1.1 jfieber 191: print $intro;
192: } else {
1.2 jfieber 193: print &html_header("/$where");
1.1 jfieber 194: print $shortinstr;
195: }
1.16 wosch 196: print "<p>";
1.22 wosch 197: print "Current CVS tree: <b>",
198: ($CVSROOTdescr{"$cvstree"} ? $CVSROOTdescr{"$cvstree"} :
199: $cvstree), "</b><br>\n";
1.16 wosch 200: print "Current directory: <b>/$where</b>\n";
1.2 jfieber 201: print "<P><HR NOSHADE>\n";
1.1 jfieber 202: # Using <MENU> in this manner violates the HTML2.0 spec but
203: # provides the results that I want in most browsers. Another
204: # case of layout spooging up HTML.
205: print "<MENU>\n";
1.9 fenner 206: lookingforattic:
207: for ($i = 0; $i <= $#dir; $i++) {
208: if ($dir[$i] eq "Attic") {
209: last lookingforattic;
210: }
211: }
1.12 fenner 212: $haveattic = 1 if ($i <= $#dir);
1.9 fenner 213: if (!$input{"showattic"} && ($i <= $#dir) &&
214: opendir(DIR, $fullname . "/Attic")) {
215: splice(@dir, $i, 1,
216: grep((s|^|Attic/|,!m|/\.|), readdir(DIR)));
217: closedir(DIR);
218: }
219: # Sort without the Attic/ pathname.
220: foreach (sort {($c=$a)=~s|.*/||;($d=$b)=~s|.*/||;($c cmp $d)} @dir) {
1.1 jfieber 221: if ($_ eq '.') {
222: next;
223: }
1.19 wosch 224: # ignore CVS lock and stale NFS files
225: next if /^#cvs\.|^,|^\.nfs/;
1.18 wosch 226:
1.9 fenner 227: if (s|^Attic/||) {
228: $attic = " (in the Attic)";
229: } else {
230: $attic = "";
231: }
1.1 jfieber 232: if ($_ eq '..') {
233: next if ($where eq '');
234: ($updir = $scriptwhere) =~ s|[^/]+$||;
235: print "<IMG SRC=\"/icons/back.gif\"> ",
1.9 fenner 236: &link("Previous Directory",$updir . $query), "<BR>";
1.7 fenner 237: # print "<IMG SRC=???> ",
238: # &link("Directory-wide diffs", $scriptwhere . '/*'), "<BR>";
1.1 jfieber 239: } elsif (-d $fullname . "/" . $_) {
240: print "<IMG SRC=\"/icons/dir.gif\"> ",
1.12 fenner 241: &link($_ . "/", $scriptwhere . '/' . $_ . '/' . $query),
242: $attic, "<BR>";
1.1 jfieber 243: } elsif (s/,v$//) {
1.7 fenner 244: # TODO: add date/time? How about sorting?
1.1 jfieber 245: print "<IMG SRC=\"/icons/text.gif\"> ",
1.9 fenner 246: &link($_, $scriptwhere . '/' .
247: ($attic ? "Attic/" : "") . $_ . $query),
1.12 fenner 248: $attic, "<BR>";
1.1 jfieber 249: }
250: }
251: print "</MENU>\n";
1.9 fenner 252: if ($input{"only_on_branch"}) {
253: print "<HR><FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
254: print "Currently showing only branch $input{'only_on_branch'}.\n";
255: $input{"only_on_branch"}="";
256: foreach $k (keys %input) {
257: print "<INPUT TYPE=hidden NAME=$k VALUE=$input{$k}>\n" if $input{$k};
258: }
259: print "<INPUT TYPE=SUBMIT VALUE=\"Show all branches\">\n";
260: print "</FORM>\n";
261: }
262: $formwhere = $scriptwhere;
263: $formwhere =~ s|Attic/?$|| if ($input{"showattic"});
1.12 fenner 264: if ($haveattic) {
265: print "<HR><FORM METHOD=\"GET\" ACTION=\"${formwhere}\">\n";
266: $input{"showattic"}=!$input{"showattic"};
267: foreach $k (keys %input) {
268: print "<INPUT TYPE=hidden NAME=$k VALUE=$input{$k}>\n" if $input{$k};
269: }
270: print "<INPUT TYPE=SUBMIT VALUE=\"";
271: print ($input{"showattic"} ? "Show" : "Hide");
272: print " attic directories\">\n";
273: print "</FORM>\n";
274: }
1.2 jfieber 275: print &html_footer;
1.1 jfieber 276: print "</BODY></HTML>\n";
277: } elsif (-f $fullname . ',v') {
1.7 fenner 278: if ($input{'rev'} =~ /^[\d\.]+$/) {
279: &checkout($fullname, $input{'rev'});
280: exit;
281: }
282: if ($input{'r1'} && $input{'r2'}) {
283: &dodiff($fullname, $input{'r1'}, $input{'tr1'},
284: $input{'r2'}, $input{'tr2'}, $input{'f'});
1.1 jfieber 285: exit;
286: }
1.12 fenner 287: print("going to dolog($fullname)\n") if ($verbose);
288: &dolog($fullname);
289: } elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" &&
290: $input{'r1'} && $input{'r2'}) {
291: # Allow diffs using the ".diff" extension
292: # so that browsers that default to the URL
293: # for a save filename don't save diff's as
294: # e.g. foo.c
295: &dodiff($fullname, $input{'r1'}, $input{'tr1'},
296: $input{'r2'}, $input{'tr2'}, $input{'f'});
297: exit;
298: } elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| &&
299: -f $newname . ",v") {
300: # The file has been removed and is in the Attic.
301: # Send a redirect pointing to the file in the Attic.
302: ($newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
303: &redirect($newplace);
304: exit;
305: } elsif (0 && (@files = &safeglob($fullname . ",v"))) {
306: print "Content-type: text/plain\n\n";
307: print "You matched the following files:\n";
308: print join("\n", @files);
309: # Find the tags from each file
310: # Display a form offering diffs between said tags
311: } else {
312: # Assume it's a module name with a potential path following it.
1.13 fenner 313: $xtra = $& if (($module = $where) =~ s|/.*||);
1.12 fenner 314: # Is there an indexed version of modules?
315: if (open(MODULES, "$cvsroot/CVSROOT/modules")) {
316: while (<MODULES>) {
317: if (/^(\S+)\s+(\S+)/o && $module eq $1
318: && -d "${cvsroot}/$2" && $module ne $2) {
319: &redirect($scriptname . '/' . $2 . $xtra);
320: }
321: }
322: }
323: &fatal("404 Not Found","$where: no such file or directory");
324: }
325:
326: sub htmlify {
327: local($string, $pr) = @_;
328:
329: $string =~ s/&/&/g;
330: $string =~ s/</</g;
331: $string =~ s/>/>/g;
332:
333: if ($pr) {
1.41 hoek 334: $string =~ s!\b((pr[:#]?\s*#?)|((advocacy|alpha|bin|conf|docs|gnu|i386|kern|misc|ports|sparc)\/))(\d+)\b!<A HREF=http://www.FreeBSD.org/cgi/query-pr.cgi?pr=\5>$&</A>!ig;
1.12 fenner 335: }
336:
337: $string;
338: }
339:
340: sub link {
341: local($name, $where) = @_;
342:
343: "<A HREF=\"$where\">$name</A>\n";
344: }
345:
346: sub revcmp {
347: local($rev1, $rev2) = @_;
348: local(@r1) = split(/\./, $rev1);
349: local(@r2) = split(/\./, $rev2);
350: local($a,$b);
351:
352: while (($a = shift(@r1)) && ($b = shift(@r2))) {
353: if ($a != $b) {
354: return $a <=> $b;
355: }
356: }
357: if (@r1) { return 1; }
358: if (@r2) { return -1; }
359: return 0;
360: }
361:
362: sub fatal {
363: local($errcode, $errmsg) = @_;
364: print "Status: $errcode\n";
365: print &html_header("Error");
366: # print "Content-type: text/html\n";
367: # print "\n";
368: # print "<HTML><HEAD><TITLE>Error</TITLE></HEAD>\n";
369: # print "<BODY>Error: $errmsg</BODY></HTML>\n";
370: print "Error: $errmsg\n";
371: print &html_footer;
372: exit(1);
373: }
374:
375: sub redirect {
376: local($url) = @_;
377: print "Status: 301 Moved\n";
378: print "Location: $url\n";
379: print &html_header("Moved");
380: # print "Content-type: text/html\n";
381: # print "\n";
382: # print "<HTML><HEAD><TITLE>Moved</TITLE></HEAD>\n";
383: # print "<BODY>This document is located <A HREF=$url>here</A>.</BODY></HTML>\n";
384: print "This document is located <A HREF=$url>here</A>.\n";
385: print &html_footer;
386: exit(1);
387: }
388:
389: sub safeglob {
390: local($filename) = @_;
391: local($dirname);
392: local(@results);
393:
394: ($dirname = $filename) =~ s|/[^/]+$||;
395: $filename =~ s|.*/||;
396:
397: if (opendir(DIR, $dirname)) {
398: $glob = $filename;
399: # transform filename from glob to regex. Deal with:
400: # [, {, ?, * as glob chars
401: # make sure to escape all other regex chars
402: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
403: $glob =~ s/\*/.*/g;
404: $glob =~ s/\?/./g;
405: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
406: foreach (readdir(DIR)) {
407: if (/^${glob}$/) {
408: push(@results, $dirname . "/" .$_);
409: }
410: }
411: }
412:
413: @results;
414: }
415:
416: sub checkout {
417: local($fullname, $rev) = @_;
418:
1.44 knu 419: if (! open(RCS, "-|")) { # child
420: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
421: exec("co", "-p$rev", $fullname);
422: }
1.12 fenner 423: # /home/ncvs/src/sys/netinet/igmp.c,v --> standard output
424: # or
425: # /home/ncvs/src/sys/netinet/igmp.c,v --> stdout
426: # revision 1.1.1.2
427: # /*
428: $_ = <RCS>;
429: if (/^(\S+),v\s+-->\s+st(andar)?d ?out(put)?\s*$/o && $1 eq $fullname) {
430: # As expected
431: } else {
432: &fatal("500 Internal Error",
433: "Unexpected output from co: $_");
434: }
435: $_ = <RCS>;
1.29 fenner 436: if ($rev eq ".") {
437: # latest rev requested, don't check
438: } elsif (/^revision\s+$rev\s*$/) {
1.12 fenner 439: # As expected
440: } else {
441: &fatal("500 Internal Error",
442: "Unexpected output from co: $_");
443: }
444: $| = 1;
445: print "Content-type: text/plain\n\n";
446: print <RCS>;
447: close(RCS);
448: }
449:
450: sub dodiff {
451: local($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
452:
453: if ($r1 =~ /([^:]+)(:(.+))?/) {
454: $rev1 = $1;
455: $sym1 = $3;
456: }
457: if ($rev1 eq 'text') {
458: $rev1 = $tr1;
459: }
460: if ($r2 =~ /([^:]+)(:(.+))?/) {
461: $rev2 = $1;
462: $sym2 = $3;
463: }
464: if ($rev2 eq 'text') {
465: $rev2 = $tr2;
466: }
467: if (!($rev1 =~ /^[\d\.]+$/) || !($rev2 =~ /^[\d\.]+$/)) {
468: &fatal("404 Not Found",
469: "Malformed query \"$ENV{'QUERY_STRING'}\"");
470: }
471: #
472: # rev1 and rev2 are now both numeric revisions.
473: # Thus we do a DWIM here and swap them if rev1 is after rev2.
474: # XXX should we warn about the fact that we do this?
475: if (&revcmp($rev1,$rev2) > 0) {
476: ($tmp1, $tmp2) = ($rev1, $sym1);
477: ($rev1, $sym1) = ($rev2, $sym2);
478: ($rev2, $sym2) = ($tmp1, $tmp2);
479: }
480: #
481: # XXX Putting '-p' here is a personal preference
482: if ($f eq 'c') {
1.45 ! knu 483: @difftype = ('-p', '-c');
1.12 fenner 484: $diffname = "Context diff";
485: } elsif ($f eq 's') {
1.45 ! knu 486: @difftype = ('--side-by-side', '--width=164');
1.12 fenner 487: $diffname = "Side by Side";
488: } else {
1.45 ! knu 489: @difftype = ('-p', '-u');
1.12 fenner 490: $diffname = "Unidiff";
491: }
492: # XXX should this just be text/plain
493: # or should it have an HTML header and then a <pre>
494: print "Content-type: text/plain\n\n";
1.44 knu 495: if (! open(RCSDIFF, "-|")) { # child
496: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
497: exec("rcsdiff", @difftype, "-r$rev1", "-r$rev2", $fullname);
498: }
1.12 fenner 499: #
500: #===================================================================
501: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
502: #retrieving revision 1.16
503: #retrieving revision 1.17
504: #diff -c -r1.16 -r1.17
505: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
506: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
507: #
508: # Ideas:
509: # - nuke the stderr output if it's what we expect it to be
510: # - Add "no differences found" if the diff command supplied no output.
511: #
512: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
513: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
514: # (bogus example, but...)
515: #
1.45 ! knu 516: if (grep($_ eq '-u', @difftype)) {
1.12 fenner 517: $f1 = '---';
518: $f2 = '\+\+\+';
519: } else {
520: $f1 = '\*\*\*';
521: $f2 = '---';
522: }
523: while (<RCSDIFF>) {
524: if (m|^$f1 $cvsroot|o) {
525: s|$cvsroot/||o;
526: if ($sym1) {
527: chop;
528: $_ .= " " . $sym1 . "\n";
529: }
530: } elsif (m|^$f2 $cvsroot|o) {
531: s|$cvsroot/||o;
532: if ($sym2) {
533: chop;
534: $_ .= " " . $sym2 . "\n";
535: }
536: }
537: print $_;
538: }
539: close(RCSDIFF);
540: }
541:
542: sub dolog {
543: local($fullname) = @_;
544: local($curbranch,$symnames); #...
545:
546: print("Going to rlog '$fullname'\n") if ($verbose);
1.44 knu 547: if (! open(RCS, "-|")) {
548: close(STDERR); # rlog may complain; ignore.
549: exec("rlog", $fullname);
550: }
1.1 jfieber 551: while (<RCS>) {
552: print if ($verbose);
1.8 fenner 553: if (/^branch:\s+([\d\.]+)/) {
554: $curbranch = $1;
555: }
1.1 jfieber 556: if ($symnames) {
557: if (/^\s+([^:]+):\s+([\d\.]+)/) {
558: $symrev{$1} = $2;
559: if ($revsym{$2}) {
560: $revsym{$2} .= ", ";
561: }
562: $revsym{$2} .= $1;
563: } else {
564: $symnames = 0;
565: }
566: } elsif (/^symbolic names/) {
567: $symnames = 1;
568: } elsif (/^-----/) {
569: last;
570: }
571: }
1.7 fenner 572:
573: if ($onlyonbranch = $input{'only_on_branch'}) {
574: ($onlyonbranch = $symrev{$onlyonbranch}) =~ s/\.0\././;
575: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
576: }
577:
1.1 jfieber 578: # each log entry is of the form:
579: # ----------------------------
580: # revision 3.7.1.1
581: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
582: # log info
583: # ----------------------------
584: logentry:
585: while (!/^=========/) {
586: $_ = <RCS>;
1.12 fenner 587: last logentry if (!defined($_)); # EOF
1.1 jfieber 588: print "R:", $_ if ($verbose);
589: if (/^revision ([\d\.]+)/) {
590: $rev = $1;
591: } elsif (/^========/ || /^----------------------------$/) {
592: next logentry;
593: } else {
1.12 fenner 594: # The rlog output is syntactically ambiguous. We must
595: # have guessed wrong about where the end of the last log
596: # message was.
597: # Since this is likely to happen when people put rlog output
598: # in their commit messages, don't even bother keeping
599: # these lines since we don't know what revision they go with
600: # any more.
601: next logentry;
602: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 603: }
604: $_ = <RCS>;
605: print "D:", $_ if ($verbose);
1.9 fenner 606: if (m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);|) {
1.1 jfieber 607: $yr = $1;
608: # damn 2-digit year routines
609: if ($yr > 100) {
610: $yr -= 1900;
611: }
612: $date{$rev} = &timelocal($6,$5,$4,$3,$2 - 1,$yr);
613: $author{$rev} = $7;
1.9 fenner 614: $state{$rev} = $8;
1.1 jfieber 615: } else {
616: &fatal("500 Internal Error", "Error parsing RCS output: $_");
617: }
618: line:
619: while (<RCS>) {
620: print "L:", $_ if ($verbose);
621: next line if (/^branches:\s/);
622: last line if (/^----------------------------$/ || /^=========/);
623: $log{$rev} .= $_;
624: }
625: print "E:", $_ if ($verbose);
626: }
627: close(RCS);
628: print "Done reading RCS file\n" if ($verbose);
629: #
630: # Sort the revisions into commit-date order.
631: @revorder = sort {$date{$b} <=> $date{$a}} keys %date;
632: print "Done sorting revisions\n" if ($verbose);
633: #
634: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 635: # branch, unless there is a branch tag in the RCS file in which case it's the
636: # highest revision on that branch. Find it by looking through @revorder; it
637: # is the first commit listed on the appropriate branch.
638: $headrev = $curbranch || "1";
1.1 jfieber 639: revision:
640: for ($i = 0; $i <= $#revorder; $i++) {
1.8 fenner 641: if ($revorder[$i] =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
1.1 jfieber 642: if ($revsym{$revorder[$i]}) {
643: $revsym{$revorder[$i]} .= ", ";
644: }
645: $revsym{$revorder[$i]} .= "HEAD";
646: $symrev{"HEAD"} = $revorder[$i];
647: last revision;
648: }
649: }
650: print "Done finding HEAD\n" if ($verbose);
651: #
652: # Now that we know all of the revision numbers, we can associate
653: # absolute revision numbers with all of the symbolic names, and
654: # pass them to the form so that the same association doesn't have
655: # to be built then.
656: #
657: # should make this a case-insensitive sort
658: foreach (sort keys %symrev) {
659: $rev = $symrev{$_};
660: if ($rev =~ /^(\d+(\.\d+)+)\.0\.(\d+)$/) {
1.7 fenner 661: push(@branchnames, $_);
1.1 jfieber 662: #
663: # A revision number of A.B.0.D really translates into
664: # "the highest current revision on branch A.B.D".
665: #
666: # If there is no branch A.B.D, then it translates into
667: # the head A.B .
668: #
669: $head = $1;
670: $branch = $3;
671: $regex = $head . "." . $branch;
672: $regex =~ s/\./\./g;
673: # <
674: # \____/
675: $rev = $head;
676:
677: revision:
678: foreach $r (@revorder) {
679: if ($r =~ /^${regex}/) {
680: $rev = $head . "." . $branch;
681: last revision;
682: }
683: }
684: $revsym{$rev} .= ", " if ($revsym{$rev});
685: $revsym{$rev} .= $_;
1.8 fenner 686: if ($rev ne $head) {
687: $branchpoint{$head} .= ", " if ($branchpoint{$head});
688: $branchpoint{$head} .= $_;
689: }
1.1 jfieber 690: }
691: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
692: }
693: print "Done associating revisions with branches\n" if ($verbose);
1.2 jfieber 694: print &html_header("CVS log for $where");
1.9 fenner 695: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
696: print "Up to ", &link($upwhere,$scriptname . "/" . $upwhere . $query);
1.1 jfieber 697: print "<BR>\n";
698: print "<A HREF=\"#diff\">Request diff between arbitrary revisions</A>\n";
1.2 jfieber 699: print "<HR NOSHADE>\n";
1.8 fenner 700: if ($curbranch) {
701: print "Default branch is ";
702: print ($revsym{$curbranch} || $curbranch);
703: } else {
704: print "No default branch";
705: }
706: print "<BR><HR NOSHADE>\n";
1.1 jfieber 707: # The other possible U.I. I can see is to have each revision be hot
708: # and have the first one you click do ?r1=foo
709: # and since there's no r2 it keeps going & the next one you click
710: # adds ?r2=foo and performs the query.
711: # I suppose there's no reason we can't try both and see which one
712: # people prefer...
713:
714: for ($i = 0; $i <= $#revorder; $i++) {
715: $_ = $revorder[$i];
1.7 fenner 716: ($br = $_) =~ s/\.\d+$//;
717: next if ($onlyonbranch && $br ne $onlyonbranch &&
718: $_ ne $onlybranchpoint);
1.4 fenner 719: print "<a NAME=\"rev$_\"></a>";
720: foreach $sym (split(", ", $revsym{$_})) {
721: print "<a NAME=\"$sym\"></a>";
722: }
723: if ($revsym{$br} && !$nameprinted{$br}) {
724: foreach $sym (split(", ", $revsym{$br})) {
725: print "<a NAME=\"$sym\"></a>";
726: }
727: $nameprinted{$br}++;
728: }
729: print "\n";
1.10 wosch 730: print "<A HREF=\"$scriptwhere?rev=$_" .
1.12 fenner 731: &cvsroot . "\"><b>$_</b></A>";
1.1 jfieber 732: if (/^1\.1\.1\.\d+$/) {
733: print " <i>(vendor branch)</i>";
734: }
1.14 wosch 735: print " <i>" . &ctime($date{$_}) . " UTC</i> by ";
1.35 wosch 736: print "<i>" . $author{$_} . "</i>\n";
1.1 jfieber 737: if ($revsym{$_}) {
738: print "<BR>CVS Tags: <b>$revsym{$_}</b>";
739: }
1.4 fenner 740: if ($revsym{$br}) {
1.1 jfieber 741: if ($revsym{$_}) {
742: print "; ";
743: } else {
744: print "<BR>";
745: }
1.8 fenner 746: print "Branch: <b>$revsym{$br}</b>\n";
747: }
748: if ($branchpoint{$_}) {
749: if ($revsym{$br} || $revsym{$_}) {
750: print "; ";
751: } else {
752: print "<BR>";
753: }
754: print "Branch point for: <b>$branchpoint{$_}</b>\n";
1.1 jfieber 755: }
756: # Find the previous revision on this branch.
757: @prevrev = split(/\./, $_);
758: if (--$prevrev[$#prevrev] == 0) {
759: # If it was X.Y.Z.1, just make it X.Y
760: if ($#prevrev > 1) {
761: pop(@prevrev);
762: pop(@prevrev);
763: } else {
764: # It was rev 1.1 (XXX does CVS use revisions
765: # greater than 1.x?)
766: if ($prevrev[0] != 1) {
767: print "<i>* I can't figure out the previous revision! *</i>\n";
768: }
769: }
770: }
771: if ($prevrev[$#prevrev] != 0) {
772: $prev = join(".", @prevrev);
1.7 fenner 773: print "<BR><A HREF=\"${scriptwhere}.diff?r1=$prev";
1.12 fenner 774: print "&r2=$_" . &cvsroot . "\">Diffs to $prev</A>\n";
1.1 jfieber 775: #
776: # Plus, if it's on a branch, and it's not a vendor branch,
777: # offer to diff with the immediately-preceding commit if it
778: # is not the previous revision as calculated above
779: # and if it is on the HEAD (or at least on a higher branch)
780: # (e.g. change gets committed and then brought
781: # over to -stable)
782: if (!/^1\.1\.1\.\d+$/ && ($i != $#revorder) &&
783: ($prev ne $revorder[$i+1])) {
784: @tmp1 = split(/\./, $revorder[$i+1]);
785: @tmp2 = split(/\./, $_);
786: if ($#tmp1 < $#tmp2) {
1.7 fenner 787: print "; <A HREF=\"${scriptwhere}.diff?r1=$revorder[$i+1]";
1.10 wosch 788: print "&r2=$_" . &cvsroot .
1.12 fenner 789: "\">Diffs to $revorder[$i+1]</A>\n";
1.1 jfieber 790: }
791: }
792: }
1.9 fenner 793: if ($state{$_} eq "dead") {
794: print "<BR><B><I>FILE REMOVED</I></B>\n";
795: }
1.1 jfieber 796: print "<PRE>\n";
1.7 fenner 797: print &htmlify($log{$_}, 1);
1.2 jfieber 798: print "</PRE><HR NOSHADE>\n";
1.1 jfieber 799: }
800: print "<A NAME=diff>\n";
801: print "This form allows you to request diff's between any two\n";
802: print "revisions of a file. You may select a symbolic revision\n";
803: print "name using the selection box or you may type in a numeric\n";
804: print "name using the type-in text box.\n";
805: print "</A><P>\n";
1.7 fenner 806: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\">\n";
1.12 fenner 807: print "<INPUT TYPE=HIDDEN NAME=\"cvsroot\" VALUE=\"$cvstree\">\n"
1.10 wosch 808: if &cvsroot;
1.1 jfieber 809: print "Diffs between \n";
810: print "<SELECT NAME=\"r1\">\n";
811: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
812: print $sel;
813: print "</SELECT>\n";
814: print "<INPUT TYPE=\"TEXT\" NAME=\"tr1\" VALUE=\"$revorder[$#revorder]\">\n";
815: print " and \n";
816: print "<SELECT NAME=\"r2\">\n";
817: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
818: print $sel;
819: print "</SELECT>\n";
820: print "<INPUT TYPE=\"TEXT\" NAME=\"tr2\" VALUE=\"$revorder[0]\">\n";
821: print "<BR><INPUT TYPE=RADIO NAME=\"f\" VALUE=u CHECKED>Unidiff<br>\n";
822: print "<INPUT TYPE=RADIO NAME=\"f\" VALUE=c>Context diff<br>\n";
1.7 fenner 823: print "<INPUT TYPE=RADIO NAME=\"f\" VALUE=s>Side-by-Side<br>\n";
1.1 jfieber 824: print "<INPUT TYPE=SUBMIT VALUE=\"Get Diffs\">\n";
825: print "</FORM>\n";
1.7 fenner 826: print "<HR noshade>\n";
827: print "<A name=branch>\n";
828: print "You may select to see revision information from only\n";
829: print "a single branch.\n";
830: print "</A><P>\n";
831: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
1.10 wosch 832: print qq{<input type=hidden name=cvsroot value=$cvstree>\n}
833: if &cvsroot;
1.7 fenner 834: print "Branch: \n";
835: print "<SELECT NAME=\"only_on_branch\">\n";
1.9 fenner 836: print "<OPTION VALUE=\"\"";
837: print " SELECTED" if ($input{"only_on_branch"} eq "");
838: print ">Show all branches\n";
1.7 fenner 839: foreach (sort @branchnames) {
1.9 fenner 840: print "<OPTION";
841: print " SELECTED" if ($input{"only_on_branch"} eq $_);
842: print ">${_}\n";
1.7 fenner 843: }
844: print "</SELECT>\n";
845: print "<INPUT TYPE=SUBMIT VALUE=\"View Branch\">\n";
846: print "</FORM>\n";
1.2 jfieber 847: print &html_footer;
1.1 jfieber 848: print "</BODY></HTML>\n";
1.10 wosch 849: }
850:
851: sub cvsroot {
852: return '' if $cvstree eq $cvstreedefault;
853: return "&cvsroot=" . $cvstree;
1.1 jfieber 854: }
CVSweb