[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svnlook log doesn't return message

From: Ryan Schmidt <subversion-2008a_at_ryandesign.com>
Date: Fri, 29 Feb 2008 03:39:25 -0600

I tried your pre-commit.php on my Mac and it looks mostly ok...

On Feb 29, 2008, at 03:12, matthieu.mary_at_externe.bnpparibas.com wrote:

> /**
> * check the php content
> */
> if (__CONTROL_PHP_FILE__)
> {
> /**
> * fetch the file list
> * this command run "C:\svn\bin\svnlook.exe"
> changed -t 1-1 D:\repositories/myproject
> */
> $cmd = exec(escapeshellarg(__SVN_LOOK_PATH__)."
> changed -t ".__TXN__." ".__REPOS__);

You're not checking the exit status of the svnlook command, which
would be given in the 3rd parameter of exec. svnlook could fail...
you never know...

> if (preg_match_all("/[A-Z]\s+(trunk\/.+php)$/i",
> $cmd, $matches)) {
> /**
> * foreach php file commited
> */
> foreach($matches[1] as $file) {
> $output = array();
> /**
> * we fetch the php content of the
> file in transaction and parse it with php client
> * this command run "C:\svn
> \bin\svnlook.exe" cat -t 1-1 "D:\repositories/myproject" "%myfile%"
> | "D:\php\php.exe" -l
> */
> $cmd = escapeshellarg
> (__SVN_LOOK_PATH__)." cat -t ".__TXN__." ".escapeshellarg
> (__REPOS__)." ".escapeshellarg($file)." | ".escapeshellarg
> (__PHP_PATH__)." -l";
> $cmd = exec($cmd, $output,
> $returnVar);
> if ($returnVar > 0) {
> Error :: Display("Your file
> $file contains errors, transaction aborded", $returnVar);
> }
> }
> }
> }
> /**
> * check some not allowed files
> */
> if (__CONTROL_NOT_ALLOWED_FILES__) {
> /**
> * fetch file list in transaction
> * this command run "C:\svn\bin\svnlook.exe"
> changed -t 1-1 D:\repositories/myproject
> */
> $cmd = exec(escapeshellarg(__SVN_LOOK_PATH__)."
> changed -t ".__TXN__." ".__REPOS__);

Same here...

> /**
> * just check files add for the first time
> */
> if (!preg_match_all("/[A]\s+([^\s]+)$/i", $cmd,
> $matches)) {
> $notAllowedFiles = array("/\.project$/", "/
> thumbs\.db/i", "/\.svn/", "/.+\.log$/","/.+\.bak$/", "/.+\.old$/","/
> cache\/[a-z0-9A-Z]+\.png$/");
> /**
> * foreach file add
> */
> foreach($matches[1] as $file) {
> foreach($notAllowedFiles as
> $currentPattern) {
> /**
> * if file is not allowed
> */
> if (preg_match
> ($currentPattern, $file)) {
> Error :: Display
> ("You try to add some files not allowed($currentPattern)",
> __ERROR_FILES_NOT_ALLOWED__);
> }
> }
> }
> }
> }
> /**
> * check if we have a message in transaction
> */
> if (__CONTROL_COMMIT_MESSAGE__)
> {
> /**
> * This command run "C:\svn\bin\svnlook.exe" log -t
> 1-1 D:\repositories/myproject
> */
> $cmd = trim(exec(escapeshellarg
> (__SVN_LOOK_PATH__)." log -t ".__TXN__." ".__REPOS__));

Same here...

> if (!preg_match("/[a-zA-Z0-9]+/", $cmd, $matches))
> {
> Error :: Display("You should set a message
> in your commit", __ERROR_CODE_LOG_MESSAGE_EMPTY__);
> }
>
> }
>
> exit(__ERROR_CODE_OK__);
> ?>
> *******************************************************
> Hope this code won't be too much hard to understand for non php users.
>
> But I'm not sure that is a pre-commit script problem because I'have
> made the same thing this morning in same circumstancies (initial
> import on trunk folder) for a new repository project, and this
> time, I had no error (error always happened for the repository that
> gave me error).

I'm guessing that svnlook is sometimes giving you an error message,
but you're not checking its exit status or the returned error message
so your code is just failing later on. You should check each exec's
exit status, and if it's non-zero, do something with the returned
error message, like either display it to the user or log it away in a
file.

Note you'll have to capture stderr from the exec'd process with
"2>&1" if you want the error message returned to you, like this:

$output = array();
$cmd = trim(exec(escapeshellarg(__SVN_LOOK_PATH__)." log -t
".__TXN__." ".__REPOS__."2>&1", $output, $returnVar));

$cmd is just going to contain the last line of output, while implode
("\n", $output) will be all lines of output (you never know, the
error output may be more than one line...).

Your repository path doesn't contain spaces or quotes or special
characters or anything does it? If it did, you would need to
escapeshellarg(__REPOS__) when putting it into a command.

Confusing that you're sometimes using $cmd for the command that will
be executed, and sometimes for the value returned from that command...

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: users-help_at_subversion.tigris.org
Received on 2008-02-29 10:41:02 CET

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.