*/
final class ArcanistGitAPI extends ArcanistRepositoryAPI {
- private $relativeCommit = null;
private $repositoryHasNoCommits = false;
const SEARCH_LENGTH_FOR_PARENT_REVISIONS = 16;
return !$this->repositoryHasNoCommits;
}
- public function setRelativeCommit($relative_commit) {
- $this->relativeCommit = $relative_commit;
- return $this;
- }
-
public function getLocalCommitInformation() {
if ($this->repositoryHasNoCommits) {
// Zero commits.
throw new Exception(
"You can't get local commit information for a repository with no ".
"commits.");
- } else if ($this->relativeCommit == self::GIT_MAGIC_ROOT_COMMIT) {
+ } else if ($this->getBaseCommit() == self::GIT_MAGIC_ROOT_COMMIT) {
// One commit.
$against = 'HEAD';
} else {
// this as being the commits X and Y. If we log "B..Y", we only show
// Y. With "Y --not B", we show X and Y.
- $against = csprintf('%s --not %s', 'HEAD', $this->getRelativeCommit());
+ $against = csprintf('%s --not %s', 'HEAD', $this->getBaseCommit());
}
// NOTE: Windows escaping of "%" symbols apparently is inherently broken;
return $commits;
}
- public function getRelativeCommit() {
- if ($this->relativeCommit === null) {
+ protected function buildBaseCommit($symbolic_commit) {
+ if ($symbolic_commit !== null) {
+ if ($symbolic_commit == ArcanistGitAPI::GIT_MAGIC_ROOT_COMMIT) {
+ $this->setBaseCommitExplanation(
+ "you explicitly specified the empty tree.");
+ return $symbolic_commit;
+ }
- // Detect zero-commit or one-commit repositories. There is only one
- // relative-commit value that makes any sense in these repositories: the
- // empty tree.
- list($err) = $this->execManualLocal('rev-parse --verify HEAD^');
+ list($err, $merge_base) = $this->execManualLocal(
+ 'merge-base %s HEAD',
+ $symbolic_commit);
if ($err) {
- list($err) = $this->execManualLocal('rev-parse --verify HEAD');
- if ($err) {
- $this->repositoryHasNoCommits = true;
- }
-
- $this->relativeCommit = self::GIT_MAGIC_ROOT_COMMIT;
-
- if ($this->repositoryHasNoCommits) {
- $this->setBaseCommitExplanation(
- "the repository has no commits.");
- } else {
- $this->setBaseCommitExplanation(
- "the repository has only one commit.");
- }
-
- return $this->relativeCommit;
+ throw new ArcanistUsageException(
+ "Unable to find any git commit named '{$symbolic_commit}' in ".
+ "this repository.");
}
- if ($this->getBaseCommitArgumentRules() ||
- $this->getWorkingCopyIdentity()->getConfigFromAnySource('base')) {
- $base = $this->resolveBaseCommit();
- if (!$base) {
- throw new ArcanistUsageException(
- "None of the rules in your 'base' configuration matched a valid ".
- "commit. Adjust rules or specify which commit you want to use ".
- "explicitly.");
- }
- $this->relativeCommit = $base;
- return $this->relativeCommit;
+ $this->setBaseCommitExplanation(
+ "it is the merge-base of '{$symbolic_commit}' and HEAD, as you ".
+ "explicitly specified.");
+ return trim($merge_base);
+ }
+
+ // Detect zero-commit or one-commit repositories. There is only one
+ // relative-commit value that makes any sense in these repositories: the
+ // empty tree.
+ list($err) = $this->execManualLocal('rev-parse --verify HEAD^');
+ if ($err) {
+ list($err) = $this->execManualLocal('rev-parse --verify HEAD');
+ if ($err) {
+ $this->repositoryHasNoCommits = true;
}
- $do_write = false;
- $default_relative = null;
- $working_copy = $this->getWorkingCopyIdentity();
- if ($working_copy) {
- $default_relative = $working_copy->getConfig(
- 'git.default-relative-commit');
+ if ($this->repositoryHasNoCommits) {
$this->setBaseCommitExplanation(
- "it is the merge-base of '{$default_relative}' and HEAD, as ".
- "specified in 'git.default-relative-commit' in '.arcconfig'. This ".
- "setting overrides other settings.");
+ "the repository has no commits.");
+ } else {
+ $this->setBaseCommitExplanation(
+ "the repository has only one commit.");
}
- if (!$default_relative) {
- list($err, $upstream) = $this->execManualLocal(
- "rev-parse --abbrev-ref --symbolic-full-name '@{upstream}'");
+ return self::GIT_MAGIC_ROOT_COMMIT;
+ }
- if (!$err) {
- $default_relative = trim($upstream);
- $this->setBaseCommitExplanation(
- "it is the merge-base of '{$default_relative}' (the Git upstream ".
- "of the current branch) HEAD.");
- }
+ if ($this->getBaseCommitArgumentRules() ||
+ $this->getWorkingCopyIdentity()->getConfigFromAnySource('base')) {
+ $base = $this->resolveBaseCommit();
+ if (!$base) {
+ throw new ArcanistUsageException(
+ "None of the rules in your 'base' configuration matched a valid ".
+ "commit. Adjust rules or specify which commit you want to use ".
+ "explicitly.");
}
+ return $base;
+ }
- if (!$default_relative) {
- $default_relative = $this->readScratchFile('default-relative-commit');
- $default_relative = trim($default_relative);
- if ($default_relative) {
- $this->setBaseCommitExplanation(
- "it is the merge-base of '{$default_relative}' and HEAD, as ".
- "specified in '.git/arc/default-relative-commit'.");
- }
- }
+ $do_write = false;
+ $default_relative = null;
+ $working_copy = $this->getWorkingCopyIdentity();
+ if ($working_copy) {
+ $default_relative = $working_copy->getConfig(
+ 'git.default-relative-commit');
+ $this->setBaseCommitExplanation(
+ "it is the merge-base of '{$default_relative}' and HEAD, as ".
+ "specified in 'git.default-relative-commit' in '.arcconfig'. This ".
+ "setting overrides other settings.");
+ }
- if (!$default_relative) {
-
- // TODO: Remove the history lesson soon.
-
- echo phutil_console_format(
- "<bg:green>** Select a Default Commit Range **</bg>\n\n");
- echo phutil_console_wrap(
- "You're running a command which operates on a range of revisions ".
- "(usually, from some revision to HEAD) but have not specified the ".
- "revision that should determine the start of the range.\n\n".
- "Previously, arc assumed you meant 'HEAD^' when you did not specify ".
- "a start revision, but this behavior does not make much sense in ".
- "most workflows outside of Facebook's historic git-svn workflow.\n\n".
- "arc no longer assumes 'HEAD^'. You must specify a relative commit ".
- "explicitly when you invoke a command (e.g., `arc diff HEAD^`, not ".
- "just `arc diff`) or select a default for this working copy.\n\n".
- "In most cases, the best default is 'origin/master'. You can also ".
- "select 'HEAD^' to preserve the old behavior, or some other remote ".
- "or branch. But you almost certainly want to select ".
- "'origin/master'.\n\n".
- "(Technically: the merge-base of the selected revision and HEAD is ".
- "used to determine the start of the commit range.)");
-
- $prompt = "What default do you want to use? [origin/master]";
- $default = phutil_console_prompt($prompt);
-
- if (!strlen(trim($default))) {
- $default = 'origin/master';
- }
+ if (!$default_relative) {
+ list($err, $upstream) = $this->execManualLocal(
+ "rev-parse --abbrev-ref --symbolic-full-name '@{upstream}'");
- $default_relative = $default;
- $do_write = true;
+ if (!$err) {
+ $default_relative = trim($upstream);
+ $this->setBaseCommitExplanation(
+ "it is the merge-base of '{$default_relative}' (the Git upstream ".
+ "of the current branch) HEAD.");
}
+ }
- list($object_type) = $this->execxLocal(
- 'cat-file -t %s',
- $default_relative);
-
- if (trim($object_type) !== 'commit') {
- throw new Exception(
- "Relative commit '{$default_relative}' is not the name of a commit!");
+ if (!$default_relative) {
+ $default_relative = $this->readScratchFile('default-relative-commit');
+ $default_relative = trim($default_relative);
+ if ($default_relative) {
+ $this->setBaseCommitExplanation(
+ "it is the merge-base of '{$default_relative}' and HEAD, as ".
+ "specified in '.git/arc/default-relative-commit'.");
}
+ }
- if ($do_write) {
- // Don't perform this write until we've verified that the object is a
- // valid commit name.
- $this->writeScratchFile('default-relative-commit', $default_relative);
- $this->setBaseCommitExplanation(
- "it is the merge-base of '{$default_relative}' and HEAD, as you ".
- "just specified.");
+ if (!$default_relative) {
+
+ // TODO: Remove the history lesson soon.
+
+ echo phutil_console_format(
+ "<bg:green>** Select a Default Commit Range **</bg>\n\n");
+ echo phutil_console_wrap(
+ "You're running a command which operates on a range of revisions ".
+ "(usually, from some revision to HEAD) but have not specified the ".
+ "revision that should determine the start of the range.\n\n".
+ "Previously, arc assumed you meant 'HEAD^' when you did not specify ".
+ "a start revision, but this behavior does not make much sense in ".
+ "most workflows outside of Facebook's historic git-svn workflow.\n\n".
+ "arc no longer assumes 'HEAD^'. You must specify a relative commit ".
+ "explicitly when you invoke a command (e.g., `arc diff HEAD^`, not ".
+ "just `arc diff`) or select a default for this working copy.\n\n".
+ "In most cases, the best default is 'origin/master'. You can also ".
+ "select 'HEAD^' to preserve the old behavior, or some other remote ".
+ "or branch. But you almost certainly want to select ".
+ "'origin/master'.\n\n".
+ "(Technically: the merge-base of the selected revision and HEAD is ".
+ "used to determine the start of the commit range.)");
+
+ $prompt = "What default do you want to use? [origin/master]";
+ $default = phutil_console_prompt($prompt);
+
+ if (!strlen(trim($default))) {
+ $default = 'origin/master';
}
- list($merge_base) = $this->execxLocal(
- 'merge-base %s HEAD',
- $default_relative);
+ $default_relative = $default;
+ $do_write = true;
+ }
- $this->relativeCommit = trim($merge_base);
+ list($object_type) = $this->execxLocal(
+ 'cat-file -t %s',
+ $default_relative);
+
+ if (trim($object_type) !== 'commit') {
+ throw new Exception(
+ "Relative commit '{$default_relative}' is not the name of a commit!");
}
- return $this->relativeCommit;
+ if ($do_write) {
+ // Don't perform this write until we've verified that the object is a
+ // valid commit name.
+ $this->writeScratchFile('default-relative-commit', $default_relative);
+ $this->setBaseCommitExplanation(
+ "it is the merge-base of '{$default_relative}' and HEAD, as you ".
+ "just specified.");
+ }
+
+ list($merge_base) = $this->execxLocal(
+ 'merge-base %s HEAD',
+ $default_relative);
+
+ return trim($merge_base);
}
private function getDiffFullOptions($detect_moves_and_renames = true) {
$options = $this->getDiffFullOptions();
list($stdout) = $this->execxLocal(
"diff {$options} %s --",
- $this->getRelativeCommit());
+ $this->getBaseCommit());
return $stdout;
}
$options = $this->getDiffFullOptions($detect_moves_and_renames);
list($stdout) = $this->execxLocal(
"diff {$options} %s -- %s",
- $this->getRelativeCommit(),
+ $this->getBaseCommit(),
$path);
return $stdout;
}
}
public function getGitCommitLog() {
- $relative = $this->getRelativeCommit();
+ $relative = $this->getBaseCommit();
if ($this->repositoryHasNoCommits) {
// No commits yet.
return '';
// 2..N commits.
list($stdout) = $this->execxLocal(
'log --first-parent --format=medium %s..HEAD',
- $this->getRelativeCommit());
+ $this->getBaseCommit());
}
return $stdout;
}
list($stdout) = $this->execxLocal(
'log --format=medium -n%d %s',
self::SEARCH_LENGTH_FOR_PARENT_REVISIONS,
- $this->getRelativeCommit());
+ $this->getBaseCommit());
return $stdout;
}
public function getSourceControlBaseRevision() {
list($stdout) = $this->execxLocal(
'rev-parse %s',
- $this->getRelativeCommit());
+ $this->getBaseCommit());
return rtrim($stdout, "\n");
}
list($stdout, $stderr) = $this->execxLocal(
'diff %C --raw %s --',
$this->getDiffBaseOptions(),
- $this->getRelativeCommit());
+ $this->getBaseCommit());
return $this->parseGitStatus($stdout);
}
$this->execxLocal(
'add -- %Ls',
$paths);
+ $this->reloadWorkingCopy();
+ return $this;
}
public function doCommit($message) {
$this->execxLocal(
'commit --amend --allow-empty -F %s',
$tmp_file);
+ $this->reloadWorkingCopy();
+ return $this;
}
public function getPreReceiveHookStatus($old_ref, $new_ref) {
// TODO: 'git blame' supports --porcelain and we should probably use it.
list($stdout) = $this->execxLocal(
'blame --date=iso -w -M %s -- %s',
- $this->getRelativeCommit(),
+ $this->getBaseCommit(),
$path);
$blame = array();
}
public function getOriginalFileData($path) {
- return $this->getFileDataAtRevision($path, $this->getRelativeCommit());
+ return $this->getFileDataAtRevision($path, $this->getBaseCommit());
}
public function getCurrentFileData($path) {
return true;
}
- public function supportsRelativeLocalCommits() {
+ public function supportsCommitRanges() {
+ return true;
+ }
+
+ public function supportsLocalCommits() {
return true;
}
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;
- $this->setBaseCommitExplanation(
- "you explicitly specified the empty tree.");
- } else {
- list($err, $merge_base) = $this->execManualLocal(
- 'merge-base %s HEAD',
- $base);
- if ($err) {
- throw new ArcanistUsageException(
- "Unable to find any git commit named '{$base}' in this repository.");
- }
- $this->setBaseCommitExplanation(
- "it is the merge-base of '{$base}' and HEAD, as you explicitly ".
- "specified.");
- }
- $this->setRelativeCommit(trim($merge_base));
- }
-
public function getAllLocalChanges() {
$diff = $this->getFullGitDiff();
if (!strlen(trim($diff))) {
public function updateWorkingCopy() {
$this->execxLocal('pull');
+ $this->reloadWorkingCopy();
}
public function getCommitSummary($commit) {
*/
final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
- private $base;
- private $relativeCommit;
private $branch;
- private $workingCopyRevision;
private $localCommitInfo;
private $includeDirectoryStateInDiffs;
private $rawDiffCache = array();
}
public function getSourceControlBaseRevision() {
- return $this->getCanonicalRevisionName($this->getRelativeCommit());
+ return $this->getCanonicalRevisionName($this->getBaseCommit());
}
public function getCanonicalRevisionName($string) {
return $this->branch;
}
- public function setRelativeCommit($commit) {
- try {
- $commit = $this->getCanonicalRevisionName($commit);
- } catch (Exception $ex) {
- throw new ArcanistUsageException(
- "Commit '{$commit}' is not a valid Mercurial commit identifier.");
- }
-
- $this->relativeCommit = $commit;
- $this->status = null;
+ public function didReloadCommitRange() {
$this->localCommitInfo = null;
-
- return $this;
}
- public function getRelativeCommit() {
- if (empty($this->relativeCommit)) {
-
- if ($this->getBaseCommitArgumentRules() ||
- $this->getWorkingCopyIdentity()->getConfigFromAnySource('base')) {
- $base = $this->resolveBaseCommit();
- if (!$base) {
- throw new ArcanistUsageException(
- "None of the rules in your 'base' configuration matched a valid ".
- "commit. Adjust rules or specify which commit you want to use ".
- "explicitly.");
- }
- $this->relativeCommit = $base;
- return $this->relativeCommit;
+ protected function buildBaseCommit($symbolic_commit) {
+ if ($symbolic_commit !== null) {
+ try {
+ $commit = $this->getCanonicalRevisionName($commit);
+ } catch (Exception $ex) {
+ throw new ArcanistUsageException(
+ "Commit '{$commit}' is not a valid Mercurial commit identifier.");
}
-
- list($err, $stdout) = $this->execManualLocal(
- 'outgoing --branch %s --style default',
- $this->getBranchName());
-
- if (!$err) {
- $logs = ArcanistMercurialParser::parseMercurialLog($stdout);
- } else {
- // Mercurial (in some versions?) raises an error when there's nothing
- // outgoing.
- $logs = array();
+ $this->setBaseCommitExplanation("you specified it explicitly.");
+ return $commit;
+ }
+
+ if ($this->getBaseCommitArgumentRules() ||
+ $this->getWorkingCopyIdentity()->getConfigFromAnySource('base')) {
+ $base = $this->resolveBaseCommit();
+ if (!$base) {
+ throw new ArcanistUsageException(
+ "None of the rules in your 'base' configuration matched a valid ".
+ "commit. Adjust rules or specify which commit you want to use ".
+ "explicitly.");
}
+ return $base;
+ }
- if (!$logs) {
+ list($err, $stdout) = $this->execManualLocal(
+ 'outgoing --branch %s --style default',
+ $this->getBranchName());
- $this->setBaseCommitExplanation(
- "you have no outgoing commits, so arc assumes you intend to submit ".
- "uncommitted changes in the working copy.");
- // In Mercurial, we support operations against uncommitted changes.
- $this->setRelativeCommit($this->getWorkingCopyRevision());
- return $this->relativeCommit;
- }
+ if (!$err) {
+ $logs = ArcanistMercurialParser::parseMercurialLog($stdout);
+ } else {
+ // Mercurial (in some versions?) raises an error when there's nothing
+ // outgoing.
+ $logs = array();
+ }
- $outgoing_revs = ipull($logs, 'rev');
+ if (!$logs) {
+ $this->setBaseCommitExplanation(
+ "you have no outgoing commits, so arc assumes you intend to submit ".
+ "uncommitted changes in the working copy.");
+ return $this->getWorkingCopyRevision();
+ }
- // This is essentially an implementation of a theoretical `hg merge-base`
- // command.
- $against = $this->getWorkingCopyRevision();
- while (true) {
- // NOTE: The "^" and "~" syntaxes were only added in hg 1.9, which is
- // new as of July 2011, so do this in a compatible way. Also, "hg log"
- // and "hg outgoing" don't necessarily show parents (even if given an
- // explicit template consisting of just the parents token) so we need
- // to separately execute "hg parents".
+ $outgoing_revs = ipull($logs, 'rev');
- list($stdout) = $this->execxLocal(
- 'parents --style default --rev %s',
- $against);
- $parents_logs = ArcanistMercurialParser::parseMercurialLog($stdout);
+ // This is essentially an implementation of a theoretical `hg merge-base`
+ // command.
+ $against = $this->getWorkingCopyRevision();
+ while (true) {
+ // NOTE: The "^" and "~" syntaxes were only added in hg 1.9, which is
+ // new as of July 2011, so do this in a compatible way. Also, "hg log"
+ // and "hg outgoing" don't necessarily show parents (even if given an
+ // explicit template consisting of just the parents token) so we need
+ // to separately execute "hg parents".
- list($p1, $p2) = array_merge($parents_logs, array(null, null));
+ list($stdout) = $this->execxLocal(
+ 'parents --style default --rev %s',
+ $against);
+ $parents_logs = ArcanistMercurialParser::parseMercurialLog($stdout);
- if ($p1 && !in_array($p1['rev'], $outgoing_revs)) {
- $against = $p1['rev'];
- break;
- } else if ($p2 && !in_array($p2['rev'], $outgoing_revs)) {
- $against = $p2['rev'];
- break;
- } else if ($p1) {
- $against = $p1['rev'];
- } else {
- // This is the case where you have a new repository and the entire
- // thing is outgoing; Mercurial literally accepts "--rev null" as
- // meaning "diff against the empty state".
- $against = 'null';
- break;
- }
- }
+ list($p1, $p2) = array_merge($parents_logs, array(null, null));
- if ($against == 'null') {
- $this->setBaseCommitExplanation(
- "this is a new repository (all changes are outgoing).");
+ if ($p1 && !in_array($p1['rev'], $outgoing_revs)) {
+ $against = $p1['rev'];
+ break;
+ } else if ($p2 && !in_array($p2['rev'], $outgoing_revs)) {
+ $against = $p2['rev'];
+ break;
+ } else if ($p1) {
+ $against = $p1['rev'];
} else {
- $this->setBaseCommitExplanation(
- "it is the first commit reachable from the working copy state ".
- "which is not outgoing.");
+ // This is the case where you have a new repository and the entire
+ // thing is outgoing; Mercurial literally accepts "--rev null" as
+ // meaning "diff against the empty state".
+ $against = 'null';
+ break;
}
+ }
- $this->setRelativeCommit($against);
+ if ($against == 'null') {
+ $this->setBaseCommitExplanation(
+ "this is a new repository (all changes are outgoing).");
+ } else {
+ $this->setBaseCommitExplanation(
+ "it is the first commit reachable from the working copy state ".
+ "which is not outgoing.");
}
- return $this->relativeCommit;
+
+ return $against;
}
public function getLocalCommitInformation() {
"log --template '%C' --rev %s --branch %s --",
"{node}\1{rev}\1{author}\1{date|rfc822date}\1".
"{branch}\1{tag}\1{parents}\1{desc}\2",
- '(ancestors(.) - ancestors('.$this->getRelativeCommit().'))',
+ '(ancestors(.) - ancestors('.$this->getBaseCommit().'))',
$this->getBranchName());
$logs = array_filter(explode("\2", $info));
public function getBlame($path) {
list($stdout) = $this->execxLocal(
'annotate -u -v -c --rev %s -- %s',
- $this->getRelativeCommit(),
+ $this->getBaseCommit(),
$path);
$blame = array();
// Diffs are against ".", so we need to drop the cache if we change the
// working copy.
$this->rawDiffCache = array();
+ $this->branch = null;
}
private function getDiffOptions() {
// copy commit" (i.e., from 'x' to '.'). The latter excludes any dirty
// changes in the working copy.
- $range = $this->getRelativeCommit();
+ $range = $this->getBaseCommit();
if (!$this->includeDirectoryStateInDiffs) {
$range .= '...';
}
}
public function getOriginalFileData($path) {
- return $this->getFileDataAtRevision($path, $this->getRelativeCommit());
+ return $this->getFileDataAtRevision($path, $this->getBaseCommit());
}
public function getCurrentFileData($path) {
}
}
- public function supportsRelativeLocalCommits() {
+ public function supportsCommitRanges() {
+ return true;
+ }
+
+ public function supportsLocalCommits() {
return true;
}
return $message;
}
- public function parseRelativeLocalCommit(array $argv) {
- if (count($argv) == 0) {
- return;
- }
- if (count($argv) != 1) {
- throw new ArcanistUsageException("Specify only one commit.");
- }
-
- $this->setBaseCommitExplanation("you explicitly specified it.");
-
- // This does the "hg id" call we need to normalize/validate the revision
- // identifier.
- $this->setRelativeCommit(reset($argv));
- }
-
public function getAllLocalChanges() {
$diff = $this->getFullMercurialDiff();
if (!strlen(trim($diff))) {
public function getCommitMessageLog() {
list($stdout) = $this->execxLocal(
"log --template '{node}\\2{desc}\\1' --rev %s --branch %s --",
- 'ancestors(.) - ancestors('.$this->getRelativeCommit().')',
+ 'ancestors(.) - ancestors('.$this->getBaseCommit().')',
$this->getBranchName());
$map = array();
public function updateWorkingCopy() {
$this->execxLocal('up');
+ $this->reloadWorkingCopy();
}
private function getMercurialConfig($key, $default = null) {
$this->execxLocal(
'add -- %Ls',
$paths);
+ $this->reloadWorkingCopy();
}
public function doCommit($message) {
$this->execxLocal(
'commit --amend -l %s',
$tmp_file);
+ $this->reloadWorkingCopy();
}
public function setIncludeDirectoryStateInDiffs($include) {
private $uncommittedStatusCache;
private $commitRangeStatusCache;
+ private $symbolicBaseCommit;
+ private $resolvedBaseCommit;
+
abstract public function getSourceControlSystemName();
public function getDiffLinesOfContext() {
$this->commitRangeStatusCache = null;
$this->didReloadWorkingCopy();
+ $this->reloadCommitRange();
return $this;
}
abstract public function getSourceControlPath();
abstract public function isHistoryDefaultImmutable();
abstract public function supportsAmend();
- abstract public function supportsRelativeLocalCommits();
abstract public function getWorkingCopyRevision();
abstract public function updateWorkingCopy();
abstract public function getMetadataPath();
throw new ArcanistCapabilityNotSupportedException($this);
}
+ abstract public function supportsLocalCommits();
+
public function doCommit($message) {
throw new ArcanistCapabilityNotSupportedException($this);
}
throw new ArcanistCapabilityNotSupportedException($this);
}
- public function parseRelativeLocalCommit(array $argv) {
- throw new ArcanistCapabilityNotSupportedException($this);
- }
-
public function getCommitSummary($commit) {
throw new ArcanistCapabilityNotSupportedException($this);
}
/* -( Base Commits )------------------------------------------------------- */
+ abstract public function supportsCommitRanges();
+
+ final public function setBaseCommit($symbolic_commit) {
+ if (!$this->supportsCommitRanges()) {
+ throw new ArcanistCapabilityNotSupportedException($this);
+ }
+
+ $this->symbolicBaseCommit = $symbolic_commit;
+ $this->reloadCommitRange();
+ return $this;
+ }
+
+ final public function getBaseCommit() {
+ if (!$this->supportsCommitRanges()) {
+ throw new ArcanistCapabilityNotSupportedException($this);
+ }
+
+ if ($this->resolvedBaseCommit === null) {
+ $commit = $this->buildBaseCommit($this->symbolicBaseCommit);
+ $this->resolvedBaseCommit = $commit;
+ }
+
+ return $this->resolvedBaseCommit;
+ }
+
+ final public function reloadCommitRange() {
+ $this->resolvedBaseCommit = null;
+ $this->baseCommitExplanation = null;
+
+ $this->didReloadCommitRange();
+
+ return $this;
+ }
+
+ protected function didReloadCommitRange() {
+ return;
+ }
+
+ protected function buildBaseCommit($symbolic_commit) {
+ throw new ArcanistCapabilityNotSupportedException($this);
+ }
public function getBaseCommitExplanation() {
return $this->baseCommitExplanation;
return false;
}
- public function supportsRelativeLocalCommits() {
+ public function supportsCommitRanges() {
+ return false;
+ }
+
+ public function supportsLocalCommits() {
return false;
}
if ($this->shouldAmend) {
$commit = head($api->getLocalCommitInformation());
$api->amendCommit($commit['message']);
- } else if ($api->supportsRelativeLocalCommits()) {
+ } else if ($api->supportsLocalCommits()) {
$api->doCommit(self::AUTO_COMMIT_TITLE);
}
}
protected function getChange($path) {
$repository_api = $this->getRepositoryAPI();
- if ($repository_api instanceof ArcanistSubversionAPI) {
+ // TODO: Very gross
+ $is_git = ($repository_api instanceof ArcanistGitAPI);
+ $is_hg = ($repository_api instanceof ArcanistMercurialAPI);
+ $is_svn = ($repository_api instanceof ArcanistSubversionAPI);
+
+ if ($is_svn) {
// NOTE: In SVN, we don't currently support a "get all local changes"
// operation, so special case it.
if (empty($this->changeCache[$path])) {
}
$this->changeCache[$path] = reset($changes);
}
- } else if ($repository_api->supportsRelativeLocalCommits()) {
+ } else if ($is_git || $is_hg) {
if (empty($this->changeCache)) {
$changes = $repository_api->getAllLocalChanges();
foreach ($changes as $change) {
}
if (empty($this->changeCache[$path])) {
- if ($repository_api instanceof ArcanistGitAPI) {
+ if ($is_git) {
// This can legitimately occur under git if you make a change, "git
// commit" it, and then revert the change in the working copy and run
// "arc lint".
}
} else {
$repository_api = $this->getRepositoryAPI();
- if ($rev) {
- $repository_api->parseRelativeLocalCommit(array($rev));
- }
+ $this->parseBaseCommitArgument(array($rev));
$paths = $repository_api->getWorkingCopyStatus();
foreach ($paths as $path => $flags) {
return $event;
}
+ public function parseBaseCommitArgument(array $argv) {
+ if (!count($argv)) {
+ return;
+ }
+
+ $api = $this->getRepositoryAPI();
+ if (!$api->supportsCommitRanges()) {
+ throw new ArcanistUsageException(
+ "This version control system does not support commit ranges.");
+ }
+
+ if (count($argv) > 1) {
+ throw new ArcanistUsageException(
+ "Specify exactly one base commit. The end of the commit range is ".
+ "always the working copy state.");
+ }
+
+ $api->setBaseCommit(head($argv));
+
+ return $this;
+ }
+
}
$in_rev = $this->getArgument('rev');
if ($in_rev) {
- // Although selectPathsForWorkflow() may set this, we want to set it
- // explicitly so we blame against the correct relative commit.
- $repository_api->parseRelativeLocalCommit(array($in_rev));
+ $this->parseBaseCommitArgument(array($in_rev));
}
$paths = $this->selectPathsForWorkflow(
$repository_api->setBaseCommitArgumentRules(
$this->getArgument('base', ''));
- if ($repository_api->supportsRelativeLocalCommits()) {
-
- // Parse the relative commit as soon as we can, to avoid generating
- // caches we need to drop later and expensive discovery operations
- // (particularly in Mercurial).
-
- $relative = $this->getArgument('paths');
- if ($relative) {
- $repository_api->parseRelativeLocalCommit($relative);
- }
+ if ($repository_api->supportsCommitRanges()) {
+ $this->parseBaseCommitArgument($this->getArgument('paths'));
}
}
}
}
- } else if ($repository_api->supportsRelativeLocalCommits()) {
- $paths = $repository_api->getWorkingCopyStatus();
} else {
- throw new Exception("Unknown VCS!");
+ $paths = $repository_api->getWorkingCopyStatus();
}
foreach ($paths as $path => $mask) {
$this->console->writeOut("Linting...\n");
try {
$argv = $this->getPassthruArgumentsAsArgv('lint');
- if ($repository_api->supportsRelativeLocalCommits()) {
+ if ($repository_api->supportsCommitRanges()) {
$argv[] = '--rev';
- $argv[] = $repository_api->getRelativeCommit();
+ $argv[] = $repository_api->getBaseCommit();
}
$lint_workflow = $this->buildChildWorkflow('lint', $argv);
$this->console->writeOut("Running unit tests...\n");
try {
$argv = $this->getPassthruArgumentsAsArgv('unit');
- if ($repository_api->supportsRelativeLocalCommits()) {
+ if ($repository_api->supportsCommitRanges()) {
$argv[] = '--rev';
- $argv[] = $repository_api->getRelativeCommit();
+ $argv[] = $repository_api->getBaseCommit();
}
$unit_workflow = $this->buildChildWorkflow('unit', $argv);
$unit_result = $unit_workflow->run();
$parser->setRepositoryAPI($repository_api);
if ($repository_api instanceof ArcanistGitAPI) {
- $repository_api->parseRelativeLocalCommit(
- $this->getArgument('paths'));
+ $this->parseBaseCommitArgument($this->getArgument('paths'));
$diff = $repository_api->getFullGitDiff();
$changes = $parser->parseDiff($diff);
$authors = $this->getConduit()->callMethodSynchronous(
$author_dict['realName'],
$repository_api->execxLocal('config user.email'));
} else if ($repository_api instanceof ArcanistMercurialAPI) {
- $repository_api->parseRelativeLocalCommit(
- $this->getArgument('paths'));
+ $repository_api->parseBaseCommitArgument($this->getArgument('paths'));
$diff = $repository_api->getFullMercurialDiff();
$changes = $parser->parseDiff($diff);
$authors = $this->getConduit()->callMethodSynchronous(
private function findRevision() {
$repository_api = $this->getRepositoryAPI();
- $repository_api->parseRelativeLocalCommit(array($this->ontoRemoteBranch));
+ $this->parseBaseCommitArgument(array($this->ontoRemoteBranch));
$revision_id = $this->getArgument('revision');
if ($revision_id) {
}
}
- // Now that we've rebased, the merge-base of origin/master and HEAD may
- // be different. Reparse the relative commit.
- $repository_api->parseRelativeLocalCommit(array($this->ontoRemoteBranch));
+ $repository_api->reloadWorkingCopy();
}
private function squash() {
if ($this->getArgument('only-new')) {
$conduit = $this->getConduit();
$api = $this->getRepositoryAPI();
- $relative_commit = ($rev ? $rev : $api->resolveBaseCommit());
- $api->setRelativeCommit($relative_commit);
+ if ($rev) {
+ $api->setBaseCommit($rev);
+ }
$svn_root = id(new PhutilURI($api->getSourceControlPath()))->getPath();
$all_paths = array();
$lint_future = $conduit->callMethod('diffusion.getlintmessages', array(
'arcanistProject' => $this->getWorkingCopy()->getProjectID(),
'branch' => '', // TODO: Tracking branch.
- 'commit' => $api->getRelativeCommit(),
+ 'commit' => $api->getBaseCommit(),
'files' => array_keys($all_paths),
));
}
// Check to see if the bundle's base revision matches the working copy
// base revision
- if ($repository_api->supportsRelativeLocalCommits()) {
+ if ($repository_api->supportsLocalCommits()) {
$bundle_base_rev = $bundle->getBaseRevision();
if (empty($bundle_base_rev)) {
// this means $source is SOURCE_PATCH || SOURCE_BUNDLE w/ $version < 2
$arg_commit = $this->getArgument('commit');
if (count($arg_commit)) {
- if (!$repository_api->supportsRelativeLocalCommits()) {
- throw new ArcanistUsageException(
- "This version control system does not support relative commits.");
- } else {
- $repository_api->parseRelativeLocalCommit($arg_commit);
- }
+ $this->parseBaseCommitArgument($arg_commit);
}
$arg = $arg_commit ? ' '.head($arg_commit) : '';
$repository_api->setBaseCommitArgumentRules(
$this->getArgument('base', ''));
- if ($repository_api->supportsRelativeLocalCommits()) {
- $relative = $repository_api->getRelativeCommit();
+ if ($repository_api->supportsCommitRanges()) {
+ $relative = $repository_api->getBaseCommit();
if ($this->getArgument('show-base')) {
echo $relative."\n";