[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