mirror of
https://github.com/facebook/sapling.git
synced 2025-01-01 09:37:56 +03:00
fastannotate: add a method to quickly get the last node of the revmap
Summary: Previously, to get changeset hashes in the revmap, we have to construct the `revmap` object, which reads all content of a revmap. In the following patches, we want to quickly get the last hash of the revmap to test if the linelog / revmap is up-to-date or not. This patch adds a method to do so. Test Plan: Modified existing tests. Reviewers: #sourcecontrol, stash Reviewed By: stash Subscribers: mjpieters Differential Revision: https://phabricator.intern.facebook.com/D4103898 Signature: t1:4103898:1477988583:15869dfe9028068563b03d1f06d2337562049751
This commit is contained in:
parent
f4f6b2411a
commit
57890ff99f
@ -227,3 +227,17 @@ class revmap(object):
|
||||
if path is not None and path != self.rev2path(rev):
|
||||
return False
|
||||
return (self.rev2flag(rev) & sidebranchflag) == 0
|
||||
|
||||
def getlastnode(path):
|
||||
"""return the last hash in a revmap, without loading its full content.
|
||||
this is equivalent to `m = revmap(path); m.rev2hsh(m.maxrev)`, but faster.
|
||||
"""
|
||||
hsh = None
|
||||
try:
|
||||
with open(path, 'rb') as f:
|
||||
f.seek(-_hshlen, 2)
|
||||
if f.tell() > len(revmap.HEADER):
|
||||
hsh = f.read(_hshlen)
|
||||
except IOError:
|
||||
pass
|
||||
return hsh
|
||||
|
@ -175,7 +175,20 @@ def testcontains():
|
||||
ensure(fakefctx(genhsh(i), path=str(i // 2)) in rm)
|
||||
ensure(fakefctx(genhsh(i), path='a') not in rm)
|
||||
|
||||
def testlastnode():
|
||||
path = gettemppath()
|
||||
ensure(revmap.getlastnode(path) is None)
|
||||
rm = revmap.revmap(path)
|
||||
ensure(revmap.getlastnode(path) is None)
|
||||
for i in xrange(1, 10):
|
||||
hsh = genhsh(i)
|
||||
rm.append(hsh, path=str(i // 2), flush=True)
|
||||
ensure(revmap.getlastnode(path) == hsh)
|
||||
rm2 = revmap.revmap(path)
|
||||
ensure(rm2.rev2hsh(rm2.maxrev) == hsh)
|
||||
|
||||
testbasicreadwrite()
|
||||
testcorruptformat()
|
||||
testcopyfrom()
|
||||
testcontains()
|
||||
testlastnode()
|
||||
|
Loading…
Reference in New Issue
Block a user