[PATCH 04 of 10] bundle: extract _processchangegroup() method

Martin von Zweigbergk martinvonz at google.com
Sat Jun 24 11:38:32 EDT 2017


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1498172347 25200
#      Thu Jun 22 15:59:07 2017 -0700
# Node ID 98852ad1ee3d67aeb6fc59961aa3b2329b9f216b
# Parent  601a13f9ae1e94fa76fda7b9819c065c31771325
bundle: extract _processchangegroup() method

The new method applies the changegroup and fills in op.records,
sharing a little bit of code between the two callers. We'll add
another caller soon.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -395,6 +395,14 @@
 
     return op
 
+def _processchangegroup(op, cg, tr, source, url, **kwargs):
+    ret, addednodes = cg.apply(op.repo, tr, source, url, **kwargs)
+    op.records.add('changegroup', {
+        'return': ret,
+        'addednodes': addednodes,
+    })
+    return ret
+
 def _processpart(op, part):
     """process a single part from a bundle
 
@@ -1524,12 +1532,8 @@
         op.repo.requirements.add('treemanifest')
         op.repo._applyopenerreqs()
         op.repo._writerequirements()
-    ret, addednodes = cg.apply(op.repo, tr, 'bundle2', 'bundle2',
-                               expectedtotal=nbchangesets)
-    op.records.add('changegroup', {
-        'return': ret,
-        'addednodes': addednodes,
-    })
+    ret = _processchangegroup(op, cg, tr, 'bundle2', 'bundle2',
+                              expectedtotal=nbchangesets)
     if op.reply is not None:
         # This is definitely not the final form of this
         # return. But one need to start somewhere.
@@ -1592,11 +1596,7 @@
     if not isinstance(cg, changegroup.cg1unpacker):
         raise error.Abort(_('%s: not a bundle version 1.0') %
             util.hidepassword(raw_url))
-    ret, addednodes = cg.apply(op.repo, tr, 'bundle2', 'bundle2')
-    op.records.add('changegroup', {
-        'return': ret,
-        'addednodes': addednodes,
-    })
+    ret = _processchangegroup(op, cg, tr, 'bundle2', 'bundle2')
     if op.reply is not None:
         # This is definitely not the final form of this
         # return. But one need to start somewhere.


More information about the Mercurial-devel mailing list