gecko-dev/webtools/bonsai/cvsquery.cgi

648 строки
16 KiB
Plaintext
Исходник Обычный вид История

#!/usr/bonsaitools/bin/perl -w
1998-06-17 01:43:24 +04:00
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is the Bonsai CVS tool.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are Copyright (C) 1998
# Netscape Communications Corporation. All Rights Reserved.
use diagnostics;
use strict;
# Shut up misguided -w warnings about "used only once". "use vars" just
# doesn't work for me.
sub sillyness {
my $zz;
$zz = $::CI_BRANCH;
$zz = $::CI_REPOSITORY;
$zz = $::lines_added;
$zz = $::lines_removed;
$zz = $::query_begin_tag;
$zz = $::query_branchtype;
$zz = $::query_date_max;
$zz = $::query_debug;
$zz = $::query_end_tag;
$zz = $::query_filetype;
$zz = $::query_logexpr;
$zz = $::query_whotype;
}
require 'CGI.pl';
require 'cvsquery.pl';
1998-06-17 01:43:24 +04:00
$::CVS_ROOT = $::FORM{'cvsroot'};
$::CVS_ROOT = pickDefaultRepository() unless $::CVS_ROOT;
$::TreeID = $::FORM{'module'}
if (!exists($::FORM{'treeid'}) &&
exists($::FORM{'module'}) &&
exists($::TreeInfo{$::FORM{'module'}}{'repository'}));
$::TreeID = 'default'
if (!exists($::TreeInfo{$::TreeID}{'repository'}) ||
exists($::TreeInfo{$::TreeID}{'nobonsai'}));
1998-06-17 01:43:24 +04:00
LoadTreeConfig();
1998-06-17 01:43:24 +04:00
my $userdomain = Param('userdomain');
1998-06-17 01:43:24 +04:00
$| = 1;
my $sm_font_tag = "<font face='Arial,Helvetica' size=-2>";
1998-06-17 01:43:24 +04:00
my $generateBackoutCVSCommands = 0;
if (defined $::FORM{'generateBackoutCVSCommands'}) {
$generateBackoutCVSCommands = 1;
}
if (!$generateBackoutCVSCommands) {
print "Content-type: text/html
1998-06-17 01:43:24 +04:00
";
print setup_script();
}
1998-06-17 01:43:24 +04:00
#print "<pre>";
my $CVS_REPOS_SUFIX = $::CVS_ROOT;
1998-06-17 01:43:24 +04:00
$CVS_REPOS_SUFIX =~ s/\//_/g;
my $CHECKIN_DATA_FILE = "data/checkinlog${CVS_REPOS_SUFIX}";
my $CHECKIN_INDEX_FILE = "data/index${CVS_REPOS_SUFIX}";
1998-06-17 01:43:24 +04:00
my $SORT_HEAD="bgcolor=\"#DDDDDD\"";
1998-06-17 01:43:24 +04:00
#
# Log the query
Log("Query [$ENV{'REMOTE_ADDR'}]: $ENV{'QUERY_STRING'}");
1998-06-17 01:43:24 +04:00
#
# build a module map
#
$::query_module = $::FORM{'module'};
1998-06-17 01:43:24 +04:00
#
# allow ?file=/a/b/c/foo.c to be synonymous with ?dir=/a/b/c&file=foo.c
#
$::FORM{'file'} = "" unless defined $::FORM{'file'};
unless ($::FORM{'dir'}) {
$::FORM{'file'} = Fix_BonsaiLink($::FORM{'file'});
if ($::FORM{'file'} =~ m@(.*?/)([^/]*)$@) {
$::FORM{'dir'} = $1;
$::FORM{'file'} = $2;
} else {
$::FORM{'dir'} = "";
}
1998-06-17 01:43:24 +04:00
}
#
# build a directory map
#
@::query_dirs = split(/[;, \t]+/, $::FORM{'dir'});
1998-06-17 01:43:24 +04:00
$::query_file = $::FORM{'file'};
$::query_filetype = $::FORM{'filetype'};
$::query_logexpr = $::FORM{'logexpr'};
1998-06-17 01:43:24 +04:00
#
# date
#
$::query_date_type = $::FORM{'date'};
if( $::query_date_type eq 'hours' ){
$::query_date_min = time - $::FORM{'hours'}*60*60;
}
elsif( $::query_date_type eq 'day' ){
$::query_date_min = time - 24*60*60;
1998-06-17 01:43:24 +04:00
}
elsif( $::query_date_type eq 'week' ){
$::query_date_min = time - 7*24*60*60;
1998-06-17 01:43:24 +04:00
}
elsif( $::query_date_type eq 'month' ){
$::query_date_min = time - 30*24*60*60;
1998-06-17 01:43:24 +04:00
}
elsif( $::query_date_type eq 'all' ){
$::query_date_min = 0;
1998-06-17 01:43:24 +04:00
}
elsif( $::query_date_type eq 'explicit' ){
if ($::FORM{'mindate'} ne "") {
$::query_date_min = parse_date($::FORM{'mindate'});
1998-06-17 01:43:24 +04:00
}
if ($::FORM{'maxdate'} ne "") {
$::query_date_max = parse_date($::FORM{'maxdate'});
1998-06-17 01:43:24 +04:00
}
}
else {
$::query_date_min = time-60*60*2;
1998-06-17 01:43:24 +04:00
}
#
# who
#
$::query_who = $::FORM{'who'};
$::query_whotype = $::FORM{'whotype'};
1998-06-17 01:43:24 +04:00
my $show_raw = 0;
$show_raw = $::FORM{'raw'} ne ''
if $::FORM{'raw'};
1998-06-17 01:43:24 +04:00
#
# branch
#
$::query_branch = $::FORM{'branch'};
if (!defined $::query_branch) {
$::query_branch = 'HEAD';
1999-03-25 04:17:36 +03:00
}
$::query_branchtype = $::FORM{'branchtype'};
1998-06-17 01:43:24 +04:00
#
# tags
#
$::query_begin_tag = $::FORM{'begin_tag'};
$::query_end_tag = $::FORM{'end_tag'};
1998-06-17 01:43:24 +04:00
#
# Get the query in english and print it.
#
my ($t, $e);
1998-06-17 01:43:24 +04:00
$t = $e = &query_to_english;
$t =~ s/<[^>]*>//g;
$::query_debug = $::FORM{'debug'};
1998-06-17 01:43:24 +04:00
my %mod_map = ();
my $result= &query_checkins( %mod_map );
my %w;
1998-06-17 01:43:24 +04:00
for my $i (@{$result}) {
$w{"$i->[$::CI_WHO]\@$userdomain"} = 1;
1998-06-17 01:43:24 +04:00
}
my @p = sort keys %w;
my $pCount = @p;
my $s = join(",%20", @p);
1998-06-17 01:43:24 +04:00
$e =~ s/Checkins in/In/;
my $menu = "
<p align=center>$e
<p align=left>
<a href=cvsqueryform.cgi?$ENV{QUERY_STRING}>Modify Query</a>
<br><a href=mailto:$s>Mail everyone on this page</a>
<NOBR>($pCount people)</NOBR>
<br><a href=cvsquery.cgi?$ENV{QUERY_STRING}&generateBackoutCVSCommands=1>Show commands which could be used to back out these changes</a>
1998-06-17 01:43:24 +04:00
";
if (defined $::FORM{'generateBackoutCVSCommands'}) {
print "Content-type: text/plain
# This page can be saved as a shell script and executed. It should be
# run at the top of your CVS work area. It will update your workarea to
# backout the changes selected by your query.
";
foreach my $ci (@{$result}) {
if ($ci->[$::CI_REV] eq "") {
print "echo 'Changes made to $ci->[$::CI_DIR]/$ci->[$::CI_FILE] need to be backed out by hand'\n";
next;
}
my $prev_revision = PrevRev($ci->[$::CI_REV]);
print "cvs update -j$ci->[$::CI_REV] -j$prev_revision $ci->[$::CI_DIR]/$ci->[$::CI_FILE]\n";
}
exit;
}
PutsHeader($t, "CVS Checkins", "$menu");
1998-06-17 01:43:24 +04:00
#
# Test code to print the results
#
$|=1;
my $head_who = '';
my $head_file = '';
my $head_directory = '';
my $head_delta = '';
my $head_date = '';
1998-06-17 01:43:24 +04:00
if( !$show_raw ) {
if( $::FORM{"sortby"} eq "Who" ){
1998-06-17 01:43:24 +04:00
$result = [sort {
$a->[$::CI_WHO] cmp $b->[$::CI_WHO]
|| $b->[$::CI_DATE] <=> $a->[$::CI_DATE]
1998-06-17 01:43:24 +04:00
} @{$result}] ;
$head_who = $SORT_HEAD;
}
elsif( $::FORM{"sortby"} eq "File" ){
1998-06-17 01:43:24 +04:00
$result = [sort {
$a->[$::CI_FILE] cmp $b->[$::CI_FILE]
|| $b->[$::CI_DATE] <=> $a->[$::CI_DATE]
|| $a->[$::CI_DIRECTORY] cmp $b->[$::CI_DIRECTORY]
1998-06-17 01:43:24 +04:00
} @{$result}] ;
$head_file = $SORT_HEAD;
}
elsif( $::FORM{"sortby"} eq "Directory" ){
1998-06-17 01:43:24 +04:00
$result = [sort {
$a->[$::CI_DIRECTORY] cmp $b->[$::CI_DIRECTORY]
|| $a->[$::CI_FILE] cmp $b->[$::CI_FILE]
|| $b->[$::CI_DATE] <=> $a->[$::CI_DATE]
1998-06-17 01:43:24 +04:00
} @{$result}] ;
$head_directory = $SORT_HEAD;
}
elsif( $::FORM{"sortby"} eq "Change Size" ){
1998-06-17 01:43:24 +04:00
$result = [sort {
($b->[$::CI_LINES_ADDED]- $b->[$::CI_LINES_REMOVED])
<=> ($a->[$::CI_LINES_ADDED]- $a->[$::CI_LINES_REMOVED])
#|| $b->[$::CI_DATE] <=> $a->[$::CI_DATE]
1998-06-17 01:43:24 +04:00
} @{$result}] ;
$head_delta = $SORT_HEAD;
}
else{
$result = [sort {$b->[$::CI_DATE] <=> $a->[$::CI_DATE]} @{$result}] ;
1998-06-17 01:43:24 +04:00
$head_date = $SORT_HEAD;
}
&print_result($result);
}
else {
print "<pre>";
for my $ci (@$result) {
$ci->[$::CI_LOG] = '';
1998-06-17 01:43:24 +04:00
$s = join("|",@$ci);
print "$s\n";
}
}
#
#
#
sub print_result {
my ($result) = @_;
my ($ci,$i,$k,$j,$max, $l, $span);
1998-06-17 01:43:24 +04:00
&print_head;
$i = 20;
$k = 0;
$max = @{$result};
while( $k < $max ){
$ci = $result->[$k];
$span = 1;
if( ($l = $ci->[$::CI_LOG]) ne '' ){
#
# Calculate the number of consequitive logs that are
1998-06-17 01:43:24 +04:00
# the same and nuke them
#
$j = $k+1;
while( $j < $max && $result->[$j]->[$::CI_LOG] eq $l ){
$result->[$j]->[$::CI_LOG] = '';
1998-06-17 01:43:24 +04:00
$j++;
}
#
1998-06-17 01:43:24 +04:00
# Make sure we don't break over a description block
#
$span = $j-$k;
if( $span-1 > $i ){
$i = $j-$k;
}
}
&print_ci( $ci, $span );
1998-06-17 01:43:24 +04:00
if( $i <= 0 ){
$i = 20;
print "</TABLE><TABLE border cellspacing=2>\n";
}
else {
$i--;
}
$k++;
}
&print_foot;
}
my $descwidth;
1998-06-17 01:43:24 +04:00
sub print_ci {
my ($ci, $span) = @_;
my ($sec,$minute,$hour,$mday,$mon,$year) = localtime( $ci->[$::CI_DATE] );
my $t = sprintf("%02d/%02d/%04d&nbsp;%02d:%02d",$mon+1,$mday,$year+1900,$hour,$minute);
1998-06-17 01:43:24 +04:00
my $log = &html_log($ci->[$::CI_LOG]);
my $rev = $ci->[$::CI_REV];
1998-06-17 01:43:24 +04:00
print "<tr>\n";
print "<TD width=2%>${sm_font_tag}$t</font>";
print "<TD width=2%><a href='../registry/who.cgi?email=$ci->[$::CI_WHO]' "
. "onClick=\"return js_who_menu('$ci->[$::CI_WHO]','',event);\" >"
. "$ci->[$::CI_WHO]</a>\n";
print "<TD width=45%><a href='cvsview2.cgi?subdir=$ci->[$::CI_DIR]&files=$ci->[$::CI_FILE]\&command=DIRECTORY&branch=$::query_branch&root=$::CVS_ROOT'\n"
. " onclick=\"return js_file_menu('$::CVS_ROOT', '$ci->[$::CI_DIR]','$ci->[$::CI_FILE]','$ci->[$::CI_REV]','$::query_branch',event)\">\n";
# if( (length $ci->[$::CI_FILE]) + (length $ci->[$::CI_DIR]) > 30 ){
# $d = $ci->[$::CI_DIR];
# if( (length $ci->[$::CI_DIR]) > 30 ){
1998-06-17 01:43:24 +04:00
# $d =~ s/([^\n]*\/)(classes\/)/$1classes\/<br>&nbsp;&nbsp/;
# # Insert a <BR> before any directory named
# # 'classes.'
# }
# print " $d/<br>&nbsp;&nbsp;$ci->[$::CI_FILE]<a>\n";
1998-06-17 01:43:24 +04:00
# }
# else{
# print " $ci->[$::CI_DIR]/$ci->[$::CI_FILE]<a>\n";
1998-06-17 01:43:24 +04:00
# }
my $d = "$ci->[$::CI_DIR]/$ci->[$::CI_FILE]";
if ($::query_module eq 'allrepositories') {
$d = "$ci->[$::CI_REPOSITORY]/$d";
}
1998-06-17 01:43:24 +04:00
$d =~ s:/:/ :g; # Insert a whitespace after any slash, so that
# we'll break long names at a reasonable place.
print "$d\n";
if( $rev ne '' ){
my $prevrev = &PrevRev( $rev );
print "<TD width=2%>${sm_font_tag}<a href='cvsview2.cgi?diff_mode=".
1998-06-17 01:43:24 +04:00
"context\&whitespace_mode=show\&subdir=".
$ci->[$::CI_DIR] . "\&command=DIFF_FRAMESET\&file=" .
$ci->[$::CI_FILE] . "\&rev1=$prevrev&rev2=$rev&root=$::CVS_ROOT'>$rev</a></font>\n";
1998-06-17 01:43:24 +04:00
}
else {
print "<TD width=2%>\&nbsp;\n";
1998-06-17 01:43:24 +04:00
}
if( !$::query_branch_head ){
print "<TD width=2%><TT><FONT SIZE=-1>$ci->[$::CI_BRANCH]&nbsp</FONT></TT>\n";
1998-06-17 01:43:24 +04:00
}
print "<TD width=2%>${sm_font_tag}$ci->[$::CI_LINES_ADDED]/$ci->[$::CI_LINES_REMOVED]</font>&nbsp\n";
1998-06-17 01:43:24 +04:00
if( $log ne '' ){
$log = MarkUpText($log);
1998-06-17 01:43:24 +04:00
# Makes numbers into links to bugsplat.
$log =~ s/\n/<BR>/g;
# Makes newlines into <BR>'s
1998-06-17 01:43:24 +04:00
if( $span > 1 ){
print "<TD WIDTH=$descwidth% VALIGN=TOP ROWSPAN=$span>$log\n";
1998-06-17 01:43:24 +04:00
}
else {
print "<TD WIDTH=$descwidth% VALIGN=TOP>$log\n";
1998-06-17 01:43:24 +04:00
}
}
print "</tr>\n";
}
sub print_head {
if ($::versioninfo ne "") {
print "<FORM action='multidiff.cgi' method=post>";
print "<INPUT TYPE='HIDDEN' name='allchanges' value = '$::versioninfo'>";
print "<INPUT TYPE='HIDDEN' name='cvsroot' value = '$::CVS_ROOT'>";
1998-06-17 01:43:24 +04:00
print "<INPUT TYPE=SUBMIT VALUE='Show me ALL the Diffs'>";
print "</FORM>";
print "<tt>(+$::lines_added/$::lines_removed)</tt> Lines changed.";
1998-06-17 01:43:24 +04:00
}
my $anchor = $ENV{QUERY_STRING};
1998-06-17 01:43:24 +04:00
$anchor =~ s/\&sortby\=[A-Za-z\ \+]*//g;
$anchor = "<a href=cvsquery.cgi?$anchor";
print "<TABLE border cellspacing=2>\n";
print "<b><TR ALIGN=LEFT>\n";
print "<TH width=2% $head_date>$anchor>When</a>\n";
print "<TH width=2% $head_who>${anchor}&sortby=Who>Who</a>\n";
print "<TH width=45% $head_file>${anchor}&sortby=File>File</a>\n";
print "<TH width=2%>Rev\n";
1998-06-17 01:43:24 +04:00
$descwidth = 47;
if( !$::query_branch_head ){
1998-06-17 01:43:24 +04:00
print "<TH width=2%>Branch\n";
$descwidth -= 2;
}
print "<TH width=2% $head_delta>${anchor}&sortby=Change+Size>+/-</a>\n";
print "<TH WIDTH=$descwidth%>Description\n";
print "</TR></b>\n";
1998-06-17 01:43:24 +04:00
}
sub print_foot {
print "</TABLE>";
print "<br><br>";
}
sub html_log {
my ( $log ) = @_;
1998-06-17 01:43:24 +04:00
$log =~ s/&/&amp;/g;
$log =~ s/</&lt;/g;
return $log;
}
sub PrevRev {
my( $rev ) = @_;
my( $i, $j, $ret, @r );
1998-06-17 01:43:24 +04:00
@r = split( /\./, $rev );
$i = @r-1;
1998-06-17 01:43:24 +04:00
$r[$i]--;
if( $r[$i] == 0 ){
$i -= 2;
}
$j = 0;
while( $j < $i ){
$ret .= "$r[$j]\.";
$j++
}
$ret .= $r[$i];
}
sub parse_date {
my($d) = @_;
my($result) = str2time($d);
if (defined $result) {
return $result;
} elsif ($d > 7000000) {
return $d;
}
return 0;
}
sub setup_script {
my $script_str =<<'ENDJS';
1998-06-17 01:43:24 +04:00
<script>
var event = 0; // Nav3.0 compatibility
1998-06-17 01:43:24 +04:00
function js_who_menu(n,extra,d) {
if( parseInt(navigator.appVersion) < 4 ||
navigator.userAgent.toLowerCase().indexOf("msie") != -1 ){
1998-06-17 01:43:24 +04:00
return true;
}
l = document.layers['popup'];
l.src="../registry/who.cgi?email="+n+extra;
if(d.target.y > window.innerHeight + window.pageYOffset - l.clip.height) {
l.top = (window.innerHeight + window.pageYOffset - l.clip.height);
} else {
l.top = d.target.y - 6;
1998-06-17 01:43:24 +04:00
}
l.left = d.target.x - 6;
1998-06-17 01:43:24 +04:00
l.visibility="show";
return false;
}
function js_file_menu(repos,dir,file,rev,branch,d) {
var fileName="";
if( parseInt(navigator.appVersion) < 4 ||
navigator.userAgent.toLowerCase().indexOf("msie") != -1 ){
1998-06-17 01:43:24 +04:00
return true;
}
for (var i=0;i<d.target.text.length;i++)
{
if (d.target.text.charAt(i)!=" ") {
fileName+=d.target.text.charAt(i);
}
}
1998-06-17 01:43:24 +04:00
l = document.layers['popup'];
l.src="../registry/file.cgi?cvsroot="+repos+"&file="+file+"&dir="+dir+"&rev="+rev+"&branch="+branch+"&linked_text="+fileName;
1998-06-17 01:43:24 +04:00
l.top = d.target.y - 6;
l.left = d.target.x - 6;
if( l.left + l.clipWidth > window.width ){
l.left = window.width - l.clipWidth;
}
l.visibility="show";
return false;
}
</script>
<layer name="popup" onMouseOut="this.visibility='hide';" left=0 top=0 bgcolor="#ffffff" visibility="hide">
</layer>
ENDJS
return $script_str;
1998-06-17 01:43:24 +04:00
}
#
# Actually do the query
#
sub query_to_english {
my $english = 'Checkins ';
if( $::query_module eq 'allrepositories' ){
1998-06-17 01:43:24 +04:00
$english .= "to <i>All Repositories</i> ";
}
elsif( $::query_module ne 'all' && @::query_dirs == 0 ){
$english .= "to module <i>$::query_module</i> ";
1998-06-17 01:43:24 +04:00
}
elsif( $::FORM{dir} ne "" ) {
1998-06-17 01:43:24 +04:00
my $word = "directory";
if (@::query_dirs > 1) {
1998-06-17 01:43:24 +04:00
$word = "directories";
}
$english .= "to $word <i>$::FORM{dir}</i> ";
1998-06-17 01:43:24 +04:00
}
if ($::query_file ne "") {
1998-06-17 01:43:24 +04:00
if ($english ne 'Checkins ') {
$english .= "and ";
}
$english .= "to file $::query_file ";
1998-06-17 01:43:24 +04:00
}
if( ! ($::query_branch =~ /^[ ]*HEAD[ ]*$/i) ){
if($::query_branch eq '' ){
1998-06-17 01:43:24 +04:00
$english .= "on all branches ";
}
else {
$english .= "on branch <i>$::query_branch</i> ";
1998-06-17 01:43:24 +04:00
}
}
if( $::query_who ne '' ){
$english .= "by $::query_who ";
1998-06-17 01:43:24 +04:00
}
$::query_date_type = $::FORM{'date'};
if( $::query_date_type eq 'hours' ){
$english .="in the last $::FORM{hours} hours";
}
elsif( $::query_date_type eq 'day' ){
1998-06-17 01:43:24 +04:00
$english .="in the last day";
}
elsif( $::query_date_type eq 'week' ){
1998-06-17 01:43:24 +04:00
$english .="in the last week";
}
elsif( $::query_date_type eq 'month' ){
1998-06-17 01:43:24 +04:00
$english .="in the last month";
}
elsif( $::query_date_type eq 'all' ){
1998-06-17 01:43:24 +04:00
$english .="since the beginning of time";
}
elsif( $::query_date_type eq 'explicit' ){
my ($w1, $w2);
if ( $::FORM{mindate} ne "" && $::FORM{maxdate} ne "" ) {
1998-06-17 01:43:24 +04:00
$w1 = "between";
$w2 = "and" ;
}
else {
$w1 = "since";
$w2 = "before";
}
if( $::FORM{'mindate'} ne "" ){
my $dd = &parse_date($::FORM{'mindate'});
my ($sec,$minute,$hour,$mday,$mon,$year) = localtime( $dd );
my $t = sprintf("%02d/%02d/%04d&nbsp;%02d:%02d",$mon+1,$mday,$year+1900,$hour,$minute);
1998-06-17 01:43:24 +04:00
$english .= "$w1 <i>$t</i> ";
}
if( $::FORM{'maxdate'} ne "" ){
my $dd = &parse_date($::FORM{'maxdate'});
my ($sec,$minute,$hour,$mday,$mon,$year) = localtime( $dd );
my $t = sprintf("%02d/%02d/%04d&nbsp;%02d:%02d",$mon+1,$mday,$year+1900,$hour,$minute);
1998-06-17 01:43:24 +04:00
$english .= "$w2 <i>$t</i> ";
}
}
return $english . ":";
}
PutsTrailer();