D7969: exchange: check the `ui.clonebundleprefers` form while processing (issue6257)

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Wed Jan 22 17:15:22 UTC 2020


mharbison72 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Otherwise the clone command will emit a long stacktrace if there is no `=`
  character.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D7969

AFFECTED FILES
  mercurial/exchange.py
  tests/test-clonebundles.t

CHANGE DETAILS

diff --git a/tests/test-clonebundles.t b/tests/test-clonebundles.t
--- a/tests/test-clonebundles.t
+++ b/tests/test-clonebundles.t
@@ -455,6 +455,13 @@
   no changes found
   2 local changesets published
 
+Test a bad attribute list
+
+  $ hg --config ui.clonebundleprefers=bad clone -U http://localhost:$HGPORT bad-input
+  abort: invalid ui.clonebundleprefers item: bad
+  (each comma separated item should be key=value pairs)
+  [255]
+
 Test interaction between clone bundles and --stream
 
 A manifest with just a gzip bundle
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -3072,7 +3072,15 @@
     if not prefers:
         return list(entries)
 
-    prefers = [p.split(b'=', 1) for p in prefers]
+    def _split(p):
+        if b'=' not in p:
+            hint = _(b"each comma separated item should be key=value pairs")
+            raise error.Abort(
+                _(b"invalid ui.clonebundleprefers item: %s") % p, hint=hint
+            )
+        return p.split(b'=', 1)
+
+    prefers = [_split(p) for p in prefers]
 
     items = sorted(clonebundleentry(v, prefers) for v in entries)
     return [i.value for i in items]



To: mharbison72, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list