Patchwork [3,of,5,modernize-streamclone] streamclone: move stream_in() from localrepo

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 2, 2015, 11:34 p.m.
Message ID <dcafb3b5c5aeda449f14.1443828843@gps-mbp.local>
Download mbox | patch
Permalink /patch/10750/
State Accepted
Headers show

Comments

Gregory Szorc - Oct. 2, 2015, 11:34 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1443826704 25200
#      Fri Oct 02 15:58:24 2015 -0700
# Node ID dcafb3b5c5aeda449f1491c08a3050b5f6b5caea
# Parent  1e126600c72f702e2d8cb3cd336ba5b4cc4724e4
streamclone: move stream_in() from localrepo

Another basic content move. The underscore from the function name was
removed to comply with naming standards.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1782,32 +1782,8 @@  class localrepository(object):
         functions, which are called before pushing changesets.
         """
         return util.hooks()
 
-    def stream_in(self, remote, remotereqs):
-        # Save remote branchmap. We will use it later
-        # to speed up branchcache creation
-        rbranchmap = None
-        if remote.capable("branchmap"):
-            rbranchmap = remote.branchmap()
-
-        fp = remote.stream_out()
-        l = fp.readline()
-        try:
-            resp = int(l)
-        except ValueError:
-            raise error.ResponseError(
-                _('unexpected response from remote server:'), l)
-        if resp == 1:
-            raise util.Abort(_('operation forbidden by server'))
-        elif resp == 2:
-            raise util.Abort(_('locking the remote repository failed'))
-        elif resp != 0:
-            raise util.Abort(_('the server sent an unknown error code'))
-
-        streamclone.applyremotedata(self, remotereqs, rbranchmap, fp)
-        return len(self.heads()) + 1
-
     def clone(self, remote, heads=[], stream=None):
         '''clone remote repository.
 
         keyword arguments:
@@ -1828,17 +1804,17 @@  class localrepository(object):
 
         if stream and not heads:
             # 'stream' means remote revlog format is revlogv1 only
             if remote.capable('stream'):
-                self.stream_in(remote, set(('revlogv1',)))
+                streamclone.streamin(self, remote, set(('revlogv1',)))
             else:
                 # otherwise, 'streamreqs' contains the remote revlog format
                 streamreqs = remote.capable('streamreqs')
                 if streamreqs:
                     streamreqs = set(streamreqs.split(','))
                     # if we support it, stream in and adjust our requirements
                     if not streamreqs - self.supportedformats:
-                        self.stream_in(remote, streamreqs)
+                        streamclone.streamin(self, remote, streamreqs)
 
         # internal config: ui.quietbookmarkmove
         quiet = self.ui.backupconfig('ui', 'quietbookmarkmove')
         try:
diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -6,13 +6,40 @@ 
 # GNU General Public License version 2 or any later version.
 
 from __future__ import absolute_import
 
+from .i18n import _
 from . import (
     branchmap,
+    error,
     exchange,
+    util,
 )
 
+def streamin(repo, remote, remotereqs):
+    # Save remote branchmap. We will use it later
+    # to speed up branchcache creation
+    rbranchmap = None
+    if remote.capable("branchmap"):
+        rbranchmap = remote.branchmap()
+
+    fp = remote.stream_out()
+    l = fp.readline()
+    try:
+        resp = int(l)
+    except ValueError:
+        raise error.ResponseError(
+            _('unexpected response from remote server:'), l)
+    if resp == 1:
+        raise util.Abort(_('operation forbidden by server'))
+    elif resp == 2:
+        raise util.Abort(_('locking the remote repository failed'))
+    elif resp != 0:
+        raise util.Abort(_('the server sent an unknown error code'))
+
+    applyremotedata(repo, remotereqs, rbranchmap, fp)
+    return len(repo.heads()) + 1
+
 def applyremotedata(repo, remotereqs, remotebranchmap, fp):
     """Apply stream clone data to a repository.
 
     "remotereqs" is a set of requirements to handle the incoming data.