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