]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve ArcanistMercurialParser's handling of unusual branch names
authorepriestley <git@epriestley.com>
Wed, 7 Mar 2012 04:14:25 +0000 (20:14 -0800)
committerepriestley <git@epriestley.com>
Wed, 7 Mar 2012 04:14:25 +0000 (20:14 -0800)
Summary:
See <https://github.com/facebook/phabricator/issues/97>. Mercurial branch names may contain any characters, but we currently reject branch names with spaces.

NOTE: Mercurial allows you to name branches things like `     ` (five spaces). We do not parse this correctly. Die in a well fire.

Test Plan:
  - Added some horrible-but-possible test cases for crazy branch names.
  - Unit tests now pass.

Reviewers: btrahan, Makinde, killermonk

Reviewed By: btrahan

CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1795

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

index 7820768a07f2457ca99fefa12da62d8237cc1d42..7ce1309735fd2406e6665e23db7fdb9dee7975ec 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -210,7 +210,7 @@ final class ArcanistMercurialParser {
       //  stable                     15095:ec222a29bdf0 (inactive)
       //
       // See the unit tests for more examples.
-      $regexp = '/^([^ ]+)\s+(\d+):([a-f0-9]+)(\s|$)/';
+      $regexp = '/^(\S+(?:\s+\S+)*)\s+(\d+):([a-f0-9]+)(\s+\\(inactive\\))?$/';
 
       if (!preg_match($regexp, $line, $matches)) {
         throw new Exception("Failed to parse 'hg branches' output: {$line}");
index 19a9f7b4879ecc5817f43d127de29f18d7caa4fb..46032a051d1a6f565a400e844c3464a2873df334 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,6 +38,20 @@ final class ArcanistMercurialParserTestCase extends ArcanistPhutilTestCase {
           array('a21ccf4412d5', 'ec222a29bdf0'),
           array_values(ipull($output, 'rev')));
         break;
+      case 'branches-with-spaces.txt':
+        $output = ArcanistMercurialParser::parseMercurialBranches($data);
+        $this->assertEqual(
+          array(
+            'm m m m m 2:ffffffffffff (inactive)',
+            'xxx yyy zzz',
+            'default',
+            "'",
+          ),
+          array_keys($output));
+        $this->assertEqual(
+          array('0b9d8290c4e0', '78963faacfc7', '5db03c5500c6', 'ffffffffffff'),
+          array_values(ipull($output, 'rev')));
+        break;
       case 'log-basic.txt':
         $output = ArcanistMercurialParser::parseMercurialLog($data);
         $this->assertEqual(
diff --git a/src/repository/parser/mercurial/__tests__/data/branches-with-spaces.txt b/src/repository/parser/mercurial/__tests__/data/branches-with-spaces.txt
new file mode 100644 (file)
index 0000000..30c999b
--- /dev/null
@@ -0,0 +1,4 @@
+m m m m m 2:ffffffffffff (inactive) 8:0b9d8290c4e0
+xxx yyy zzz                    7:78963faacfc7 (inactive)
+default                        6:5db03c5500c6 (inactive)
+'                              9:ffffffffffff (inactive)
\ No newline at end of file