Search code examples
perlbatch-filesvnvisualsvn-serverpost-commit-hook

svnlook changed -t "$rev" "$repos" not getting executed


As in title I am calling from my post-commit hook script written in perl which has command

$msg = `$svnlook changed -t "$rev" "$repos"`;

which should execute and than I should send $msg to my service. But when I run

if ( length($msg) == 0 )
{
    print STDERR "msg length is 0";
    exit(1);
}

I get this error message on console, so why is this svnlook command not being executed?

I am using windows 7 and VisualSVN server.

On other note, I had other theory to run this command in hook itself like

@echo off
set repos=%1
set rev=%2
set changes=svnlook changed %repos% -r %rev% 
C:\Perl64\bin\perl C:\repositories\myproject\hooks\myhook.pl %1 %2 changes

but I don't know how to pass this changes parameter, so if this could work, it could answer as well.

How to pass parameter from batch to perl script?


Solution

  • running svnlook changed help display the list of valid options to svnlook changed and their expected format:

    $ svnlook help changed
    changed: usage: svnlook changed REPOS_PATH
    
    Print the paths that were changed.
    
    Valid options:
      -r [--revision] ARG      : specify revision number ARG
      -t [--transaction] ARG   : specify transaction name ARG
      --copy-info              : show details for copies
    

    Normally you would specify either a transaction number with -t or a revision number with -r. You appear to be passing a revision number with -t which will lead to unexpected results: either no results or results that are unrelated to the revision you wish to example.

    I believe the correct usage in your case would be:

    my $msg = `$svnlook changed -r "$rev" "$repos"`;
    

    The above command is going to give you one long string that is delimited by newlines. You can get this is a more manageable array format by using the same command in list context:

    my @changes = `$svnlook changed -r "$rev" "$repos"`;
    

    additionally these lines will all have trailing newlines, you can eliminate them using the chomp() built-in:

    my @changes; 
    chomp(@changes = `$svnlook changed -r "$rev" "$repos"`);
    

    Alternatively, you could look at SVN::SVNLook which a Perl wrapper around the svnlook command.