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