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