thanks again
this is wat my perl file looks like
# Turn on warnings the best way depending on the Perl version.
BEGIN {
if ( $] >= 5.006_000)
{ require warnings; import warnings; }
else
{ $^W = 1; }
}
use strict;
use Carp;
######################################################################
# Configuration section.
# Svnlook path.
my $svnlook;
if ($^O eq 'MSWin32') {
$svnlook = '"c:\Program Files\subversion\bin\svnlook.exe"';
} else {
$svnlook = '/usr/local/bin/svnlook';
}
# Since the path to svnlook depends upon the local installation
# preferences, check that the required program exists to insure that
# the administrator has set up the script properly.
{
my $ok = 1;
foreach my $program ($svnlook)
{
if (-e $program)
{
unless (-x $program)
{
warn "$0: required program `$program' is not executable, ",
"edit $0.\n";
$ok = 0;
}
}
else
{
warn "$0: required program `$program' does not exist, edit $0.\n";
$ok = 0;
}
}
exit 1 unless $ok;
}
######################################################################
# Initial setup/command-line handling.
&usage unless @ARGV == 3;
my $repos = shift;
my $txn = shift;
my $package_dir = shift;
unless (-e $repos)
{
&usage("$0: repository directory `$repos' does not exist.");
}
unless (-d $repos)
{
&usage("$0: repository directory `$repos' is not a directory.");
}
# Define two constant subroutines to stand for read-only or read-write
# access to the repository.
sub ACCESS_READ_ONLY () { 'read-only' }
sub ACCESS_READ_WRITE () { 'read-write' }
######################################################################
# Load the configuration file and validate it.
######################################################################
# Harvest data using svnlook.
# Change into /tmp so that svnlook diff can create its .svnlook
# directory.
# This need to be changed for deployment
my $tmp_dir = '/tmp';
chdir($tmp_dir)
or die "$0: cannot chdir `$tmp_dir': $!\n";
# Get the author from svnlook.
my @svnlooklines = &read_from_process($svnlook, 'author', $repos, '-t', $txn);
my $author = shift @svnlooklines;
unless (length $author)
{
die "$0: txn `$txn' has no author.\n";
}
# Figure out what files have changed using svnlook.
my @files_changed;
foreach my $line (&read_from_process($svnlook, 'changed', $repos, '-t', $txn))
{
# Split the line up into the modification code and path, ignoring
# property modifications.
if ($line =~ /^.. (.*)$/)
{
push(@files_changed, $1);
}
}
# Figure out what directories have changed using svnlook..
my @dirs_changed = &read_from_process($svnlook, 'dirs-changed', $repos,
'-t', $txn);
# Lose the trailing slash in the directory names if one exists, except
# in the case of '/'.
my $rootchanged = 0;
for (my $i=0; $i<@dirs_changed; ++$i)
{
if ($dirs_changed[$i] eq '/')
{
$rootchanged = 1;
}
else
{
$dirs_changed[$i] =~ s#^(.+)[/\\]$#$1#;
}
}
# Create the list of all modified paths.
my @changed = ( @files_changed ,@dirs_changed);
# There should always be at least one changed path. If there are
# none, then there maybe something fishy going on, so just exit now
# indicating that the commit should not proceed.
unless (@changed)
{
die "$0: no changed paths found in txn `$txn'.\n";
}
my @allfiles = ();
foreach my $path (@changed)
{
my @ps = split("/", $path);
my $file = $ps[$#ps];
$file = "$tmp_dir/$file";
open F, "> $file" or die "Can't open $file : $!";
# foreach my $line (&read_from_process($svnlook, 'cat', $repos, '-t', $txn, $path)){
# print F $line . "\n";
# }
close F;
push @allfiles, $file;
}
my $files = join(' ', @allfiles);
my @t = localtime(time);
my $tempfile = "$tmp_dir/$t[5]$t[4]$t[3]$t[2].$$";
#open F, "> $tempfile.txt" or die "Can't open $tempfile : $!";
#print F $files;
#close F;
system("java -jar $package_dir/satmetrix-checker-1.0-jar-with-dependencies.jar -o $tempfile $files");
open F, "< $tempfile" or die "Can't open $tempfile : $!";
my @f = <F>;
close F;
my @finallines=();
foreach my $line (@f)
{
if ($line !~ /^(Starting audit...|Audit done.)$/i) {
push @finallines, $line;
}
}
#### delete files
unlink($tempfile);
foreach my $file (@allfiles){
unlink($file);
}
##TODO
if (@finallines)
{
warn "$0: ",
join("\n ", @changed) . join("\n", @finallines), "\n";
exit 1;
}
else
{
warn "$0: ",
join("\n ", @changed), "\n";
exit 0;
}
sub usage
{
my (@cmd) = @_;
warn "@cmd\n" if @cmd;
die "usage: $0 REPOS TXN-NAME \n";
}
sub safe_read_from_pipe
{
my (@cmd) = @_;
unless (@cmd)
{
croak "$0: safe_read_from_pipe passed no arguments.\n";
}
print "Running @cmd\n";
my $pid = open(SAFE_READ, '-|');
unless (defined $pid)
{
die "$0: cannot fork: $!\n";
}
unless ($pid)
{
open(STDERR, ">&STDOUT")
or die "$0: cannot dup STDOUT: $!\n";
exec(@cmd)
or die "$0: cannot exec `@cmd': $!\n";
}
my @output;
while (<SAFE_READ>)
{
chomp;
push(@output, $_);
}
close(SAFE_READ);
my $result = $?;
my $exit = $result >> 8;
my $signal = $result & 127;
my $cd = $result & 128 ? "with core dump" : "";
if ($signal or $cd)
{
warn "$0: pipe from `@cmd' failed $cd: exit=$exit signal=$signal\n";
}
if (wantarray)
{
return ($result, @output);
}
else
{
return $result;
}
}
sub read_from_process
{
my(@cmd) = @_;
unless (@cmd)
{
croak "$0: read_from_process passed no arguments.\n";
}
my ($status, @output) = &safe_read_from_pipe(@cmd);
if ($status)
{
if (@output)
{
die "$0: `@cmd' failed with this output:\n", join("\n", @output), "\n";
}
else
{
die "$0: `@cmd' failed with no output.\n";
}
}
else
{
return @output;
}
}
--- On Sat, 30/8/08, Andy Levy <andy.levy_at_gmail.com> wrote:
From: Andy Levy <andy.levy_at_gmail.com>
Subject: Re: how to enable pre-commit when checkin all the directories
To: users_at_tortoisesvn.tigris.org
Date: Saturday, 30 August, 2008, 7:18 PM
On Sat, Aug 30, 2008 at 08:38, sangeeth jagadish <sanioautoz_at_yahoo.co.in>
wrote:
> Thanks in advance
>
> I have developed a perl script that is invoked by the pre-commit hook to
> check whether the code that is committed is free of checkstyle
> errors,adheres to the coding standards of different MIME/Extensions.
>
>
> The hook works fine when we are commiting files but when we commit a
> directory with the error output the path is not a file
>
> Please help me on this
TortoiseSVN is a Subversion *client*. Hook scripts run on the
*server*. This type of question is better directed at the Subversion
Users mailing list.
At this point, only you can help you. You've not provided any insight
into the contents of your script. The fix should be pretty simple -
you developed the script under the assumption that files would always
be committed, not just a directory. So, modify your script to check
each item that's been committed, and if it's a directory, don't
perform any operations.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_tortoisesvn.tigris.org
For additional commands, e-mail: users-help_at_tortoisesvn.tigris.org
Received on 2008-08-30 16:08:49 CEST