[PATCH] convert: parse quoted keys and values in mapfiles

Ingmar Blonk ingmar.blonk at gmail.com
Mon Sep 18 20:28:45 UTC 2017


# HG changeset patch
# User Ingmar Blonk <ingmar.blonk at gmail.com>
# Date 1505662991 -7200
#      Sun Sep 17 17:43:11 2017 +0200
# Node ID af658bed1729dd0e48a60c67a82f4bc44f578c97
# Parent  448725a2ef7356524bcc9638a5c5eaaf59f263af
convert: parse quoted keys and values in mapfiles

Parsing quoted texts in mapfiles allows whitespace usage for e.g. branch 
names
in a banchmap.

diff -r 448725a2ef73 -r af658bed1729 hgext/convert/__init__.py
--- a/hgext/convert/__init__.py    Fri Sep 15 00:01:57 2017 -0700
+++ b/hgext/convert/__init__.py    Sun Sep 17 17:43:11 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 448725a2ef73 -r af658bed1729 hgext/convert/common.py
--- a/hgext/convert/common.py    Fri Sep 15 00:01:57 2017 -0700
+++ b/hgext/convert/common.py    Sun Sep 17 17:43:11 2017 +0200
@@ -11,6 +11,7 @@
  import errno
  import os
  import re
+import shlex
  import subprocess

  from mercurial.i18n import _
@@ -461,7 +462,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')
diff -r 448725a2ef73 -r af658bed1729 tests/test-convert.t
--- a/tests/test-convert.t    Fri Sep 15 00:01:57 2017 -0700
+++ b/tests/test-convert.t    Sun Sep 17 17:43:11 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