abstract public function getCurrentFileData($path);
abstract public function getLocalCommitInformation();
+
+ abstract public function supportsRelativeLocalCommits();
+
+ public function parseRelativeLocalCommit(array $argv) {
+ throw new Exception("This VCS does not support relative local commits.");
+ }
+
+ public function getAllLocalChanges() {
+ throw new Exception("This VCS does not support getting all local changes.");
+ }
+
}
return trim($owner);
}
+ public function supportsRelativeLocalCommits() {
+ return true;
+ }
+
+ public function parseRelativeLocalCommit(array $argv) {
+ if (count($argv) == 0) {
+ return;
+ }
+ if (count($argv) != 1) {
+ throw new ArcanistUsageException("Specify only one commit.");
+ }
+ $base = reset($argv);
+ if ($base == ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT) {
+ $merge_base = $base;
+ } else {
+ list($err, $merge_base) = exec_manual(
+ '(cd %s; git merge-base %s HEAD)',
+ $this->getPath(),
+ $base);
+ if ($err) {
+ throw new ArcanistUsageException(
+ "Unable to parse git commit name '{$base}'.");
+ }
+ }
+ $this->setRelativeCommit(trim($merge_base));
+ }
+
+ public function getAllLocalChanges() {
+ $diff = $this->getFullGitDiff();
+ $parser = new ArcanistDiffParser();
+ return $parser->parseDiff($diff);
+ }
+
}
+phutil_require_module('arcanist', 'exception/usage');
+phutil_require_module('arcanist', 'parser/diff');
phutil_require_module('arcanist', 'repository/api/base');
phutil_require_module('phutil', 'future');
return trim($match[1]);
}
+ public function supportsRelativeLocalCommits() {
+ return true;
+ }
+
+ public function parseRelativeLocalCommit(array $argv) {
+ if (count($argv) == 0) {
+ return;
+ }
+ if (count($argv) != 1) {
+ throw new ArcanistUsageException("Specify only one commit.");
+ }
+ // This does the "hg id" call we need to normalize/validate the revision
+ // identifier.
+ $this->setRelativeCommit(reset($argv));
+ }
+
+ public function getAllLocalChanges() {
+ $diff = $this->getFullMercurialDiff();
+ $parser = new ArcanistDiffParser();
+ return $parser->parseDiff($diff);
+ }
+
}
return null;
}
+ public function supportsRelativeCommits() {
+ return false;
+ }
+
}
$repository_api = $this->getRepositoryAPI();
if ($repository_api instanceof ArcanistSubversionAPI) {
+ // NOTE: In SVN, we don't currently support a "get all local changes"
+ // operation, so special case it.
if (empty($this->changeCache[$path])) {
$diff = $repository_api->getRawDiffText($path);
$parser = new ArcanistDiffParser();
}
$this->changeCache[$path] = reset($changes);
}
- } else {
+ } else if ($repository_api->supportsRelativeLocalCommits()) {
if (empty($this->changeCache)) {
- $diff = $repository_api->getFullGitDiff();
- $parser = new ArcanistDiffParser();
- $changes = $parser->parseDiff($diff);
+ $changes = $repository_api->getAllLocalChanges();
foreach ($changes as $change) {
$this->changeCache[$change->getCurrentPath()] = $change;
}
}
+ } else {
+ throw new Exception("Missing VCS support.");
}
if (empty($this->changeCache[$path])) {
}
}
- protected function parseGitRelativeCommit(ArcanistGitAPI $api, array $argv) {
- if (count($argv) == 0) {
- return;
- }
- if (count($argv) != 1) {
- throw new ArcanistUsageException(
- "Specify exactly one commit.");
- }
- $base = reset($argv);
- if ($base == ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT) {
- $merge_base = $base;
- } else {
- list($err, $merge_base) = exec_manual(
- '(cd %s; git merge-base %s HEAD)',
- $api->getPath(),
- $base);
- if ($err) {
- throw new ArcanistUsageException(
- "Unable to parse git commit name '{$base}'.");
- }
- }
- $api->setRelativeCommit(trim($merge_base));
- }
-
protected function normalizeRevisionID($revision_id) {
return ltrim(strtoupper($revision_id), 'D');
}
phutil_require_module('arcanist', 'parser/bundle');
phutil_require_module('arcanist', 'parser/diff');
phutil_require_module('arcanist', 'parser/diff/change');
-phutil_require_module('arcanist', 'repository/api/git');
phutil_require_module('phutil', 'conduit/client');
phutil_require_module('phutil', 'console');
}
}
- } else if ($repository_api instanceof ArcanistGitAPI) {
- $this->parseGitRelativeCommit(
- $repository_api,
+ } else if ($repository_api->supportsRelativeLocalCommits()) {
+ $repository_api->parseRelativeLocalCommit(
$this->getArgument('paths', array()));
$paths = $repository_api->getWorkingCopyStatus();
- } else if ($repository_api instanceof ArcanistMercurialAPI) {
- // TODO: Unify this and the previous block.
-
- // TODO: Parse the relative commit.
-
- $paths = $repository_api->getWorkingCopyStatus();
} else {
throw new Exception("Unknown VCS!");
}
unset($paths[$path]);
}
}
- } else {
- $this->parseGitRelativeCommit(
- $repository_api,
- $this->getArgument('paths'));
+ } else if ($repository_api->supportsRelativeLocalCommits()) {
+ $repository_api->parseRelativeLocalCommit(
+ $this->getArgument('paths', array()));
$paths = $repository_api->getWorkingCopyStatus();
+ } else {
+ throw new Exception("Unknown VCS!");
}
foreach ($paths as $path => $flags) {
}
$paths = array_keys($paths);
-
} else {
$paths = $this->getArgument('paths');
if (empty($paths)) {