]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Handle empty output from `hg --debug branches` in the parser
authorepriestley <git@epriestley.com>
Mon, 4 Nov 2013 20:15:12 +0000 (12:15 -0800)
committerepriestley <git@epriestley.com>
Mon, 4 Nov 2013 20:15:12 +0000 (12:15 -0800)
Summary: Ref T1493. Also consolidate this a bit more.

Test Plan: Unit tests.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran
Maniphest Tasks: T1493

Differential Revision: https://secure.phabricator.com/D7481

src/repository/api/ArcanistMercurialAPI.php
src/repository/parser/ArcanistMercurialParser.php
src/repository/parser/__tests__/ArcanistMercurialParserTestCase.php
src/repository/parser/__tests__/mercurial/branches-empty.txt [new file with mode: 0644]

index ba2f2b4e710bdcfcf36dc93b53218947d015b62f..5ad75746b9be9566496dbfb6d2a45f6e454ece59 100644 (file)
@@ -984,22 +984,15 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
   }
 
   public function getBranches() {
-    $branches = array();
-
-    list($raw_output) = $this->execxLocal('branches');
-    $raw_output = trim($raw_output);
-
-    foreach (explode("\n", $raw_output) as $line) {
-      // example line: default                 0:a5ead76cdf85 (inactive)
-      list($name, $rev_line) = $this->splitBranchOrBookmarkLine($line);
-
-      // strip off the '(inactive)' bit if it exists
-      $rev_parts = explode(' ', $rev_line);
-      $revision = $rev_parts[0];
+    list($stdout) = $this->execxLocal('--debug branches');
+    $lines = ArcanistMercurialParser::parseMercurialBranches($stdout);
 
+    $branches = array();
+    foreach ($lines as $name => $spec) {
       $branches[] = array(
         'name' => $name,
-        'revision' => $revision);
+        'revision' => $spec['rev'],
+      );
     }
 
     return $branches;
index 884e37bb0e1bf24811dd25483f475d1d4554f385..62df7789083fd8e7a65f892b8dfd4680c3146586 100644 (file)
@@ -188,7 +188,13 @@ final class ArcanistMercurialParser {
    * @task parse
    */
   public static function parseMercurialBranches($stdout) {
-    $lines = explode("\n", trim($stdout));
+    $stdout = rtrim($stdout, "\n");
+    if (!strlen($stdout)) {
+      // No branches; commonly, this occurs in a newly initialized repository.
+      return array();
+    }
+
+    $lines = explode("\n", $stdout);
 
     $branches = array();
     foreach ($lines as $line) {
index 418dbfb54549040265adceb2019f452374c0652a..8e199669cf278237486df7d420272c5348cef688 100644 (file)
@@ -36,6 +36,10 @@ final class ArcanistMercurialParserTestCase extends ArcanistTestCase {
           array('0b9d8290c4e0', '78963faacfc7', '5db03c5500c6', 'ffffffffffff'),
           array_values(ipull($output, 'rev')));
         break;
+      case 'branches-empty.txt':
+        $output = ArcanistMercurialParser::parseMercurialBranches($data);
+        $this->assertEqual(array(), $output);
+        break;
       case 'log-basic.txt':
         $output = ArcanistMercurialParser::parseMercurialLog($data);
         $this->assertEqual(
diff --git a/src/repository/parser/__tests__/mercurial/branches-empty.txt b/src/repository/parser/__tests__/mercurial/branches-empty.txt
new file mode 100644 (file)
index 0000000..e69de29