mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-29 10:12:41 +01:00
[Arcanist] mercurial base commit DSL support
Summary: This adds Mercurial support to the base commit DSL that's equivalent to git's, though not identical. Specifically, Mercurial has arc:outgoing instead of arc:upstream, and hg:gca(commit) instead of git:merge-base(commit), though they have similar behaviors. Test Plan: [13:37:13 Thu Jun 21 2012] dschleimer@dev4022.snc6 ~/hg-dummy hg-dummy 20536 $ hg log -G -r master:: @ changeset: 11:6970e9263ab8 | bookmark: something | tag: tip | user: David Schleimer <dschleimer@fb.com> | date: Thu Jun 21 13:03:46 2012 -0700 | summary: thing | o changeset: 10:433a93023f03 | parent: 8:f47ccfe34267 | user: David Schleimer <dschleimer@fb.com> | date: Thu Jun 21 13:03:34 2012 -0700 | summary: some | | o changeset: 9:c8379ef32b0d |/ bookmark: other | user: David Schleimer <dschleimer@fb.com> | date: Thu Jun 21 13:01:04 2012 -0700 | summary: other | o changeset: 8:f47ccfe34267 | bookmark: master | user: David Schleimer <dschleimer@fb.com> | date: Mon Jun 04 14:30:47 2012 -0700 | summary: typo-fix | [13:38:00 Thu Jun 21 2012] dschleimer@dev4022.snc6 ~/hg-dummy hg-dummy 20536 $ ~/devtools/arcanist/bin/arc which --show-base --base hg:.^ .^ [13:38:11 Thu Jun 21 2012] dschleimer@dev4022.snc6 ~/hg-dummy hg-dummy 20536 $ ~/devtools/arcanist/bin/arc which --show-base --base 'hg:gca(other)' f47ccfe34267592dd2e336174a3a311b8783c024 [13:38:21 Thu Jun 21 2012] dschleimer@dev4022.snc6 ~/hg-dummy hg-dummy 20536 $ hg id -r f47ccfe34267592dd2e336174a3a311b8783c024 f47ccfe34267 master [13:38:31 Thu Jun 21 2012] dschleimer@dev4022.snc6 ~/hg-dummy hg-dummy 20537 $ ~/devtools/arcanist/bin/arc which --show-base --base 'arc:empty' null [13:38:44 Thu Jun 21 2012] dschleimer@dev4022.snc6 ~/hg-dummy hg-dummy 20538 $ hg id -r null 000000000000 [13:38:48 Thu Jun 21 2012] dschleimer@dev4022.snc6 ~/hg-dummy hg-dummy 20538 $ ~/devtools/arcanist/bin/arc which --show-base --base 'arc:outgoing' f47ccfe34267592dd2e336174a3a311b8783c024 Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1233 Differential Revision: https://secure.phabricator.com/D2822
This commit is contained in:
parent
a9dbb937e8
commit
7f640b9db9
1 changed files with 72 additions and 0 deletions
|
@ -99,6 +99,20 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
list($err, $stdout) = $this->execManualLocal(
|
||||
'outgoing --branch `hg branch` --style default');
|
||||
|
||||
|
@ -608,4 +622,62 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
|
|||
return trim($summary);
|
||||
}
|
||||
|
||||
public function resolveBaseCommitRule($rule, $source) {
|
||||
list($type, $name) = explode(':', $rule, 2);
|
||||
|
||||
switch ($type) {
|
||||
case 'hg':
|
||||
$matches = null;
|
||||
if (preg_match('/^gca\((.+)\)$/', $name, $matches)) {
|
||||
list($err, $merge_base) = $this->execManualLocal(
|
||||
'log --template={node} --rev %s',
|
||||
sprintf('ancestor(., %s)', $matches[1]));
|
||||
if (!$err) {
|
||||
$this->setBaseCommitExplanation(
|
||||
"it is the greatest common ancestor of '{$matches[1]}' and ., as".
|
||||
"specified by '{$rule}' in your {$source} 'base' ".
|
||||
"configuration.");
|
||||
return trim($merge_base);
|
||||
}
|
||||
} else {
|
||||
list($err) = $this->execManualLocal(
|
||||
'id -r %s',
|
||||
$name);
|
||||
if (!$err) {
|
||||
$this->setBaseCommitExplanation(
|
||||
"it is specified by '{$rule}' in your {$source} 'base' ".
|
||||
"configuration.");
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'arc':
|
||||
switch ($name) {
|
||||
case 'empty':
|
||||
$this->setBaseCommitExplanation(
|
||||
"you specified '{$rule}' in your {$source} 'base' ".
|
||||
"configuration.");
|
||||
return 'null';
|
||||
case 'outgoing':
|
||||
list($err, $outgoing_base) = $this->execManualLocal(
|
||||
'log --template={node} --rev %s',
|
||||
'limit(reverse(ancestors(.) - outgoing()), 1)'
|
||||
);
|
||||
if (!$err) {
|
||||
$this->setBaseCommitExplanation(
|
||||
"it is the first ancestor of the working copy that is not ".
|
||||
"outgoing, and it matched the rule {$rule} in your {$source} ".
|
||||
"'base' configuration.");
|
||||
return trim($outgoing_base);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue