@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

Disambiguate Git ref selectors in some Git command line invocations

Summary: Ref T13589. See that task for discussion.

Test Plan: Executed most commands via "bin/conduit" or in isolation.

Maniphest Tasks: T13589

Differential Revision: https://secure.phabricator.com/D21510

+24 -23
+8 -7
src/applications/diffusion/conduit/DiffusionBrowseQueryConduitAPIMethod.php
··· 48 48 } else { 49 49 try { 50 50 list($stdout) = $repository->execxLocalCommand( 51 - 'cat-file -t %s:%s', 51 + 'cat-file -t -- %s:%s', 52 52 $commit, 53 53 $path); 54 54 } catch (CommandException $e) { ··· 62 62 63 63 list($sub_err, $sub_stdout) = $repository->execLocalCommand( 64 64 'ls-tree %s -- %s', 65 - $commit, 65 + gitsprintf('%s', $commit), 66 66 $path); 67 67 if (!$sub_err) { 68 68 // If the path failed "cat-file" but "ls-tree" worked, we assume it ··· 86 86 if (preg_match('/^fatal: Not a valid object name/', $stderr)) { 87 87 // Grab two logs, since the first one is when the object was deleted. 88 88 list($stdout) = $repository->execxLocalCommand( 89 - 'log -n2 --format="%%H" %s -- %s', 90 - $commit, 89 + 'log -n2 %s %s -- %s', 90 + '--format=%H', 91 + gitsprintf('%s', $commit), 91 92 $path); 92 93 $stdout = trim($stdout); 93 94 if ($stdout) { ··· 121 122 } 122 123 123 124 list($stdout) = $repository->execxLocalCommand( 124 - 'ls-tree -z -l %s:%s', 125 - $commit, 125 + 'ls-tree -z -l %s -- %s', 126 + gitsprintf('%s', $commit), 126 127 $path); 127 128 128 129 $submodules = array(); ··· 207 208 // the wild. 208 209 209 210 list($err, $contents) = $repository->execLocalCommand( 210 - 'cat-file blob %s:.gitmodules', 211 + 'cat-file blob -- %s:.gitmodules', 211 212 $commit); 212 213 213 214 if (!$err) {
+1 -1
src/applications/diffusion/conduit/DiffusionExistsQueryConduitAPIMethod.php
··· 25 25 $repository = $this->getDiffusionRequest()->getRepository(); 26 26 $commit = $request->getValue('commit'); 27 27 list($err, $merge_base) = $repository->execLocalCommand( 28 - 'cat-file -t %s', 28 + 'cat-file -t -- %s', 29 29 $commit); 30 30 return !$err; 31 31 }
+1 -1
src/applications/diffusion/conduit/DiffusionHistoryQueryConduitAPIMethod.php
··· 64 64 $offset, 65 65 $limit, 66 66 '%H:%P', 67 - $commit_range, 67 + gitsprintf('%s', $commit_range), 68 68 // Git omits merge commits if the path is provided, even if it is empty. 69 69 (strlen($path) ? csprintf('%s', $path) : '')); 70 70
+1 -1
src/applications/diffusion/conduit/DiffusionLastModifiedQueryConduitAPIMethod.php
··· 34 34 } 35 35 list($hash) = $repository->execxLocalCommand( 36 36 'log -n1 --format=%%H %s -- %s', 37 - $commit, 37 + gitsprintf('%s', $commit), 38 38 $path); 39 39 $results[$path] = trim($hash); 40 40 }
+4 -4
src/applications/diffusion/conduit/DiffusionMergedCommitsQueryConduitAPIMethod.php
··· 35 35 $limit = $this->getLimit($request); 36 36 37 37 list($parents) = $repository->execxLocalCommand( 38 - 'log -n 1 --format=%s %s', 38 + 'log -n 1 --format=%s %s --', 39 39 '%P', 40 - $commit); 40 + gitsprintf('%s', $commit)); 41 41 42 42 $parents = preg_split('/\s+/', trim($parents)); 43 43 if (count($parents) < 2) { ··· 54 54 // NOTE: "+ 1" accounts for the merge commit itself. 55 55 $limit + 1, 56 56 '%H', 57 - $commit, 58 - '^'.$first_parent); 57 + gitsprintf('%s', $commit), 58 + gitsprintf('%s', '^'.$first_parent)); 59 59 60 60 $hashes = explode("\n", trim($logs)); 61 61
+1 -1
src/applications/diffusion/conduit/DiffusionQueryPathsConduitAPIMethod.php
··· 45 45 46 46 $future = $repository->getLocalCommandFuture( 47 47 'ls-tree --name-only -r -z %s -- %s', 48 - $commit, 48 + gitsprintf('%s', $commit), 49 49 $path); 50 50 51 51 $lines = id(new LinesOfALargeExecFuture($future))->setDelimiter("\0");
+1 -1
src/applications/diffusion/conduit/DiffusionSearchQueryConduitAPIMethod.php
··· 64 64 $future = $repository->getLocalCommandFuture( 65 65 // NOTE: --perl-regexp is available only with libpcre compiled in. 66 66 'grep --extended-regexp --null -n --no-color -f - %s -- %s', 67 - $drequest->getStableCommit(), 67 + gitsprintf('%s', $drequest->getStableCommit()), 68 68 $path); 69 69 70 70 // NOTE: We're writing the pattern on stdin to avoid issues with UTF8
+1 -1
src/applications/diffusion/query/blame/DiffusionGitBlameQuery.php
··· 13 13 14 14 return $repository->getLocalCommandFuture( 15 15 '--no-pager blame --root -s -l %s -- %s', 16 - $commit, 16 + gitsprintf('%s', $commit), 17 17 $path); 18 18 } 19 19
+1 -1
src/applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php
··· 10 10 $commit = $drequest->getCommit(); 11 11 12 12 return $repository->getLocalCommandFuture( 13 - 'cat-file blob %s:%s', 13 + 'cat-file blob -- %s:%s', 14 14 $commit, 15 15 $path); 16 16 }
+2 -2
src/applications/diffusion/query/lowlevel/DiffusionLowLevelParentsQuery.php
··· 37 37 $repository = $this->getRepository(); 38 38 39 39 list($stdout) = $repository->execxLocalCommand( 40 - 'log -n 1 --format=%s %s', 40 + 'log -n 1 --format=%s %s --', 41 41 '%P', 42 - $this->identifier); 42 + gitsprintf('%s', $this->identifier)); 43 43 44 44 return preg_split('/\s+/', trim($stdout)); 45 45 }
+3 -3
src/applications/diffusion/query/rawdiff/DiffusionGitRawDiffQuery.php
··· 25 25 list($parents) = $repository->execxLocalCommand( 26 26 'log -n 1 --format=%s %s --', 27 27 '%P', 28 - $commit); 28 + gitsprintf('%s', $commit)); 29 29 30 30 if (strlen(trim($parents))) { 31 31 $against = $commit.'^'; ··· 42 42 return $repository->getLocalCommandFuture( 43 43 'diff %Ls %s %s -- %s', 44 44 $options, 45 - $against, 46 - $commit, 45 + gitsprintf('%s', $against), 46 + gitsprintf('%s', $commit), 47 47 $path); 48 48 } 49 49