[PATCH 1 of 8 RFC] localrepo: extend "changeid in repo" to return True for workingctx revision

Yuya Nishihara yuya at tcha.org
Tue Aug 19 17:56:15 CDT 2014


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1408242931 -32400
#      Sun Aug 17 11:35:31 2014 +0900
# Node ID 0e8b104fd419419ddf9ec3c9df4df1991e9ba3a5
# Parent  8dda6f6ff564d8fe6ac7b8ce4c74eb9bfb5de14a
localrepo: extend "changeid in repo" to return True for workingctx revision

This is necessary to implement revision specifier for workingctx, that will
be used like

    $ hg annotate -r workingdir FILE

In principle, "rev in repo" should be True if "repo[rev]" can return context
object.  But when it was implemented by ea3acaae25bb, lookup() had long logic
to map all sorts of changeid to node, and "None in repo" did crash because
lookup() did not support it.  So I guess the case of changeid=None was not
considered.

Since now "None in repo" doesn't crash, it should be True for workingctx
revision.

Behavior of "changeid in repo":

     X in repo  "null"  existing rev  None (workingctx)
    ----------  ------  ------------  -----------------
    original*   True    True          TypeError
    current     True    True          False
    this patch  True    True          True

    (*original: ea3acaae25bb)

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -449,7 +449,8 @@ class localrepository(object):
 
     def __contains__(self, changeid):
         try:
-            return bool(self.lookup(changeid))
+            self[changeid]
+            return True
         except error.RepoLookupError:
             return False
 


More information about the Mercurial-devel mailing list