mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 08:12:40 +01:00
Improve Arcanist Mercurial compatibility
Summary: - Use "hg parents" to figure out where outgoing changes originate from, not "~1", since that's a new feature in Mercurial. - Add "--style default" all over the place since hg config can override this (similar to the date config issues we saw in git). - Cache working copy status so we don't run full hg diffs like 30 times (similar to git/svn APIs). - Use full "--git" flag instead of rather cryptic "-g". Test Plan: Ran "arc diff" in my hg working copy, got the diff I expected. Reviewers: Makinde, aran, jungejason, nh, tuomaspelkonen Reviewed By: Makinde CC: aran, Makinde Differential Revision: 934
This commit is contained in:
parent
1c9746a46e
commit
9df1b8a4bd
1 changed files with 66 additions and 44 deletions
|
@ -69,22 +69,40 @@ class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
|
|||
public function getRelativeCommit() {
|
||||
if (empty($this->relativeCommit)) {
|
||||
list($stdout) = execx(
|
||||
'(cd %s && hg outgoing --branch `hg branch` --limit 1)',
|
||||
'(cd %s && hg outgoing --branch `hg branch` --limit 1 --style default)',
|
||||
$this->getPath());
|
||||
$logs = $this->parseMercurialLog($stdout);
|
||||
if (!count($logs)) {
|
||||
throw new ArcanistUsageException("You have no outgoing changes!");
|
||||
}
|
||||
$oldest_log = head($logs);
|
||||
$oldest_rev = $oldest_log['rev'];
|
||||
|
||||
$this->relativeCommit = $oldest_log['rev'].'~1';
|
||||
// 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($stdout) = execx(
|
||||
'(cd %s && hg parents --style default --rev %s)',
|
||||
$this->getPath(),
|
||||
$oldest_rev);
|
||||
$parents_logs = $this->parseMercurialLog($stdout);
|
||||
$first_parent = head($parents_logs);
|
||||
if (!$first_parent) {
|
||||
throw new ArcanistUsageException(
|
||||
"Oldest outgoing change has no parent revision!");
|
||||
}
|
||||
|
||||
$this->relativeCommit = $first_parent['rev'];
|
||||
}
|
||||
return $this->relativeCommit;
|
||||
}
|
||||
|
||||
public function getLocalCommitInformation() {
|
||||
list($info) = execx(
|
||||
'(cd %s && hg log --rev %s..%s --)',
|
||||
'(cd %s && hg log --style default --rev %s..%s --)',
|
||||
$this->getPath(),
|
||||
$this->getRelativeCommit(),
|
||||
$this->getWorkingCopyRevision());
|
||||
|
@ -128,6 +146,7 @@ class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
|
|||
|
||||
public function getWorkingCopyStatus() {
|
||||
|
||||
if (!isset($this->status)) {
|
||||
// A reviewable revision spans multiple local commits in Mercurial, but
|
||||
// there is no way to get file change status across multiple commits, so
|
||||
// just take the entire diff and parse it to figure out what's changed.
|
||||
|
@ -173,12 +192,15 @@ class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
|
|||
}
|
||||
}
|
||||
|
||||
return $status_map;
|
||||
$this->status = $status_map;
|
||||
}
|
||||
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
private function getDiffOptions() {
|
||||
$options = array(
|
||||
'-g',
|
||||
'--git',
|
||||
'-U'.$this->getDiffLinesOfContext(),
|
||||
);
|
||||
return implode(' ', $options);
|
||||
|
|
Loading…
Reference in a new issue