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