Page MenuHomePhabricator

D9369.id22711.diff
No OneTemporary

D9369.id22711.diff

diff --git a/src/parser/__tests__/ArcanistBundleTestCase.php b/src/parser/__tests__/ArcanistBundleTestCase.php
--- a/src/parser/__tests__/ArcanistBundleTestCase.php
+++ b/src/parser/__tests__/ArcanistBundleTestCase.php
@@ -84,7 +84,9 @@
$configuration_manager);
$repository_api->setBaseCommitArgumentRules('arc:this');
- $diff = $repository_api->getFullGitDiff();
+ $diff = $repository_api->getFullGitDiff(
+ $repository_api->getBaseCommit(),
+ $repository_api->getHeadCommit());
$parser = new ArcanistDiffParser();
$parser->setRepositoryAPI($repository_api);
diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php
--- a/src/repository/api/ArcanistGitAPI.php
+++ b/src/repository/api/ArcanistGitAPI.php
@@ -80,14 +80,15 @@
/**
* Tests if a child commit is descendant of a parent commit.
+ * If child and parent are the same, it returns false.
* @param child commit SHA.
* @param parent commit SHA.
* @return bool
*/
- public function isDescendant($child, $parent) {
+ private function isDescendant($child, $parent) {
list($common_ancestor) =
$this->execxLocal('merge-base %s %s', $child, $parent);
- $common_ancestor = trim($common_ancestor, " \n\2");
+ $common_ancestor = trim($common_ancestor);
return $common_ancestor == $parent && $common_ancestor != $child;
}
@@ -126,9 +127,9 @@
$base_commit = $this->getBaseCommit();
$head_commit = $this->getHeadCommit();
if ($this->isDescendant($head_commit, $base_commit) === false) {
- throw new Exception(
- "base commit ${head_commit} is not a child of head commit ".
- "${base_commit}");
+ throw new ArcanistUsageException(
+ "base commit ${base_commit} is not a child of head commit ".
+ "${head_commit}");
}
$against = csprintf('%s --not %s',
@@ -329,10 +330,6 @@
}
public function getHeadCommit() {
- if (!$this->supportsCommitRanges()) {
- throw new ArcanistCapabilityNotSupportedException($this);
- }
-
if ($this->resolvedHeadCommit === null) {
$this->resolvedHeadCommit =
$this->resolveCommit($this->symbolicHeadCommit);
@@ -397,12 +394,22 @@
return implode(' ', $options);
}
- public function getFullGitDiff() {
+ /**
+ * @param the base revision
+ * @param head revision. If this is null, the generated diff will include the
+ * working copy
+ */
+ public function getFullGitDiff($base, $head=null) {
$options = $this->getDiffFullOptions();
+
+ $diff_revision = $base;
+ if ($head) {
+ $diff_revision .= '..'.$head;
+ }
+
list($stdout) = $this->execxLocal(
- "diff {$options} %s..%s --",
- $this->getBaseCommit(),
- $this->getHeadCommit());
+ "diff {$options} %s --",
+ $diff_revision);
return $stdout;
}
@@ -888,7 +895,7 @@
}
public function getAllLocalChanges() {
- $diff = $this->getFullGitDiff();
+ $diff = $this->getFullGitDiff($this->getBaseCommit());
if (!strlen(trim($diff))) {
return array();
}
diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php
--- a/src/workflow/ArcanistDiffWorkflow.php
+++ b/src/workflow/ArcanistDiffWorkflow.php
@@ -446,11 +446,11 @@
}
$repo = $this->getRepositoryAPI();
- $head_commit = $this->getArgument('head', null);
+ $head_commit = $this->getArgument('head');
$range_supported = $repo->supportsCommitRanges();
if ($head_commit) {
if (!$range_supported) {
- throw new Exception('ranged are not supported');
+ throw new ArcanistUsageException('Ranged are not supported');
}
$repo->setHeadCommit($head_commit);
@@ -962,7 +962,9 @@
$repository_api,
$paths);
} else if ($repository_api instanceof ArcanistGitAPI) {
- $diff = $repository_api->getFullGitDiff();
+ $diff = $repository_api->getFullGitDiff(
+ $repository_api->getBaseCommit(),
+ $repository_api->getHeadCommit());
if (!strlen($diff)) {
throw new ArcanistUsageException(
'No changes found. (Did you specify the wrong commit range?)');
diff --git a/src/workflow/ArcanistExportWorkflow.php b/src/workflow/ArcanistExportWorkflow.php
--- a/src/workflow/ArcanistExportWorkflow.php
+++ b/src/workflow/ArcanistExportWorkflow.php
@@ -178,7 +178,9 @@
if ($repository_api instanceof ArcanistGitAPI) {
$this->parseBaseCommitArgument($this->getArgument('paths'));
- $diff = $repository_api->getFullGitDiff();
+ $diff = $repository_api->getFullGitDiff(
+ $repository_api->getBaseCommit(),
+ $repository_api->getHeadCommit());
$changes = $parser->parseDiff($diff);
$authors = $this->getConduit()->callMethodSynchronous(
'user.query',
diff --git a/src/workflow/ArcanistWhichWorkflow.php b/src/workflow/ArcanistWhichWorkflow.php
--- a/src/workflow/ArcanistWhichWorkflow.php
+++ b/src/workflow/ArcanistWhichWorkflow.php
@@ -95,7 +95,7 @@
}
$head_commit = $this->getArgument('head');
- $arg .= " --head ${head_commit}";
+ $arg .= " --head {$head_commit}";
$repository_api->setHeadCommit($head_commit);
}
@@ -127,7 +127,8 @@
$relative = substr($relative, 0, 16);
if ($repository_api instanceof ArcanistGitAPI) {
- $command = "git diff {$relative}..HEAD";
+ $head = $this->getArgument('head', 'HEAD');
+ $command = "git diff {$relative}..{$head}";
} else if ($repository_api instanceof ArcanistMercurialAPI) {
$command = "hg diff --rev {$relative}";
} else {

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 15, 11:22 PM (1 w, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7737092
Default Alt Text
D9369.id22711.diff (5 KB)

Event Timeline