1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-10 00:42:40 +01:00

Improve ArcanistMercurialParser's handling of unusual branch names

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
This commit is contained in:
epriestley 2012-03-06 20:14:25 -08:00
parent 0e35dc64a9
commit 81019a790e
3 changed files with 21 additions and 3 deletions

View 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}");

View 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(

View file

@ -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)