localrepo: cache headnodes instead of headrevs

Summary:
With segmented changelog backend, the revs can be changed, even if len(repo)
didn't change. Caching revs might not get invalidated properly. Let's cache
head nodes instead.

Reviewed By: DurhamG

Differential Revision: D23856176

fbshipit-source-id: c5154c536298c348b847a12de8c4f582f877f96e
This commit is contained in:
Jun Wu 2020-09-22 18:09:28 -07:00 committed by Facebook GitHub Bot
parent 4691e11012
commit 1b7c3b6a13

View File

@ -2688,7 +2688,7 @@ class localrepository(object):
"""Used by workingctx to clear post-dirstate-status hooks."""
del self._postdsstatus[:]
def _cachedheadrevs(self, includepublic=True, includedraft=True):
def _cachedheadnodes(self, includepublic=True, includedraft=True):
"""Get nodes of both public and draft heads.
Cached. Invalidate on transaction commit.
@ -2737,12 +2737,20 @@ class localrepository(object):
hasnode = cl.hasnode
nodes = [n for n in set(nodes) if n != nullid and hasnode(n)]
headnodes = cl.dag.headsancestors(nodes)
headrevs = list(cl.torevs(headnodes))
else:
revs = [r for r in map(torev, nodes) if r is not None and r >= 0]
headrevs = cl.index2.headsancestors(revs)
self._headcache[key] = headrevs
return headrevs
headnodes = list(map(cl.node, headrevs))
self._headcache[key] = headnodes
return headnodes
def _cachedheadrevs(self, includepublic=True, includedraft=True):
nodes = self._cachedheadnodes(includepublic, includedraft)
cl = self.changelog
if cl.userust("index2"):
return list(cl.torevs(nodes))
else:
return list(map(cl.rev, nodes))
def headrevs(self, start=None, includepublic=True, includedraft=True, reverse=True):
cl = self.changelog