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

Annotation of cvsweb/cvsweb.cgi, Revision 1.29

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

CVSweb