[BACK]Return to cvsweb.cgi CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / cvsweb

Annotation of cvsweb/cvsweb.cgi, Revision 1.42

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

CVSweb