engine: refactor actual cloning code into separate function
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 14 Dec 2020 14:18:38 +0530
changeset 46193 85f7cf314b39
parent 46192 25d11b24dedf
child 46194 4d1cec4e5e1f
engine: refactor actual cloning code into separate function The `for ...` under which this cloning code exists is too complicated and based on certain assumptions. I am going to refactor it in next patches and make it bit saner. Differential Revision: https://phab.mercurial-scm.org/D9579
mercurial/upgrade_utils/engine.py
--- a/mercurial/upgrade_utils/engine.py	Mon Dec 14 13:48:25 2020 +0530
+++ b/mercurial/upgrade_utils/engine.py	Mon Dec 14 14:18:38 2020 +0530
@@ -118,6 +118,42 @@
     return UPGRADE_FILELOGS in revlogfilter
 
 
+def _perform_clone(
+    ui,
+    dstrepo,
+    tr,
+    old_revlog,
+    unencoded,
+    deltareuse,
+    forcedeltabothparents,
+    revlogs,
+    sidedatacompanion,
+    oncopiedrevision,
+):
+    """ returns the new revlog object created"""
+    newrl = None
+    if matchrevlog(revlogs, unencoded):
+        ui.note(
+            _(b'cloning %d revisions from %s\n') % (len(old_revlog), unencoded)
+        )
+        newrl = _revlogfrompath(dstrepo, unencoded)
+        old_revlog.clone(
+            tr,
+            newrl,
+            addrevisioncb=oncopiedrevision,
+            deltareuse=deltareuse,
+            forcedeltabothparents=forcedeltabothparents,
+            sidedatacompanion=sidedatacompanion,
+        )
+    else:
+        msg = _(b'blindly copying %s containing %i revisions\n')
+        ui.note(msg % (unencoded, len(old_revlog)))
+        _copyrevlog(tr, dstrepo, old_revlog, unencoded)
+
+        newrl = _revlogfrompath(dstrepo, unencoded)
+    return newrl
+
+
 def _clonerevlogs(
     ui,
     srcrepo,
@@ -292,26 +328,18 @@
                 _(b'file revisions'), total=frevcount
             )
 
-        if matchrevlog(revlogs, unencoded):
-            ui.note(
-                _(b'cloning %d revisions from %s\n') % (len(oldrl), unencoded)
-            )
-            newrl = _revlogfrompath(dstrepo, unencoded)
-            oldrl.clone(
-                tr,
-                newrl,
-                addrevisioncb=oncopiedrevision,
-                deltareuse=deltareuse,
-                forcedeltabothparents=forcedeltabothparents,
-                sidedatacompanion=sidedatacompanion,
-            )
-        else:
-            msg = _(b'blindly copying %s containing %i revisions\n')
-            ui.note(msg % (unencoded, len(oldrl)))
-            _copyrevlog(tr, dstrepo, oldrl, unencoded)
-
-            newrl = _revlogfrompath(dstrepo, unencoded)
-
+        newrl = _perform_clone(
+            ui,
+            dstrepo,
+            tr,
+            oldrl,
+            unencoded,
+            deltareuse,
+            forcedeltabothparents,
+            revlogs,
+            sidedatacompanion,
+            oncopiedrevision,
+        )
         info = newrl.storageinfo(storedsize=True)
         datasize = info[b'storedsize'] or 0