From 7f640b9db98c24b52f8b9e7c6fcdb277d0cac93d Mon Sep 17 00:00:00 2001 From: dschleimer Date: Thu, 21 Jun 2012 18:12:09 -0700 Subject: [PATCH] [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 | date: Thu Jun 21 13:03:46 2012 -0700 | summary: thing | o changeset: 10:433a93023f03 | parent: 8:f47ccfe34267 | user: David Schleimer | date: Thu Jun 21 13:03:34 2012 -0700 | summary: some | | o changeset: 9:c8379ef32b0d |/ bookmark: other | user: David Schleimer | date: Thu Jun 21 13:01:04 2012 -0700 | summary: other | o changeset: 8:f47ccfe34267 | bookmark: master | user: David Schleimer | 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 --- src/repository/api/ArcanistMercurialAPI.php | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/repository/api/ArcanistMercurialAPI.php b/src/repository/api/ArcanistMercurialAPI.php index ea82a930..6fecb573 100644 --- a/src/repository/api/ArcanistMercurialAPI.php +++ b/src/repository/api/ArcanistMercurialAPI.php @@ -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; + + } + } -- 2.43.0