Patchwork D1754: streamclone: move wire protocol status code from wireproto command

login
register
mail settings
Submitter phabricator
Date Dec. 26, 2017, 2:11 p.m.
Message ID <7e30cba42a74c101e7bf04c73171ba29@localhost.localdomain>
Download mbox | patch
Permalink /patch/26439/
State Not Applicable
Headers show

Comments

phabricator - Dec. 26, 2017, 2:11 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGded3a63f305b: streamclone: move wire protocol status code from wireproto command (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1754?vs=4604&id=4614

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

AFFECTED FILES
  mercurial/streamclone.py
  mercurial/wireproto.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, yuja
Cc: mercurial-devel

Patch

diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -954,21 +954,7 @@ 
     capability with a value representing the version and flags of the repo
     it is serving. Client checks to see if it understands the format.
     '''
-    if not streamclone.allowservergeneration(repo):
-        return '1\n'
-
-    def getstream(it):
-        yield '0\n'
-        for chunk in it:
-            yield chunk
-
-    try:
-        # LockError may be raised before the first result is yielded. Don't
-        # emit output until we're sure we got the lock successfully.
-        it = streamclone.generatev1wireproto(repo)
-        return streamres(gen=getstream(it))
-    except error.LockError:
-        return '2\n'
+    return streamres(streamclone.generatev1wireproto(repo))
 
 @wireprotocommand('unbundle', 'heads')
 def unbundle(repo, proto, heads):
diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -235,10 +235,26 @@ 
 def generatev1wireproto(repo):
     """Emit content for version 1 of streaming clone suitable for the wire.
 
-    This is the data output from ``generatev1()`` with a header line
-    indicating file count and byte size.
+    This is the data output from ``generatev1()`` with 2 header lines. The
+    first line indicates overall success. The 2nd contains the file count and
+    byte size of payload.
+
+    The success line contains "0" for success, "1" for stream generation not
+    allowed, and "2" for error locking the repository (possibly indicating
+    a permissions error for the server process).
     """
-    filecount, bytecount, it = generatev1(repo)
+    if not allowservergeneration(repo):
+        yield '1\n'
+        return
+
+    try:
+        filecount, bytecount, it = generatev1(repo)
+    except error.LockError:
+        yield '2\n'
+        return
+
+    # Indicates successful response.
+    yield '0\n'
     yield '%d %d\n' % (filecount, bytecount)
     for chunk in it:
         yield chunk