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