Annotation of cvsweb/cvsweb.cgi, Revision 3.4
3.1 knu 1: #!/usr/bin/perl -ws
1.1 jfieber 2: #
3.1 knu 3: # cvsweb - a CGI interface to CVS trees.
1.1 jfieber 4: #
3.1 knu 5: # Written in their spare time by
6: # Bill Fenner <fenner@FreeBSD.org> (original work)
7: # extended by Henner Zeller <zeller@think.de>,
8: # Henrik Nordstrom <hno@hem.passagen.se>
9: # Ken Coar <coar@Apache.Org>
10: # Dick Balaska <dick@buckosoft.com>
11: # Akinori MUSHA <knu@FreeBSD.org>
12: #
13: # Based on:
14: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
15: # http://www.freebsd.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1 jfieber 16: #
1.21 wosch 17: # Copyright (c) 1996-1998 Bill Fenner
3.1 knu 18: # (c) 1998-1999 Henner Zeller
19: # (c) 1999 Henrik Nordstrom
20: # (c) 2000 Akinori MUSHA
1.21 wosch 21: # All rights reserved.
22: #
23: # Redistribution and use in source and binary forms, with or without
24: # modification, are permitted provided that the following conditions
25: # are met:
26: # 1. Redistributions of source code must retain the above copyright
27: # notice, this list of conditions and the following disclaimer.
28: # 2. Redistributions in binary form must reproduce the above copyright
29: # notice, this list of conditions and the following disclaimer in the
30: # documentation and/or other materials provided with the distribution.
31: #
32: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
33: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
36: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42: # SUCH DAMAGE.
43: #
3.4 ! knu 44: # $Id: cvsweb.cgi,v 3.3 2000/07/27 16:16:41 knu Exp $
1.21 wosch 45: #
3.1 knu 46: ###
47:
48: use strict;
1.21 wosch 49:
3.1 knu 50: use vars qw (
51: $config $allow_version_select $verbose
52: %CVSROOT %CVSROOTdescr %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
53: %alltags @tabcolors %fileinfo %tags @branchnames %nameprinted
54: %symrev %revsym @allrevisions %date %author @revdisplayorder
55: @revisions %state %difflines %log %branchpoint @revorder $prcgi
56: @prcategories $prcategories
57: $checkoutMagic $doCheckout $scriptname $scriptwhere
3.3 knu 58: $where $pathinfo $Browser $nofilelinks $maycompress @stickyvars
59: %funcline_regexp $is_mod_perl
60: $is_lynx $is_msie $is_mozilla3
3.1 knu 61: %input $query $barequery $sortby $bydate $byrev $byauthor
62: $bylog $byfile $hr_default $logsort $cvstree $cvsroot
63: $mimetype $defaultTextPlain $defaultViewable $allow_compress
64: $GZIPBIN $backicon $diricon $fileicon $fullname $newname
65: $cvstreedefault $body_tag $logo $defaulttitle $address
66: $backcolor $long_intro $short_instruction $shortLogLen
67: $show_author $dirtable $tablepadding $columnHeaderColorDefault
3.3 knu 68: $columnHeaderColorSorted $hr_breakable $showfunc $hr_ignwhite
3.1 knu 69: $hr_ignkeysubst $diffcolorHeading $diffcolorEmpty $diffcolorRemove
70: $diffcolorChange $diffcolorAdd $diffcolorDarkChange $difffontface
71: $difffontsize $inputTextSize $mime_types $allow_annotate
72: $allow_markup $use_java_script $open_extern_window
73: $extern_window_width $extern_window_height $edit_option_form
74: $checkout_magic $show_subdir_lastmod $show_log_in_markup $v
75: $navigationHeaderColor $tableBorderColor $markupLogColor
76: $tabstop $state $annTable $sel $curbranch @HideModules
77: $module $use_descriptions %descriptions @mytz $dwhere $moddate
78: $use_moddate
79: );
80:
81: ##### Start of Configuration Area ########
82: # == EDIT this ==
83: # User configuration is stored in
3.3 knu 84: $config = defined($ENV{CVSWEB_CONFIG}) ? $ENV{CVSWEB_CONFIG} : '/usr/local/etc/cvsweb.conf';
3.1 knu 85:
86: # == Configuration defaults ==
87: # Defaults for configuration variables that shouldn't need
88: # to be configured..
89: $allow_version_select = 1;
90:
91: ##### End of Configuration Area ########
92:
93: ######## Configuration variables #########
94: # These are defined to allow checking with perl -cw
95: %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS = %MTYPES =
96: %tags = %alltags = @tabcolors = ();
97: $cvstreedefault = $body_tag = $logo = $defaulttitle = $address =
98: $backcolor = $long_intro = $short_instruction = $shortLogLen =
99: $show_author = $dirtable = $tablepadding = $columnHeaderColorDefault =
3.3 knu 100: $columnHeaderColorSorted = $hr_breakable = $showfunc = $hr_ignwhite =
3.1 knu 101: $hr_ignkeysubst = $diffcolorHeading = $diffcolorEmpty = $diffcolorRemove =
102: $diffcolorChange = $diffcolorAdd = $diffcolorDarkChange = $difffontface =
103: $difffontsize = $inputTextSize = $mime_types = $allow_annotate =
104: $allow_markup = $use_java_script = $open_extern_window =
105: $extern_window_width = $extern_window_height = $edit_option_form =
106: $checkout_magic = $show_subdir_lastmod = $show_log_in_markup = $v =
107: $navigationHeaderColor = $tableBorderColor = $markupLogColor =
108: $tabstop = $use_moddate = $moddate = undef;
1.21 wosch 109:
3.1 knu 110: ##### End of configuration variables #####
111:
112: use Time::Local;
113: use IPC::Open2;
1.1 jfieber 114:
115: $verbose = $v;
3.1 knu 116: $checkoutMagic = "~checkout~";
3.3 knu 117: $pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
118: $where = $pathinfo;
3.1 knu 119: $doCheckout = ($where =~ /^\/$checkoutMagic/);
120: $where =~ s|^/($checkoutMagic)?||;
121: $where =~ s|/+$||;
3.3 knu 122: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
123: $scriptname =~ s|^/?|/|;
3.1 knu 124: $scriptname =~ s|/+$||;
3.3 knu 125: $scriptwhere = $scriptname;
3.1 knu 126: if ($where) {
3.3 knu 127: $scriptwhere .= '/' . urlencode($where);
3.1 knu 128: }
3.3 knu 129:
130: $is_mod_perl = defined($ENV{MOD_PERL});
3.1 knu 131:
132: # in lynx, it it very annoying to have two links
133: # per file, so disable the link at the icon
134: # in this case:
3.3 knu 135: $Browser = $ENV{HTTP_USER_AGENT} || '';
136: $is_lynx = ($Browser =~ m`^Lynx/`);
137: $is_msie = ($Browser =~ m`MSIE`);
138: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3456789]`);
139:
140: $nofilelinks = $is_lynx;
3.1 knu 141:
142: # newer browsers accept gzip content encoding
143: # and state this in a header
144: # (netscape did always but didn't state it)
145: # It has been reported that these
146: # braindamaged MS-Internet Exploders claim that they
147: # accept gzip .. but don't in fact and
148: # display garbage then :-/
149: # Turn off gzip if running under mod_perl. piping does
150: # not work as expected inside the server. One can probably
151: # achieve the same result using Apache::GZIPFilter.
3.3 knu 152: $maycompress =(($ENV{HTTP_ACCEPT_ENCODING} =~ m`gzip`
153: || $is_mozilla3)
154: && !$is_msie
155: && !$is_mod_perl);
3.1 knu 156:
157: # put here the variables we need in order
158: # to hold our state - they will be added (with
159: # their current value) to any link/query string
160: # you construct
3.3 knu 161: @stickyvars = qw(cvsroot hideattic sortby logsort fonly_with_tag);
1.1 jfieber 162:
3.1 knu 163: if (-f $config) {
3.3 knu 164: do $config;
3.1 knu 165: }
166: else {
167: &fatal("500 Internal Error",
168: 'Configuration not found. Set the variable <code>$config</code> '
169: . 'in cvsweb.cgi, or the environment variable '
170: . '<code>CVSWEB_CONFIG</code>, to your <b>cvsweb.conf</b> '
171: . 'configuration file first.');
172: }
173:
174: undef %input;
3.3 knu 175: $query = $ENV{QUERY_STRING};
176:
177: if ($query ne '') {
1.9 fenner 178: foreach (split(/&/, $query)) {
1.7 fenner 179: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
180: if (/(\S+)=(.*)/) {
3.1 knu 181: $input{$1} = $2 if ($2 ne "");
182: }
183: else {
1.7 fenner 184: $input{$_}++;
185: }
186: }
187: }
1.10 wosch 188:
3.1 knu 189: # For backwards compability, set only_with_tag to only_on_branch if set.
190: $input{only_with_tag} = $input{only_on_branch}
191: if (defined($input{only_on_branch}));
1.10 wosch 192:
3.1 knu 193: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
1.10 wosch 194:
3.1 knu 195: foreach (keys %DEFAULTVALUE)
196: {
197: # replace not given parameters with the default parameters
198: if (!defined($input{$_}) || $input{$_} eq "") {
199: # Empty Checkboxes in forms return -- nothing. So we define a helper
200: # variable in these forms (copt) which indicates that we just set
201: # parameters with a checkbox
202: if (!defined($input{"copt"})) {
203: # 'copt' isn't defined --> empty input is not the result
204: # of empty input checkbox --> set default
205: $input{$_} = $DEFAULTVALUE{$_} if (defined($DEFAULTVALUE{$_}));
206: }
207: else {
208: # 'copt' is defined -> the result of empty input checkbox
209: # -> set to zero (disable) if default is a boolean (0|1).
210: $input{$_} = 0
211: if (defined($DEFAULTVALUE{$_})
212: && ($DEFAULTVALUE{$_} eq "0" || $DEFAULTVALUE{$_} eq "1"));
213: }
1.10 wosch 214: }
215: }
3.1 knu 216:
217: $barequery = "";
218: foreach (@stickyvars) {
219: # construct a query string with the sticky non default parameters set
3.4 ! knu 220: if (defined($input{$_}) && $input{$_} ne '' &&
! 221: !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_})) {
! 222: if ($barequery) {
3.1 knu 223: $barequery = $barequery . "&";
224: }
225: my $thisval = urlencode($_) . "=" . urlencode($input{$_});
226: $barequery .= $thisval;
227: }
228: }
229: # is there any query ?
230: if ($barequery) {
231: $query = "?$barequery";
232: $barequery = "&" . $barequery;
233: }
234: else {
235: $query = "";
236: }
237:
238: # get actual parameters
239: $sortby = $input{"sortby"};
240: $bydate = 0;
241: $byrev = 0;
242: $byauthor = 0;
243: $bylog = 0;
244: $byfile = 0;
245: if ($sortby eq "date") {
246: $bydate = 1;
247: }
248: elsif ($sortby eq "rev") {
249: $byrev = 1;
250: }
251: elsif ($sortby eq "author") {
252: $byauthor = 1;
253: }
254: elsif ($sortby eq "log") {
255: $bylog = 1;
256: }
257: else {
258: $byfile = 1;
259: }
260:
261: $hr_default = $input{'f'} eq 'h';
262:
3.3 knu 263: $logsort = $input{'logsort'};
1.10 wosch 264:
1.12 fenner 265:
3.1 knu 266: ## Default CVS-Tree
267: if (!defined($CVSROOT{$cvstreedefault})) {
268: &fatal("500 Internal Error",
269: "<code>\$cvstreedefault</code> points to a repository "
270: . "not defined in <code>%CVSROOT</code> "
271: . "(edit your configuration file $config)");
272: }
273:
274: # alternate CVS-Tree, configured in cvsweb.conf
275: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
276: $cvstree = $input{'cvsroot'};
277: } else {
278: $cvstree = $cvstreedefault;
1.10 wosch 279: }
280:
3.1 knu 281: $cvsroot = $CVSROOT{$cvstree};
1.10 wosch 282:
3.1 knu 283: # create icons out of description
284: foreach my $k (keys %ICONS) {
285: no strict 'refs';
286: my ($itxt,$ipath,$iwidth,$iheight) = @{$ICONS{$k}};
287: if ($ipath) {
3.3 knu 288: ${"${k}icon"} = "<IMG SRC=\"$ipath\" ALT=\"$itxt\" BORDER=\"0\" WIDTH=\"$iwidth\" HEIGHT=\"$iheight\">";
1.16 wosch 289: }
3.1 knu 290: else {
3.3 knu 291: ${"${k}icon"} = $itxt;
1.24 wosch 292: }
293: }
294:
3.1 knu 295: # Do some special configuration for cvstrees
296: do "$config-$cvstree" if (-f "$config-$cvstree");
297:
298: $prcategories = '(?:' . join('|', @prcategories) . ')';
1.24 wosch 299:
3.1 knu 300: $fullname = $cvsroot . '/' . $where;
301: $mimetype = &getMimeTypeFromSuffix ($fullname);
302: $defaultTextPlain = ($mimetype eq "text/plain");
303: $defaultViewable = $allow_markup && viewable($mimetype);
304:
305: # search for GZIP if compression allowed
306: # We've to find out if the GZIP-binary exists .. otherwise
307: # ge get an Internal Server Error if we try to pipe the
308: # output through the nonexistent gzip ..
309: # any more elegant ways to prevent this are welcome!
310: if ($allow_compress && $maycompress) {
311: foreach (split(/:/, $ENV{PATH})) {
312: if (-x "$_/gzip") {
313: $GZIPBIN = "$_/gzip";
314: last;
1.16 wosch 315: }
316: }
317: }
318:
3.1 knu 319: if (-d $fullname) {
320: #
321: # ensure, that directories always end with (exactly) one '/'
322: # to allow relative URL's. If they're not, make a redirect.
323: ##
324: if (!($pathinfo =~ m|/$|) || ($pathinfo =~ m |/{2,}$|)) {
325: redirect ($scriptwhere . '/' . $query);
326: }
327: else {
328: $where .= '/';
329: $scriptwhere .= '/';
330: }
331: }
332:
333: if (!-d $cvsroot) {
334: &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.');
335: }
336:
337: #
338: # See if the module is in our forbidden list.
339: #
340: $where =~ m:([^/]*):;
341: $module = $1;
342: if ($module && &forbidden_module($module)) {
343: &fatal("403 Forbidden", "Access to $where forbidden.");
344: }
345: ##############################
346: # View a directory
347: ###############################
348: elsif (-d $fullname) {
349: my $dh = do {local(*DH);};
350: opendir($dh, $fullname) || &fatal("404 Not Found","$where: $!");
351: my @dir = readdir($dh);
352: closedir($dh);
353: my @subLevelFiles = findLastModifiedSubdirs(@dir)
354: if ($show_subdir_lastmod);
355: getDirLogs($cvsroot,$where,@subLevelFiles);
356:
357: if ($where eq '/') {
3.3 knu 358: html_header($defaulttitle);
3.2 knu 359: $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
3.1 knu 360: print $long_intro;
361: }
362: else {
3.3 knu 363: html_header($where);
3.1 knu 364: print $short_instruction;
365: }
366:
367: my $descriptions;
368: if (($use_descriptions) && open (DESC, "<$cvsroot/CVSROOT/descriptions")) {
369: while (<DESC>) {
370: chomp;
371: my ($dir,$description) = /(\S+)\s+(.*)/;
372: $descriptions{$dir} = $description;
373: }
374: }
375:
376: print "<P><a name=\"dirlist\"></a>\n";
377: # give direct access to dirs
378: if ($where eq '/') {
379: chooseMirror();
380: chooseCVSRoot();
381: }
382: else {
383: print "<p>Current directory: <b>", &clickablePath($where,0), "</b>\n";
384:
385: print "<P>Current tag: <B>", $input{only_with_tag}, "</b>\n" if
386: $input{only_with_tag};
1.16 wosch 387:
1.1 jfieber 388: }
3.1 knu 389:
390:
391: print "<HR NOSHADE>\n";
1.1 jfieber 392: # Using <MENU> in this manner violates the HTML2.0 spec but
393: # provides the results that I want in most browsers. Another
394: # case of layout spooging up HTML.
3.1 knu 395:
396: my $infocols = 0;
397: if ($dirtable) {
398: if (defined($tableBorderColor)) {
399: # Can't this be done by defining the border for the inner table?
400: print "<table border=0 cellpadding=0 width=\"100%\"><tr><td bgcolor=\"$tableBorderColor\">";
401: }
402: print "<table width=\"100%\" border=0 cellspacing=1 cellpadding=$tablepadding>\n";
403: $infocols++;
404: print "<tr><th align=left bgcolor=\"" . (($byfile) ?
405: $columnHeaderColorSorted :
406: $columnHeaderColorDefault) . "\">";
407: print "<a href=\"./" . &toggleQuery("sortby","file") .
408: "#dirlist\">" if (!$byfile);
409: print "File";
410: print "</a>" if (!$byfile);
411: print "</th>";
412: # do not display the other column-headers, if we do not have any files
413: # with revision information:
414: if (scalar(%fileinfo)) {
415: $infocols++;
416: print "<th align=left bgcolor=\"" . (($byrev) ?
417: $columnHeaderColorSorted :
418: $columnHeaderColorDefault) . "\">";
419: print "<a href=\"./" . &toggleQuery ("sortby","rev") .
420: "#dirlist\">" if (!$byrev);
421: print "Rev.";
422: print "</a>" if (!$byrev);
423: print "</th>";
424: $infocols++;
425: print "<th align=left bgcolor=\"" . (($bydate) ?
426: $columnHeaderColorSorted :
427: $columnHeaderColorDefault) . "\">";
428: print "<a href=\"./" . &toggleQuery ("sortby","date") .
429: "#dirlist\">" if (!$bydate);
430: print "Age";
431: print "</a>" if (!$bydate);
432: print "</th>";
433: if ($show_author) {
434: $infocols++;
435: print "<th align=left bgcolor=\"" . (($byauthor) ?
436: $columnHeaderColorSorted :
437: $columnHeaderColorDefault) . "\">";
438: print "<a href=\"./" . &toggleQuery ("sortby","author") .
439: "#dirlist\">" if (!$byauthor);
440: print "Author";
441: print "</a>" if (!$byauthor);
442: print "</th>";
443: }
444: $infocols++;
445: print "<th align=left bgcolor=\"" . (($bylog) ?
446: $columnHeaderColorSorted :
447: $columnHeaderColorDefault) . "\">";
448: print "<a href=\"./", toggleQuery("sortby","log"), "#dirlist\">" if (!$bylog);
449: print "Last log entry";
450: print "</a>" if (!$bylog);
451: print "</th>";
452: }
453: elsif ($use_descriptions) {
454: print "<th align=left bgcolor=\"". $columnHeaderColorDefault . "\">";
455: print "Description";
456: $infocols++;
457: }
458: print "</tr>\n";
459: }
460: else {
461: print "<menu>\n";
462: }
463: my $dirrow = 0;
464:
465: my $i;
1.9 fenner 466: lookingforattic:
467: for ($i = 0; $i <= $#dir; $i++) {
468: if ($dir[$i] eq "Attic") {
3.1 knu 469: last lookingforattic;
1.9 fenner 470: }
471: }
3.1 knu 472: if (!$input{'hideattic'} && ($i <= $#dir) &&
473: opendir($dh, $fullname . "/Attic")) {
474: splice(@dir, $i, 1,
475: grep((s|^|Attic/|,!m|/\.|), readdir($dh)));
476: closedir($dh);
1.9 fenner 477: }
3.1 knu 478:
479: my $hideAtticToggleLink = "<a href=\"./" .
480: &toggleQuery ("hideattic") .
481: "#dirlist\">[Hide]</a>" if (!$input{'hideattic'});
482:
1.9 fenner 483: # Sort without the Attic/ pathname.
3.1 knu 484: # place directories first
485:
486: my $attic;
487: my $url;
488: my $fileurl;
489: my $filesexists;
490: my $filesfound;
491:
492: foreach (sort { &fileSortCmp } @dir) {
1.1 jfieber 493: if ($_ eq '.') {
494: next;
495: }
1.19 wosch 496: # ignore CVS lock and stale NFS files
3.1 knu 497: next if (/^#cvs\.|^,|^\.nfs/);
498:
499: # Check whether to show the CVSROOT path
500: next if ($input{'hidecvsroot'} && ($_ eq 'CVSROOT'));
501:
502: # Check whether the module is in the restricted list
503: next if ($_ && &forbidden_module($_));
504:
505: # Ignore non-readable files
506: next if ($input{'hidenonreadable'} && !(-r "$fullname/$_"));
1.18 wosch 507:
1.9 fenner 508: if (s|^Attic/||) {
3.1 knu 509: $attic = " (in the Attic) " . $hideAtticToggleLink;
510: }
511: else {
1.9 fenner 512: $attic = "";
513: }
3.1 knu 514:
515: if ($_ eq '..' || -d "$fullname/$_") {
516: next if ($_ eq '..' && $where eq '/');
517: my ($rev,$date,$log,$author,$filename) = @{$fileinfo{$_}}
518: if (defined($fileinfo{$_}));
519: print "<tr bgcolor=\"" . @tabcolors[$dirrow%2] . "\"><td>" if ($dirtable);
520: if ($_ eq '..') {
521: $url = "../" . $query;
522: if ($nofilelinks) {
523: print $backicon;
524: }
525: else {
526: print &link($backicon,$url);
527: }
528: print " ", &link("Previous Directory",$url);
529: }
530: else {
531: $url = urlencode($_) . '/' . $query;
532: print "<A NAME=\"$_\"></A>";
533: if ($nofilelinks) {
534: print $diricon;
535: }
536: else {
537: print &link($diricon,$url);
538: }
539: print " ", &link($_ . "/", $url), $attic;
540: if ($_ eq "Attic") {
541: print " <a href=\"./" .
542: &toggleQuery ("hideattic") .
543: "#dirlist\">[Don't hide]</a>";
544: }
545: }
546: # Show last change in dir
547: if ($filename) {
548: print "</td><td> </td><td> " if ($dirtable);
549: if ($date) {
550: print " <i>" . readableTime(time() - $date,0) . "</i>";
551: }
552: if ($show_author) {
553: print "</td><td> " if ($dirtable);
554: print $author;
555: }
556: print "</td><td> " if ($dirtable);
557: $filename =~ s%^[^/]+/%%;
558: print "$filename/$rev";
559: print "<BR>" if ($dirtable);
560: if ($log) {
561: print " <font size=-1>"
562: . &htmlify(substr($log,0,$shortLogLen));
563: if (length $log > 80) {
564: print "...";
565: }
566: print "</font>";
567: }
568: }
569: else {
570: my ($dwhere) = ($where ne "/" ? $where : "") . $_;
571: if ($use_descriptions && defined $descriptions{$dwhere}) {
572: print "<TD COLSPAN=" . ($infocols-1) . "> " if $dirtable;
573: print $descriptions{$dwhere};
574: } elsif ($dirtable && $infocols > 1) {
575: # close the row with the appropriate number of
576: # columns, so that the vertical seperators are visible
577: my($cols) = $infocols;
578: while ($cols > 1) {
579: print "</td><td> ";
580: $cols--;
581: }
582: }
583: }
584: if ($dirtable) {
585: print "</td></tr>\n";
586: }
587: else {
588: print "<br>\n";
589: }
590: $dirrow++;
1.9 fenner 591: }
3.1 knu 592: elsif (s/,v$//) {
593: $fileurl = ($attic ? "Attic/" : "") . urlencode($_);
594: $url = $fileurl . $query;
595: my $rev = '';
596: my $date = '';
597: my $log = '';
598: my $author = '';
599: $filesexists++;
600: next if (!defined($fileinfo{$_}));
601: ($rev,$date,$log,$author) = @{$fileinfo{$_}};
602: $filesfound++;
603: print "<tr bgcolor=\"" . @tabcolors[$dirrow%2] . "\"><td>" if ($dirtable);
604: print "<A NAME=\"$_\"></A>";
605: if ($nofilelinks) {
606: print $fileicon;
607: }
608: else {
609: print &link($fileicon,$url);
610: }
611: print " ", &link($_, $url), $attic;
612: print "</td><td> " if ($dirtable);
613: download_link($fileurl,
614: $rev, $rev,
615: $defaultViewable ? "text/x-cvsweb-markup" : undef);
616: print "</td><td> " if ($dirtable);
617: if ($date) {
618: print " <i>" . readableTime(time() - $date,0) . "</i>";
619: }
620: if ($show_author) {
621: print "</td><td> " if ($dirtable);
622: print $author;
623: }
624: print "</td><td> " if ($dirtable);
625: if ($log) {
626: print " <font size=-1>" . &htmlify(substr($log,0,$shortLogLen));
627: if (length $log > 80) {
628: print "...";
629: }
630: print "</font>";
631: }
632: print "</td>" if ($dirtable);
633: print (($dirtable) ? "</tr>" : "<br>");
634: $dirrow++;
635: }
636: print "\n";
637: }
638: if ($dirtable && defined($tableBorderColor)) {
639: print "</td></tr></table>";
640: }
641: print "". ($dirtable == 1) ? "</table>" : "</menu>" . "\n";
642:
643: if ($filesexists && !$filesfound) {
644: print "<P><B>NOTE:</B> There are $filesexists files, but none matches the current tag ($input{only_with_tag})\n";
645: }
646: if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
647: %tags = %alltags
648: }
649: if (scalar %tags
650: || $input{only_with_tag}
651: || $edit_option_form
652: || defined($input{"options"})) {
653: print "<hr size=1 NOSHADE>";
654: }
655:
656: if (scalar %tags || $input{only_with_tag}) {
657: print "<FORM METHOD=\"GET\" ACTION=\"./\">\n";
658: foreach my $var (@stickyvars) {
659: print "<INPUT TYPE=HIDDEN NAME=\"$var\" VALUE=\"$input{$var}\">\n"
660: if (defined($input{$var})
661: && $input{$var} ne $DEFAULTVALUE{$var}
662: && $input{$var} ne ""
663: && $var ne "only_with_tag");
664: }
665: print "Show only files with tag:\n";
666: print "<SELECT NAME=only_with_tag";
667: print " onchange=\"submit()\"" if ($use_java_script);
668: print ">";
669: print "<OPTION VALUE=\"\">All tags / default branch\n";
670: foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
671: print "<OPTION",defined($input{only_with_tag}) &&
672: $input{only_with_tag} eq $tag ? " SELECTED":"",
673: ">$tag\n";
674: }
675: print "</SELECT>\n";
676: print "<INPUT TYPE=SUBMIT VALUE=\"Go\">\n";
1.9 fenner 677: print "</FORM>\n";
678: }
3.1 knu 679: my $formwhere = $scriptwhere;
680: $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
681:
682: if ($edit_option_form || defined($input{"options"})) {
683: print "<FORM METHOD=\"GET\" ACTION=\"${formwhere}\">\n";
684: print "<INPUT TYPE=HIDDEN NAME=\"copt\" VALUE=\"1\">\n";
685: if ($cvstree ne $cvstreedefault) {
686: print "<INPUT TYPE=HIDDEN NAME=\"cvsroot\" VALUE=\"$cvstree\">\n";
687: }
688: print "<center><table cellpadding=0 cellspacing=0>";
689: print "<tr bgcolor=\"$columnHeaderColorDefault\"><th colspan=2>Preferences</th></tr>";
690: print "<tr><td>Sort files by <SELECT name=\"sortby\">";
691: print "<OPTION VALUE=\"\">File";
692: print "<OPTION",$bydate ? " SELECTED" : ""," VALUE=date>Age";
693: print "<OPTION",$byauthor ? " SELECTED" : ""," VALUE=author>Author"
694: if ($show_author);
695: print "<OPTION",$byrev ? " SELECTED" : ""," VALUE=rev>Revision";
696: print "<OPTION",$bylog ? " SELECTED" : ""," VALUE=log>Log message";
697: print "</SELECT></td>";
698: print "<td>revisions by: \n";
699: print "<SELECT NAME=logsort>\n";
700: print "<OPTION VALUE=cvs",$logsort eq "cvs" ? " SELECTED" : "", ">Not sorted";
701: print "<OPTION VALUE=date",$logsort eq "date" ? " SELECTED" : "", ">Commit date";
702: print "<OPTION VALUE=rev",$logsort eq "rev" ? " SELECTED" : "", ">Revision";
703: print "</SELECT></td></tr>";
704: print "<tr><td>Diff format: ";
705: printDiffSelect();
706: print "</td>";
707: print "<td>Show Attic files: ";
708: print "<INPUT NAME=hideattic TYPE=CHECKBOX", $input{'hideattic'}?" CHECKED":"",
709: "></td></tr>\n";
710: print "<tr><td align=center colspan=2><input type=submit value=\"Change Options\">";
711: print "</td></tr></table></center></FORM>\n";
1.12 fenner 712: }
1.2 jfieber 713: print &html_footer;
1.1 jfieber 714: print "</BODY></HTML>\n";
3.1 knu 715: }
716:
717: ###############################
718: # View Files
719: ###############################
720: elsif (-f $fullname . ',v') {
721: if (defined($input{'rev'}) || $doCheckout) {
722: &doCheckout($fullname, $input{'rev'});
723: exit;
724: }
725: if (defined($input{'annotate'}) && $allow_annotate) {
726: &doAnnotate($input{'annotate'});
727: exit;
728: }
729: if (defined($input{'r1'}) && defined($input{'r2'})) {
730: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
731: $input{'r2'}, $input{'tr2'}, $input{'f'});
732: exit;
733: }
734: print("going to dolog($fullname)\n") if ($verbose);
735: &doLog($fullname);
736: ##############################
737: # View Diff
738: ##############################
739: }
740: elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" &&
741: $input{'r1'} && $input{'r2'}) {
742:
743: # $where-diff-removal if 'cvs rdiff' is used
744: # .. but 'cvs rdiff'doesn't support some options
745: # rcsdiff does (-w and -p), so it is disabled
746: # $where =~ s/\.diff$//;
747:
1.12 fenner 748: # Allow diffs using the ".diff" extension
749: # so that browsers that default to the URL
750: # for a save filename don't save diff's as
751: # e.g. foo.c
3.1 knu 752: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1.12 fenner 753: $input{'r2'}, $input{'tr2'}, $input{'f'});
754: exit;
3.1 knu 755: }
756: elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| &&
757: -f $newname . ",v") {
1.12 fenner 758: # The file has been removed and is in the Attic.
759: # Send a redirect pointing to the file in the Attic.
3.1 knu 760: (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
1.12 fenner 761: &redirect($newplace);
762: exit;
3.1 knu 763: }
764: elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
765: http_header("text/plain");
1.12 fenner 766: print "You matched the following files:\n";
767: print join("\n", @files);
768: # Find the tags from each file
769: # Display a form offering diffs between said tags
3.1 knu 770: }
771: else {
772: my $fh = do {local(*FH);};
773: my ($xtra, $module);
1.12 fenner 774: # Assume it's a module name with a potential path following it.
1.13 fenner 775: $xtra = $& if (($module = $where) =~ s|/.*||);
1.12 fenner 776: # Is there an indexed version of modules?
3.1 knu 777: if (open($fh, "$cvsroot/CVSROOT/modules")) {
778: while (<$fh>) {
779: if (/^(\S+)\s+(\S+)/o && $module eq $1
780: && -d "${cvsroot}/$2" && $module ne $2) {
781: &redirect($scriptname . '/' . $2 . $xtra);
1.12 fenner 782: }
3.1 knu 783: }
1.12 fenner 784: }
785: &fatal("404 Not Found","$where: no such file or directory");
3.1 knu 786: }
787: ## End MAIN
788:
789: sub printDiffSelect {
790: my ($use_java_script) = @_;
791: $use_java_script = 0 if (!defined($use_java_script));
792: my ($f) = $input{'f'};
793: print "<SELECT NAME=\"f\"";
794: print " onchange=\"submit()\"" if ($use_java_script);
795: print ">\n";
796: print "<OPTION VALUE=h",$f eq "h" ? " SELECTED" : "", ">Colored Diff";
797: print "<OPTION VALUE=H",$f eq "H" ? " SELECTED" : "", ">Long Colored Diff";
798: print "<OPTION VALUE=u",$f eq "u" ? " SELECTED" : "", ">Unidiff";
799: print "<OPTION VALUE=c",$f eq "c" ? " SELECTED" : "", ">Context Diff";
800: print "<OPTION VALUE=s",$f eq "s" ? " SELECTED" : "", ">Side by Side";
801: print "</SELECT>";
802: }
803:
804: sub findLastModifiedSubdirs {
805: my (@dirs) = @_;
806: my ($dirname, @files);
807:
808: foreach $dirname (@dirs) {
809: next if ($dirname eq ".");
810: next if ($dirname eq "..");
811: my ($dir) = "$fullname/$dirname";
812: next if (!-d $dir);
813:
814: my ($lastmod) = undef;
815: my ($lastmodtime) = undef;
816: my $dh = do {local(*DH);};
817:
818: opendir($dh,$dir) || next;
819: my (@filenames) = readdir($dh);
820: closedir($dh);
821:
822: foreach my $filename (@filenames) {
823: $filename = "$dirname/$filename";
824: my ($file) = "$fullname/$filename";
825: next if ($filename !~ /,v$/ || !-f $file);
826: $filename =~ s/,v$//;
827: my $modtime = -M $file;
828: if (!defined($lastmod) || $modtime < $lastmodtime) {
829: $lastmod = $filename;
830: $lastmodtime = $modtime;
831: }
832: }
833: push(@files, $lastmod) if (defined($lastmod));
834: }
835: return @files;
1.12 fenner 836: }
837:
838: sub htmlify {
3.1 knu 839: my($string, $pr) = @_;
1.12 fenner 840:
3.1 knu 841: # Special Characters; RFC 1866
1.12 fenner 842: $string =~ s/&/&/g;
3.1 knu 843: $string =~ s/\"/"/g;
1.12 fenner 844: $string =~ s/</</g;
845: $string =~ s/>/>/g;
846:
3.1 knu 847: # get URL's as link ..
848: $string =~ s`(http|ftp|https)(://[-a-zA-Z0-9%.~:_/]+)([?&]([-a-zA-Z0-9%.~:_]+)=([-a-zA-Z0-9%.~:_])+)*`<A HREF="$1$2$3">$1$2$3</A>`;
849: # get e-mails as link
850: $string =~ s`([-a-zA-Z0-9_.]+@([-a-zA-Z0-9]+\.)+[A-Za-z]{2,4})`<A HREF="mailto:$1">$1</A>`;
851:
852: # get #PR as link ..
853: if ($pr && defined($prcgi)) {
854: 1 while $string =~ s`\b(pr[:#]?\s*(?:#?\d+[,\s]\s*)*#?)(\d+)\b`$1<A HREF="$prcgi?pr=$2">$2</A>`i;
855: $string =~ s`\b${prcategories}/(\d+)\b`<A HREF="$prcgi?pr=$1">$&</A>`igo;
856: }
857:
858: return $string;
859: }
860:
861: sub spacedHtmlText {
862: my($string, $pr) = @_;
863:
864: # Cut trailing spaces
865: s/\s+$//;
866:
867: # Expand tabs
868: $string =~ s/\t+/' ' x (length($&) * $tabstop - length($`) % $tabstop)/e
869: if (defined($tabstop));
870:
871: # replace <tab> and <space> (\001 is to protect us from htmlify)
872: # gzip can make excellent use of this repeating pattern :-)
873: $string =~ s/\001/\001%/g; #protect our & substitute
874: if ($hr_breakable) {
875: # make every other space 'breakable'
876: $string =~ s/ / \001nbsp; \001nbsp; \001nbsp; \001nbsp;/g; # <tab>
877: $string =~ s/ / \001nbsp;/g; # 2 * <space>
878: # leave single space as it is
879: }
880: else {
881: $string =~ s/ /\001nbsp;\001nbsp;\001nbsp;\001nbsp;\001nbsp;\001nbsp;\001nbsp;\001nbsp;/g;
882: $string =~ s/ /\001nbsp;/g;
1.12 fenner 883: }
884:
3.1 knu 885: $string = htmlify($string);
886:
887: # unescape
888: $string =~ s/\001([^%])/&$1/g;
889: $string =~ s/\001%/\001/g;
890:
891: return $string;
1.12 fenner 892: }
893:
894: sub link {
3.1 knu 895: my($name, $where) = @_;
1.12 fenner 896:
3.1 knu 897: return "<A HREF=\"$where\">$name</A>\n";
1.12 fenner 898: }
899:
900: sub revcmp {
3.1 knu 901: my($rev1, $rev2) = @_;
902: my(@r1) = split(/\./, $rev1);
903: my(@r2) = split(/\./, $rev2);
904: my($a,$b);
1.12 fenner 905:
906: while (($a = shift(@r1)) && ($b = shift(@r2))) {
907: if ($a != $b) {
908: return $a <=> $b;
909: }
910: }
911: if (@r1) { return 1; }
912: if (@r2) { return -1; }
913: return 0;
914: }
915:
916: sub fatal {
3.1 knu 917: my($errcode, $errmsg) = @_;
3.3 knu 918: if ($is_mod_perl) {
3.1 knu 919: Apache->request->status((split(/ /, $errcode))[0]);
920: }
921: else {
3.4 ! knu 922: print "Status: $errcode\r\n";
3.1 knu 923: }
924: html_header("Error");
1.12 fenner 925: print "Error: $errmsg\n";
926: print &html_footer;
927: exit(1);
928: }
929:
930: sub redirect {
3.1 knu 931: my($url) = @_;
3.3 knu 932: if ($is_mod_perl) {
3.1 knu 933: Apache->request->status(301);
934: Apache->request->header_out(Location => $url);
935: }
936: else {
3.4 ! knu 937: print "Status: 301 Moved\r\n";
! 938: print "Location: $url\r\n";
3.1 knu 939: }
940: html_header("Moved");
1.12 fenner 941: print "This document is located <A HREF=$url>here</A>.\n";
942: print &html_footer;
943: exit(1);
944: }
945:
946: sub safeglob {
3.1 knu 947: my ($filename) = @_;
948: my ($dirname);
949: my (@results);
950: my $dh = do {local(*DH);};
1.12 fenner 951:
952: ($dirname = $filename) =~ s|/[^/]+$||;
953: $filename =~ s|.*/||;
954:
3.1 knu 955: if (opendir($dh, $dirname)) {
956: my $glob = $filename;
957: my $t;
1.12 fenner 958: # transform filename from glob to regex. Deal with:
959: # [, {, ?, * as glob chars
960: # make sure to escape all other regex chars
961: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
962: $glob =~ s/\*/.*/g;
963: $glob =~ s/\?/./g;
964: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
3.1 knu 965: foreach (readdir($dh)) {
1.12 fenner 966: if (/^${glob}$/) {
967: push(@results, $dirname . "/" .$_);
968: }
969: }
970: }
971:
972: @results;
973: }
974:
3.1 knu 975: sub getMimeTypeFromSuffix {
976: my ($fullname) = @_;
977: my ($mimetype, $suffix);
978: my $fh = do {local(*FH);};
979:
980: ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
981: $mimetype = $MTYPES{$suffix};
982: $mimetype = $MTYPES{'*'} if (!$mimetype);
983:
984: if (!$mimetype && -f $mime_types) {
985: # okey, this is something special - search the
986: # mime.types database
987: open ($fh, "<$mime_types");
988: while (<$fh>) {
989: if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
990: $mimetype = $1;
991: last;
992: }
993: }
994: close ($fh);
995: }
996:
997: # okey, didn't find anything useful ..
998: if (!($mimetype =~ /\S\/\S/)) {
999: $mimetype = "text/plain";
1000: }
1001: return $mimetype;
1002: }
1003:
1004: ###############################
1005: # show Annotation
1006: ###############################
1007: sub doAnnotate ($$) {
1008: my ($rev) = @_;
1009: my ($pid);
1010: my ($pathname, $filename);
1011: my $reader = do {local(*FH);};
1012: my $writer = do {local(*FH);};
1013:
1014: # make sure the revisions a wellformed, for security
1015: # reasons ..
1016: if (!($rev =~ /^[\d\.]+$/)) {
1017: &fatal("404 Not Found",
3.3 knu 1018: "Malformed query \"$ENV{QUERY_STRING}\"");
3.1 knu 1019: }
1.12 fenner 1020:
3.1 knu 1021: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1022: ($filename = $where) =~ s/^.*\///;
1023:
1024: http_header();
1025:
1026: navigateHeader ($scriptwhere,$pathname,$filename,$rev, "annotate");
1027: print "<h3 align=center>Annotation of $pathname$filename, Revision $rev</h3>\n";
1028:
1029: # this seems to be necessary
1030: $| = 1; $| = 0; # Flush
1031:
1032: # this annotate version is based on the
1033: # cvs annotate-demo Perl script by Cyclic Software
1034: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1035: # the public domain.
1036: # we could abandon the use of rlog, rcsdiff and co using
1037: # the cvsserver in a similiar way one day (..after rewrite)
1038: $pid = open2($reader, $writer, "cvs server") || fatal ("500 Internal Error",
1039: "Fatal Error - unable to open cvs for annotation");
1040:
1041: # OK, first send the request to the server. A simplified example is:
1042: # Root /home/kingdon/zwork/cvsroot
1043: # Argument foo/xx
1044: # Directory foo
1045: # /home/kingdon/zwork/cvsroot/foo
1046: # Directory .
1047: # /home/kingdon/zwork/cvsroot
1048: # annotate
1049: # although as you can see there are a few more details.
1050:
1051: print $writer "Root $cvsroot\n";
1052: print $writer "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1053: # Don't worry about sending valid-requests, the server just needs to
1054: # support "annotate" and if it doesn't, there isn't anything to be done.
1055: print $writer "UseUnchanged\n";
1056: print $writer "Argument -r\n";
1057: print $writer "Argument $rev\n";
1058: print $writer "Argument $where\n";
1059:
1060: # The protocol requires us to fully fake a working directory (at
1061: # least to the point of including the directories down to the one
1062: # containing the file in question).
1063: # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
3.3 knu 1064: my @dirs = split('/', $where);
3.1 knu 1065: my $path = "";
1066: foreach (@dirs) {
1067: if ($path eq "") {
1068: # In our example, $_ is "dir".
1069: $path = $_;
1.44 knu 1070: }
3.1 knu 1071: else {
3.3 knu 1072: print $writer "Directory $path\n";
1073: print $writer "$cvsroot/$path\n";
3.1 knu 1074: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1075: # And the next time, "file" and "dir/sdir/file" (which then gets
1076: # ignored, because we don't need to send Directory for the file).
3.3 knu 1077: $path .= "/$_";
3.1 knu 1078: }
1079: }
1080: # And the last "Directory" before "annotate" is the top level.
1081: print $writer "Directory .\n";
1082: print $writer "$cvsroot\n";
1083:
1084: print $writer "annotate\n";
1085: # OK, we've sent our command to the server. Thing to do is to
1086: # close the writer side and get all the responses. If "cvs server"
1087: # were nicer about buffering, then we could just leave it open, I think.
1088: close ($writer) || die "cannot close: $!";
1089:
1090: # Ready to get the responses from the server.
1091: # For example:
1092: # E Annotations for foo/xx
1093: # E ***************
1094: # M 1.3 (kingdon 06-Sep-97): hello
1095: # ok
1096: my ($lineNr) = 0;
1097: my ($oldLrev, $oldLusr) = ("", "");
1098: my ($revprint, $usrprint);
1099: if ($annTable) {
1100: print "<table border=0 cellspacing=0 cellpadding=0>\n";
1101: }
1102: else {
1103: print "<pre>";
1104: }
1105: while (<$reader>) {
1106: my @words = split;
1107: # Adding one is for the (single) space which follows $words[0].
1108: my $rest = substr ($_, length ($words[0]) + 1);
1109: if ($words[0] eq "E") {
1110: next;
1111: }
1112: elsif ($words[0] eq "M") {
1113: $lineNr++;
1114: my $lrev = substr ($_, 2, 13);
1115: my $lusr = substr ($_, 16, 9);
1116: my $line = substr ($_, 36);
1117: # we should parse the date here ..
1118: if ($lrev eq $oldLrev) {
1119: $revprint = " ";
1120: }
1121: else {
1122: $revprint = $lrev; $oldLusr = "";
1123: }
1124: if ($lusr eq $oldLusr) {
1125: $usrprint = " ";
1126: }
1127: else {
1128: $usrprint = $lusr;
1129: }
1130: $oldLrev = $lrev;
1131: $oldLusr = $lusr;
1132: # is there a less timeconsuming way to strip spaces ?
1133: ($lrev = $lrev) =~ s/\s+//g;
3.3 knu 1134: my $isCurrentRev = ($rev eq $lrev);
3.1 knu 1135:
1136: print "<b>" if ($isCurrentRev);
1137: printf ("%8s%s%8s %4d:", $revprint, ($isCurrentRev ? "|" : " "), $usrprint, $lineNr);
1138: print spacedHtmlText($line);
1139: print "</b>" if ($isCurrentRev);
1140: }
1141: elsif ($words[0] eq "ok") {
1142: # We could complain about any text received after this, like the
1143: # CVS command line client. But for simplicity, we don't.
1144: }
1145: elsif ($words[0] eq "error") {
1146: fatal ("500 Internal Error", "Error occured during annotate: <b>$_</b>");
1147: }
1148: }
1149: if ($annTable) {
1150: print "</table>";
1151: }
1152: else {
1153: print "</pre>";
1154: }
1155: close ($reader) || warn "cannot close: $!";
1156: wait;
1157: }
1158:
1159: ###############################
1160: # make Checkout
1161: ###############################
1162: sub doCheckout {
1163: my ($fullname, $rev) = @_;
1164: my ($mimetype,$revopt);
1165: my $fh = do {local(*FH);};
1166:
1167: # make sure the revisions a wellformed, for security
1168: # reasons ..
1169: if (defined($rev) && !($rev =~ /^[\d\.]+$/)) {
1170: &fatal("404 Not Found",
3.3 knu 1171: "Malformed query \"$ENV{QUERY_STRING}\"");
3.1 knu 1172: }
1173:
1174: # get mimetype
1175: if (defined($input{"content-type"}) && ($input{"content-type"} =~ /\S\/\S/)) {
1176: $mimetype = $input{"content-type"}
1177: }
1178: else {
1179: $mimetype = &getMimeTypeFromSuffix($fullname);
1180: }
1181:
1182: if (defined($rev)) {
1183: $revopt = "-r$rev";
1184: if ($use_moddate) {
1185: readLog($fullname,$rev);
1186: $moddate=$date{$rev};
1187: }
1188: }
1189: else {
1190: $revopt = "-rHEAD";
1191: if ($use_moddate) {
1192: readLog($fullname);
1193: $moddate=$date{$symrev{HEAD}};
1194: }
1195: }
1196:
1197: ### just for the record:
1198: ### 'cvs co' seems to have a bug regarding single checkout of
1199: ### directories/files having spaces in it;
1200: ### this is an issue that should be resolved on cvs's side
1201: #
1202: # Safely for a child process to read from.
1203: if (! open($fh, "-|")) { # child
1204: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
3.3 knu 1205: exec("cvs", "-d", $cvsroot, "co", "-p", $revopt, $where);
3.1 knu 1206: }
1207: #===================================================================
1208: #Checking out squid/src/ftp.c
1209: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1210: #VERS: 1.1.1.28.6.2
1211: #***************
1212:
1213: # Parse CVS header
1214: my ($revision, $filename, $cvsheader);
1215: while(<$fh>) {
1216: last if (/^\*\*\*\*/);
1217: $revision = $1 if (/^VERS: (.*)$/);
1218: if (/^Checking out (.*)$/) {
1219: $filename = $1;
1220: $filename =~ s/^\.\/*//;
1.12 fenner 1221: }
3.1 knu 1222: $cvsheader .= $_;
1223: }
1224: if ($filename ne $where) {
1225: &fatal("500 Internal Error",
1226: "Unexpected output from cvs co: $cvsheader"
1227: . "<p><b>Check whether the directory $cvsroot/CVSROOT exists "
1228: . "and the script has write-access to the CVSROOT/history "
1229: . "file if it exists."
1230: . "<br>The script needs to place lock files in the "
1231: . "directory the file is in as well.</b>");
1232: }
1233: $| = 1;
1234:
1235: if ($mimetype eq "text/x-cvsweb-markup") {
1236: &cvswebMarkup($fh,$fullname,$revision);
1237: }
1238: else {
1239: http_header($mimetype);
1240: print <$fh>;
1241: }
1242: close($fh);
1243: }
1244:
1245: sub cvswebMarkup {
1246: my ($filehandle,$fullname,$revision) = @_;
1247: my ($pathname, $filename);
1248:
1249: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1250: ($filename = $where) =~ s/^.*\///;
1251: my ($fileurl) = urlencode($filename);
1252:
1253: http_header();
1254:
1255: navigateHeader ($scriptwhere, $pathname, $filename, $revision, "view");
1256: print "<HR noshade>";
1257: print "<table width=\"100%\"><tr><td bgcolor=\"$markupLogColor\">";
1258: print "File: ", &clickablePath($where, 1);
1259: print " ";
1260: &download_link(urlencode($fileurl), $revision, "(download)");
1261: if (!$defaultTextPlain) {
1262: print " ";
1263: &download_link(urlencode($fileurl), $revision, "(as text)",
1264: "text/plain");
1265: }
1266: print "<BR>\n";
1267: if ($show_log_in_markup) {
1268: readLog($fullname); #,$revision);
1269: printLog($revision,0);
1270: }
1271: else {
1272: print "Version: <B>$revision</B><BR>\n";
1273: print "Tag: <B>", $input{only_with_tag}, "</b><br>\n" if
1274: $input{only_with_tag};
1275: }
1276: print "</td></tr></table>";
1277: my @content = <$filehandle>;
1278: my $url = download_url($fileurl, $revision, $mimetype);
1279: print "<HR noshade>";
1280: if ($mimetype =~ /^image/) {
1281: print "<IMG SRC=\"$url$barequery\"><BR>";
1282: }
1283: else {
1284: print "<PRE>";
1285: foreach (@content) {
1286: print spacedHtmlText($_);
1.12 fenner 1287: }
3.1 knu 1288: print "</PRE>";
1289: }
1.12 fenner 1290: }
1291:
3.1 knu 1292: sub viewable($) {
1293: my ($mimetype) = @_;
1294:
1295: $mimetype =~ m%^text/% ||
1296: $mimetype =~ m%^image/% ||
1297: 0;
1298: }
1299:
1300: ###############################
1301: # Show Colored Diff
1302: ###############################
1303: sub doDiff {
1304: my($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1305: my $fh = do {local(*FH);};
1306: my ($rev1, $rev2, $sym1, $sym2, @difftype, $diffname, $f1, $f2);
1.12 fenner 1307:
1308: if ($r1 =~ /([^:]+)(:(.+))?/) {
1309: $rev1 = $1;
1310: $sym1 = $3;
1311: }
3.1 knu 1312: if ($r1 eq 'text') {
1.12 fenner 1313: $rev1 = $tr1;
3.1 knu 1314: $sym1 = "";
1.12 fenner 1315: }
1316: if ($r2 =~ /([^:]+)(:(.+))?/) {
1317: $rev2 = $1;
1318: $sym2 = $3;
1319: }
3.1 knu 1320: if ($r2 eq 'text') {
1.12 fenner 1321: $rev2 = $tr2;
3.1 knu 1322: $sym2 = "";
1.12 fenner 1323: }
3.1 knu 1324: # make sure the revisions a wellformed, for security
1325: # reasons ..
1.12 fenner 1326: if (!($rev1 =~ /^[\d\.]+$/) || !($rev2 =~ /^[\d\.]+$/)) {
1327: &fatal("404 Not Found",
3.3 knu 1328: "Malformed query \"$ENV{QUERY_STRING}\"");
1.12 fenner 1329: }
1330: #
1331: # rev1 and rev2 are now both numeric revisions.
1332: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1333: # XXX should we warn about the fact that we do this?
1334: if (&revcmp($rev1,$rev2) > 0) {
3.1 knu 1335: my ($tmp1, $tmp2) = ($rev1, $sym1);
1.12 fenner 1336: ($rev1, $sym1) = ($rev2, $sym2);
1337: ($rev2, $sym2) = ($tmp1, $tmp2);
1338: }
3.1 knu 1339: my $human_readable = 0;
1.12 fenner 1340: if ($f eq 'c') {
3.1 knu 1341: @difftype = qw{-c};
1.12 fenner 1342: $diffname = "Context diff";
3.1 knu 1343: }
1344: elsif ($f eq 's') {
1345: @difftype = qw{--side-by-side --width=164};
1.12 fenner 1346: $diffname = "Side by Side";
3.1 knu 1347: }
1348: elsif ($f eq 'H') {
1349: $human_readable = 1;
1350: @difftype = qw{--unified=15};
1351: $diffname = "Long Human readable";
1352: }
1353: elsif ($f eq 'h') {
1354: @difftype =qw{-u};
1355: $human_readable = 1;
1356: $diffname = "Human readable";
1357: }
1358: elsif ($f eq 'u') {
1359: @difftype = qw{-u};
1.12 fenner 1360: $diffname = "Unidiff";
1361: }
3.1 knu 1362: else {
1363: fatal ("400 Bad arguments", "Diff format $f not understood");
1364: }
1365:
1366: # apply special options
3.3 knu 1367: if ($showfunc) {
1368: push @difftype, '-p';
3.1 knu 1369:
3.3 knu 1370: my($re1, $re2);
3.1 knu 1371:
3.3 knu 1372: while (($re1, $re2) = each %funcline_regexp) {
1373: if ($fullname =~ /$re1/) {
1374: push @difftype, '-F', '$re2';
1375: last;
3.1 knu 1376: }
1377: }
3.3 knu 1378: }
1379: if ($human_readable) {
3.1 knu 1380: if ($hr_ignwhite) {
1381: push @difftype, '-w';
1382: }
1383: if ($hr_ignkeysubst) {
1384: push @difftype, '-kk';
1385: }
1386: }
1387: if (! open($fh, "-|")) { # child
3.3 knu 1388: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1389: exec("rcsdiff",@difftype,"-r$rev1","-r$rev2",$fullname);
3.1 knu 1390: }
1391: if ($human_readable) {
1392: http_header();
1393: &human_readable_diff($fh, $rev2);
1394: exit;
1395: }
1396: else {
1397: http_header("text/plain");
1.44 knu 1398: }
1.12 fenner 1399: #
1400: #===================================================================
1401: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
1402: #retrieving revision 1.16
1403: #retrieving revision 1.17
1404: #diff -c -r1.16 -r1.17
1405: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1406: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
1407: #
1408: # Ideas:
1409: # - nuke the stderr output if it's what we expect it to be
1410: # - Add "no differences found" if the diff command supplied no output.
1411: #
1412: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1413: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
1414: # (bogus example, but...)
1415: #
3.1 knu 1416: if (grep { $_ eq '-u'} @difftype) {
1.12 fenner 1417: $f1 = '---';
1418: $f2 = '\+\+\+';
3.1 knu 1419: }
1420: else {
1.12 fenner 1421: $f1 = '\*\*\*';
1422: $f2 = '---';
1423: }
3.1 knu 1424: while (<$fh>) {
1.12 fenner 1425: if (m|^$f1 $cvsroot|o) {
1426: s|$cvsroot/||o;
1427: if ($sym1) {
1428: chop;
1429: $_ .= " " . $sym1 . "\n";
1430: }
3.1 knu 1431: }
1432: elsif (m|^$f2 $cvsroot|o) {
1.12 fenner 1433: s|$cvsroot/||o;
1434: if ($sym2) {
1435: chop;
1436: $_ .= " " . $sym2 . "\n";
1437: }
1438: }
1439: print $_;
1440: }
3.1 knu 1441: close($fh);
1.12 fenner 1442: }
1443:
3.1 knu 1444: ###############################
1445: # Show Logs ..
1446: ###############################
1447: sub getDirLogs {
1448: my ($cvsroot,$dirname,@otherFiles) = @_;
1449: my ($state,$otherFiles,$tag, $file, $date, $branchpoint, $branch, $log);
1450: my ($rev, $revision, $revwanted, $filename, $head, $author);
1451:
1452: $tag = $input{only_with_tag};
1453:
1454: my ($DirName) = "$cvsroot/$where";
1455: my (@files, @filetags);
1456: my $fh = do {local(*FH);};
1457:
1458: push(@files, &safeglob("$DirName/*,v"));
1459: push(@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
1460: foreach $file (@otherFiles) {
1461: push(@files, "$DirName/$file");
1462: }
1463:
1464: # just execute rlog if there are any files
1465: if ($#files < 0) {
1466: return;
1467: }
1468:
1469: if ($tag) {
1470: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
1471: if (! open($fh, "-|")) {
1472: close(STDERR); # rlog may complain; ignore.
1473: exec("rlog",@files);
1474: }
1475: }
1476: else {
1477: my $kidpid = open($fh, "-|");
1478: if (! $kidpid) {
3.4 ! knu 1479: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
3.1 knu 1480: exec("rlog","-r",@files);
1481: }
1482: }
1483: $state = "start";
1484: while (<$fh>) {
1485: if ($state eq "start") {
1486: #Next file. Initialize file variables
1487: $rev = undef;
1488: $revwanted = undef;
1489: $branch = undef;
1490: $branchpoint = undef;
1491: $filename = undef;
1492: $log = undef;
1493: $revision = undef;
1494: $branch = undef;
1495: %symrev = ();
1496: @filetags = ();
1497: #jump to head state
1498: $state = "head";
1499: }
1500: print "$state:$_" if ($verbose);
1501: again:
1502: if ($state eq "head") {
1503: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
1504: $filename = $1 if (/^Working file: (.+)$/);
1505: $head = $1 if (/^head: (.+)$/);
1506: $branch = $1 if (/^branch: (.+)$/);
1507: }
1508: if ($state eq "head" && /^symbolic names/) {
1509: $state = "tags";
1510: ($branch = $head) =~ s/\.\d+$// if (!defined($branch));
1511: $branch =~ s/(\.?)(\d+)$/${1}0.$2/;
1512: $symrev{MAIN} = $branch;
1513: $symrev{HEAD} = $branch;
1514: $alltags{MAIN} = 1;
1515: $alltags{HEAD} = 1;
1516: push (@filetags, "MAIN", "HEAD");
1517: next;
1518: }
1519: if ($state eq "tags" &&
1520: /^\s+(.+):\s+([\d\.]+)\s+$/) {
1521: push (@filetags, $1);
1522: $symrev{$1} = $2;
1523: $alltags{$1} = 1;
1524: next;
1525: }
1526: if ($state eq "tags" && /^\S/) {
1527: if (defined($tag) && (defined($symrev{$tag}) || $tag eq "HEAD")) {
1528: $revwanted = $tag eq "HEAD" ? $symrev{"MAIN"} : $symrev{$tag};
1529: ($branch = $revwanted) =~ s/\b0\.//;
1530: ($branchpoint = $branch) =~ s/\.?\d+$//;
1531: $revwanted = undef if ($revwanted ne $branch);
1532: }
1533: elsif (defined($tag) && $tag ne "HEAD") {
1534: print "Tag not found, skip this file" if ($verbose);
1535: $state = "skip";
1536: next;
1537: }
1538: foreach my $tagfound (@filetags) {
1539: $tags{$tagfound} = 1;
1540: }
1541: $state = "head";
1542: goto again;
1543: }
1544: if ($state eq "head" && /^----------------------------$/) {
1545: $state = "log";
1546: $rev = undef;
1547: $date = undef;
1548: $log = "";
1549: # Try to reconstruct the relative filename if RCS spits out a full path
1550: $filename =~ s%^\Q$DirName\E/%%;
1551: next;
1552: }
1553: if ($state eq "log") {
1554: if (/^----------------------------$/
1555: || /^=============================/) {
1556: # End of a log entry.
1557: my $revbranch;
1558: ($revbranch = $rev) =~ s/\.\d+$//;
1559: print "$filename $rev Wanted: $revwanted "
1560: . "Revbranch: $revbranch Branch: $branch "
1561: . "Branchpoint: $branchpoint\n" if ($verbose);
1562: if (!defined($revwanted) && defined($branch)
1563: && $branch eq $revbranch || !defined($tag)) {
1564: print "File revision $rev found for branch $branch\n"
1565: if ($verbose);
1566: $revwanted = $rev;
1567: }
1568: if (defined($revwanted) ? $rev eq $revwanted :
1569: defined($branchpoint) ? $rev eq $branchpoint :
1570: 0 && ($rev eq $head)) { # Don't think head is needed here..
1571: print "File info $rev found for $filename\n" if ($verbose);
1572: my @finfo = ($rev,$date,$log,$author,$filename);
1573: my ($name);
1574: ($name = $filename) =~ s%/.*%%;
1575: $fileinfo{$name} = [ @finfo ];
1576: $state = "done" if ($rev eq $revwanted);
1577: }
1578: $rev = undef;
1579: $date = undef;
1580: $log = "";
1581: }
1582: elsif (!defined($date) && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
1583: my $yr = $1;
1584: # damn 2-digit year routines :-)
1585: if ($yr > 100) {
1586: $yr -= 1900;
1587: }
1588: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1589: ($author) = /author: ([^;]+)/;
1590: $state = "log";
1591: $log = '';
1592: next;
1593: }
1594: elsif (!defined($rev) && m/^revision (.*)$/) {
1595: $rev = $1;
1596: next;
1597: }
1598: else {
1599: $log = $log . $_;
1600: }
1601: }
1602: if (/^===============/) {
1603: $state = "start";
1604: next;
1605: }
1606: }
1607: if ($. == 0) {
1608: fatal("500 Internal Error",
1609: "Failed to spawn GNU rlog on <em>'".join(", ", @files)."'</em><p>did you set the <b>\$ENV{PATH}</b> in your configuration file correctly ?");
1610: }
1611: close($fh);
1612: }
1613:
1614: sub readLog {
1615: my($fullname,$revision) = @_;
1616: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
1617: my $fh = do {local(*FH);};
1618:
1619: if (defined($revision)) {
1620: $revision = "-r$revision";
1621: }
1622: else {
1623: $revision = "";
1624: }
1625:
1626: undef %symrev;
1627: undef %revsym;
1628: undef @allrevisions;
1629: undef %date;
1630: undef %author;
1631: undef %state;
1632: undef %difflines;
1633: undef %log;
1.12 fenner 1634:
1635: print("Going to rlog '$fullname'\n") if ($verbose);
3.1 knu 1636: if (! open($fh, "-|")) { # child
1637: if ($revision ne '') {
1638: exec("rlog",$revision,$fullname);
1639: }
1640: else {
1641: exec("rlog",$fullname);
1642: }
1.44 knu 1643: }
3.1 knu 1644: while (<$fh>) {
1.1 jfieber 1645: print if ($verbose);
1646: if ($symnames) {
1647: if (/^\s+([^:]+):\s+([\d\.]+)/) {
1648: $symrev{$1} = $2;
3.1 knu 1649: }
1650: else {
1.1 jfieber 1651: $symnames = 0;
1652: }
3.1 knu 1653: }
1654: elsif (/^head:\s+([\d\.]+)/) {
1655: $head = $1;
1656: }
1657: elsif (/^branch:\s+([\d\.]+)/) {
1658: $curbranch = $1;
1659: }
1660: elsif (/^symbolic names/) {
1.1 jfieber 1661: $symnames = 1;
3.1 knu 1662: }
1663: elsif (/^-----/) {
1.1 jfieber 1664: last;
1665: }
1666: }
3.1 knu 1667: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7 fenner 1668:
1.1 jfieber 1669: # each log entry is of the form:
1670: # ----------------------------
1671: # revision 3.7.1.1
1672: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
1673: # log info
1674: # ----------------------------
1675: logentry:
1676: while (!/^=========/) {
3.1 knu 1677: $_ = <$fh>;
1.12 fenner 1678: last logentry if (!defined($_)); # EOF
1.1 jfieber 1679: print "R:", $_ if ($verbose);
1680: if (/^revision ([\d\.]+)/) {
1681: $rev = $1;
3.1 knu 1682: unshift(@allrevisions,$rev);
1683: }
1684: elsif (/^========/ || /^----------------------------$/) {
1.1 jfieber 1685: next logentry;
3.1 knu 1686: }
1687: else {
1.12 fenner 1688: # The rlog output is syntactically ambiguous. We must
1689: # have guessed wrong about where the end of the last log
1690: # message was.
1691: # Since this is likely to happen when people put rlog output
1692: # in their commit messages, don't even bother keeping
1693: # these lines since we don't know what revision they go with
1694: # any more.
1695: next logentry;
1696: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 1697: }
3.1 knu 1698: $_ = <$fh>;
1.1 jfieber 1699: print "D:", $_ if ($verbose);
3.1 knu 1700: if (m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|) {
1701: my $yr = $1;
1702: # damn 2-digit year routines :-)
1703: if ($yr > 100) {
1704: $yr -= 1900;
1705: }
1706: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 1707: $author{$rev} = $7;
1.9 fenner 1708: $state{$rev} = $8;
3.1 knu 1709: $difflines{$rev} = $10;
1710: }
1711: else {
1.1 jfieber 1712: &fatal("500 Internal Error", "Error parsing RCS output: $_");
1713: }
1714: line:
3.1 knu 1715: while (<$fh>) {
1.1 jfieber 1716: print "L:", $_ if ($verbose);
1717: next line if (/^branches:\s/);
1718: last line if (/^----------------------------$/ || /^=========/);
1719: $log{$rev} .= $_;
1720: }
1721: print "E:", $_ if ($verbose);
1722: }
3.1 knu 1723: close($fh);
1.1 jfieber 1724: print "Done reading RCS file\n" if ($verbose);
3.1 knu 1725:
1726: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
1727: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
1728:
1.1 jfieber 1729: #
1730: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 1731: # branch, unless there is a branch tag in the RCS file in which case it's the
1732: # highest revision on that branch. Find it by looking through @revorder; it
1733: # is the first commit listed on the appropriate branch.
3.1 knu 1734: # This is not neccesary the same revision as marked as head in the RCS file.
1735: my $headrev = $curbranch || "1";
1736: ($symrev{"MAIN"} = $headrev) =~ s/(\.?)(\d+)$/${1}0.$2/;
1.1 jfieber 1737: revision:
3.1 knu 1738: foreach $rev (@revorder) {
1739: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
1740: $symrev{"HEAD"} = $rev;
1.1 jfieber 1741: last revision;
1742: }
1743: }
3.1 knu 1744: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
1745: if (!defined($symrev{"HEAD"}));
1.1 jfieber 1746: print "Done finding HEAD\n" if ($verbose);
1747: #
1748: # Now that we know all of the revision numbers, we can associate
1749: # absolute revision numbers with all of the symbolic names, and
1750: # pass them to the form so that the same association doesn't have
1751: # to be built then.
1752: #
3.1 knu 1753: undef @branchnames;
1754: undef %branchpoint;
1755: undef $sel;
1756:
1757: foreach (reverse sort keys %symrev) {
1.1 jfieber 1758: $rev = $symrev{$_};
3.1 knu 1759: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
1.7 fenner 1760: push(@branchnames, $_);
1.1 jfieber 1761: #
1762: # A revision number of A.B.0.D really translates into
1763: # "the highest current revision on branch A.B.D".
1764: #
1765: # If there is no branch A.B.D, then it translates into
1766: # the head A.B .
1767: #
3.1 knu 1768: # This reasoning also applies to the main branch A.B,
1769: # with the branch number 0.A, with the exception that
1770: # it has no head to translate to if there is nothing on
1771: # the branch, but I guess this can never happen?
1772: # (the code below gracefully forgets about the branch
1773: # if it should happen)
1774: #
1775: $head = defined($2) ? $2 : "";
1.1 jfieber 1776: $branch = $3;
3.1 knu 1777: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
1778: my $regex;
1779: ($regex = $branchrev) =~ s/\./\\./g;
1.1 jfieber 1780: $rev = $head;
1781:
1782: revision:
3.1 knu 1783: foreach my $r (@revorder) {
1784: if ($r =~ /^${regex}\b/) {
1785: $rev = $branchrev;
1.1 jfieber 1786: last revision;
1787: }
1788: }
3.1 knu 1789: next if ($rev eq "");
1790: if ($rev ne $head && $head ne "") {
1.8 fenner 1791: $branchpoint{$head} .= ", " if ($branchpoint{$head});
1792: $branchpoint{$head} .= $_;
1793: }
1.1 jfieber 1794: }
3.1 knu 1795: $revsym{$rev} .= ", " if ($revsym{$rev});
1796: $revsym{$rev} .= $_;
1.1 jfieber 1797: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
1798: }
1799: print "Done associating revisions with branches\n" if ($verbose);
3.1 knu 1800:
1801: my ($onlyonbranch, $onlybranchpoint);
1802: if ($onlyonbranch = $input{'only_with_tag'}) {
1803: $onlyonbranch = $symrev{$onlyonbranch};
1804: if ($onlyonbranch =~ s/\b0\.//) {
1805: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
1806: }
1807: else {
1808: $onlybranchpoint = $onlyonbranch;
1809: }
1810: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
1811: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
1812: }
1.8 fenner 1813: }
1.1 jfieber 1814:
3.1 knu 1815: undef @revisions;
1816:
1817: foreach (@allrevisions) {
1.7 fenner 1818: ($br = $_) =~ s/\.\d+$//;
3.1 knu 1819: ($brp = $br) =~ s/\.\d+$//;
1.7 fenner 1820: next if ($onlyonbranch && $br ne $onlyonbranch &&
3.1 knu 1821: $_ ne $onlybranchpoint);
1822: unshift(@revisions,$_);
1823: }
1824:
1825: if ($logsort eq "date") {
1826: # Sort the revisions in commit order an secondary sort on revision
1827: # (secondary sort needed for imported sources, or the first main
1828: # revision gets before the same revision on the 1.1.1 branch)
1829: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
1830: }
1831: elsif ($logsort eq "rev") {
1832: # Sort the revisions in revision order, highest first
1833: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
1834: }
1835: else {
1836: # No sorting. Present in the same order as rlog / cvs log
1837: @revdisplayorder = @revisions;
1838: }
1839:
1840: }
1841:
1842: sub printLog($;$) {
1843: my ($link, $br, $brp);
1844: ($_,$link) = @_;
1845: ($br = $_) =~ s/\.\d+$//;
1846: ($brp = $br) =~ s/\.?\d+$//;
1847: my ($isDead, $prev);
1848:
1849: $link = 1 if (!defined($link));
1850: $isDead = ($state{$_} eq "dead");
1851:
1852: if ($link && !$isDead) {
1853: my ($filename);
1854: ($filename = $where) =~ s/^.*\///;
1855: my ($fileurl) = urlencode($filename);
1.4 fenner 1856: print "<a NAME=\"rev$_\"></a>";
3.1 knu 1857: if (defined($revsym{$_})) {
1858: foreach my $sym (split(", ", $revsym{$_})) {
1859: print "<a NAME=\"$sym\"></a>";
1860: }
1.4 fenner 1861: }
3.1 knu 1862: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
1863: foreach my $sym (split(", ", $revsym{$br})) {
1.4 fenner 1864: print "<a NAME=\"$sym\"></a>";
1865: }
3.1 knu 1866: $nameprinted{$br} = 1;
1.4 fenner 1867: }
3.1 knu 1868: print "\n Revision ";
1869: &download_link($fileurl, $_, $_,
1870: $defaultViewable ? "text/x-cvsweb-markup" : undef);
1871: if ($defaultViewable) {
1872: print " / ";
1873: &download_link($fileurl, $_, "(download)", $mimetype);
1874: }
1875: if (not $defaultTextPlain) {
1876: print " / ";
1877: &download_link($fileurl, $_, "(as text)",
1878: "text/plain");
1879: }
1880: if (!$defaultViewable) {
1881: print " / ";
1882: &download_link($fileurl, $_, "(view)", "text/x-cvsweb-markup");
1883: }
1884: if ($allow_annotate) {
1885: print " - <a href=\"" . $scriptname . "/" . urlencode($where) . "?annotate=$_$barequery\">";
1886: print "annotate</a>";
1887: }
1888: # Plus a select link if enabled, and this version isn't selected
1889: if ($allow_version_select) {
1890: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
1891: print " - <A HREF=\"${scriptwhere}?r1=$_$barequery" .
1892: "\">[select for diffs]</A>\n";
1893: }
1894: else {
1895: print " - <b>[selected]</b>";
1896: }
1897: }
1898: }
1899: else {
1900: print "Revision <B>$_</B>";
1901: }
1902: if (/^1\.1\.1\.\d+$/) {
1903: print " <i>(vendor branch)</i>";
1904: }
1905: if (defined @mytz) {
1906: my ($est) = $mytz[(localtime($date{$_}))[8]];
1907: print ", <i>" . scalar localtime($date{$_}) . " $est</i> (";
1908: } else {
1909: print ", <i>" . scalar gmtime($date{$_}) . " UTC</i> (";
1910: }
1911: print readableTime(time() - $date{$_},1) . " ago)";
1912: print " by ";
1913: print "<i>" . $author{$_} . "</i>\n";
1914: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
1915: if ($revsym{$br});
1916: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
1917: if ($revsym{$_});
1918: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
1919: if ($branchpoint{$_});
1920: # Find the previous revision
1921: my @prevrev = split(/\./, $_);
1922: do {
1923: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 1924: # If it was X.Y.Z.1, just make it X.Y
3.1 knu 1925: pop(@prevrev);
1926: pop(@prevrev);
1927: }
1928: $prev = join(".", @prevrev);
1929: } until (defined($date{$prev}) || $prev eq "");
1930: if ($prev ne "") {
1931: if ($difflines{$_}) {
1932: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
1933: }
1934: }
1935: if ($isDead) {
1936: print "<BR><B><I>FILE REMOVED</I></B>\n";
1937: }
1938: elsif ($link) {
1939: my %diffrev = ();
1940: $diffrev{$_} = 1;
1941: $diffrev{""} = 1;
1942: print "<BR>Diff";
1943: #
1944: # Offer diff to previous revision
1945: if ($prev) {
1946: $diffrev{$prev} = 1;
1947: print " to previous <A HREF=\"${scriptwhere}.diff?r1=$prev";
1948: print "&r2=$_" . $barequery . "\">$prev</A>\n";
1949: if (!$hr_default) { # offer a human readable version if not default
1950: print "(<A HREF=\"${scriptwhere}.diff?r1=$prev";
1951: print "&r2=$_" . $barequery . "&f=h\">colored</A>)\n";
1952: }
1953: }
1954: #
1955: # Plus, if it's on a branch, and it's not a vendor branch,
1956: # offer a diff with the branch point.
1957: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
1958: print " to branchpoint <A HREF=\"${scriptwhere}.diff?r1=$brp";
1959: print "&r2=$_" . $barequery . "\">$brp</A>\n";
1960: if (!$hr_default) { # offer a human readable version if not default
1961: print "(<A HREF=\"${scriptwhere}.diff?r1=$brp";
1962: print "&r2=$_" . $barequery . "&f=h\">colored</A>)\n";
1.1 jfieber 1963: }
1964: }
3.1 knu 1965: #
1966: # Plus, if it's on a branch, and it's not a vendor branch,
1967: # offer to diff with the next revision of the higher branch.
1968: # (e.g. change gets committed and then brought
1969: # over to -stable)
1970: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
1971: my ($i,$nextmain);
1972: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
1973: my (@tmp2) = split(/\./, $_);
1974: for ($nextmain = ""; $i > 0; $i--) {
1975: my ($next) = $revorder[$i-1];
1976: my (@tmp1) = split(/\./, $next);
1.1 jfieber 1977: if ($#tmp1 < $#tmp2) {
3.1 knu 1978: $nextmain = $next;
1979: last;
1980: }
1981: # Only the highest version on a branch should have
1982: # a diff for the "next main".
1983: last if (join(".",@tmp1[0..$#tmp1-1])
1984: eq join(".",@tmp2[0..$#tmp1-1]));
1985: }
1986: if (!defined($diffrev{$nextmain})) {
1987: $diffrev{$nextmain} = 1;
1988: print " next main <A HREF=\"${scriptwhere}.diff?r1=$nextmain";
1989: print "&r2=$_" . $barequery .
1990: "\">$nextmain</A>\n";
1991: if (!$hr_default) { # offer a human readable version if not default
1992: print "(<A HREF=\"${scriptwhere}.diff?r1=$nextmain";
1993: print "&r2=$_" . $barequery .
1994: "&f=h\">colored</A>)\n";
1.1 jfieber 1995: }
1996: }
1997: }
3.1 knu 1998: # Plus if user has selected only r1, then present a link
1999: # to make a diff to that revision
2000: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2001: $diffrev{$input{"r1"}} = 1;
2002: print " to selected <A HREF=\"${scriptwhere}.diff?"
2003: . "r1=$input{'r1'}&r2=$_" . $barequery
2004: . "\">$input{'r1'}</A>\n";
2005: if (!$hr_default) { # offer a human readable version if not default
2006: print "(<A HREF=\"${scriptwhere}.diff?r1=$input{'r1'}";
2007: print "&r2=$_" . $barequery .
2008: "&f=h\">colored</A>)\n";
2009:
2010: }
1.9 fenner 2011: }
1.1 jfieber 2012: }
3.1 knu 2013: print "<PRE>\n";
2014: print &htmlify($log{$_}, 1);
2015: print "</PRE>\n";
2016: }
2017:
2018: sub doLog {
2019: my($fullname) = @_;
2020: my ($diffrev, $upwhere, $filename, $backurl);
2021:
2022: readLog($fullname);
2023:
2024: html_header("CVS log for $where");
2025: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2026: ($filename = $where) =~ s|^.*/||;
2027: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2028: print &link($backicon, "$backurl#$filename"),
2029: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
3.3 knu 2030: print <<EOF;
2031: <A HREF="#diff">Request diff between arbitrary revisions</A>
2032: <HR NOSHADE>
2033: EOF
3.1 knu 2034: if ($curbranch) {
3.3 knu 2035: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
3.1 knu 2036: }
2037: else {
2038: print "No default branch";
2039: }
2040: print "<BR>\n";
2041: if ($input{only_with_tag}) {
2042: print "Current tag: $input{only_with_tag}<BR>\n";
2043: }
2044:
2045: undef %nameprinted;
2046:
2047: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2048: print "<HR size=1 NOSHADE>";
2049: printLog($revdisplayorder[$i]);
2050: }
2051:
2052: print "<HR NOSHADE>";
1.1 jfieber 2053: print "<A NAME=diff>\n";
2054: print "This form allows you to request diff's between any two\n";
2055: print "revisions of a file. You may select a symbolic revision\n";
2056: print "name using the selection box or you may type in a numeric\n";
2057: print "name using the type-in text box.\n";
2058: print "</A><P>\n";
3.1 knu 2059: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2060: foreach (@stickyvars) {
2061: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
2062: if (defined($input{$_})
2063: && ($input{$_} ne $DEFAULTVALUE{$_} && $input{$_} ne ""));
2064: }
1.1 jfieber 2065: print "Diffs between \n";
2066: print "<SELECT NAME=\"r1\">\n";
2067: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2068: print $sel;
2069: print "</SELECT>\n";
3.1 knu 2070: $diffrev = $revdisplayorder[$#revdisplayorder];
2071: $diffrev = $input{"r1"} if (defined($input{"r1"}));
2072: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'>\n";
1.1 jfieber 2073: print " and \n";
2074: print "<SELECT NAME=\"r2\">\n";
2075: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2076: print $sel;
2077: print "</SELECT>\n";
3.1 knu 2078: $diffrev = $revdisplayorder[0];
2079: $diffrev = $input{"r2"} if (defined($input{"r2"}));
2080: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='docuement.diff_select.r2.selectedIndex=0'>\n";
2081: print "<BR>Type of Diff should be a ";
2082: printDiffSelect();
2083: print "<INPUT TYPE=SUBMIT VALUE=\" Get Diffs \">\n";
1.1 jfieber 2084: print "</FORM>\n";
1.7 fenner 2085: print "<HR noshade>\n";
3.1 knu 2086: if (@branchnames) {
2087: print "<A name=branch></A>\n";
2088: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
2089: foreach (@stickyvars) {
2090: next if ($_ eq "only_with_tag");
2091: next if ($_ eq "logsort");
2092: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
2093: if (defined($input{$_}) && $input{$_} ne $DEFAULTVALUE{$_}
2094: && $input{$_} ne "");
2095: }
2096: print "View only Branch: \n";
2097: print "<SELECT NAME=\"only_with_tag\"";
2098: print " onchange=\"submit()\"" if ($use_java_script);
2099: print ">\n";
2100: print "<OPTION VALUE=\"\"";
2101: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2102: $input{"only_with_tag"} eq "");
2103: print ">Show all branches\n";
2104: foreach (reverse sort @branchnames) {
1.9 fenner 2105: print "<OPTION";
3.1 knu 2106: print " SELECTED" if (defined($input{"only_with_tag"})
2107: && $input{"only_with_tag"} eq $_);
1.9 fenner 2108: print ">${_}\n";
3.1 knu 2109: }
2110: print "</SELECT>\n";
2111: print "<INPUT TYPE=SUBMIT VALUE=\" View Branch \">\n";
2112: print "</FORM>\n";
1.7 fenner 2113: }
3.1 knu 2114: print "<A name=logsort></A>\n";
2115: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
2116: foreach (@stickyvars) {
2117: next if ($_ eq "only_with_tag");
2118: next if ($_ eq "logsort");
2119: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
2120: if (defined($input{$_}) && $input{$_} ne $DEFAULTVALUE{$_}
2121: && $input{$_} ne "");
2122: }
2123: print "Sort log by: \n";
2124: print "<SELECT NAME=\"logsort\"";
2125: print " onchange=\"submit()\"" if ($use_java_script);
2126: print ">\n";
2127: print "<OPTION VALUE=cvs",$logsort eq "cvs" ? " SELECTED" : "", ">Not sorted";
2128: print "<OPTION VALUE=date",$logsort eq "date" ? " SELECTED" : "", ">Commit date";
2129: print "<OPTION VALUE=rev",$logsort eq "rev" ? " SELECTED" : "", ">Revision";
1.7 fenner 2130: print "</SELECT>\n";
3.1 knu 2131: print "<INPUT TYPE=SUBMIT VALUE=\" Sort \">\n";
1.7 fenner 2132: print "</FORM>\n";
1.2 jfieber 2133: print &html_footer;
1.1 jfieber 2134: print "</BODY></HTML>\n";
1.10 wosch 2135: }
2136:
3.1 knu 2137: sub flush_diff_rows ($$$$)
2138: {
2139: my $j;
2140: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2141: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2142: for ($j = 0 ; $j < $leftRow; $j++) {
2143: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2144: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2145: }
2146: }
2147: elsif ($state eq "PreChange") { # state eq "PreChange"
2148: # we got removes with subsequent adds
2149: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2150: print "<tr>";
2151: if ($j < $leftRow) {
2152: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2153: }
2154: else {
2155: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2156: }
2157: if ($j < $rightRow) {
2158: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2159: }
2160: else {
2161: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2162: }
2163: print "</tr>\n";
2164: }
2165: }
2166: }
2167:
2168: ##
2169: # Function to generate Human readable diff-files
2170: # human_readable_diff(String revision_to_return_to);
2171: ##
2172: sub human_readable_diff($){
2173: my ($i,$difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
2174: my ($fh, $rev) = @_;
2175: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2176: my (@rightCol, @leftCol);
2177:
2178: ($where_nd = $where) =~ s/.diff$//;
2179: ($filename = $where_nd) =~ s/^.*\///;
2180: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2181: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2182:
2183: navigateHeader ($scriptwhere_nd, $pathname, $filename, $rev, "diff");
2184:
2185: # Read header to pick up read revision and date, if possible
2186: while (<$fh>) {
2187: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2188: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2189: last if (/^\+\+\+ /);
2190: }
2191: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2192: $rev1 = $r1r;
2193: $date1 = $r1d;
2194: }
2195: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2196: $rev2 = $r2r;
2197: $date2 = $r2d;
2198: }
2199:
2200: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n";
2201:
2202: print "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n";
2203: print "<tr bgcolor=\"#ffffff\">\n";
2204: print "<th width=\"50%\" valign=TOP>";
2205: print "version $rev1";
2206: print ", $date1" if (defined($date1));
2207: print "<br>Tag: $sym1\n" if ($sym1);
2208: print "</th>\n";
2209: print "<th width=\"50%\" valign=TOP>";
2210: print "version $rev2";
2211: print ", $date2" if (defined($date2));
2212: print "<br>Tag: $sym2\n" if ($sym1);
2213: print "</th>\n";
2214:
2215: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\">";
2216: my $fe = "</font>";
2217:
2218: my $leftRow = 0;
2219: my $rightRow = 0;
2220: my ($oldline, $newline, $funname, $diffcode, $rest);
2221:
2222: # Process diff text
2223: # The diffrows are could make excellent use of
2224: # cascading style sheets because we've to set the
2225: # font and color for each row. anyone ...?
2226: ####
2227: while (<$fh>) {
2228: $difftxt = $_;
2229:
2230: if ($difftxt =~ /^@@/) {
2231: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2232: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2233: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2234: print " <font size=-1>$funname</font></td></tr></table>";
2235: print "</td><td width=\"50%\">";
2236: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2237: print " <font size=-1>$funname</font></td></tr></table>";
2238: print "</td>\n";
2239: $state = "dump";
2240: $leftRow = 0;
2241: $rightRow = 0;
2242: }
2243: else {
2244: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
2245: $_ = spacedHtmlText ($rest);
2246:
2247: # Add fontface, size
2248: $_ = "$fs $_$fe";
2249:
2250: #########
2251: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2252: # in order to get some nice 'ediff'-mode output
2253: # states:
2254: # "dump" - just dump the value
2255: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2256: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2257: ##########
2258:
2259: if ($diffcode eq '+') {
2260: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2261: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2262: }
2263: else { # we got minus before
2264: $state = "PreChange";
2265: $rightCol[$rightRow++] = $_;
2266: }
2267: }
2268: elsif ($diffcode eq '-') {
2269: $state = "PreChangeRemove";
2270: $leftCol[$leftRow++] = $_;
2271: }
2272: else { # empty diffcode
2273: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2274: print "<tr><td>$_</td><td>$_</td></tr>\n";
2275: $state = "dump";
2276: $leftRow = 0;
2277: $rightRow = 0;
2278: }
2279: }
2280: }
2281: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2282:
2283: # state is empty if we didn't have any change
2284: if (!$state) {
2285: print "<tr><td colspan=2> </td></tr>";
2286: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2287: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2288: }
2289: print "</table>";
2290: close($fh);
2291:
2292: print "<br><hr noshade width=\"100%\">\n";
2293:
2294: print "<table border=0>";
2295:
2296: print "<tr><td>";
2297: # print legend
2298: print "<table border=1><tr><td>";
2299: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2300: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2301: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2302: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2303: print "</table></td></tr></table>\n";
2304:
2305: print "<td>";
2306: # Print format selector
2307: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2308: foreach my $var (keys %input) {
2309: next if ($var eq "f");
2310: next if (defined($DEFAULTVALUE{$var})
2311: && $DEFAULTVALUE{$var} eq $input{$var});
2312: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2313: urlencode($input{$var}),"\">\n";
2314: }
2315: printDiffSelect($use_java_script);
2316: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2317: print "</FORM>\n";
2318: print "</td>";
2319:
2320: print "</tr></table>";
2321: }
2322:
2323: sub navigateHeader ($$$$$) {
2324: my ($swhere,$path,$filename,$rev,$title) = @_;
2325: $swhere = "" if ($swhere eq $scriptwhere);
2326: $swhere = urlencode($filename) if ($swhere eq "");
2327: print "<\!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
2328: print "<HTML>\n<HEAD>\n";
3.4 ! knu 2329: print '<!-- CVSweb $Revision: 3.3 $ -->';
3.1 knu 2330: print "\n<TITLE>$path$filename - $title - $rev</TITLE></HEAD>\n";
2331: print "<BODY BGCOLOR=\"$backcolor\">\n";
2332: print "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$navigationHeaderColor\">";
2333: print "<tr valign=bottom><td>";
2334: print "<a href=\"$swhere$query#rev$rev\">$backicon";
2335: print "</a> <b>Return to ", &link("$filename","$swhere$query#rev$rev")," CVS log";
2336: print "</b> $fileicon</td>";
2337:
2338: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2339: print "</tr></table>";
2340: }
2341:
2342: sub plural_write ($$)
2343: {
2344: my ($num,$text) = @_;
2345: if ($num != 1) {
2346: $text = $text . "s";
2347: }
2348: if ($num > 0) {
2349: return $num . " " . $text;
2350: }
2351: else {
2352: return "";
2353: }
2354: }
2355:
2356: ##
2357: # print readable timestamp in terms of
2358: # '..time ago'
2359: # H. Zeller <zeller@think.de>
2360: ##
2361: sub readableTime ($$)
2362: {
2363: my ($i, $break, $retval);
2364: my ($secs,$long) = @_;
2365:
2366: # this function works correct for time >= 2 seconds
2367: if ($secs < 2) {
2368: return "very little time";
2369: }
2370:
2371: my %desc = (1 , 'second',
2372: 60, 'minute',
2373: 3600, 'hour',
2374: 86400, 'day',
2375: 604800, 'week',
2376: 2628000, 'month',
2377: 31536000, 'year');
2378: my @breaks = sort {$a <=> $b} keys %desc;
2379: $i = 0;
2380: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
2381: $i++;
2382: }
2383: $i--;
2384: $break = $breaks[$i];
3.3 knu 2385: $retval = plural_write(int ($secs / $break), $desc{$break});
3.1 knu 2386:
2387: if ($long == 1 && $i > 0) {
2388: my $rest = $secs % $break;
2389: $i--;
2390: $break = $breaks[$i];
2391: my $resttime = plural_write(int ($rest / $break),
3.3 knu 2392: $desc{$break});
3.1 knu 2393: if ($resttime) {
2394: $retval = $retval . ", " . $resttime;
2395: }
2396: }
2397:
2398: return $retval;
2399: }
2400:
2401: ##
2402: # clickablePath(String pathname, boolean last_item_clickable)
2403: #
2404: # returns a html-ified path whereas each directory is a link for
2405: # faster navigation. last_item_clickable controls whether the
2406: # basename (last directory/file) is a link as well
2407: ##
2408: sub clickablePath($$) {
2409: my ($pathname,$clickLast) = @_;
2410: my $retval = '';
2411:
2412: if ($pathname eq '/') {
2413: # this should never happen - chooseCVSRoot() is
2414: # intended to do this
2415: $retval = "[$cvstree]";
2416: }
2417: else {
2418: $retval = $retval . " <a href=\"${scriptname}/${query}#dirlist\">[$cvstree]</a>";
2419: my $wherepath = '';
2420: my ($lastslash) = $pathname =~ m|/$|;
2421: foreach (split(/\//, $pathname)) {
2422: $retval = $retval . " / ";
2423: $wherepath = $wherepath . '/' . $_;
2424: my ($last) = "$wherepath/" eq "/$pathname"
3.3 knu 2425: || $wherepath eq "/$pathname";
3.1 knu 2426: if ($clickLast || !$last) {
2427: $retval = $retval . "<a href=\"${scriptname}"
2428: . urlencode($wherepath)
2429: . (!$last || $lastslash ? '/' : '')
2430: . ${query}
2431: . (!$last || $lastslash ? "#dirlist" : "")
2432: . "\">$_</a>";
2433: }
2434: else { # do not make a link to the current dir
2435: $retval = $retval . $_;
2436: }
2437: }
2438: }
2439: return $retval;
2440: }
2441:
2442: sub chooseCVSRoot() {
2443: my @foo;
2444: foreach (sort keys %CVSROOT) {
2445: if (-d $CVSROOT{$_}) {
2446: push(@foo, $_);
2447: }
2448: }
2449: if (@foo > 1) {
2450: my ($k);
2451: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2452: foreach $k (keys %input) {
2453: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
2454: if ($input{$k}) && ($k ne "cvsroot");
2455: }
2456: # Form-Elements look wierd in Netscape if the background
2457: # isn't gray and the form elements are not placed
2458: # within a table ...
2459: print "<table><tr>";
2460: print "<td>CVS Root:</td>";
2461: print "<td>\n<select name=\"cvsroot\"";
2462: print " onchange=\"submit()\"" if ($use_java_script);
2463: print ">\n";
2464: foreach $k (@foo) {
2465: print "<option value=\"$k\"";
3.3 knu 2466: print " selected" if ($k eq $cvstree);
2467: print ">" . ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} :
3.1 knu 2468: $k). "</option>\n";
2469: }
2470: print "</select>\n</td>";
2471: print "<td><input type=submit value=\"Go\"></td>";
2472: print "</tr></table></form>";
2473: }
2474: else {
2475: # no choice ..
2476: print "CVS Root: <b>[$cvstree]</b>";
2477: }
2478: }
2479:
2480: sub chooseMirror() {
2481: my ($mirror,$moremirrors);
2482: $moremirrors = 0;
2483: # This code comes from the original BSD-cvsweb
2484: # and may not be useful for your site; If you don't
2485: # set %MIRRORS this won't show up, anyway
2486: #
2487: # Should perhaps exlude the current site somehow..
2488: if (keys %MIRRORS) {
2489: print "\nThis cvsweb is mirrored in:\n";
2490: foreach $mirror (keys %MIRRORS) {
2491: print ", " if ($moremirrors);
2492: print qq(<a href="$MIRRORS{$mirror}">$mirror</A>\n);
2493: $moremirrors = 1;
2494: }
2495: print "<p>\n";
2496: }
2497: }
2498:
2499: sub fileSortCmp {
2500: my ($comp) = 0;
2501: my ($c,$d,$af,$bf);
2502:
2503: ($af = $a) =~ s/,v$//;
2504: ($bf = $b) =~ s/,v$//;
2505: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2506: if (defined($fileinfo{$af}));
2507: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2508: if (defined($fileinfo{$bf}));
2509:
2510: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2511: # Two files
2512: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2513: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2514: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2515: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2516: }
2517: if ($comp == 0) {
2518: # Directories first, then sorted on name if no other sort critera
2519: # available.
2520: my $ad = ((-d "$fullname/$a")?"D":"F");
2521: my $bd = ((-d "$fullname/$b")?"D":"F");
2522: ($c=$a) =~ s|.*/||;
2523: ($d=$b) =~ s|.*/||;
2524: $comp = ("$ad$c" cmp "$bd$d");
2525: }
2526: return $comp;
2527: }
2528:
2529: # make A url for downloading
2530: sub download_url {
2531: my ($url,$revision,$mimetype) = @_;
2532:
2533: $revision =~ s/\b0\.//;
2534:
2535: if (defined($checkout_magic)
2536: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
2537: my ($path);
2538: ($path = $where) =~ s|/[^/]*$|/|;
2539: $url = "$scriptname/$checkoutMagic/${path}$url";
2540: }
2541: $url .= "?rev=$revision";
2542: $url .= "&content-type=$mimetype" if (defined($mimetype));
2543:
2544: return $url;
2545: }
2546:
2547: # Presents a link to download the
2548: # selected revision
2549: sub download_link {
2550: my ($url,$revision,$textlink,$mimetype) = @_;
2551: my ($fullurl) = download_url($url,$revision,$mimetype);
2552: my ($paren) = $textlink =~ /^\(/;
2553: $textlink =~ s/^\(// if ($paren);
2554: $textlink =~ s/\)$// if ($paren);
2555: print "(" if ($paren);
2556: print "<A HREF=\"$fullurl";
2557: print $barequery;
2558: print "\"";
2559: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
2560: print " target=\"cvs_checkout\"";
2561: # we should have
2562: # 'if (document.cvswin==null) document.cvswin=window.open(...'
2563: # in order to allow the user to resize the window; otherwise
2564: # the user may resize the window, but on next checkout - zap -
2565: # its original (configured s. cvsweb.conf) size is back again
2566: # .. annoying (if $extern_window_(width|height) is defined)
2567: # but this if (..) solution is far from perfect
2568: # what we need to do as well is
2569: # 1) save cvswin in an invisible frame that always exists
2570: # (document.cvswin will be void on next load)
2571: # 2) on close of the cvs_checkout - window set the cvswin
2572: # variable to 'null' again - so that it will be
2573: # reopenend with the configured size
2574: # anyone a JavaScript programmer ?
2575: # .. so here without if (..):
2576: # currently, the best way is to comment out the size parameters
2577: # ($extern_window...) in cvsweb.conf.
2578: if ($use_java_script) {
2579: print " onClick=\"window.open('$fullurl','cvs_checkout',";
2580: print "'resizeable,scrollbars";
2581: print ",status,toolbar" if (defined($mimetype)
2582: && $mimetype eq "text/html");
2583: print ",width=$extern_window_width" if (defined($extern_window_width));
2584: print ",height=$extern_window_height" if (defined($extern_window_height));
2585: print"');\"";
2586: }
2587: }
2588: print "><b>$textlink</b></A>";
2589: print ")" if ($paren);
2590: }
2591:
2592: # Returns a Query string with the
2593: # specified parameter toggled
2594: sub toggleQuery($$) {
2595: my ($toggle,$value) = @_;
2596: my ($newquery,$var);
2597: my (%vars);
2598: %vars = %input;
2599: if (defined($value)) {
2600: $vars{$toggle} = $value;
2601: }
2602: else {
2603: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
2604: }
2605: # Build a new query of non-default paramenters
2606: $newquery = "";
2607: foreach $var (@stickyvars) {
2608: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
2609: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
2610: if ($value ne $default) {
2611: $newquery .= "&" if ($newquery ne "");
2612: $newquery .= urlencode($var) . "=" . urlencode($value);
2613: }
2614: }
2615: if ($newquery) {
2616: return '?' . $newquery;
2617: }
2618: return "";
2619: }
2620:
2621: sub urlencode {
2622: my ($in) = @_;
2623: my ($out);
2624: ($out = $in) =~ s/([\000-+{-\377])/sprintf("%%%02x", ord($1))/ge;
2625: return $out;
2626: }
2627:
2628: sub http_header {
2629: my $content_type = shift || "text/html";
2630: if (defined($moddate)) {
2631: if ($is_mod_perl) {
2632: Apache->request->header_out(Last_modified => scalar gmtime($moddate) . " GMT");
2633: }
2634: else {
3.4 ! knu 2635: print "Last-Modified: " . scalar gmtime($moddate) . " GMT\r\n";
3.1 knu 2636: }
2637: }
2638: if ($is_mod_perl) {
2639: Apache->request->content_type($content_type);
2640: }
2641: else {
3.4 ! knu 2642: print "Content-type: $content_type\r\n";
3.1 knu 2643: }
2644: if ($allow_compress && $maycompress) {
2645: my $fh = do {local(*FH);};
2646: if (defined($GZIPBIN) && open($fh, "|$GZIPBIN -1 -c")) {
2647: if ($is_mod_perl) {
2648: Apache->request->content_encoding("x-gzip");
2649: Apache->request->header_out(Vary => "Accept-Encoding");
2650: Apache->request->send_http_header;
2651: }
2652: else {
3.4 ! knu 2653: print "Content-encoding: x-gzip\r\n";
! 2654: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
! 2655: print "\r\n"; # Close headers
3.1 knu 2656: }
2657: $| = 1; $| = 0; # Flush header output
2658: select ($fh);
2659: # print "<!-- gzipped -->" if ($content_type eq "text/html");
2660: }
2661: else {
2662: if ($is_mod_perl) {
2663: Apache->request->send_http_header;
2664: }
2665: else {
3.4 ! knu 2666: print "\r\n"; # Close headers
3.1 knu 2667: }
2668: print "<font size=-1>Unable to find gzip binary in the \$PATH to compress output</font><br>";
2669: }
2670: }
2671: else {
2672: if ($is_mod_perl) {
2673: Apache->request->send_http_header;
2674: }
2675: else {
3.4 ! knu 2676: print "\r\n"; # Close headers
3.1 knu 2677: }
2678: }
2679: }
2680:
2681: sub html_header($) {
2682: my ($title) = @_;
3.4 ! knu 2683: my $version = '$Revision: 3.3 $';
3.1 knu 2684: http_header();
2685: print <<EOH;
2686: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
2687: "http://www.w3.org/TR/REC-html40/loose.dtd">
2688: <html>
2689: <title>$title</title>
3.3 knu 2690: <!-- CVSweb $version -->
3.1 knu 2691: </head>
2692: $body_tag
2693: $logo <h1 align="center">$title</h1>
2694: EOH
2695: }
2696:
2697: sub html_footer {
2698: return "<hr noshade><address>$address</address>\n";
2699: }
2700:
2701: sub link_tags
2702: {
2703: my ($tags) = @_;
2704: my ($ret) = "";
2705: my ($fileurl,$filename);
2706:
2707: ($filename = $where) =~ s/^.*\///;
2708: $fileurl = urlencode($filename);
2709:
2710: foreach my $sym (split(", ", $tags)) {
2711: $ret .= ",\n" if ($ret ne "");
2712: $ret .= "<A HREF=\"$fileurl"
2713: . toggleQuery('only_with_tag',$sym) . "\">$sym</A>";
2714: }
2715: return $ret."\n";
2716: }
2717:
2718: #
2719: # See if a module is listed in the config file's @HideModule list.
2720: #
2721: sub forbidden_module {
2722: my($module) = @_;
2723:
2724: for (my $i=0; $i < @HideModules; $i++) {
2725: return 1 if $module eq $HideModules[$i];
2726: }
2727:
2728: return 0;
1.1 jfieber 2729: }
CVSweb