changeset 46193:85f7cf314b39

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
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 14 Dec 2020 14:18:38 +0530
parents 25d11b24dedf
children 4d1cec4e5e1f
files mercurial/upgrade_utils/engine.py
diffstat 1 files changed, 48 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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