]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Use full-length hashes in Mercurial local commit information
authorepriestley <git@epriestley.com>
Mon, 26 Sep 2011 21:35:42 +0000 (14:35 -0700)
committerepriestley <git@epriestley.com>
Mon, 26 Sep 2011 22:13:18 +0000 (15:13 -0700)
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

src/repository/api/mercurial/ArcanistMercurialAPI.php
src/repository/api/mercurial/__init__.php

index c288e37fb9659462e653dc4f36b6b42223035688..79d80c66de6c4b61c13d7078bf29094ca60c863a 100644 (file)
@@ -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() {
index 4fad8a3a7ea2589fd73be320347aecdebd8c7633..d4aa19c14c1f79042e4195f7a0fe03b786a25545 100644 (file)
@@ -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');