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

Réf. : Re: svnlook log doesn't return message

From: <matthieu.mary_at_externe.bnpparibas.com>
Date: Fri, 29 Feb 2008 10:12:29 +0100

Hello,
thanks for your feedback

So my pre-commit script is a bat file which call a php script file:
here's the bat content:
*****************************************************
@echo off
rem pre commit hook script
rem only two parameters are pass to this script: transaction number and
repository folder
rem
rem this bat is run with apache acces right
rem
rem output must be throw to stderr
rem

:run
"D:\php\php.exe" %~dp0pre-commit.php %1 %2
*****************************************************

and here the pre-commit.php script content:
******************************************************************
<?php
/**
 * $Id: pre-commit.php 7 2008-02-28 12:47:15Z myuser $
 */
/**
 * How does it work?
 * Before files commit, we does our controls. if something is wrong, we
have an error and return code is diffrent than 0
 *
 * Under windows, the output message must be wrote on STDERR to be display
to client
 * @author Matthieu MARY
 */
 
/**
 * errors codes
 */
define('__ERROR_CODE_OK__', 0);
define('__TECHNICAL_ERROR__', 1); // erreur technique
define('__ERROR_CODE_PARSE_ERROR__', 2); // error parsing php file
define('__ERROR_CODE_LOG_MESSAGE_EMPTY__', 3); // error when message is
empty
define('__ERROR_FILES_NOT_ALLOWED__', 4); // error file is not allowed

/**
 * controls to do
 */
// does we need to control log message?
define('__CONTROL_COMMIT_MESSAGE__', true);
// does we need to check php parsing validity?
define('__CONTROL_PHP_FILE__', false);
// does we need to check if there is some files not allowed?
define('__CONTROL_NOT_ALLOWED_FILES__', true);

/**
 * controls required to
 */
define('__REPOS__', $_SERVER['argv'][1]); // repository path
define('__TXN__', $_SERVER['argv'][2]); // the transaction number
define('__SVN_LOOK_PATH__', 'C:\svn\bin\svnlook.exe'); // full path to
svnlook
define('__PHP_PATH__', 'D:\php\php.exe'); // full path to php client
/**
 * just a class that display error in stderr
 */
class Error
{
        /**
         * @ccess public
         * @param string $msg the error message
         * @param int $code the error code
         */
        function Display($msg, $code)
        {
                $fp = fopen('php://stderr', 'w');
                fwrite($fp, "********** " .$msg." (code d'erreur:
".$code.") **********");
                fclose($fp);
                exit($code);
        }

}

        /**
         * check if there is all parameters
         */
        if ($_SERVER['argc'] != 3) {
                Error :: Display("Technical error", __TECHNICAL_ERROR__);
        }

        /**
         * 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__);
                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__);
                /**
                 * 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__));
                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).

Best regards,

Matthieu

Internet
subversion-2008a_at_ryandesign.com
28/02/2008 23:22

Pour
Matthieu MARY
cc
users_at_subversion.tigris.org
Objet
Re: svnlook log doesn't return message

On Feb 28, 2008, at 09:56, matthieu.mary_at_externe.bnpparibas.com wrote:

> [Thu Feb 28 16:09:05 2008] [error] [client 192.168.10.2] 'pre-
> commit' hook failed with error output:\n********** You should set
> a log message (error code: 3) ********** [409, #165001]
>
> Could you help me please? There something I don't understand, but
> don't know why and have look for solution in ressources without
> succes.

If you're absolutely sure you're specifying a log message, then it
sounds like a problem in your pre-commit hook script. So you'll have
to show us your pre-commit hook script so we can help you debug it.

This message and any attachments (the "message") is
intended solely for the addressees and is confidential.
If you receive this message in error, please delete it and
immediately notify the sender. Any use not in accord with
its purpose, any dissemination or disclosure, either whole
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message.
BNP PARIBAS (and its subsidiaries) shall (will) not
therefore be liable for the message if modified.
Do not print this message unless it is necessary,
consider the environment.

                ---------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le
"message") sont etablis a l'intention exclusive de ses
destinataires et sont confidentiels. Si vous recevez ce
message par erreur, merci de le detruire et d'en avertir
immediatement l'expediteur. Toute utilisation de ce
message non conforme a sa destination, toute diffusion
ou toute publication, totale ou partielle, est interdite, sauf
autorisation expresse. L'internet ne permettant pas
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce
message, dans l'hypothese ou il aurait ete modifie.
N'imprimez ce message que si necessaire,
pensez a l'environnement.
Received on 2008-02-29 10:13:51 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.