comparison mercurial/revlogutils/deltas.py @ 51334:ac8b798e602b

delta-find: drop the temporary indent Now that the complicated change is made, we can do the noisy one.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 04 Jan 2024 14:39:10 +0100
parents 898c212e1b2f
children 2407af4f2eea
comparison
equal deleted inserted replaced
51333:898c212e1b2f 51334:ac8b798e602b
740 self.tested.add(rev) 740 self.tested.add(rev)
741 return group 741 return group
742 742
743 def _pre_filter_rev(self, rev): 743 def _pre_filter_rev(self, rev):
744 """return True if it seems okay to test a rev, False otherwise""" 744 """return True if it seems okay to test a rev, False otherwise"""
745 if True: 745 # no need to try a delta against nullrev, this will be done as
746 # no need to try a delta against nullrev, this will be done as 746 # a last resort.
747 # a last resort. 747 if rev == nullrev:
748 if rev == nullrev: 748 return False
749 return False 749 # filter out revision we tested already
750 # filter out revision we tested already 750 if rev in self.tested:
751 if rev in self.tested: 751 return False
752 return False 752
753 753 # an higher authority deamed the base unworthy (e.g. censored)
754 # an higher authority deamed the base unworthy (e.g. censored) 754 if self.excluded_bases is not None and rev in self.excluded_bases:
755 if self.excluded_bases is not None and rev in self.excluded_bases: 755 return False
756 return False 756 # We are in some recomputation cases and that rev is too high
757 # We are in some recomputation cases and that rev is too high 757 # in the revlog
758 # in the revlog 758 if self.target_rev is not None and rev >= self.target_rev:
759 if self.target_rev is not None and rev >= self.target_rev: 759 return False
760 return False 760
761 761 deltas_limit = self.revinfo.textlen * LIMIT_DELTA2TEXT
762 deltas_limit = self.revinfo.textlen * LIMIT_DELTA2TEXT 762 # filter out delta base that will never produce good delta
763 # filter out delta base that will never produce good delta 763 #
764 # 764 # if the delta of that base is already bigger than the limit
765 # if the delta of that base is already bigger than the limit 765 # for the delta chain size, doing a delta is hopeless.
766 # for the delta chain size, doing a delta is hopeless. 766 if deltas_limit < self.revlog.length(rev):
767 if deltas_limit < self.revlog.length(rev): 767 return False
768 return False 768
769 769 sparse = self.revlog.delta_config.sparse_revlog
770 sparse = self.revlog.delta_config.sparse_revlog 770 # if the revision we test again is too small, the resulting delta
771 # if the revision we test again is too small, the resulting delta 771 # will be large anyway as that amount of data to be added is big
772 # will be large anyway as that amount of data to be added is big 772 if sparse and self.revlog.rawsize(rev) < (
773 if sparse and self.revlog.rawsize(rev) < ( 773 self.textlen // LIMIT_BASE2TEXT
774 self.textlen // LIMIT_BASE2TEXT 774 ):
775 ): 775 return False
776 return False 776
777 777 # no delta for rawtext-changing revs (see "candelta" for why)
778 # no delta for rawtext-changing revs (see "candelta" for why) 778 if self.revlog.flags(rev) & REVIDX_RAWTEXT_CHANGING_FLAGS:
779 if self.revlog.flags(rev) & REVIDX_RAWTEXT_CHANGING_FLAGS: 779 return False
780 return False 780
781 781 # If we reach here, we are about to build and test a delta.
782 # If we reach here, we are about to build and test a delta. 782 # The delta building process will compute the chaininfo in all
783 # The delta building process will compute the chaininfo in all 783 # case, since that computation is cached, it is fine to access
784 # case, since that computation is cached, it is fine to access 784 # it here too.
785 # it here too. 785 chainlen, chainsize = self.revlog._chaininfo(rev)
786 chainlen, chainsize = self.revlog._chaininfo(rev) 786 # if chain will be too long, skip base
787 # if chain will be too long, skip base 787 if (
788 if ( 788 self.revlog.delta_config.max_chain_len
789 self.revlog.delta_config.max_chain_len 789 and chainlen >= self.revlog.delta_config.max_chain_len
790 and chainlen >= self.revlog.delta_config.max_chain_len 790 ):
791 ): 791 return False
792 return False 792 # if chain already have too much data, skip base
793 # if chain already have too much data, skip base 793 if deltas_limit < chainsize:
794 if deltas_limit < chainsize: 794 return False
795 return False 795 if sparse and self.revlog.delta_config.upper_bound_comp is not None:
796 if sparse and self.revlog.delta_config.upper_bound_comp is not None: 796 maxcomp = self.revlog.delta_config.upper_bound_comp
797 maxcomp = self.revlog.delta_config.upper_bound_comp 797 basenotsnap = (self.p1, self.p2, nullrev)
798 basenotsnap = (self.p1, self.p2, nullrev) 798 if rev not in basenotsnap and self.revlog.issnapshot(rev):
799 if rev not in basenotsnap and self.revlog.issnapshot(rev): 799 snapshotdepth = self.revlog.snapshotdepth(rev)
800 snapshotdepth = self.revlog.snapshotdepth(rev) 800 # If text is significantly larger than the base, we can
801 # If text is significantly larger than the base, we can 801 # expect the resulting delta to be proportional to the size
802 # expect the resulting delta to be proportional to the size 802 # difference
803 # difference 803 revsize = self.revlog.rawsize(rev)
804 revsize = self.revlog.rawsize(rev) 804 rawsizedistance = max(self.textlen - revsize, 0)
805 rawsizedistance = max(self.textlen - revsize, 0) 805 # use an estimate of the compression upper bound.
806 # use an estimate of the compression upper bound. 806 lowestrealisticdeltalen = rawsizedistance // maxcomp
807 lowestrealisticdeltalen = rawsizedistance // maxcomp 807
808 808 # check the absolute constraint on the delta size
809 # check the absolute constraint on the delta size 809 snapshotlimit = self.textlen >> snapshotdepth
810 snapshotlimit = self.textlen >> snapshotdepth 810 if snapshotlimit < lowestrealisticdeltalen:
811 if snapshotlimit < lowestrealisticdeltalen: 811 # delta lower bound is larger than accepted upper
812 # delta lower bound is larger than accepted upper 812 # bound
813 # bound 813 return False
814 return False 814
815 815 # check the relative constraint on the delta size
816 # check the relative constraint on the delta size 816 revlength = self.revlog.length(rev)
817 revlength = self.revlog.length(rev) 817 if revlength < lowestrealisticdeltalen:
818 if revlength < lowestrealisticdeltalen: 818 # delta probable lower bound is larger than target
819 # delta probable lower bound is larger than target 819 # base
820 # base 820 return False
821 return False
822 return True 821 return True
823 822
824 def _refined_groups(self): 823 def _refined_groups(self):
825 good = None 824 good = None
826 # First we try to reuse a the delta contained in the bundle. (or from 825 # First we try to reuse a the delta contained in the bundle. (or from