Mercurial > public > mercurial-scm > hg-stable
diff mercurial/filelog.py @ 40387:f1a39128da95
filelog: add a hasnode() method (API)
Missing in the file storage interface is the ability to query whether
a specified value is a known node.
This commit defines that interface member and implements it on the
revlog and sqlite file stores.
Storage unit tests have been added.
The revlog implementation is a bit more complicated because index lookups
don't consistently raise the same exception. For SQLite, we can simply look
for a key in a dict.
Differential Revision: https://phab.mercurial-scm.org/D5163
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 03 Oct 2018 14:57:29 -0700 |
parents | 324b4b10351e |
children | 1b183edbb68e |
line wrap: on
line diff
--- a/mercurial/filelog.py Sun Oct 21 22:26:00 2018 -0400 +++ b/mercurial/filelog.py Wed Oct 03 14:57:29 2018 -0700 @@ -7,6 +7,10 @@ from __future__ import absolute_import +from .node import ( + nullid, + nullrev, +) from . import ( error, repository, @@ -33,6 +37,16 @@ def __iter__(self): return self._revlog.__iter__() + def hasnode(self, node): + if node in (nullid, nullrev): + return False + + try: + self._revlog.rev(node) + return True + except (TypeError, ValueError, IndexError, error.LookupError): + return False + def revs(self, start=0, stop=None): return self._revlog.revs(start=start, stop=stop)