Annotation of cvsweb/cvsweb.cgi, Revision 1.24
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.24 ! wosch 31: # $fId: cvsweb.cgi,v 1.23 1998/08/15 09:59:11 wosch 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',
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.24 ! wosch 74: %mirrors = (
! 75: 'Germany', 'http://www.de.freebsd.org/cgi/cvsweb.cgi',
! 76: 'Japan', 'http://www.jp.freebsd.org/www.freebsd.org/cgi/cvsweb.cgi',
! 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) {
158: $intro .= "<p>\nThis script support the following CVS trees:\n";
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) {
332: $string =~ s|\bpr(\W+[a-z]+/\W*)(\d+)|<A HREF=/cgi/query-pr.cgi?pr=$2>$&</A>|ig;
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>;
432: if (/^revision\s+$rev\s*$/) {
433: # As expected
434: } else {
435: &fatal("500 Internal Error",
436: "Unexpected output from co: $_");
437: }
438: $| = 1;
439: print "Content-type: text/plain\n\n";
440: print <RCS>;
441: close(RCS);
442: }
443:
444: sub dodiff {
445: local($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
446:
447: if ($r1 =~ /([^:]+)(:(.+))?/) {
448: $rev1 = $1;
449: $sym1 = $3;
450: }
451: if ($rev1 eq 'text') {
452: $rev1 = $tr1;
453: }
454: if ($r2 =~ /([^:]+)(:(.+))?/) {
455: $rev2 = $1;
456: $sym2 = $3;
457: }
458: if ($rev2 eq 'text') {
459: $rev2 = $tr2;
460: }
461: if (!($rev1 =~ /^[\d\.]+$/) || !($rev2 =~ /^[\d\.]+$/)) {
462: &fatal("404 Not Found",
463: "Malformed query \"$ENV{'QUERY_STRING'}\"");
464: }
465: #
466: # rev1 and rev2 are now both numeric revisions.
467: # Thus we do a DWIM here and swap them if rev1 is after rev2.
468: # XXX should we warn about the fact that we do this?
469: if (&revcmp($rev1,$rev2) > 0) {
470: ($tmp1, $tmp2) = ($rev1, $sym1);
471: ($rev1, $sym1) = ($rev2, $sym2);
472: ($rev2, $sym2) = ($tmp1, $tmp2);
473: }
474: #
475: # XXX Putting '-p' here is a personal preference
476: if ($f eq 'c') {
477: $difftype = '-p -c';
478: $diffname = "Context diff";
479: } elsif ($f eq 's') {
480: $difftype = '--side-by-side --width=164';
481: $diffname = "Side by Side";
482: } else {
483: $difftype = '-p -u';
484: $diffname = "Unidiff";
485: }
486: # XXX should this just be text/plain
487: # or should it have an HTML header and then a <pre>
488: print "Content-type: text/plain\n\n";
489: open(RCSDIFF, "rcsdiff $difftype -r$rev1 -r$rev2 '$fullname' 2>&1 |") ||
490: &fail("500 Internal Error", "Couldn't rcsdiff: $!");
491: #
492: #===================================================================
493: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
494: #retrieving revision 1.16
495: #retrieving revision 1.17
496: #diff -c -r1.16 -r1.17
497: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
498: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
499: #
500: # Ideas:
501: # - nuke the stderr output if it's what we expect it to be
502: # - Add "no differences found" if the diff command supplied no output.
503: #
504: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
505: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
506: # (bogus example, but...)
507: #
508: if ($difftype eq '-u') {
509: $f1 = '---';
510: $f2 = '\+\+\+';
511: } else {
512: $f1 = '\*\*\*';
513: $f2 = '---';
514: }
515: while (<RCSDIFF>) {
516: if (m|^$f1 $cvsroot|o) {
517: s|$cvsroot/||o;
518: if ($sym1) {
519: chop;
520: $_ .= " " . $sym1 . "\n";
521: }
522: } elsif (m|^$f2 $cvsroot|o) {
523: s|$cvsroot/||o;
524: if ($sym2) {
525: chop;
526: $_ .= " " . $sym2 . "\n";
527: }
528: }
529: print $_;
530: }
531: close(RCSDIFF);
532: }
533:
534: sub dolog {
535: local($fullname) = @_;
536: local($curbranch,$symnames); #...
537:
538: print("Going to rlog '$fullname'\n") if ($verbose);
1.1 jfieber 539: open(RCS, "rlog '$fullname'|") || &fatal("500 Internal Error",
540: "Failed to spawn rlog");
541: while (<RCS>) {
542: print if ($verbose);
1.8 fenner 543: if (/^branch:\s+([\d\.]+)/) {
544: $curbranch = $1;
545: }
1.1 jfieber 546: if ($symnames) {
547: if (/^\s+([^:]+):\s+([\d\.]+)/) {
548: $symrev{$1} = $2;
549: if ($revsym{$2}) {
550: $revsym{$2} .= ", ";
551: }
552: $revsym{$2} .= $1;
553: } else {
554: $symnames = 0;
555: }
556: } elsif (/^symbolic names/) {
557: $symnames = 1;
558: } elsif (/^-----/) {
559: last;
560: }
561: }
1.7 fenner 562:
563: if ($onlyonbranch = $input{'only_on_branch'}) {
564: ($onlyonbranch = $symrev{$onlyonbranch}) =~ s/\.0\././;
565: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
566: }
567:
1.1 jfieber 568: # each log entry is of the form:
569: # ----------------------------
570: # revision 3.7.1.1
571: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
572: # log info
573: # ----------------------------
574: logentry:
575: while (!/^=========/) {
576: $_ = <RCS>;
1.12 fenner 577: last logentry if (!defined($_)); # EOF
1.1 jfieber 578: print "R:", $_ if ($verbose);
579: if (/^revision ([\d\.]+)/) {
580: $rev = $1;
581: } elsif (/^========/ || /^----------------------------$/) {
582: next logentry;
583: } else {
1.12 fenner 584: # The rlog output is syntactically ambiguous. We must
585: # have guessed wrong about where the end of the last log
586: # message was.
587: # Since this is likely to happen when people put rlog output
588: # in their commit messages, don't even bother keeping
589: # these lines since we don't know what revision they go with
590: # any more.
591: next logentry;
592: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 593: }
594: $_ = <RCS>;
595: print "D:", $_ if ($verbose);
1.9 fenner 596: if (m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);|) {
1.1 jfieber 597: $yr = $1;
598: # damn 2-digit year routines
599: if ($yr > 100) {
600: $yr -= 1900;
601: }
602: $date{$rev} = &timelocal($6,$5,$4,$3,$2 - 1,$yr);
603: $author{$rev} = $7;
1.9 fenner 604: $state{$rev} = $8;
1.1 jfieber 605: } else {
606: &fatal("500 Internal Error", "Error parsing RCS output: $_");
607: }
608: line:
609: while (<RCS>) {
610: print "L:", $_ if ($verbose);
611: next line if (/^branches:\s/);
612: last line if (/^----------------------------$/ || /^=========/);
613: $log{$rev} .= $_;
614: }
615: print "E:", $_ if ($verbose);
616: }
617: close(RCS);
618: print "Done reading RCS file\n" if ($verbose);
619: #
620: # Sort the revisions into commit-date order.
621: @revorder = sort {$date{$b} <=> $date{$a}} keys %date;
622: print "Done sorting revisions\n" if ($verbose);
623: #
624: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 625: # branch, unless there is a branch tag in the RCS file in which case it's the
626: # highest revision on that branch. Find it by looking through @revorder; it
627: # is the first commit listed on the appropriate branch.
628: $headrev = $curbranch || "1";
1.1 jfieber 629: revision:
630: for ($i = 0; $i <= $#revorder; $i++) {
1.8 fenner 631: if ($revorder[$i] =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
1.1 jfieber 632: if ($revsym{$revorder[$i]}) {
633: $revsym{$revorder[$i]} .= ", ";
634: }
635: $revsym{$revorder[$i]} .= "HEAD";
636: $symrev{"HEAD"} = $revorder[$i];
637: last revision;
638: }
639: }
640: print "Done finding HEAD\n" if ($verbose);
641: #
642: # Now that we know all of the revision numbers, we can associate
643: # absolute revision numbers with all of the symbolic names, and
644: # pass them to the form so that the same association doesn't have
645: # to be built then.
646: #
647: # should make this a case-insensitive sort
648: foreach (sort keys %symrev) {
649: $rev = $symrev{$_};
650: if ($rev =~ /^(\d+(\.\d+)+)\.0\.(\d+)$/) {
1.7 fenner 651: push(@branchnames, $_);
1.1 jfieber 652: #
653: # A revision number of A.B.0.D really translates into
654: # "the highest current revision on branch A.B.D".
655: #
656: # If there is no branch A.B.D, then it translates into
657: # the head A.B .
658: #
659: $head = $1;
660: $branch = $3;
661: $regex = $head . "." . $branch;
662: $regex =~ s/\./\./g;
663: # <
664: # \____/
665: $rev = $head;
666:
667: revision:
668: foreach $r (@revorder) {
669: if ($r =~ /^${regex}/) {
670: $rev = $head . "." . $branch;
671: last revision;
672: }
673: }
674: $revsym{$rev} .= ", " if ($revsym{$rev});
675: $revsym{$rev} .= $_;
1.8 fenner 676: if ($rev ne $head) {
677: $branchpoint{$head} .= ", " if ($branchpoint{$head});
678: $branchpoint{$head} .= $_;
679: }
1.1 jfieber 680: }
681: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
682: }
683: print "Done associating revisions with branches\n" if ($verbose);
1.2 jfieber 684: print &html_header("CVS log for $where");
1.9 fenner 685: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
686: print "Up to ", &link($upwhere,$scriptname . "/" . $upwhere . $query);
1.1 jfieber 687: print "<BR>\n";
688: print "<A HREF=\"#diff\">Request diff between arbitrary revisions</A>\n";
1.2 jfieber 689: print "<HR NOSHADE>\n";
1.8 fenner 690: if ($curbranch) {
691: print "Default branch is ";
692: print ($revsym{$curbranch} || $curbranch);
693: } else {
694: print "No default branch";
695: }
696: print "<BR><HR NOSHADE>\n";
1.1 jfieber 697: # The other possible U.I. I can see is to have each revision be hot
698: # and have the first one you click do ?r1=foo
699: # and since there's no r2 it keeps going & the next one you click
700: # adds ?r2=foo and performs the query.
701: # I suppose there's no reason we can't try both and see which one
702: # people prefer...
703:
704: for ($i = 0; $i <= $#revorder; $i++) {
705: $_ = $revorder[$i];
1.7 fenner 706: ($br = $_) =~ s/\.\d+$//;
707: next if ($onlyonbranch && $br ne $onlyonbranch &&
708: $_ ne $onlybranchpoint);
1.4 fenner 709: print "<a NAME=\"rev$_\"></a>";
710: foreach $sym (split(", ", $revsym{$_})) {
711: print "<a NAME=\"$sym\"></a>";
712: }
713: if ($revsym{$br} && !$nameprinted{$br}) {
714: foreach $sym (split(", ", $revsym{$br})) {
715: print "<a NAME=\"$sym\"></a>";
716: }
717: $nameprinted{$br}++;
718: }
719: print "\n";
1.10 wosch 720: print "<A HREF=\"$scriptwhere?rev=$_" .
1.12 fenner 721: &cvsroot . "\"><b>$_</b></A>";
1.1 jfieber 722: if (/^1\.1\.1\.\d+$/) {
723: print " <i>(vendor branch)</i>";
724: }
1.14 wosch 725: print " <i>" . &ctime($date{$_}) . " UTC</i> by ";
1.1 jfieber 726: print "<i>" . $author{$_} . "</i>\n";
727: if ($revsym{$_}) {
728: print "<BR>CVS Tags: <b>$revsym{$_}</b>";
729: }
1.4 fenner 730: if ($revsym{$br}) {
1.1 jfieber 731: if ($revsym{$_}) {
732: print "; ";
733: } else {
734: print "<BR>";
735: }
1.8 fenner 736: print "Branch: <b>$revsym{$br}</b>\n";
737: }
738: if ($branchpoint{$_}) {
739: if ($revsym{$br} || $revsym{$_}) {
740: print "; ";
741: } else {
742: print "<BR>";
743: }
744: print "Branch point for: <b>$branchpoint{$_}</b>\n";
1.1 jfieber 745: }
746: # Find the previous revision on this branch.
747: @prevrev = split(/\./, $_);
748: if (--$prevrev[$#prevrev] == 0) {
749: # If it was X.Y.Z.1, just make it X.Y
750: if ($#prevrev > 1) {
751: pop(@prevrev);
752: pop(@prevrev);
753: } else {
754: # It was rev 1.1 (XXX does CVS use revisions
755: # greater than 1.x?)
756: if ($prevrev[0] != 1) {
757: print "<i>* I can't figure out the previous revision! *</i>\n";
758: }
759: }
760: }
761: if ($prevrev[$#prevrev] != 0) {
762: $prev = join(".", @prevrev);
1.7 fenner 763: print "<BR><A HREF=\"${scriptwhere}.diff?r1=$prev";
1.12 fenner 764: print "&r2=$_" . &cvsroot . "\">Diffs to $prev</A>\n";
1.1 jfieber 765: #
766: # Plus, if it's on a branch, and it's not a vendor branch,
767: # offer to diff with the immediately-preceding commit if it
768: # is not the previous revision as calculated above
769: # and if it is on the HEAD (or at least on a higher branch)
770: # (e.g. change gets committed and then brought
771: # over to -stable)
772: if (!/^1\.1\.1\.\d+$/ && ($i != $#revorder) &&
773: ($prev ne $revorder[$i+1])) {
774: @tmp1 = split(/\./, $revorder[$i+1]);
775: @tmp2 = split(/\./, $_);
776: if ($#tmp1 < $#tmp2) {
1.7 fenner 777: print "; <A HREF=\"${scriptwhere}.diff?r1=$revorder[$i+1]";
1.10 wosch 778: print "&r2=$_" . &cvsroot .
1.12 fenner 779: "\">Diffs to $revorder[$i+1]</A>\n";
1.1 jfieber 780: }
781: }
782: }
1.9 fenner 783: if ($state{$_} eq "dead") {
784: print "<BR><B><I>FILE REMOVED</I></B>\n";
785: }
1.1 jfieber 786: print "<PRE>\n";
1.7 fenner 787: print &htmlify($log{$_}, 1);
1.2 jfieber 788: print "</PRE><HR NOSHADE>\n";
1.1 jfieber 789: }
790: print "<A NAME=diff>\n";
791: print "This form allows you to request diff's between any two\n";
792: print "revisions of a file. You may select a symbolic revision\n";
793: print "name using the selection box or you may type in a numeric\n";
794: print "name using the type-in text box.\n";
795: print "</A><P>\n";
1.7 fenner 796: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\">\n";
1.12 fenner 797: print "<INPUT TYPE=HIDDEN NAME=\"cvsroot\" VALUE=\"$cvstree\">\n"
1.10 wosch 798: if &cvsroot;
1.1 jfieber 799: print "Diffs between \n";
800: print "<SELECT NAME=\"r1\">\n";
801: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
802: print $sel;
803: print "</SELECT>\n";
804: print "<INPUT TYPE=\"TEXT\" NAME=\"tr1\" VALUE=\"$revorder[$#revorder]\">\n";
805: print " and \n";
806: print "<SELECT NAME=\"r2\">\n";
807: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
808: print $sel;
809: print "</SELECT>\n";
810: print "<INPUT TYPE=\"TEXT\" NAME=\"tr2\" VALUE=\"$revorder[0]\">\n";
811: print "<BR><INPUT TYPE=RADIO NAME=\"f\" VALUE=u CHECKED>Unidiff<br>\n";
812: print "<INPUT TYPE=RADIO NAME=\"f\" VALUE=c>Context diff<br>\n";
1.7 fenner 813: print "<INPUT TYPE=RADIO NAME=\"f\" VALUE=s>Side-by-Side<br>\n";
1.1 jfieber 814: print "<INPUT TYPE=SUBMIT VALUE=\"Get Diffs\">\n";
815: print "</FORM>\n";
1.7 fenner 816: print "<HR noshade>\n";
817: print "<A name=branch>\n";
818: print "You may select to see revision information from only\n";
819: print "a single branch.\n";
820: print "</A><P>\n";
821: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
1.10 wosch 822: print qq{<input type=hidden name=cvsroot value=$cvstree>\n}
823: if &cvsroot;
1.7 fenner 824: print "Branch: \n";
825: print "<SELECT NAME=\"only_on_branch\">\n";
1.9 fenner 826: print "<OPTION VALUE=\"\"";
827: print " SELECTED" if ($input{"only_on_branch"} eq "");
828: print ">Show all branches\n";
1.7 fenner 829: foreach (sort @branchnames) {
1.9 fenner 830: print "<OPTION";
831: print " SELECTED" if ($input{"only_on_branch"} eq $_);
832: print ">${_}\n";
1.7 fenner 833: }
834: print "</SELECT>\n";
835: print "<INPUT TYPE=SUBMIT VALUE=\"View Branch\">\n";
836: print "</FORM>\n";
1.2 jfieber 837: print &html_footer;
1.1 jfieber 838: print "</BODY></HTML>\n";
1.10 wosch 839: }
840:
841: sub cvsroot {
842: return '' if $cvstree eq $cvstreedefault;
843: return "&cvsroot=" . $cvstree;
1.1 jfieber 844: }
CVSweb