Patchwork D9579: engine: refactor actual cloning code into separate function

login
register
mail settings
Submitter phabricator
Date Dec. 14, 2020, 9:55 a.m.
Message ID <differential-rev-PHID-DREV-ev3zpi7pyt6g6t7txmsl-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47877/
State Superseded
Headers show

Comments

phabricator - Dec. 14, 2020, 9:55 a.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9579

AFFECTED FILES
  mercurial/upgrade_utils/engine.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/upgrade_utils/engine.py b/mercurial/upgrade_utils/engine.py
--- a/mercurial/upgrade_utils/engine.py
+++ b/mercurial/upgrade_utils/engine.py
@@ -212,6 +212,34 @@ 
 
     sidedatacompanion = getsidedatacompanion(srcrepo, dstrepo)
 
+    def _perform_clone(
+        old_revlog,
+        unencoded,
+    ):
+        """ 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)
+            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(old_revlog)))
+            _copyrevlog(tr, dstrepo, old_revlog, unencoded)
+
+            newrl = _revlogfrompath(dstrepo, unencoded)
+        return newrl
+
     # Do the actual copying.
     # FUTURE this operation can be farmed off to worker processes.
     seen = set()
@@ -292,26 +320,7 @@ 
                 _(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(oldrl, unencoded)
         info = newrl.storageinfo(storedsize=True)
         datasize = info[b'storedsize'] or 0