1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

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
This commit is contained in:
epriestley 2021-01-12 11:31:55 -08:00
parent c63c2aadef
commit ea9cb0b625
11 changed files with 24 additions and 23 deletions

View file

@ -48,7 +48,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
} else { } else {
try { try {
list($stdout) = $repository->execxLocalCommand( list($stdout) = $repository->execxLocalCommand(
'cat-file -t %s:%s', 'cat-file -t -- %s:%s',
$commit, $commit,
$path); $path);
} catch (CommandException $e) { } catch (CommandException $e) {
@ -62,7 +62,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
list($sub_err, $sub_stdout) = $repository->execLocalCommand( list($sub_err, $sub_stdout) = $repository->execLocalCommand(
'ls-tree %s -- %s', 'ls-tree %s -- %s',
$commit, gitsprintf('%s', $commit),
$path); $path);
if (!$sub_err) { if (!$sub_err) {
// If the path failed "cat-file" but "ls-tree" worked, we assume it // If the path failed "cat-file" but "ls-tree" worked, we assume it
@ -86,8 +86,9 @@ final class DiffusionBrowseQueryConduitAPIMethod
if (preg_match('/^fatal: Not a valid object name/', $stderr)) { if (preg_match('/^fatal: Not a valid object name/', $stderr)) {
// Grab two logs, since the first one is when the object was deleted. // Grab two logs, since the first one is when the object was deleted.
list($stdout) = $repository->execxLocalCommand( list($stdout) = $repository->execxLocalCommand(
'log -n2 --format="%%H" %s -- %s', 'log -n2 %s %s -- %s',
$commit, '--format=%H',
gitsprintf('%s', $commit),
$path); $path);
$stdout = trim($stdout); $stdout = trim($stdout);
if ($stdout) { if ($stdout) {
@ -121,8 +122,8 @@ final class DiffusionBrowseQueryConduitAPIMethod
} }
list($stdout) = $repository->execxLocalCommand( list($stdout) = $repository->execxLocalCommand(
'ls-tree -z -l %s:%s', 'ls-tree -z -l %s -- %s',
$commit, gitsprintf('%s', $commit),
$path); $path);
$submodules = array(); $submodules = array();
@ -207,7 +208,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
// the wild. // the wild.
list($err, $contents) = $repository->execLocalCommand( list($err, $contents) = $repository->execLocalCommand(
'cat-file blob %s:.gitmodules', 'cat-file blob -- %s:.gitmodules',
$commit); $commit);
if (!$err) { if (!$err) {

View file

@ -25,7 +25,7 @@ final class DiffusionExistsQueryConduitAPIMethod
$repository = $this->getDiffusionRequest()->getRepository(); $repository = $this->getDiffusionRequest()->getRepository();
$commit = $request->getValue('commit'); $commit = $request->getValue('commit');
list($err, $merge_base) = $repository->execLocalCommand( list($err, $merge_base) = $repository->execLocalCommand(
'cat-file -t %s', 'cat-file -t -- %s',
$commit); $commit);
return !$err; return !$err;
} }

View file

@ -64,7 +64,7 @@ final class DiffusionHistoryQueryConduitAPIMethod
$offset, $offset,
$limit, $limit,
'%H:%P', '%H:%P',
$commit_range, gitsprintf('%s', $commit_range),
// Git omits merge commits if the path is provided, even if it is empty. // Git omits merge commits if the path is provided, even if it is empty.
(strlen($path) ? csprintf('%s', $path) : '')); (strlen($path) ? csprintf('%s', $path) : ''));

View file

@ -34,7 +34,7 @@ final class DiffusionLastModifiedQueryConduitAPIMethod
} }
list($hash) = $repository->execxLocalCommand( list($hash) = $repository->execxLocalCommand(
'log -n1 --format=%%H %s -- %s', 'log -n1 --format=%%H %s -- %s',
$commit, gitsprintf('%s', $commit),
$path); $path);
$results[$path] = trim($hash); $results[$path] = trim($hash);
} }

View file

@ -35,9 +35,9 @@ final class DiffusionMergedCommitsQueryConduitAPIMethod
$limit = $this->getLimit($request); $limit = $this->getLimit($request);
list($parents) = $repository->execxLocalCommand( list($parents) = $repository->execxLocalCommand(
'log -n 1 --format=%s %s', 'log -n 1 --format=%s %s --',
'%P', '%P',
$commit); gitsprintf('%s', $commit));
$parents = preg_split('/\s+/', trim($parents)); $parents = preg_split('/\s+/', trim($parents));
if (count($parents) < 2) { if (count($parents) < 2) {
@ -54,8 +54,8 @@ final class DiffusionMergedCommitsQueryConduitAPIMethod
// NOTE: "+ 1" accounts for the merge commit itself. // NOTE: "+ 1" accounts for the merge commit itself.
$limit + 1, $limit + 1,
'%H', '%H',
$commit, gitsprintf('%s', $commit),
'^'.$first_parent); gitsprintf('%s', '^'.$first_parent));
$hashes = explode("\n", trim($logs)); $hashes = explode("\n", trim($logs));

View file

@ -45,7 +45,7 @@ final class DiffusionQueryPathsConduitAPIMethod
$future = $repository->getLocalCommandFuture( $future = $repository->getLocalCommandFuture(
'ls-tree --name-only -r -z %s -- %s', 'ls-tree --name-only -r -z %s -- %s',
$commit, gitsprintf('%s', $commit),
$path); $path);
$lines = id(new LinesOfALargeExecFuture($future))->setDelimiter("\0"); $lines = id(new LinesOfALargeExecFuture($future))->setDelimiter("\0");

View file

@ -64,7 +64,7 @@ final class DiffusionSearchQueryConduitAPIMethod
$future = $repository->getLocalCommandFuture( $future = $repository->getLocalCommandFuture(
// NOTE: --perl-regexp is available only with libpcre compiled in. // NOTE: --perl-regexp is available only with libpcre compiled in.
'grep --extended-regexp --null -n --no-color -f - %s -- %s', 'grep --extended-regexp --null -n --no-color -f - %s -- %s',
$drequest->getStableCommit(), gitsprintf('%s', $drequest->getStableCommit()),
$path); $path);
// NOTE: We're writing the pattern on stdin to avoid issues with UTF8 // NOTE: We're writing the pattern on stdin to avoid issues with UTF8

View file

@ -13,7 +13,7 @@ final class DiffusionGitBlameQuery extends DiffusionBlameQuery {
return $repository->getLocalCommandFuture( return $repository->getLocalCommandFuture(
'--no-pager blame --root -s -l %s -- %s', '--no-pager blame --root -s -l %s -- %s',
$commit, gitsprintf('%s', $commit),
$path); $path);
} }

View file

@ -10,7 +10,7 @@ final class DiffusionGitFileContentQuery extends DiffusionFileContentQuery {
$commit = $drequest->getCommit(); $commit = $drequest->getCommit();
return $repository->getLocalCommandFuture( return $repository->getLocalCommandFuture(
'cat-file blob %s:%s', 'cat-file blob -- %s:%s',
$commit, $commit,
$path); $path);
} }

View file

@ -37,9 +37,9 @@ final class DiffusionLowLevelParentsQuery
$repository = $this->getRepository(); $repository = $this->getRepository();
list($stdout) = $repository->execxLocalCommand( list($stdout) = $repository->execxLocalCommand(
'log -n 1 --format=%s %s', 'log -n 1 --format=%s %s --',
'%P', '%P',
$this->identifier); gitsprintf('%s', $this->identifier));
return preg_split('/\s+/', trim($stdout)); return preg_split('/\s+/', trim($stdout));
} }

View file

@ -25,7 +25,7 @@ final class DiffusionGitRawDiffQuery extends DiffusionRawDiffQuery {
list($parents) = $repository->execxLocalCommand( list($parents) = $repository->execxLocalCommand(
'log -n 1 --format=%s %s --', 'log -n 1 --format=%s %s --',
'%P', '%P',
$commit); gitsprintf('%s', $commit));
if (strlen(trim($parents))) { if (strlen(trim($parents))) {
$against = $commit.'^'; $against = $commit.'^';
@ -42,8 +42,8 @@ final class DiffusionGitRawDiffQuery extends DiffusionRawDiffQuery {
return $repository->getLocalCommandFuture( return $repository->getLocalCommandFuture(
'diff %Ls %s %s -- %s', 'diff %Ls %s %s -- %s',
$options, $options,
$against, gitsprintf('%s', $against),
$commit, gitsprintf('%s', $commit),
$path); $path);
} }