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