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