# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1568348579 25200
#      Thu Sep 12 21:22:59 2019 -0700
# Node ID c2676b5a9f597155506cb750a3ba307db7316b32
# Parent  5fadf61037905db7c0da8554b8cdc7304646d800
narrow: don't hexify paths and double-hexify known nodes on wire (BC)

It isn't obvious, but wireprototypes.encodelist() is meant only for
binary nodeids. So when we used it for encoding hex nodeids and paths,
the encoded result was surprising and hard to read.

This patch changes the encoding to make the list of paths a
comma-separated list and the list of common nodes to be a
encodelist()-encoded list of binary nodeids (so the result is just
singly-hexified nodeids).

This is clearly a breaking change, but the feature is experimental and
we're not aware of anyone running a server using this command yet.

Differential Revision: https://phab.mercurial-scm.org/D6851

diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py
--- a/hgext/narrow/narrowcommands.py
+++ b/hgext/narrow/narrowcommands.py
@@ -293,7 +293,7 @@
         else:
             known = []
             if ellipsesremote:
-                known = [node.hex(ctx.node()) for ctx in
+                known = [ctx.node() for ctx in
                          repo.set('::%ln', common)
                          if ctx.node() != node.nullid]
             with remote.commandexecutor() as e:
diff --git a/hgext/narrow/narrowwirepeer.py b/hgext/narrow/narrowwirepeer.py
--- a/hgext/narrow/narrowwirepeer.py
+++ b/hgext/narrow/narrowwirepeer.py
@@ -13,7 +13,6 @@
     extensions,
     hg,
     narrowspec,
-    node as nodemod,
     pycompat,
     wireprototypes,
     wireprotov1peer,
@@ -61,10 +60,13 @@
 
     preferuncompressed = False
     try:
-        oldincludes = wireprototypes.decodelist(oldincludes)
-        newincludes = wireprototypes.decodelist(newincludes)
-        oldexcludes = wireprototypes.decodelist(oldexcludes)
-        newexcludes = wireprototypes.decodelist(newexcludes)
+        def splitpaths(data):
+            # work around ''.split(',') => ['']
+            return data.split(b',') if data else []
+        oldincludes = splitpaths(oldincludes)
+        newincludes = splitpaths(newincludes)
+        oldexcludes = splitpaths(oldexcludes)
+        newexcludes = splitpaths(newexcludes)
         # validate the patterns
         narrowspec.validatepatterns(set(oldincludes))
         narrowspec.validatepatterns(set(newincludes))
@@ -73,7 +75,6 @@
 
         common = wireprototypes.decodelist(commonheads)
         known = wireprototypes.decodelist(known)
-        known = {nodemod.bin(n) for n in known}
         if ellipses == '0':
             ellipses = False
         else:
@@ -106,10 +107,12 @@
                                     prefer_uncompressed=preferuncompressed)
 
 def peernarrowwiden(remote, **kwargs):
-    for ch in (r'oldincludes', r'newincludes', r'oldexcludes', r'newexcludes',
-               r'commonheads', r'known'):
+    for ch in (r'commonheads', r'known'):
         kwargs[ch] = wireprototypes.encodelist(kwargs[ch])
 
+    for ch in (r'oldincludes', r'newincludes', r'oldexcludes', r'newexcludes'):
+        kwargs[ch] = b','.join(kwargs[ch])
+
     kwargs[r'ellipses'] = '%i' % bool(kwargs[r'ellipses'])
     f = remote._callcompressable('narrow_widen', **kwargs)
     return bundle2.getunbundler(remote.ui, f)
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -22,5 +22,9 @@
    you can override it by setting `$HGTEST_SHELL` or by passing it to
    `run-tests.py --shell <shell>`.
 
+ * The (experimental) narrow extension's wire protocol changed. If
+   you're using it, you'll need to make sure to upgrade server and
+   client at the same time.
+
 == Internal API Changes ==