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

Annotation of cvsweb/cvsweb.cgi, Revision 1.35

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

CVSweb