[PATCH V2] convert: parse quoted keys and values in mapfiles (BC)
Ingmar Blonk
ingmar.blonk at gmail.com
Sun Sep 24 16:44:57 UTC 2017
# HG changeset patch
# User Ingmar Blonk <ingmar.blonk at gmail.com>
# Date 1506267061 -7200
#Â Â Â Â Â Sun Sep 24 17:31:01 2017 +0200
# Node ID 9d95751ccea50ed91a457315762c18f3a9cf69f4
# Parent 575097b4dce054a5b8d992fe15797d9d62ceaf71
convert: parse quoted keys and values in mapfiles (BC)
Parsing quoted texts in mapfiles allows whitespace usage for e.g. branch
names
in a banchmap.
diff -r 575097b4dce0 -r 9d95751ccea5 hgext/convert/__init__.py
--- a/hgext/convert/__init__.py   Thu Sep 14 13:14:32 2017 -0700
+++ b/hgext/convert/__init__.py   Sun Sep 24 17:31:01 2017 +0200
@@ -263,8 +263,8 @@
    where "original_branch_name" is the name of the branch in the
    source repository, and "new_branch_name" is the name of the branch
-Â Â Â is the destination repository. No whitespace is allowed in the new
-Â Â Â branch name. This can be used to (for instance) move code in one
+Â Â Â is the destination repository. Branch names containing whitespace
+Â Â Â should be quoted. This can be used to (for instance) move code in one
    repository from "default" to a named branch.
    Mercurial Source
diff -r 575097b4dce0 -r 9d95751ccea5 hgext/convert/common.py
--- a/hgext/convert/common.py   Thu Sep 14 13:14:32 2017 -0700
+++ b/hgext/convert/common.py   Sun Sep 24 17:31:01 2017 +0200
@@ -10,7 +10,9 @@
 import datetime
 import errno
 import os
+import pipes
 import re
+import shlex
 import subprocess
 from mercurial.i18n import _
@@ -461,7 +463,7 @@
                # Ignore blank lines
                continue
            try:
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â key, value = line.rsplit(' ', 1)
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â key, value = shlex.split(line, posix=True)
            except ValueError:
                raise error.Abort(
                    _('syntax error in %s(%d): key/value pair expected')
@@ -479,7 +481,7 @@
                raise error.Abort(
                    _('could not open map file %r: %s') %
                    (self.path, encoding.strtolocal(err.strerror)))
-Â Â Â Â Â Â Â self.fp.write('%s %s\n' % (key, value))
+Â Â Â Â Â Â Â self.fp.write('%s %s\n' % (pipes.quote(key), pipes.quote(value)))
        self.fp.flush()
        super(mapfile, self).__setitem__(key, value)
diff -r 575097b4dce0 -r 9d95751ccea5 tests/test-convert.t
--- a/tests/test-convert.t   Thu Sep 14 13:14:32 2017 -0700
+++ b/tests/test-convert.t   Sun Sep 24 17:31:01 2017 +0200
@@ -125,9 +125,9 @@
      where "original_branch_name" is the name of the branch in the source
      repository, and "new_branch_name" is the name of the branch is the
-Â Â Â Â Â destination repository. No whitespace is allowed in the new
branch name.
-Â Â Â Â Â This can be used to (for instance) move code in one repository from
-Â Â Â Â Â "default" to a named branch.
+Â Â Â Â Â destination repository. Branch names containing whitespace should be
+Â Â Â Â Â quoted. This can be used to (for instance) move code in one
repository
+Â Â Â Â Â from "default" to a named branch.
      Mercurial Source
      ################
@@ -589,7 +589,7 @@
  convert_source=mysource
  $ cat > branchmap.txt << EOF
-Â > old branch new_branch
+Â > "old branch" new_branch
  > EOF
  $ hg -R a branch -q 'old branch'
More information about the Mercurial-devel
mailing list