Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/deltas.py @ 39333:5d343a24bff5
revlogdeltas: always return a delta info object in finddeltainfo
Previously, the method returned `None` when a full snapshot was needed. The
caller had to determine how to produce one itself.
In practice, building a `_deltainfo` object for a full snapshot is simple. So
we build it at the `finddeltainfo` level and always return a `_deltainfo`
object.
The caller can now simply process the `_deltainfo` return in all cases.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Thu, 16 Aug 2018 04:38:57 +0200 |
parents | 6f4b8f607a31 |
children | 507f5b1dd7c8 |
comparison
equal
deleted
inserted
replaced
39332:6f4b8f607a31 | 39333:5d343a24bff5 |
---|---|
688 | 688 |
689 return _deltainfo(dist, deltalen, (header, data), deltabase, | 689 return _deltainfo(dist, deltalen, (header, data), deltabase, |
690 chainbase, chainlen, compresseddeltalen, | 690 chainbase, chainlen, compresseddeltalen, |
691 snapshotdepth) | 691 snapshotdepth) |
692 | 692 |
693 def _fullsnapshotinfo(self, fh, revinfo): | |
694 curr = len(self.revlog) | |
695 rawtext = self.buildtext(revinfo, fh) | |
696 data = self.revlog.compress(rawtext) | |
697 compresseddeltalen = deltalen = dist = len(data[1]) + len(data[0]) | |
698 deltabase = chainbase = curr | |
699 snapshotdepth = 0 | |
700 chainlen = 1 | |
701 | |
702 return _deltainfo(dist, deltalen, data, deltabase, | |
703 chainbase, chainlen, compresseddeltalen, | |
704 snapshotdepth) | |
705 | |
693 def finddeltainfo(self, revinfo, fh): | 706 def finddeltainfo(self, revinfo, fh): |
694 """Find an acceptable delta against a candidate revision | 707 """Find an acceptable delta against a candidate revision |
695 | 708 |
696 revinfo: information about the revision (instance of _revisioninfo) | 709 revinfo: information about the revision (instance of _revisioninfo) |
697 fh: file handle to either the .i or the .d revlog file, | 710 fh: file handle to either the .i or the .d revlog file, |
698 depending on whether it is inlined or not | 711 depending on whether it is inlined or not |
699 | 712 |
700 Returns the first acceptable candidate revision, as ordered by | 713 Returns the first acceptable candidate revision, as ordered by |
701 _getcandidaterevs | 714 _getcandidaterevs |
715 | |
716 If no suitable deltabase is found, we return delta info for a full | |
717 snapshot. | |
702 """ | 718 """ |
703 if not revinfo.textlen: | 719 if not revinfo.textlen: |
704 return None # empty file do not need delta | 720 return self._fullsnapshotinfo(fh, revinfo) |
705 | 721 |
706 # no delta for flag processor revision (see "candelta" for why) | 722 # no delta for flag processor revision (see "candelta" for why) |
707 # not calling candelta since only one revision needs test, also to | 723 # not calling candelta since only one revision needs test, also to |
708 # avoid overhead fetching flags again. | 724 # avoid overhead fetching flags again. |
709 if revinfo.flags & REVIDX_RAWTEXT_CHANGING_FLAGS: | 725 if revinfo.flags & REVIDX_RAWTEXT_CHANGING_FLAGS: |
710 return None | 726 return self._fullsnapshotinfo(fh, revinfo) |
711 | 727 |
712 cachedelta = revinfo.cachedelta | 728 cachedelta = revinfo.cachedelta |
713 p1 = revinfo.p1 | 729 p1 = revinfo.p1 |
714 p2 = revinfo.p2 | 730 p2 = revinfo.p2 |
715 revlog = self.revlog | 731 revlog = self.revlog |
740 nominateddeltas.append(candidatedelta) | 756 nominateddeltas.append(candidatedelta) |
741 if nominateddeltas: | 757 if nominateddeltas: |
742 deltainfo = min(nominateddeltas, key=lambda x: x.deltalen) | 758 deltainfo = min(nominateddeltas, key=lambda x: x.deltalen) |
743 break | 759 break |
744 | 760 |
761 if deltainfo is None: | |
762 deltainfo = self._fullsnapshotinfo(fh, revinfo) | |
745 return deltainfo | 763 return deltainfo |