From: epriestley Date: Mon, 26 Sep 2011 21:35:42 +0000 (-0700) Subject: Use full-length hashes in Mercurial local commit information X-Git-Tag: conduit-4~272 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=fe5355e4e468f7cc9d45c565f74be22db453748b;p=arcanist.git Use full-length hashes in Mercurial local commit information Summary: Expand 12-character hashes to 40-character hashes so other things will work properly. Also use "hg id" instead of "hg summary" to figure out where the working copy is, since it's substantially simpler. Test Plan: Ran "arc diff" and got properly 40-character hashes. Reviewers: Makinde, aran Reviewed By: Makinde CC: aran, Makinde Differential Revision: 962 --- diff --git a/src/repository/api/mercurial/ArcanistMercurialAPI.php b/src/repository/api/mercurial/ArcanistMercurialAPI.php index c288e37f..79d80c66 100644 --- a/src/repository/api/mercurial/ArcanistMercurialAPI.php +++ b/src/repository/api/mercurial/ArcanistMercurialAPI.php @@ -112,6 +112,27 @@ class ArcanistMercurialAPI extends ArcanistRepositoryAPI { // is inclusive, while "hg diff" is exclusive. array_shift($logs); + // Expand short hashes (12 characters) to full hashes (40 characters) by + // issuing a big "hg log" command. Possibly we should do this with parents + // too, but nothing uses them directly at the moment. + if ($logs) { + $cmd = array(); + foreach (ipull($logs, 'rev') as $rev) { + $cmd[] = csprintf('--rev %s', $rev); + } + + list($full) = execx( + '(cd %s && hg log --template %s %C --)', + $this->getPath(), + '{node}\\n', + implode(' ', $cmd)); + + $full = explode("\n", trim($full)); + foreach ($logs as $key => $dict) { + $logs[$key]['rev'] = array_pop($full); + } + } + return $logs; } @@ -257,20 +278,12 @@ class ArcanistMercurialAPI extends ArcanistRepositoryAPI { // use "hg summary" to figure out what is actually in the working copy. // For instance, "hg up 4 && arc diff" should not show commits 5 and above. - // The output of "hg summary" is different from the output of other hg - // commands so just parse it manually. + // Without arguments, "hg id" shows the current working directory's commit, + // and "--debug" expands it to a 40-character hash. list($stdout) = execx( - '(cd %s && hg summary)', + '(cd %s && hg --debug id --id)', $this->getPath()); - $lines = explode("\n", $stdout); - - $first = head($lines); - $match = null; - if (!preg_match('/^parent: \d+:([^ ]+)( |$)/', $first, $match)) { - throw new Exception("Unable to parse 'hg summary'."); - } - - return trim($match[1]); + return trim($stdout); } public function supportsRelativeLocalCommits() { diff --git a/src/repository/api/mercurial/__init__.php b/src/repository/api/mercurial/__init__.php index 4fad8a3a..d4aa19c1 100644 --- a/src/repository/api/mercurial/__init__.php +++ b/src/repository/api/mercurial/__init__.php @@ -14,6 +14,7 @@ phutil_require_module('arcanist', 'repository/parser/mercurial'); phutil_require_module('phutil', 'future/exec'); phutil_require_module('phutil', 'utils'); +phutil_require_module('phutil', 'xsprintf/csprintf'); phutil_require_source('ArcanistMercurialAPI.php');