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