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

Annotation of cvsweb/cvsweb.cgi, Revision 1.20

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

CVSweb