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

Allow Diffusion to display the initial commit in Git repositories

Summary: See T507. Since you can't do "xxxxxxxx^" where "xxxxxxxx" is the first
commit in a repository, fall back to diffing against the empty tree if we fail
to diff against the parent commit.

Test Plan: Looked at the first commit in libphutil on my local.

Reviewers: edward, jungejason, nh, tuomaspelkonen, aran

Reviewed By: nh

CC: aran, edward, epriestley, nh

Differential Revision: 953
This commit is contained in:
epriestley 2011-09-21 16:05:43 -07:00
parent 05084b2e57
commit 8e8d91a1ff
3 changed files with 32 additions and 7 deletions

View file

@ -44,12 +44,36 @@ final class DiffusionGitDiffQuery extends DiffusionDiffQuery {
);
$options = implode(' ', $options);
list($raw_diff) = execx(
"(cd %s && git diff {$options} %s^ %s -- %s)",
$repository->getDetail('local-path'),
$effective_commit,
$effective_commit,
$drequest->getPath());
try {
list($raw_diff) = execx(
"(cd %s && git diff %C %s^ %s -- %s)",
$repository->getDetail('local-path'),
$options,
$effective_commit,
$effective_commit,
$drequest->getPath());
} catch (CommandException $ex) {
// Check if this is the root commit by seeing if it has parents.
list($parents) = execx(
'(cd %s && git log --format=%s %s --)',
$repository->getDetail('local-path'),
'%P', // "parents"
$effective_commit);
if (!strlen(trim($parents))) {
// No parents means we're looking at the root revision. Diff against
// the empty tree hash instead, since there is no parent so "^" does
// not work. See ArcanistGitAPI for more discussion.
list($raw_diff) = execx(
'(cd %s && git diff %C %s %s -- %s)',
$repository->getDetail('local-path'),
$options,
ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT,
$effective_commit,
$drequest->getPath());
} else {
throw $ex;
}
}
$parser = new ArcanistDiffParser();
$parser->setDetectBinaryFiles(true);

View file

@ -7,6 +7,7 @@
phutil_require_module('arcanist', 'parser/diff');
phutil_require_module('arcanist', 'repository/api/git');
phutil_require_module('phabricator', 'applications/differential/storage/diff');
phutil_require_module('phabricator', 'applications/diffusion/query/diff/base');

View file

@ -405,7 +405,7 @@ class PhabricatorRepositoryEditController
if ($is_git) {
$instructions =
'Enter the URI to clone this repository from. It should look like '.
'<tt>git@github.com:example/example.git</tt>, <tt> '.
'<tt>git@github.com:example/example.git</tt> or '.
'<tt>ssh://user@host.com/git/example.git</tt>';
} else if ($is_mercurial) {
$instructions =