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