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