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