From 63e9be178d9d0305a487a9aa78851c8e3129074a Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Sun, 16 Nov 2008 08:53:33 +0200 Subject: [PATCH] New config option: 'git' for the binary path. run_git* functions also now accept only the "git " as command parameter (eg. "git" is assumed). --- inc/config.php | 4 ++++ inc/functions.php | 20 ++++++++++---------- index.php | 6 +++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/inc/config.php b/inc/config.php index 22b9e39..53ad918 100644 --- a/inc/config.php +++ b/inc/config.php @@ -8,6 +8,10 @@ $conf['projects'] = array( // 'name' => array('repo' => '/path/to/repo'), ); +// Where git is. Default is to search from PATH, but you can use an absolute +// path as well. +$conf['git'] = '/usr/bin/git'; + // If set, contains an array of globs/wildcards where to include projects. // Use this if you have a lot of projects under a directory. //$conf['projects_globs'] = array('/path/to/*/.git', '/var/git/*.git'); diff --git a/inc/functions.php b/inc/functions.php index 6e3b2c2..7a49b68 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -79,7 +79,7 @@ function git_diffstat($project, $commit, $commit_base = null) if (is_null($commit_base)) { $commit_base = "$commit^"; } - return join("\n", run_git($project, "git diff --stat $commit_base..$commit")); + return join("\n", run_git($project, "diff --stat $commit_base..$commit")); } /** @@ -94,7 +94,7 @@ function git_get_commit_info($project, $hash = 'HEAD') $info['message_full'] = ''; $info['parents'] = array(); - $output = run_git($project, "git rev-list --header --max-count=1 $hash"); + $output = run_git($project, "rev-list --header --max-count=1 $hash"); // tree // parent // author "<"">" @@ -144,7 +144,7 @@ function git_get_heads($project) { $heads = array(); - $output = run_git($project, 'git show-ref --heads'); + $output = run_git($project, 'show-ref --heads'); foreach ($output as $line) { $fullname = substr($line, 41); $name = array_pop(explode('/', $fullname)); @@ -191,9 +191,9 @@ function git_get_path_info($project, $root_hash, $path) */ function git_get_rev_list($project, $max_count = null, $start = 'HEAD') { - $cmd = "git rev-list $start"; + $cmd = "rev-list $start"; if (!is_null($max_count)) { - $cmd = "git rev-list --max-count=$max_count $start"; + $cmd = "rev-list --max-count=$max_count $start"; } return run_git($project, $cmd); @@ -206,7 +206,7 @@ function git_get_tags($project) { $tags = array(); - $output = run_git($project, 'git show-ref --tags'); + $output = run_git($project, 'show-ref --tags'); foreach ($output as $line) { $fullname = substr($line, 41); $name = array_pop(explode('/', $fullname)); @@ -223,7 +223,7 @@ function git_get_tags($project) function git_ls_tree($project, $tree) { $entries = array(); - $output = run_git($project, "git ls-tree $tree"); + $output = run_git($project, "ls-tree $tree"); // 100644 blob 493b7fc4296d64af45dac64bceac2d9a96c958c1 .gitignore // 040000 tree 715c78b1011dc58106da2a1af2fe0aa4c829542f doc foreach ($output as $line) { @@ -256,7 +256,7 @@ function git_ls_tree_part($project, $tree, $name) */ function git_ref_list($project, $tags = true, $heads = true, $remotes = true) { - $cmd = "git show-ref --dereference"; + $cmd = "show-ref --dereference"; if (!$remotes) { if ($tags) { $cmd .= " --tags"; } if ($heads) { $cmd .= " --heads"; } @@ -407,7 +407,7 @@ function run_git($project, $command) global $conf; $output = array(); - $cmd = "GIT_DIR=". $conf['projects'][$project]['repo'] ." $command"; + $cmd = "GIT_DIR=". $conf['projects'][$project]['repo'] ." ". $conf['git'] ." $command"; exec($cmd, $output); return $output; } @@ -420,7 +420,7 @@ function run_git_passthru($project, $command) { global $conf; - $cmd = "GIT_DIR=". $conf['projects'][$project]['repo'] ." $command"; + $cmd = "GIT_DIR=". $conf['projects'][$project]['repo'] ." ". $conf['git'] ." $command"; $result = 0; passthru($cmd, $result); return $result; diff --git a/index.php b/index.php index a566622..abf595e 100644 --- a/index.php +++ b/index.php @@ -71,13 +71,13 @@ elseif ($action === 'archive') { header("Content-Type: application/x-tar-gz"); header("Content-Transfer-Encoding: binary"); header("Content-Disposition: attachment; filename=\"$basename.tar.gz\";"); - run_git_passthru($project, "git archive --format=tar $tree |gzip"); + run_git_passthru($project, "archive --format=tar $tree |gzip"); } elseif ($type === 'zip') { header("Content-Type: application/x-zip"); header("Content-Transfer-Encoding: binary"); header("Content-Disposition: attachment; filename=\"$basename.zip\";"); - run_git_passthru($project, "git archive --format=zip $tree"); + run_git_passthru($project, "archive --format=zip $tree"); } else { die('Invalid archive type requested'); @@ -100,7 +100,7 @@ elseif ($action === 'blob') { header('Content-type: application/octet-stream'); header("Content-Disposition: attachment; filename=$name"); // FIXME needs quotation - run_git_passthru($project, "git cat-file blob $hash"); + run_git_passthru($project, "cat-file blob $hash"); die(); } -- 2.11.4.GIT