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

Annotation of cvsweb/cvsweb.cgi, Revision 1.22

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

CVSweb