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