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