bundle: extract _processchangegroup() method
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 22 Jun 2017 15:59:07 -0700
changeset 33038 f0efd2bffe1e
parent 33037 d765ad56081f
child 33039 b82615afde65
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.
mercurial/bundle2.py
--- a/mercurial/bundle2.py	Thu Jun 22 14:04:13 2017 -0700
+++ b/mercurial/bundle2.py	Thu Jun 22 15:59:07 2017 -0700
@@ -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.