1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +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 {
try {
list($stdout) = $repository->execxLocalCommand(
'cat-file -t %s:%s',
'cat-file -t -- %s:%s',
$commit,
$path);
} catch (CommandException $e) {
@ -62,7 +62,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
list($sub_err, $sub_stdout) = $repository->execLocalCommand(
'ls-tree %s -- %s',
$commit,
gitsprintf('%s', $commit),
$path);
if (!$sub_err) {
// 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)) {
// Grab two logs, since the first one is when the object was deleted.
list($stdout) = $repository->execxLocalCommand(
'log -n2 --format="%%H" %s -- %s',
$commit,
'log -n2 %s %s -- %s',
'--format=%H',
gitsprintf('%s', $commit),
$path);
$stdout = trim($stdout);
if ($stdout) {
@ -121,8 +122,8 @@ final class DiffusionBrowseQueryConduitAPIMethod
}
list($stdout) = $repository->execxLocalCommand(
'ls-tree -z -l %s:%s',
$commit,
'ls-tree -z -l %s -- %s',
gitsprintf('%s', $commit),
$path);
$submodules = array();
@ -207,7 +208,7 @@ final class DiffusionBrowseQueryConduitAPIMethod
// the wild.
list($err, $contents) = $repository->execLocalCommand(
'cat-file blob %s:.gitmodules',
'cat-file blob -- %s:.gitmodules',
$commit);
if (!$err) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -64,7 +64,7 @@ final class DiffusionSearchQueryConduitAPIMethod
$future = $repository->getLocalCommandFuture(
// NOTE: --perl-regexp is available only with libpcre compiled in.
'grep --extended-regexp --null -n --no-color -f - %s -- %s',
$drequest->getStableCommit(),
gitsprintf('%s', $drequest->getStableCommit()),
$path);
// 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(
'--no-pager blame --root -s -l %s -- %s',
$commit,
gitsprintf('%s', $commit),
$path);
}

View file

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

View file

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

View file

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