Added the ability to configure the paths to the SCM executables.

This commit is contained in:
Manuel Eidenberger 2009-02-25 14:28:14 +01:00 committed by Loic d'Anterroches
parent 64dc8ec3b8
commit 42c6f53fbc
7 changed files with 46 additions and 34 deletions

View File

@ -192,7 +192,7 @@ class IDF_Plugin_SyncGit_Serve
{ {
mkdir($fullpath, 0750, true); mkdir($fullpath, 0750, true);
exec(sprintf(Pluf::f('idf_exec_cmd_prefix', ''). exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '').
'git --git-dir=%s init', escapeshellarg($fullpath)), Pluf::f('git_path', 'git').' --git-dir=%s init', escapeshellarg($fullpath)),
$out, $res); $out, $res);
if ($res != 0) { if ($res != 0) {
throw new Exception(sprintf('Init repository error, exit status %d.', $res)); throw new Exception(sprintf('Init repository error, exit status %d.', $res));

View File

@ -77,7 +77,7 @@ class IDF_Plugin_SyncMercurial
} }
$return = 0; $return = 0;
$output = array(); $output = array();
$cmd = sprintf('hg init %s', $cmd = sprintf(Pluf::f('hg_path', 'hg').' init %s',
escapeshellarg($mercurial_path.'/'.$shortname)); escapeshellarg($mercurial_path.'/'.$shortname));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$ll = exec($cmd, $output, $return); $ll = exec($cmd, $output, $return);

View File

@ -77,7 +77,7 @@ class IDF_Plugin_SyncSvn
} }
$return = 0; $return = 0;
$output = array(); $output = array();
$cmd = sprintf('svnadmin create %s', $cmd = sprintf(Pluf::f('svnadmin_path', 'svnadmin').' create %s',
escapeshellarg($svn_path.'/'.$shortname)); escapeshellarg($svn_path.'/'.$shortname));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$ll = exec($cmd, $output, $return); $ll = exec($cmd, $output, $return);

View File

@ -98,7 +98,7 @@ class IDF_Scm_Git
*/ */
public function testHash($hash, $dummy=null) public function testHash($hash, $dummy=null)
{ {
$cmd = sprintf('GIT_DIR=%s git cat-file -t %s', $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' cat-file -t %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
escapeshellarg($hash)); escapeshellarg($hash));
$ret = 0; $out = array(); $ret = 0; $out = array();
@ -143,7 +143,7 @@ class IDF_Scm_Git
// get the raw log corresponding to this commit to find the // get the raw log corresponding to this commit to find the
// origin of each file. // origin of each file.
$rawlog = array(); $rawlog = array();
$cmd = sprintf('GIT_DIR=%s git log --raw --abbrev=40 --pretty=oneline -5000 %s', $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --raw --abbrev=40 --pretty=oneline -5000 %s',
escapeshellarg($this->repo), escapeshellarg($commit)); escapeshellarg($this->repo), escapeshellarg($commit));
IDF_Scm::exec($cmd, $rawlog); IDF_Scm::exec($cmd, $rawlog);
// We reverse the log to be able to use a fixed efficient // We reverse the log to be able to use a fixed efficient
@ -182,7 +182,7 @@ class IDF_Scm_Git
if ('tree' != $this->testHash($tree)) { if ('tree' != $this->testHash($tree)) {
throw new Exception(sprintf(__('Not a valid tree: %s.'), $tree)); throw new Exception(sprintf(__('Not a valid tree: %s.'), $tree));
} }
$cmd_tmpl = 'GIT_DIR=%s git ls-tree%s -t -l %s %s'; $cmd_tmpl = 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' ls-tree%s -t -l %s %s';
$cmd = sprintf($cmd_tmpl, $cmd = sprintf($cmd_tmpl,
escapeshellarg($this->repo), escapeshellarg($this->repo),
($recurse) ? ' -r' : '', ($recurse) ? ' -r' : '',
@ -209,7 +209,7 @@ class IDF_Scm_Git
*/ */
public function getFileInfo($totest, $commit='HEAD') public function getFileInfo($totest, $commit='HEAD')
{ {
$cmd_tmpl = 'GIT_DIR=%s git ls-tree -r -t -l %s'; $cmd_tmpl = 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' ls-tree -r -t -l %s';
$cmd = sprintf($cmd_tmpl, $cmd = sprintf($cmd_tmpl,
escapeshellarg($this->repo), escapeshellarg($this->repo),
escapeshellarg($commit)); escapeshellarg($commit));
@ -236,7 +236,7 @@ class IDF_Scm_Git
public function getBlob($request_file_info, $dummy=null) public function getBlob($request_file_info, $dummy=null)
{ {
return shell_exec(sprintf(Pluf::f('idf_exec_cmd_prefix', ''). return shell_exec(sprintf(Pluf::f('idf_exec_cmd_prefix', '').
'GIT_DIR=%s git cat-file blob %s', 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' cat-file blob %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
escapeshellarg($request_file_info->hash))); escapeshellarg($request_file_info->hash)));
} }
@ -249,7 +249,7 @@ class IDF_Scm_Git
public function getBranches() public function getBranches()
{ {
$out = array(); $out = array();
IDF_Scm::exec(sprintf('GIT_DIR=%s git branch', IDF_Scm::exec(sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' branch',
escapeshellarg($this->repo)), $out); escapeshellarg($this->repo)), $out);
$res = array(); $res = array();
foreach ($out as $b) { foreach ($out as $b) {
@ -268,12 +268,12 @@ class IDF_Scm_Git
public function getCommit($commit='HEAD', $getdiff=false) public function getCommit($commit='HEAD', $getdiff=false)
{ {
if ($getdiff) { if ($getdiff) {
$cmd = sprintf('GIT_DIR=%s git show --date=iso --pretty=format:%s %s', $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' show --date=iso --pretty=format:%s %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
"'".$this->mediumtree_fmt."'", "'".$this->mediumtree_fmt."'",
escapeshellarg($commit)); escapeshellarg($commit));
} else { } else {
$cmd = sprintf('GIT_DIR=%s git log -1 --date=iso --pretty=format:%s %s', $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log -1 --date=iso --pretty=format:%s %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
"'".$this->mediumtree_fmt."'", "'".$this->mediumtree_fmt."'",
escapeshellarg($commit)); escapeshellarg($commit));
@ -306,7 +306,7 @@ class IDF_Scm_Git
*/ */
public function isCommitLarge($commit='HEAD') public function isCommitLarge($commit='HEAD')
{ {
$cmd = sprintf('GIT_DIR=%s git log --numstat -1 --pretty=format:%s %s', $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --numstat -1 --pretty=format:%s %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
"'commit %H%n'", "'commit %H%n'",
escapeshellarg($commit)); escapeshellarg($commit));
@ -339,7 +339,7 @@ class IDF_Scm_Git
{ {
if ($n === null) $n = ''; if ($n === null) $n = '';
else $n = ' -'.$n; else $n = ' -'.$n;
$cmd = sprintf('GIT_DIR=%s git log%s --date=iso --pretty=format:\'%s\' %s', $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log%s --date=iso --pretty=format:\'%s\' %s',
escapeshellarg($this->repo), $n, $this->mediumtree_fmt, escapeshellarg($this->repo), $n, $this->mediumtree_fmt,
escapeshellarg($commit)); escapeshellarg($commit));
$out = array(); $out = array();
@ -412,7 +412,7 @@ class IDF_Scm_Git
public function getArchiveCommand($commit, $prefix='git-repo-dump/') public function getArchiveCommand($commit, $prefix='git-repo-dump/')
{ {
return sprintf(Pluf::f('idf_exec_cmd_prefix', ''). return sprintf(Pluf::f('idf_exec_cmd_prefix', '').
'GIT_DIR=%s git archive --format=zip --prefix=%s %s', 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' archive --format=zip --prefix=%s %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
escapeshellarg($prefix), escapeshellarg($prefix),
escapeshellarg($commit)); escapeshellarg($commit));

View File

@ -85,7 +85,7 @@ class IDF_Scm_Mercurial
*/ */
public function testHash($hash, $dummy=null) public function testHash($hash, $dummy=null)
{ {
$cmd = sprintf('hg log -R %s -r %s', $cmd = sprintf(Pluf::f('hg_path', 'hg').' log -R %s -r %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
escapeshellarg($hash)); escapeshellarg($hash));
$ret = 0; $ret = 0;
@ -139,7 +139,7 @@ class IDF_Scm_Mercurial
if ('commit' != $this->testHash($tree)) { if ('commit' != $this->testHash($tree)) {
throw new Exception(sprintf(__('Not a valid tree: %s.'), $tree)); throw new Exception(sprintf(__('Not a valid tree: %s.'), $tree));
} }
$cmd_tmpl = 'hg manifest -R %s --debug -r %s'; $cmd_tmpl = Pluf::f('hg_path', 'hg').' manifest -R %s --debug -r %s';
$cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), $tree, ($recurse) ? '' : ''); $cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), $tree, ($recurse) ? '' : '');
$out = array(); $out = array();
$res = array(); $res = array();
@ -195,7 +195,7 @@ class IDF_Scm_Mercurial
*/ */
public function getFileInfo($totest, $commit='tip') public function getFileInfo($totest, $commit='tip')
{ {
$cmd_tmpl = 'hg manifest -R %s --debug -r %s'; $cmd_tmpl = Pluf::f('hg_path', 'hg').' manifest -R %s --debug -r %s';
$cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), $commit); $cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), $commit);
$out = array(); $out = array();
$res = array(); $res = array();
@ -248,7 +248,7 @@ class IDF_Scm_Mercurial
*/ */
public function getBlob($request_file_info, $dummy=null) public function getBlob($request_file_info, $dummy=null)
{ {
return IDF_Scm::shell_exec(sprintf('hg cat -R %s -r %s %s', return IDF_Scm::shell_exec(sprintf(Pluf::f('hg_path', 'hg').' cat -R %s -r %s %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
$dummy, $dummy,
escapeshellarg($this->repo . '/' . $request_file_info->file))); escapeshellarg($this->repo . '/' . $request_file_info->file)));
@ -262,7 +262,7 @@ class IDF_Scm_Mercurial
public function getBranches() public function getBranches()
{ {
$out = array(); $out = array();
IDF_Scm::exec(sprintf('hg branches -R %s', IDF_Scm::exec(sprintf(Pluf::f('hg_path', 'hg').' branches -R %s',
escapeshellarg($this->repo)), $out); escapeshellarg($this->repo)), $out);
$res = array(); $res = array();
foreach ($out as $b) { foreach ($out as $b) {
@ -282,7 +282,7 @@ class IDF_Scm_Mercurial
public function getCommit($commit='tip', $getdiff=false) public function getCommit($commit='tip', $getdiff=false)
{ {
$tmpl = ($getdiff) ? $tmpl = ($getdiff) ?
'hg log -p -r %s -R %s' : 'hg log -r %s -R %s'; Pluf::f('hg_path', 'hg').' log -p -r %s -R %s' : Pluf::f('hg_path', 'hg').' log -r %s -R %s';
$cmd = sprintf($tmpl, $cmd = sprintf($tmpl,
escapeshellarg($commit), escapeshellarg($this->repo)); escapeshellarg($commit), escapeshellarg($this->repo));
$out = array(); $out = array();
@ -325,7 +325,7 @@ class IDF_Scm_Mercurial
*/ */
public function getChangeLog($commit='tip', $n=10) public function getChangeLog($commit='tip', $n=10)
{ {
$cmd = sprintf('hg log -R %s -l%s ', escapeshellarg($this->repo), $n, $commit); $cmd = sprintf(Pluf::f('hg_path', 'hg').' log -R %s -l%s ', escapeshellarg($this->repo), $n, $commit);
$out = array(); $out = array();
IDF_Scm::exec($cmd, $out); IDF_Scm::exec($cmd, $out);
return self::parseLog($out, 6); return self::parseLog($out, 6);
@ -399,7 +399,7 @@ class IDF_Scm_Mercurial
public function getArchiveCommand($commit, $prefix='') public function getArchiveCommand($commit, $prefix='')
{ {
return sprintf(Pluf::f('idf_exec_cmd_prefix', ''). return sprintf(Pluf::f('idf_exec_cmd_prefix', '').
'hg archive --type=zip -R %s -r %s -', Pluf::f('hg_path', 'hg').' archive --type=zip -R %s -r %s -',
escapeshellarg($this->repo), escapeshellarg($this->repo),
escapeshellarg($commit)); escapeshellarg($commit));
} }

View File

@ -108,7 +108,7 @@ class IDF_Scm_Svn
} }
// Else, test the path on revision // Else, test the path on revision
$cmd = sprintf('svn info --xml --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' info --xml --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo.'/'.$path), escapeshellarg($this->repo.'/'.$path),
@ -146,7 +146,7 @@ class IDF_Scm_Svn
*/ */
public function filesAtCommit($rev='HEAD', $folder='') public function filesAtCommit($rev='HEAD', $folder='')
{ {
$cmd = sprintf('svn ls --xml --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' ls --xml --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo.'/'.$folder), escapeshellarg($this->repo.'/'.$folder),
@ -190,7 +190,7 @@ class IDF_Scm_Svn
*/ */
private function getCommitMessage($file, $rev='HEAD') private function getCommitMessage($file, $rev='HEAD')
{ {
$cmd = sprintf('svn log --xml --limit 1 --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml --limit 1 --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($file), escapeshellarg($file),
@ -210,7 +210,7 @@ class IDF_Scm_Svn
*/ */
public function getFileInfo($totest, $rev='HEAD') public function getFileInfo($totest, $rev='HEAD')
{ {
$cmd = sprintf('svn info --xml --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' info --xml --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo.'/'.$totest), escapeshellarg($this->repo.'/'.$totest),
@ -242,7 +242,7 @@ class IDF_Scm_Svn
*/ */
public function getBlob($request_file_info, $rev) public function getBlob($request_file_info, $rev)
{ {
$cmd = sprintf('svn cat --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' cat --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo.'/'.$request_file_info->fullpath), escapeshellarg($this->repo.'/'.$request_file_info->fullpath),
@ -273,7 +273,7 @@ class IDF_Scm_Svn
public function getCommit($rev='HEAD', $getdiff=false) public function getCommit($rev='HEAD', $getdiff=false)
{ {
$res = array(); $res = array();
$cmd = sprintf('svn log --xml -v --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml -v --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo), escapeshellarg($this->repo),
@ -303,7 +303,7 @@ class IDF_Scm_Svn
// We have a locally hosted repository, we can query it with // We have a locally hosted repository, we can query it with
// svnlook // svnlook
$repo = substr($this->repo, 7); $repo = substr($this->repo, 7);
$cmd = sprintf('svnlook changed -r %s %s', $cmd = sprintf(Pluf::f('svnlook_path', 'svnlook').' changed -r %s %s',
escapeshellarg($commit), escapeshellarg($commit),
escapeshellarg($repo)); escapeshellarg($repo));
$out = IDF_Scm::shell_exec($cmd); $out = IDF_Scm::shell_exec($cmd);
@ -314,7 +314,7 @@ class IDF_Scm_Svn
private function getDiff($rev='HEAD') private function getDiff($rev='HEAD')
{ {
$res = array(); $res = array();
$cmd = sprintf('svn diff -c %s --username=%s --password=%s %s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' diff -c %s --username=%s --password=%s %s',
escapeshellarg($rev), escapeshellarg($rev),
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
@ -334,7 +334,7 @@ class IDF_Scm_Svn
public function getChangeLog($rev='HEAD', $n=10) public function getChangeLog($rev='HEAD', $n=10)
{ {
$res = array(); $res = array();
$cmd = sprintf('svn log --xml -v --limit %s --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml -v --limit %s --username=%s --password=%s %s@%s',
escapeshellarg($n), escapeshellarg($n),
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
@ -383,7 +383,7 @@ class IDF_Scm_Svn
public function getProperties($rev, $path='') public function getProperties($rev, $path='')
{ {
$res = array(); $res = array();
$cmd = sprintf('svn proplist --xml --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' proplist --xml --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo.'/'.$path), escapeshellarg($this->repo.'/'.$path),
@ -417,7 +417,7 @@ class IDF_Scm_Svn
private function getProperty($property, $rev, $path='') private function getProperty($property, $rev, $path='')
{ {
$res = array(); $res = array();
$cmd = sprintf('svn propget --xml %s --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' propget --xml %s --username=%s --password=%s %s@%s',
escapeshellarg($property), escapeshellarg($property),
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
@ -440,7 +440,7 @@ class IDF_Scm_Svn
public function getLastCommit($rev='HEAD') public function getLastCommit($rev='HEAD')
{ {
$xmlInfo = ''; $xmlInfo = '';
$cmd = sprintf('svn info --xml --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' info --xml --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo), escapeshellarg($this->repo),

View File

@ -215,4 +215,16 @@ $cfg['allowed_scm'] = array('git' => 'IDF_Scm_Git',
# variables not being set correctly. Note the trailing space. # variables not being set correctly. Note the trailing space.
# $cfg['idf_exec_cmd_prefix'] = '/usr/bin/env -i '; # $cfg['idf_exec_cmd_prefix'] = '/usr/bin/env -i ';
# Path to the SCM binaries. These binaries are not necessarily in
# the path of your webserver or fastcgi process. In that case you
# may need to set the path manually here. This is the case with OSX.
# To know which path you need to provide, just run:
# $ which git
# from the command line. This will give you the path to git.
# $cfg['svn_path'] = 'svn';
# $cfg['svnlook_path'] = 'svnlook';
# $cfg['svnadmin_path'] = 'svnadmin';
# $cfg['hg_path'] = 'hg';
# $cfg['git_path'] = 'git';
return $cfg; return $cfg;