[PATCH 3 of 9] context: add findbyrevnum to examine by revision number strictly

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Mar 30 16:58:46 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 1427653751 -32400
> #      Mon Mar 30 03:29:11 2015 +0900
> # Node ID 5f035c783b0443fabc15e773af176c7ef092c1de
> # Parent  501346a6222d37bf0e841175ecde906d79673044
> context: add findbyrevnum to examine by revision number strictly
>
> Before this patch, there is no easy way to examine existence of the
> revision by revision number strictly.
>
>    - "revnum in repo.changelog":
>      PROS: "out of range" and "hidden revision" causes False
>      CONS: additional examination is needed to distinguish between them
>            (= FilteredRepoLookupError should be raised explicitly)
>
>    - "repo[revnum]":
>      PROS: "hidden revision" causes aborting by FilteredRepoLookupError
>      CONS: additional examination is needed to avoid that negative
>            value is treated as "sequential offsets from the tip".
>
> In both cases, RepoLookupError should be raised explicitly to abort.
>
> This patch adds "findbyrevnum()" to examine existence of the revision
> by revision number strictly and easily.
>
> In this patch, "_findbyrevnum()" examines also "len(repo.changelog) <=
> changeid", because "changelog.node(chagneid)" doesn't raise IndexError
> even if "changeid" is "len(changelog) + 1" (this may be needed for
> "changectx.__init__()", too).
>
> This is a preparation to fix equivalence problem of revset predicate
> "rev()".
>
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -393,6 +393,29 @@ def _wraplookup(lookupfunc, repo, change
>
>       return found
>
> +def _findbyrevnum(repo, changeid):
> +    if changeid == nullrev:
> +        return (nullid, nullrev)
> +    elif changeid < 0 or len(repo.changelog) <= changeid:
> +        return None
> +    return (repo.changelog.node(changeid), changeid)

Function could probably use some docstring

> +def findbyrevnum(repo, revnum, abort=False):
> +    """Find the revision by revision number
> +
> +    ``revnum`` should be ``int``. All negative values other than
> +    ``-1`` (as null revision) are treated as invalid revision number.
> +
> +    This returns ``(node, revnum)`` tuple, if the revision
> +    corresponded to the specified ``revnum`` is found. If that
> +    revision is hidden one, this raises FilteredRepoLookupError.
> +
> +    Other wise, this returns ``None`` (or raises RepoLookupError if
> +    ``abort`` is true).
> +    """
> +    assert isinstance(revnum, int)

The rest of the code appear to use "long" We are probably up to very 
confusing crash at some point in the future.


-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list