[PATCH 7 of 9] context: enhance findbyhash for partial hash ID
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Mon Mar 30 17:13:41 CDT 2015
On 03/29/2015 11:34 AM, FUJIWARA Katsunori wrote:
> # 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 ce47b26e3c0d6104b5bfb2d15e59b5a2af573956
> # Parent 5070134e83f1a46a55f74e6e6dce6ebd75a5eee9
> context: enhance findbyhash for partial hash ID
>
> Before this patch, there is no easy way to examine existence of the
> revision by partial hash ID strictly.
>
> "hashid in repo" may match against bookmarks, tags and so on.
>
> This patch factors out the logic for it in "changectx.__init__()" and
> enhance "findbyhash()" with it, to avoid duplication of similar code.
>
> This is a preparation to fix equivalence problem of revset predicate
> "id()".
>
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -426,6 +426,12 @@ def _findby40hash(repo, changeid):
> except (TypeError, LookupError):
> return None
>
> +def _findbypartialhash(repo, changeid):
> + node = repo.unfiltered().changelog._partialmatch(changeid)
> + if node is not None:
> + return (node, repo.changelog.rev(node))
> + return None
> +
> def findbyhash(repo, hashid, abort=False):
> """Find the revision by hash ID
>
> @@ -443,8 +449,12 @@ def findbyhash(repo, hashid, abort=False
> branches and so on.
> """
> assert isinstance(hashid, str)
> - assert len(hashid) == 40
> - return _wraplookup(_findby40hash, repo, hashid, abort)
> + assert len(hashid) <= 40
> + if len(hashid) == 40:
> + lookupfunc = _findby40hash
> + else:
> + lookupfunc = _findbypartialhash
Why are we not using _partialmatch in all case ?.
> + return _wraplookup(lookupfunc, repo, hashid, abort)
>
> class changectx(basectx):
> """A changecontext object makes access to data related to a particular
> @@ -528,9 +538,9 @@ class changectx(basectx):
> except error.RepoLookupError:
> pass
>
> - self._node = repo.unfiltered().changelog._partialmatch(changeid)
> - if self._node is not None:
> - self._rev = repo.changelog.rev(self._node)
> + found = _findbypartialhash(repo, changeid)
> + if found:
> + self._node, self._rev = found
> return
>
> # lookup failed
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
--
Pierre-Yves David
More information about the Mercurial-devel
mailing list