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