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