[PATCH 8 of 9] localrepo: add findbyhash for convenience

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Mar 29 13:34:30 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1427653752 -32400
#      Mon Mar 30 03:29:12 2015 +0900
# Node ID 8a0e73ddbd401236f42f0afd65f254c4cdcdce08
# Parent  ce47b26e3c0d6104b5bfb2d15e59b5a2af573956
localrepo: add findbyhash for convenience

This allows to use "context.findbyhash()" easily, without additional
importing "context".

Using "repo.findbyhash(hashid)" instead of "hashid in repo" is also
useful to avoid meaningless matching against "repo.dirstate.p1()",
reserved names (e.g. "null", "tip", "."), bookmarks, tags, branches
and so on.

Matching against "repo.dirstate.p1()" is especially inefficient,
because it may cause useless (re-)loading from ".hg/dirstate" or
invoking "changelog.rev(bin(hashid))" for validation.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1915,6 +1915,20 @@ class localrepository(object):
         """
         return context.findbyrevnum(self, revnum, abort=abort)
 
+    def findbyhash(self, hashid, abort=False):
+        """Find the revision by hash ID in this repository
+
+        ``hashid`` should be ``str``.
+
+        This returns ``(node, revnum)`` tuple, if the revision
+        corresponded to the specified ``hashid`` is found. If that
+        revision is hidden one, this raises FilteredRepoLookupError.
+
+        Other wise, this returns ``None`` (or raises RepoLookupError if
+        ``abort``).
+        """
+        return context.findbyhash(self, hashid, abort=abort)
+
 # used to avoid circular references so destructors work
 def aftertrans(files):
     renamefiles = [tuple(t) for t in files]


More information about the Mercurial-devel mailing list