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