From 470e2eca67d2b1dda701886c113125d7394675b0 Mon Sep 17 00:00:00 2001 From: dschleimer Date: Sat, 30 Jun 2012 16:00:48 -0700 Subject: [PATCH] [Arcanist] collect svn and bookmark info for Mercurial Summary: This increases the amount of information arc diff collects in Mercurial repositories. IN particular, it collects the active bookmark, if there is one, and svn information in hgsubversion repositories. The Phabricator half of this is https://secure.phabricator.com/D2897 Test Plan: [14:06:59 Sat Jun 30 2012] dschleimer@dev4022.snc6 ~/www-hg www-hg 2941 $ ~/devtools/arcanist/bin/arc diff --only --conduit-uri http://phabricator.dschleimer.dev4022.facebook.com HipHop Notice: Undefined index: 1 in /data/users/dschleimer/devtools/arcanist/src/repository/api/ArcanistMercurialAPI.php on line 708 Created a new Differential diff: Diff URI: http://phabricator.dschleimer.dev4022.facebook.com/differential/diff/126/ Included changes: A foo HipHop Notice: Undefined index: 1 in /data/users/dschleimer/www-hg/lib/arcanist/arcanist/FacebookArcanistConfiguration.php on line 81 mcproxy on this server is out of date version: , expected version: please restart (http://fburl.com/1787362) [14:07:46 Sat Jun 30 2012] dschleimer@dev4022.snc6 ~/www-hg www-hg 2941 $ echo '{"diff_id": 126}' | ~/devtools/arcanist/bin/arc call-conduit differential.getdiff --conduit-uri http://phabricator.dschleimer.dev4022.facebook.com | json_pretty | egrep -i 'bookmark|sourcecontrol' "bookmark": "bar", "sourceControlBaseRevision": "svn+ssh://tubbs/svnroot/tfb/trunk/www@583442", "sourceControlPath": "svn+ssh://tubbs/svnroot/tfb/trunk/www", "sourceControlSystem": "hg", Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1331 Differential Revision: https://secure.phabricator.com/D2896 --- src/repository/api/ArcanistMercurialAPI.php | 44 +++++++++++++++++++++ src/workflow/ArcanistDiffWorkflow.php | 12 +++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/repository/api/ArcanistMercurialAPI.php b/src/repository/api/ArcanistMercurialAPI.php index 058707f5..3d8196ca 100644 --- a/src/repository/api/ArcanistMercurialAPI.php +++ b/src/repository/api/ArcanistMercurialAPI.php @@ -698,4 +698,48 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { } + public function getSubversionInfo() { + $info = array(); + $base_path = null; + $revision = null; + list($err, $raw_info) = $this->execManualLocal('svn info'); + if (!$err) { + foreach (explode("\n", trim($raw_info)) as $line) { + list($key, $value) = explode(': ', $line, 2); + switch ($key) { + case 'URL': + $info['base_path'] = $value; + $base_path = $value; + break; + case 'Repository UUID': + $info['uuid'] = $value; + break; + case 'Revision': + $revision = $value; + break; + default: + break; + } + } + if ($base_path && $revision) { + $info['base_revision'] = $base_path.'@'.$revision; + } + } + return $info; + } + + public function getActiveBookmark() { + list($raw_output) = $this->execxLocal('bookmarks'); + $raw_output = trim($raw_output); + if ($raw_output !== 'no bookmarks set') { + foreach (explode("\n", $raw_output) as $line) { + $line = trim($line); + if ('*' === $line[0]) { + return idx(explode(' ', $line, 3), 1); + } + } + } + return null; + } + } diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index 2dea677e..485d3089 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -1974,6 +1974,7 @@ EOTEXT $parent = null; $source_path = null; $branch = null; + $bookmark = null; if (!$this->isRawDiffSource()) { $repository_api = $this->getRepositoryAPI(); @@ -2001,7 +2002,15 @@ EOTEXT } else if ($repository_api instanceof ArcanistSubversionAPI) { $repo_uuid = $repository_api->getRepositorySVNUUID(); } else if ($repository_api instanceof ArcanistMercurialAPI) { - // TODO: Provide this information. + + $bookmark = $repository_api->getActiveBookmark(); + $svn_info = $repository_api->getSubversionInfo(); + $repo_uuid = idx($svn_info, 'uuid'); + $base_path = idx($svn_info, 'base_path', $base_path); + $base_revision = idx($svn_info, 'base_revision', $base_revision); + + // TODO: provide parent info + } else { throw new Exception("Unsupported repository API!"); } @@ -2016,6 +2025,7 @@ EOTEXT 'sourceMachine' => php_uname('n'), 'sourcePath' => $source_path, 'branch' => $branch, + 'bookmark' => $bookmark, 'sourceControlSystem' => $vcs, 'sourceControlPath' => $base_path, 'sourceControlBaseRevision' => $base_revision,