Patchwork [4,of,8] revlog: extract 'builddelta' closure function from _addrevision

login
register
mail settings
Submitter Paul Morelle
Date Jan. 14, 2018, 10:28 a.m.
Message ID <c9069bebf72b906229e7.1515925700@taranis.localdomain>
Download mbox | patch
Permalink /patch/26730/
State Accepted
Headers show

Comments

Paul Morelle - Jan. 14, 2018, 10:28 a.m.
# HG changeset patch
# User Paul Morelle <paul.morelle@octobus.net>
# Date 1515777003 -3600
#      Fri Jan 12 18:10:03 2018 +0100
# Node ID c9069bebf72b906229e740bf8fe4beee37570dc9
# Parent  2f39856d4feee57695b05c9298a3bf1789edf173
# EXP-Topic refactor-revlog
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c9069bebf72b
revlog: extract 'builddelta' closure function from _addrevision

Patch

diff -r 2f39856d4fee -r c9069bebf72b mercurial/revlog.py
--- a/mercurial/revlog.py	Fri Jan 12 15:55:25 2018 +0100
+++ b/mercurial/revlog.py	Fri Jan 12 18:10:03 2018 +0100
@@ -1923,6 +1923,35 @@ 
                 raise
         return btext[0]
 
+    def _builddelta(self, node, rev, p1, p2, btext, cachedelta, fh, flags):
+        # can we use the cached delta?
+        if cachedelta and cachedelta[0] == rev:
+            delta = cachedelta[1]
+        else:
+            t = self._buildtext(node, p1, p2, btext, cachedelta, fh, flags)
+            if self.iscensored(rev):
+                # deltas based on a censored revision must replace the
+                # full content in one patch, so delta works everywhere
+                header = mdiff.replacediffheader(self.rawsize(rev), len(t))
+                delta = header + t
+            else:
+                ptext = self.revision(rev, _df=fh, raw=True)
+                delta = mdiff.textdiff(ptext, t)
+        header, data = self.compress(delta)
+        deltalen = len(header) + len(data)
+        chainbase = self.chainbase(rev)
+        offset = self.end(len(self) - 1)
+        dist = deltalen + offset - self.start(chainbase)
+        if self._generaldelta:
+            base = rev
+        else:
+            base = chainbase
+        chainlen, compresseddeltalen = self._chaininfo(rev)
+        chainlen += 1
+        compresseddeltalen += deltalen
+        return (dist, deltalen, (header, data), base,
+                chainbase, chainlen, compresseddeltalen)
+
     def _addrevision(self, node, rawtext, transaction, link, p1, p2, flags,
                      cachedelta, ifh, dfh, alwayscache=False):
         """internal function to add revisions to the log
@@ -1949,34 +1978,6 @@ 
 
         btext = [rawtext]
 
-        def builddelta(rev):
-            # can we use the cached delta?
-            if cachedelta and cachedelta[0] == rev:
-                delta = cachedelta[1]
-            else:
-                t = self._buildtext(node, p1, p2, btext, cachedelta, fh, flags)
-                if self.iscensored(rev):
-                    # deltas based on a censored revision must replace the
-                    # full content in one patch, so delta works everywhere
-                    header = mdiff.replacediffheader(self.rawsize(rev), len(t))
-                    delta = header + t
-                else:
-                    ptext = self.revision(rev, _df=fh, raw=True)
-                    delta = mdiff.textdiff(ptext, t)
-            header, data = self.compress(delta)
-            deltalen = len(header) + len(data)
-            chainbase = self.chainbase(rev)
-            dist = deltalen + offset - self.start(chainbase)
-            if self._generaldelta:
-                base = rev
-            else:
-                base = chainbase
-            chainlen, compresseddeltalen = self._chaininfo(rev)
-            chainlen += 1
-            compresseddeltalen += deltalen
-            return (dist, deltalen, (header, data), base,
-                    chainbase, chainlen, compresseddeltalen)
-
         curr = len(self)
         prev = curr - 1
         offset = self.end(prev)
@@ -1994,7 +1995,9 @@ 
         for candidaterevs in self._getcandidaterevs(p1, p2, cachedelta):
             nominateddeltas = []
             for candidaterev in candidaterevs:
-                candidatedelta = builddelta(candidaterev)
+                candidatedelta = self._builddelta(node, candidaterev, p1, p2,
+                                                  btext, cachedelta, fh,
+                                                  flags)
                 if self._isgooddelta(candidatedelta, textlen):
                     nominateddeltas.append(candidatedelta)
             if nominateddeltas: