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

Annotation of cvsweb/cvsweb.cgi, Revision 1.10

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

CVSweb