# HG changeset patch # User Matt Mackall # Date 1288424854 18000 # Node ID ad01fe38afe686e2e43a8aa15bc0ab8414aab70a # Parent 8ce6240587b1ac3add9e5ad3e7efb6d845f01ff4 revlog: extract delta building to a subfunction diff -r 8ce6240587b1 -r ad01fe38afe6 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