0

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?

bahrep
  • 29,961
  • 12
  • 103
  • 150
Darko Rodic
  • 1,010
  • 3
  • 10
  • 27
  • I'm confused why do you need to pass *changes* if you are already performing the *svnlook* command inside of your Perl script? It seems like all you need to pass to your script is the revision# and the repository path. – Hunter McMillen Mar 25 '15 at 16:13
  • 1
    You should also note that there are two forms of svnlook, one that accepts a transaction number and one that accepts a revision number. You seem to be using both here for some reason. – Hunter McMillen Mar 25 '15 at 16:14
  • there is a line in middle of question post, first part is where I am trying to execute command in perl script and it is not being executed in second part I was trying to execute command in batch and then pass result to my script and neither is working – Darko Rodic Mar 25 '15 at 16:18
  • where am I using different svnlooks? – Darko Rodic Mar 25 '15 at 16:20
  • 1
    well your first example is probably just a mistake then, you are passing a revision number using `-t` flag which accepts a transaction number. The command should be `\`$svnlook changed -r "$rev" "$repos"\``; You also never explained what you mean by doesn't work? Do you get output you don't expect? Do you get no output? Do you get an error message? – Hunter McMillen Mar 25 '15 at 16:22
  • oh yes, its a stupid typo, because I was doing some copy paste. thats it man if you want, write a post and I will mark it as correct :) – Darko Rodic Mar 25 '15 at 16:25

1 Answers1

1

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.

Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
  • is there some fast way to turn this output from array to json, I am not very familliar with perl? – Darko Rodic Mar 25 '15 at 16:49
  • what would you expect the key to be for the json? The name of the file that was altered? If so you could create a hash reference using `{ filename => \@changes }` and pass that to [`JSON`](https://metacpan.org/pod/JSON#PERL---JSON) module's [`to_json`](https://metacpan.org/pod/JSON#to_json) function. – Hunter McMillen Mar 25 '15 at 18:02