comparison mercurial/revlogutils/deltas.py @ 51347:555826073625

delta-find: introduce and use specialized _DeltaSearch class For now, we introduce some very simple variant, but they are still useful to display how having the class can helps keeping the simple case simple and their special case out of more advanced logic.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 07 Jan 2024 03:34:27 +0100
parents 2a333d791ecf
children d58e14262587
comparison
equal deleted inserted replaced
51346:2a333d791ecf 51347:555826073625
781 @abc.abstractmethod 781 @abc.abstractmethod
782 def _init_group(self): 782 def _init_group(self):
783 pass 783 pass
784 784
785 785
786 class _NoDeltaSearch(_BaseDeltaSearch):
787 """Search for no delta.
788
789 This search variant is to be used in case where we should not store delta.
790 """
791
792 def _init_group(self):
793 pass
794
795 def next_group(self, good_delta=None):
796 pass
797
798
799 class _PrevDeltaSearch(_BaseDeltaSearch):
800 """Search for delta against the previous revision only
801
802 This search variant is to be used when the format does not allow for delta
803 against arbitrary bases.
804 """
805
806 def _init_group(self):
807 self.current_group = [self.target_rev - 1]
808
809 def next_group(self, good_delta=None):
810 self.current_group = None
811
812
786 class _DeltaSearch(_BaseDeltaSearch): 813 class _DeltaSearch(_BaseDeltaSearch):
814 """Generic delta search variants
815
816 (expect this to be split further)
817 """
818
787 def _init_group(self): 819 def _init_group(self):
820 # Why search for delta base if we cannot use a delta base ?
821 # also see issue6056
822 assert self.revlog.delta_config.general_delta
788 self._candidates_iterator = self._candidate_groups() 823 self._candidates_iterator = self._candidate_groups()
789 self._last_good = None 824 self._last_good = None
790 self.current_group = self._candidates_iterator.send(self._last_good) 825 self.current_group = self._candidates_iterator.send(self._last_good)
791 826
792 def next_group(self, good_delta=None): 827 def next_group(self, good_delta=None):
799 834
800 This top level function focus on emitting groups with unique and 835 This top level function focus on emitting groups with unique and
801 worthwhile content. See _raw_candidate_groups for details about the 836 worthwhile content. See _raw_candidate_groups for details about the
802 group order. 837 group order.
803 """ 838 """
804 # should we try to build a delta?
805 if not (len(self.revlog) and self.revlog._storedeltachains):
806 yield None
807 return
808
809 if not self.revlog.delta_config.general_delta:
810 # before general delta, there is only one possible delta base
811 yield (self.target_rev - 1,)
812 yield None
813 return
814
815 good = None 839 good = None
816 840
817 group_chunk_size = self.revlog.delta_config.candidate_group_chunk_size 841 group_chunk_size = self.revlog.delta_config.candidate_group_chunk_size
818 842
819 tested = self.tested # prefetch for speed and code compactness 843 tested = self.tested # prefetch for speed and code compactness
1060 This lower level function focus on emitting delta theorically 1084 This lower level function focus on emitting delta theorically
1061 interresting without looking it any practical details. 1085 interresting without looking it any practical details.
1062 1086
1063 The group order aims at providing fast or small candidates first. 1087 The group order aims at providing fast or small candidates first.
1064 """ 1088 """
1065 # Why search for delta base if we cannot use a delta base ?
1066 assert self.revlog.delta_config.general_delta
1067 # also see issue6056
1068 sparse = self.revlog.delta_config.sparse_revlog 1089 sparse = self.revlog.delta_config.sparse_revlog
1069 prev = self.target_rev - 1 1090 prev = self.target_rev - 1
1070 deltachain = lambda rev: self.revlog._deltachain(rev)[0] 1091 deltachain = lambda rev: self.revlog._deltachain(rev)[0]
1071 1092
1072 # exclude already lazy tested base if any 1093 # exclude already lazy tested base if any
1546 if self._debug_search: 1567 if self._debug_search:
1547 msg = b"DBG-DELTAS-SEARCH: SEARCH rev=%d\n" 1568 msg = b"DBG-DELTAS-SEARCH: SEARCH rev=%d\n"
1548 msg %= target_rev 1569 msg %= target_rev
1549 self._write_debug(msg) 1570 self._write_debug(msg)
1550 1571
1551 search = _DeltaSearch( 1572 # should we try to build a delta?
1573 if not (len(self.revlog) and self.revlog._storedeltachains):
1574 search_cls = _NoDeltaSearch
1575 elif not self.revlog.delta_config.general_delta:
1576 # before general delta, there is only one possible delta base
1577 search_cls = _PrevDeltaSearch
1578 else:
1579 search_cls = _DeltaSearch
1580
1581 search = search_cls(
1552 self.revlog, 1582 self.revlog,
1553 revinfo, 1583 revinfo,
1554 p1r, 1584 p1r,
1555 p2r, 1585 p2r,
1556 cachedelta, 1586 cachedelta,