D6899: upgrade: move most of revlog.clone method into a _clone method

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Fri Sep 27 16:22:44 EDT 2019


marmoute created this revision.
Herald added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The content of the clone method now focus on parameters validation and
  processing. The `_clone` method focus on the actual cloning logic.
  
  Splitting the method out save some indentation and clarify each method code
  since it a focussed on one goal.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/revlog.py

CHANGE DETAILS

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2337,7 +2337,7 @@
     DELTAREUSEALL = {'always', 'samerevs', 'never', 'fulladd'}
 
     def clone(self, tr, destrevlog, addrevisioncb=None,
-              deltareuse=DELTAREUSESAMEREVS, forcedeltabothparents=None):
+            deltareuse=DELTAREUSESAMEREVS, forcedeltabothparents=None):
         """Copy this revlog to another, possibly with format changes.
 
         The destination revlog will contain the same revisions and nodes.
@@ -2405,60 +2405,66 @@
 
             destrevlog._deltabothparents = forcedeltabothparents or oldamd
 
-            deltacomputer = deltautil.deltacomputer(destrevlog)
-            index = self.index
-            for rev in self:
-                entry = index[rev]
-
-                # Some classes override linkrev to take filtered revs into
-                # account. Use raw entry from index.
-                flags = entry[0] & 0xffff
-                linkrev = entry[4]
-                p1 = index[entry[5]][7]
-                p2 = index[entry[6]][7]
-                node = entry[7]
-
-                # (Possibly) reuse the delta from the revlog if allowed and
-                # the revlog chunk is a delta.
-                cachedelta = None
-                rawtext = None
-                if (deltareuse != self.DELTAREUSEFULLADD
-                        and destrevlog._lazydelta):
-                    dp = self.deltaparent(rev)
-                    if dp != nullrev:
-                        cachedelta = (dp, bytes(self._chunk(rev)))
-
-                if not cachedelta:
-                    rawtext = self.rawdata(rev)
-
-
-                if deltareuse == self.DELTAREUSEFULLADD:
-                    destrevlog.addrevision(rawtext, tr, linkrev, p1, p2,
-                                           cachedelta=cachedelta,
-                                           node=node, flags=flags,
-                                           deltacomputer=deltacomputer)
-                else:
-                    ifh = destrevlog.opener(destrevlog.indexfile, 'a+',
-                                            checkambig=False)
-                    dfh = None
-                    if not destrevlog._inline:
-                        dfh = destrevlog.opener(destrevlog.datafile, 'a+')
-                    try:
-                        destrevlog._addrevision(node, rawtext, tr, linkrev, p1,
-                                                p2, flags, cachedelta, ifh, dfh,
-                                                deltacomputer=deltacomputer)
-                    finally:
-                        if dfh:
-                            dfh.close()
-                        ifh.close()
-
-                if addrevisioncb:
-                    addrevisioncb(self, rev, node)
+            self._clone(tr, destrevlog, addrevisioncb, deltareuse,
+                        forcedeltabothparents)
+
         finally:
             destrevlog._lazydelta = oldlazydelta
             destrevlog._lazydeltabase = oldlazydeltabase
             destrevlog._deltabothparents = oldamd
 
+    def _clone(self, tr, destrevlog, addrevisioncb, deltareuse,
+               forcedeltabothparents):
+        """perform the core duty of `revlog.clone` after parameter processing"""
+        deltacomputer = deltautil.deltacomputer(destrevlog)
+        index = self.index
+        for rev in self:
+            entry = index[rev]
+
+            # Some classes override linkrev to take filtered revs into
+            # account. Use raw entry from index.
+            flags = entry[0] & 0xffff
+            linkrev = entry[4]
+            p1 = index[entry[5]][7]
+            p2 = index[entry[6]][7]
+            node = entry[7]
+
+            # (Possibly) reuse the delta from the revlog if allowed and
+            # the revlog chunk is a delta.
+            cachedelta = None
+            rawtext = None
+            if (deltareuse != self.DELTAREUSEFULLADD and destrevlog._lazydelta):
+                dp = self.deltaparent(rev)
+                if dp != nullrev:
+                    cachedelta = (dp, bytes(self._chunk(rev)))
+
+            if not cachedelta:
+                rawtext = self.rawdata(rev)
+
+
+            if deltareuse == self.DELTAREUSEFULLADD:
+                destrevlog.addrevision(rawtext, tr, linkrev, p1, p2,
+                                       cachedelta=cachedelta,
+                                       node=node, flags=flags,
+                                       deltacomputer=deltacomputer)
+            else:
+                ifh = destrevlog.opener(destrevlog.indexfile, 'a+',
+                                        checkambig=False)
+                dfh = None
+                if not destrevlog._inline:
+                    dfh = destrevlog.opener(destrevlog.datafile, 'a+')
+                try:
+                    destrevlog._addrevision(node, rawtext, tr, linkrev, p1,
+                                            p2, flags, cachedelta, ifh, dfh,
+                                            deltacomputer=deltacomputer)
+                finally:
+                    if dfh:
+                        dfh.close()
+                    ifh.close()
+
+            if addrevisioncb:
+                addrevisioncb(self, rev, node)
+
     def censorrevision(self, tr, censornode, tombstone=b''):
         if (self.version & 0xFFFF) == REVLOGV0:
             raise error.RevlogError(_('cannot censor with version %d revlogs') %



To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list