revlog: extract delta building to a subfunction stable
authorMatt Mackall <mpm@selenic.com>
Sat, 30 Oct 2010 02:47:34 -0500
branchstable
changeset 12888 ad01fe38afe6
parent 12887 8ce6240587b1
child 12889 5482c6b826f4
revlog: extract delta building to a subfunction
mercurial/revlog.py
--- a/mercurial/revlog.py	Sat Oct 30 02:47:34 2010 -0500
+++ b/mercurial/revlog.py	Sat Oct 30 02:47:34 2010 -0500
@@ -1172,6 +1172,20 @@
                 raise RevlogError(_("consistency error in delta"))
             return btext[0]
 
+        def builddelta(rev):
+            # can we use the cached delta?
+            if cachedelta and cachedelta[0] == rev:
+                delta = cachedelta[1]
+            else:
+                t = buildtext()
+                ptext = self.revision(self.node(rev))
+                delta = mdiff.textdiff(ptext, t)
+            data = compress(delta)
+            l = len(data[1]) + len(data[0])
+            base = self.base(rev)
+            dist = l + offset - self.start(base)
+            return dist, l, data, base
+
         curr = len(self)
         prev = curr - 1
         base = curr
@@ -1187,17 +1201,8 @@
 
         # should we try to build a delta?
         if deltarev != nullrev:
-            # can we use the cached delta?
-            if cachedelta and cachedelta[0] == deltarev:
-                d = cachedelta[1]
-            else:
-                t = buildtext()
-                ptext = self.revision(deltanode)
-                d = mdiff.textdiff(ptext, t)
-            data = compress(d)
-            l = len(data[1]) + len(data[0])
-            base = self.base(deltarev)
-            dist = l + offset - self.start(base)
+            d = builddelta(deltarev)
+            dist, l, data, base = d
 
         # full versions are inserted when the needed deltas
         # become comparable to the uncompressed text