comparison mercurial/revlog.py @ 48761:2e949ede7350

rank: naive rank property computation and retrieval This stores the rank (size of the ancestor set of a revision, including itself) in a changelog field and allows this property to be retrieved. This new property is used as part of stable-range computations, which will be introduced later on. The value is computed in a naive way from the definition of the rank. This will be replaced by a more efficient version subsequently. Differential Revision: https://phab.mercurial-scm.org/D12139
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 28 Jan 2022 11:33:01 +0100
parents e845537f6adb
children 580660518459
comparison
equal deleted inserted replaced
48760:93d6f0e7ba2f 48761:2e949ede7350
38 ALL_KINDS, 38 ALL_KINDS,
39 CHANGELOGV2, 39 CHANGELOGV2,
40 COMP_MODE_DEFAULT, 40 COMP_MODE_DEFAULT,
41 COMP_MODE_INLINE, 41 COMP_MODE_INLINE,
42 COMP_MODE_PLAIN, 42 COMP_MODE_PLAIN,
43 ENTRY_RANK,
43 FEATURES_BY_VERSION, 44 FEATURES_BY_VERSION,
44 FLAG_GENERALDELTA, 45 FLAG_GENERALDELTA,
45 FLAG_INLINE_DATA, 46 FLAG_INLINE_DATA,
46 INDEX_HEADER, 47 INDEX_HEADER,
47 KIND_CHANGELOG, 48 KIND_CHANGELOG,
49 RANK_UNKNOWN,
48 REVLOGV0, 50 REVLOGV0,
49 REVLOGV1, 51 REVLOGV1,
50 REVLOGV1_FLAGS, 52 REVLOGV1_FLAGS,
51 REVLOGV2, 53 REVLOGV2,
52 REVLOGV2_FLAGS, 54 REVLOGV2_FLAGS,
854 flags = self.flags(rev) 856 flags = self.flags(rev)
855 if flags & (flagutil.REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0: 857 if flags & (flagutil.REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0:
856 return self.rawsize(rev) 858 return self.rawsize(rev)
857 859
858 return len(self.revision(rev)) 860 return len(self.revision(rev))
861
862 def fast_rank(self, rev):
863 """Return the rank of a revision if already known, or None otherwise.
864
865 The rank of a revision is the size of the sub-graph it defines as a
866 head. Equivalently, the rank of a revision `r` is the size of the set
867 `ancestors(r)`, `r` included.
868
869 This method returns the rank retrieved from the revlog in constant
870 time. It makes no attempt at computing unknown values for versions of
871 the revlog which do not persist the rank.
872 """
873 rank = self.index[rev][ENTRY_RANK]
874 if rank == RANK_UNKNOWN:
875 return None
876 return rank
859 877
860 def chainbase(self, rev): 878 def chainbase(self, rev):
861 base = self._chainbasecache.get(rev) 879 base = self._chainbasecache.get(rev)
862 if base is not None: 880 if base is not None:
863 return base 881 return base
2442 # Don't store the offset if the sidedata is empty, that way 2460 # Don't store the offset if the sidedata is empty, that way
2443 # we can easily detect empty sidedata and they will be no different 2461 # we can easily detect empty sidedata and they will be no different
2444 # than ones we manually add. 2462 # than ones we manually add.
2445 sidedata_offset = 0 2463 sidedata_offset = 0
2446 2464
2465 rank = RANK_UNKNOWN
2466 if self._format_version == CHANGELOGV2:
2467 rank = len(list(self.ancestors([p1r, p2r], inclusive=True))) + 1
2468
2447 e = revlogutils.entry( 2469 e = revlogutils.entry(
2448 flags=flags, 2470 flags=flags,
2449 data_offset=offset, 2471 data_offset=offset,
2450 data_compressed_length=deltainfo.deltalen, 2472 data_compressed_length=deltainfo.deltalen,
2451 data_uncompressed_length=textlen, 2473 data_uncompressed_length=textlen,
2456 parent_rev_2=p2r, 2478 parent_rev_2=p2r,
2457 node_id=node, 2479 node_id=node,
2458 sidedata_offset=sidedata_offset, 2480 sidedata_offset=sidedata_offset,
2459 sidedata_compressed_length=len(serialized_sidedata), 2481 sidedata_compressed_length=len(serialized_sidedata),
2460 sidedata_compression_mode=sidedata_compression_mode, 2482 sidedata_compression_mode=sidedata_compression_mode,
2483 rank=rank,
2461 ) 2484 )
2462 2485
2463 self.index.append(e) 2486 self.index.append(e)
2464 entry = self.index.entry_binary(curr) 2487 entry = self.index.entry_binary(curr)
2465 if curr == 0 and self._docket is None: 2488 if curr == 0 and self._docket is None: