| 1 | --- a/src/IDF/Scm/Git.php ␊ |
| 2 | +++ b/src/IDF/Scm/Git.php ␊ |
| 3 | @@ -56,11 +56,10 @@␊ |
| 4 | */␊ |
| 5 | public function getChanges($commit)␊ |
| 6 | {␊ |
| 7 | - $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' show %s --name-status --pretty="format:" --diff-filter="[A|D|M|R]" -M',␊ |
| 8 | - escapeshellarg($this->repo),␊ |
| 9 | + $cmd = $this->getGitCmdLine();␊ |
| 10 | + $cmd .= sprintf('show %s --name-status --pretty="format:" --diff-filter="[A|D|M|R]" -M',␊ |
| 11 | escapeshellarg($commit));␊ |
| 12 | $out = array();␊ |
| 13 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;␊ |
| 14 | self::exec('IDF_Scm_Git::getChanges', $cmd, $out);␊ |
| 15 | ␊ |
| 16 | $return = (object) array(␊ |
| 17 | @@ -119,14 +118,19 @@␊ |
| 18 | return (count($branches) > 0);␊ |
| 19 | }␊ |
| 20 | ␊ |
| 21 | + private function getGitCmdLine()␊ |
| 22 | + {␊ |
| 23 | + $cmd = Pluf::f('idf_exec_cmd_prefix', '');␊ |
| 24 | + $cmd .= sprintf(escapeshellarg(Pluf::f('git_path', 'git')).' --git-dir=%s ', $this->repo);␊ |
| 25 | + return $cmd;␊ |
| 26 | + }␊ |
| 27 | + ␊ |
| 28 | public function getBranches()␊ |
| 29 | {␊ |
| 30 | if (isset($this->cache['branches'])) {␊ |
| 31 | return $this->cache['branches'];␊ |
| 32 | }␊ |
| 33 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '')␊ |
| 34 | - .sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' branch',␊ |
| 35 | - escapeshellarg($this->repo));␊ |
| 36 | + $cmd = $this->getGitCmdLine() . 'branch';␊ |
| 37 | self::exec('IDF_Scm_Git::getBranches',␊ |
| 38 | $cmd, $out, $return);␊ |
| 39 | if ($return != 0) {␊ |
| 40 | @@ -172,11 +176,8 @@␊ |
| 41 | return $this->cache['inBranches'][$commit];␊ |
| 42 | }␊ |
| 43 | ␊ |
| 44 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '')␊ |
| 45 | - .sprintf('GIT_DIR=%s %s branch --contains %s',␊ |
| 46 | - escapeshellarg($this->repo),␊ |
| 47 | - Pluf::f('git_path', 'git'),␊ |
| 48 | - escapeshellarg($commit));␊ |
| 49 | + $cmd = $this->getGitCmdLine();␊ |
| 50 | + $cmd .= sprintf('branch --contains %s', escapeshellarg($commit));␊ |
| 51 | self::exec('IDF_Scm_Git::inBranches', $cmd, $out, $return);␊ |
| 52 | if (0 != $return) {␊ |
| 53 | throw new IDF_Scm_Exception(sprintf($this->error_tpl,␊ |
| 54 | @@ -209,10 +210,8 @@␊ |
| 55 | if (isset($this->cache['tags'])) {␊ |
| 56 | return $this->cache['tags'];␊ |
| 57 | }␊ |
| 58 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '')␊ |
| 59 | - .sprintf('GIT_DIR=%s %s for-each-ref --format="%%(objectname) %%(refname)" refs/tags',␊ |
| 60 | - escapeshellarg($this->repo),␊ |
| 61 | - Pluf::f('git_path', 'git'));␊ |
| 62 | + $cmd = $this->getGitCmdLine();␊ |
| 63 | + $cmd .= 'for-each-ref --format="%%(objectname) %%(refname)" refs/tags';␊ |
| 64 | self::exec('IDF_Scm_Git::getTags', $cmd, $out, $return);␊ |
| 65 | if (0 != $return) {␊ |
| 66 | throw new IDF_Scm_Exception(sprintf($this->error_tpl,␊ |
| 67 | @@ -240,11 +239,8 @@␊ |
| 68 | return $this->cache['inTags'][$commit];␊ |
| 69 | }␊ |
| 70 | ␊ |
| 71 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '')␊ |
| 72 | - .sprintf('GIT_DIR=%s %s tag --contains %s',␊ |
| 73 | - escapeshellarg($this->repo),␊ |
| 74 | - Pluf::f('git_path', 'git'),␊ |
| 75 | - escapeshellarg($commit));␊ |
| 76 | + $cmd = $this->getGitCmdLine();␊ |
| 77 | + $cmd .= sprintf('tag --contains %s', escapeshellarg($commit));␊ |
| 78 | self::exec('IDF_Scm_Git::inTags', $cmd, $out, $return);␊ |
| 79 | // `git tag` gained the `--contains` option in 1.6.2, earlier␊ |
| 80 | // versions report a bad usage error (129) which we ignore here␊ |
| 81 | @@ -409,11 +405,9 @@␊ |
| 82 | */␊ |
| 83 | public function testHash($hash)␊ |
| 84 | {␊ |
| 85 | - $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' cat-file -t %s',␊ |
| 86 | - escapeshellarg($this->repo),␊ |
| 87 | - escapeshellarg($hash));␊ |
| 88 | + $cmd = $this->getGitCmdLine();␊ |
| 89 | + $cmd .= sprintf('cat-file -t %s', escapeshellarg($hash));␊ |
| 90 | $ret = 0; $out = array();␊ |
| 91 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;␊ |
| 92 | self::exec('IDF_Scm_Git::testHash', $cmd, $out, $ret);␊ |
| 93 | if ($ret != 0) return false;␊ |
| 94 | return trim($out[0]);␊ |
| 95 | @@ -432,10 +426,9 @@␊ |
| 96 | if (!in_array($this->testHash($tree), array('tree', 'commit', 'tag'))) {␊ |
| 97 | throw new Exception(sprintf(__('Not a valid tree: %s.'), $tree));␊ |
| 98 | }␊ |
| 99 | - $cmd_tmpl = 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' ls-tree -l %s %s';␊ |
| 100 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '')␊ |
| 101 | - .sprintf($cmd_tmpl, escapeshellarg($this->repo),␊ |
| 102 | - escapeshellarg($tree), escapeshellarg($folder));␊ |
| 103 | + $cmd_tmpl = $this->getGitCmdLine();␊ |
| 104 | + $cmd_tmpl .= 'ls-tree -l %s %s';␊ |
| 105 | + $cmd = sprintf($cmd_tmpl, escapeshellarg($tree), escapeshellarg($folder));␊ |
| 106 | $out = array();␊ |
| 107 | $res = array();␊ |
| 108 | self::exec('IDF_Scm_Git::getTreeInfo', $cmd, $out);␊ |
| 109 | @@ -457,12 +450,10 @@␊ |
| 110 | */␊ |
| 111 | public function getPathInfo($totest, $commit='HEAD')␊ |
| 112 | {␊ |
| 113 | - $cmd_tmpl = 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' ls-tree -r -t -l %s';␊ |
| 114 | - $cmd = sprintf($cmd_tmpl,␊ |
| 115 | - escapeshellarg($this->repo),␊ |
| 116 | - escapeshellarg($commit));␊ |
| 117 | + $cmd_tmpl = $this->getGitCmdLine();␊ |
| 118 | + $cmd_tmpl .= 'ls-tree -r -t -l %s';␊ |
| 119 | + $cmd = sprintf($cmd_tmpl, escapeshellarg($commit));␊ |
| 120 | $out = array();␊ |
| 121 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;␊ |
| 122 | self::exec('IDF_Scm_Git::getPathInfo', $cmd, $out);␊ |
| 123 | foreach ($out as $line) {␊ |
| 124 | list($perm, $type, $hash, $size, $file) = preg_split('/ |\t/', $line, 5, PREG_SPLIT_NO_EMPTY);␊ |
| 125 | @@ -479,10 +470,8 @@␊ |
| 126 | ␊ |
| 127 | public function getFile($def, $cmd_only=false)␊ |
| 128 | {␊ |
| 129 | - $cmd = sprintf(Pluf::f('idf_exec_cmd_prefix', '').␊ |
| 130 | - 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' cat-file blob %s',␊ |
| 131 | - escapeshellarg($this->repo),␊ |
| 132 | - escapeshellarg($def->hash));␊ |
| 133 | + $cmd = $this->getGitCmdLine();␊ |
| 134 | + $cmd .= sprintf('cat-file blob %s', escapeshellarg($def->hash));␊ |
| 135 | return ($cmd_only)␊ |
| 136 | ? $cmd : self::shell_exec('IDF_Scm_Git::getFile', $cmd);␊ |
| 137 | }␊ |
| 138 | @@ -496,18 +485,16 @@␊ |
| 139 | */␊ |
| 140 | public function getCommit($commit, $getdiff=false)␊ |
| 141 | {␊ |
| 142 | + $cmd = $this->getGitCmdLine();␊ |
| 143 | if ($getdiff) {␊ |
| 144 | - $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' show --date=iso --pretty=format:%s %s',␊ |
| 145 | - escapeshellarg($this->repo),␊ |
| 146 | - "'".$this->mediumtree_fmt."'",␊ |
| 147 | - escapeshellarg($commit));␊ |
| 148 | + $cmd .= sprintf('show --date=iso --pretty=format:"%s" %s',␊ |
| 149 | + $this->mediumtree_fmt,␊ |
| 150 | + $commit);␊ |
| 151 | } else {␊ |
| 152 | - $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log -1 --date=iso --pretty=format:%s %s',␊ |
| 153 | - escapeshellarg($this->repo),␊ |
| 154 | - "'".$this->mediumtree_fmt."'",␊ |
| 155 | - escapeshellarg($commit));␊ |
| 156 | - }␊ |
| 157 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;␊ |
| 158 | + $cmd .= sprintf('log -1 --date=iso --pretty=format:"%s" %s',␊ |
| 159 | + $this->mediumtree_fmt,␊ |
| 160 | + $commit);␊ |
| 161 | + }␊ |
| 162 | $out = self::shell_exec('IDF_Scm_Git::getCommit', $cmd);␊ |
| 163 | if (strlen($out) == 0) {␊ |
| 164 | return false;␊ |
| 165 | @@ -540,12 +527,11 @@␊ |
| 166 | */␊ |
| 167 | public function isCommitLarge($commit='HEAD')␊ |
| 168 | {␊ |
| 169 | - $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --numstat -1 --pretty=format:%s %s',␊ |
| 170 | - escapeshellarg($this->repo),␊ |
| 171 | - "'commit %H%n'",␊ |
| 172 | + $cmd = $this->getGitCmdLine();␊ |
| 173 | + $cmd .= sprintf('log --numstat -1 --pretty=format:%s %s',␊ |
| 174 | + '"commit %H%n"',␊ |
| 175 | escapeshellarg($commit));␊ |
| 176 | $out = array();␊ |
| 177 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;␊ |
| 178 | self::exec('IDF_Scm_Git::isCommitLarge', $cmd, $out);␊ |
| 179 | $affected = count($out) - 2;␊ |
| 180 | $added = 0;␊ |
| 181 | @@ -574,11 +560,11 @@␊ |
| 182 | {␊ |
| 183 | if ($n === null) $n = '';␊ |
| 184 | else $n = ' -'.$n;␊ |
| 185 | - $cmd = sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log%s --date=iso --pretty=format:\'%s\' %s',␊ |
| 186 | - escapeshellarg($this->repo), $n, $this->mediumtree_fmt,␊ |
| 187 | + $cmd = $this->getGitCmdLine();␊ |
| 188 | + $cmd .= sprintf('log%s --date=iso --pretty=format:"%s" %s',␊ |
| 189 | + $n, $this->mediumtree_fmt,␊ |
| 190 | escapeshellarg($commit));␊ |
| 191 | $out = array();␊ |
| 192 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;␊ |
| 193 | self::exec('IDF_Scm_Git::getChangeLog', $cmd, $out);␊ |
| 194 | return self::parseLog($out);␊ |
| 195 | }␊ |
| 196 | @@ -652,9 +638,8 @@␊ |
| 197 | ␊ |
| 198 | public function getArchiveStream($commit, $prefix='repository/')␊ |
| 199 | {␊ |
| 200 | - $cmd = sprintf(Pluf::f('idf_exec_cmd_prefix', '').␊ |
| 201 | - 'GIT_DIR=%s '.Pluf::f('git_path', 'git').' archive --format=zip --prefix=%s %s',␊ |
| 202 | - escapeshellarg($this->repo),␊ |
| 203 | + $cmd = $this->getGitCmdLine();␊ |
| 204 | + $cmd .= sprintf('archive --format=zip --prefix=%s %s',␊ |
| 205 | escapeshellarg($prefix),␊ |
| 206 | escapeshellarg($commit));␊ |
| 207 | return new Pluf_HTTP_Response_CommandPassThru($cmd, 'application/x-zip');␊ |
| 208 | @@ -755,9 +740,8 @@␊ |
| 209 | public function appendBlobInfoCache($blobs)␊ |
| 210 | {␊ |
| 211 | $rawlog = array();␊ |
| 212 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '')␊ |
| 213 | - .sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --raw --abbrev=40 --pretty=oneline -5000 --skip=%%s',␊ |
| 214 | - escapeshellarg($this->repo));␊ |
| 215 | + $cmd = $this->getGitCmdLine();␊ |
| 216 | + $cmd .= ' log --raw --abbrev=40 --pretty=oneline -5000 --skip=%%s';␊ |
| 217 | $skip = 0;␊ |
| 218 | $res = array();␊ |
| 219 | self::exec('IDF_Scm_Git::appendBlobInfoCache',␊ |
| 220 | @@ -805,9 +789,8 @@␊ |
| 221 | public function buildBlobInfoCache()␊ |
| 222 | {␊ |
| 223 | $rawlog = array();␊ |
| 224 | - $cmd = Pluf::f('idf_exec_cmd_prefix', '')␊ |
| 225 | - .sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --raw --abbrev=40 --pretty=oneline -500 --skip=%%s',␊ |
| 226 | - escapeshellarg($this->repo));␊ |
| 227 | + $cmd = $this->getGitCmdLine();␊ |
| 228 | + $cmd .= ' log --raw --abbrev=40 --pretty=oneline -500 --skip=%%s';␊ |
| 229 | $skip = 0;␊ |
| 230 | self::exec('IDF_Scm_Git::buildBlobInfoCache',␊ |
| 231 | sprintf($cmd, $skip), $rawlog);␊ |
| 232 | |