mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-02-08 21:08:29 +01:00
Provide hgsprintf() for building hg revsets
Summary: I guess this is correct? See T2387 for discussion. Test Plan: Unit tests. Reviewers: bos, DurhamGoode Reviewed By: DurhamGoode CC: aran Maniphest Tasks: T2387 Differential Revision: https://secure.phabricator.com/D4711
This commit is contained in:
parent
fd909479d0
commit
2613ea196f
3 changed files with 66 additions and 0 deletions
|
@ -108,6 +108,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistPhutilTestTerminatedException' => 'unit/engine/phutil/testcase/ArcanistPhutilTestTerminatedException.php',
|
'ArcanistPhutilTestTerminatedException' => 'unit/engine/phutil/testcase/ArcanistPhutilTestTerminatedException.php',
|
||||||
'ArcanistPyFlakesLinter' => 'lint/linter/ArcanistPyFlakesLinter.php',
|
'ArcanistPyFlakesLinter' => 'lint/linter/ArcanistPyFlakesLinter.php',
|
||||||
'ArcanistPyLintLinter' => 'lint/linter/ArcanistPyLintLinter.php',
|
'ArcanistPyLintLinter' => 'lint/linter/ArcanistPyLintLinter.php',
|
||||||
|
'ArcanistRepoUtilsTestCase' => 'repository/util/__tests__/ArcanistRepoUtilsTestCase.php',
|
||||||
'ArcanistRepositoryAPI' => 'repository/api/ArcanistRepositoryAPI.php',
|
'ArcanistRepositoryAPI' => 'repository/api/ArcanistRepositoryAPI.php',
|
||||||
'ArcanistRepositoryAPIMiscTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php',
|
'ArcanistRepositoryAPIMiscTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php',
|
||||||
'ArcanistRepositoryAPIStateTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIStateTestCase.php',
|
'ArcanistRepositoryAPIStateTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIStateTestCase.php',
|
||||||
|
@ -158,6 +159,8 @@ phutil_register_library_map(array(
|
||||||
),
|
),
|
||||||
'function' =>
|
'function' =>
|
||||||
array(
|
array(
|
||||||
|
'hgsprintf' => 'repository/util/hgsprintf.php',
|
||||||
|
'xsprintf_mercurial' => 'repository/util/hgsprintf.php',
|
||||||
),
|
),
|
||||||
'xmap' =>
|
'xmap' =>
|
||||||
array(
|
array(
|
||||||
|
@ -233,6 +236,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistPhutilTestTerminatedException' => 'Exception',
|
'ArcanistPhutilTestTerminatedException' => 'Exception',
|
||||||
'ArcanistPyFlakesLinter' => 'ArcanistLinter',
|
'ArcanistPyFlakesLinter' => 'ArcanistLinter',
|
||||||
'ArcanistPyLintLinter' => 'ArcanistLinter',
|
'ArcanistPyLintLinter' => 'ArcanistLinter',
|
||||||
|
'ArcanistRepoUtilsTestCase' => 'ArcanistTestCase',
|
||||||
'ArcanistRepositoryAPIMiscTestCase' => 'ArcanistTestCase',
|
'ArcanistRepositoryAPIMiscTestCase' => 'ArcanistTestCase',
|
||||||
'ArcanistRepositoryAPIStateTestCase' => 'ArcanistTestCase',
|
'ArcanistRepositoryAPIStateTestCase' => 'ArcanistTestCase',
|
||||||
'ArcanistRubyLinter' => 'ArcanistLinter',
|
'ArcanistRubyLinter' => 'ArcanistLinter',
|
||||||
|
|
23
src/repository/util/__tests__/ArcanistRepoUtilsTestCase.php
Normal file
23
src/repository/util/__tests__/ArcanistRepoUtilsTestCase.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ArcanistRepoUtilsTestCase extends ArcanistTestCase {
|
||||||
|
|
||||||
|
public function testhgsprintf() {
|
||||||
|
$this->assertEqual(
|
||||||
|
"'version-1'",
|
||||||
|
hgsprintf('%s', 'version-1'));
|
||||||
|
|
||||||
|
$this->assertEqual(
|
||||||
|
"'single\\'quote'",
|
||||||
|
hgsprintf('%s', "single'quote"));
|
||||||
|
|
||||||
|
$this->assertEqual(
|
||||||
|
"'back\\\\slash'",
|
||||||
|
hgsprintf('%s', 'back\\slash'));
|
||||||
|
|
||||||
|
$this->assertEqual(
|
||||||
|
"'33%'",
|
||||||
|
hgsprintf('%R', hgsprintf('%s', '33%')));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
39
src/repository/util/hgsprintf.php
Normal file
39
src/repository/util/hgsprintf.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a Mercurial revset expression. Supports the following conversions:
|
||||||
|
*
|
||||||
|
* %s Symbol
|
||||||
|
* Escapes a Mercurial symbol, like a branch or bookmark name.
|
||||||
|
*
|
||||||
|
* %R Rrraw Rreferrrence / Rrrrevset
|
||||||
|
* Passes text through unescaped (e.g., an already-escaped revset).
|
||||||
|
*
|
||||||
|
* @group mercurial
|
||||||
|
*/
|
||||||
|
function hgsprintf($pattern /* , ... */) {
|
||||||
|
$args = func_get_args();
|
||||||
|
return xsprintf('xsprintf_mercurial', null, $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xsprintf() callback for Mercurial encoding.
|
||||||
|
*
|
||||||
|
* @group mercurial
|
||||||
|
*/
|
||||||
|
function xsprintf_mercurial($userdata, &$pattern, &$pos, &$value, &$length) {
|
||||||
|
|
||||||
|
$type = $pattern[$pos];
|
||||||
|
|
||||||
|
switch ($type) {
|
||||||
|
case 's':
|
||||||
|
$value = "'".addcslashes($value, "'\\")."'";
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
$type = 's';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pattern[$pos] = $type;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue