Patchwork [1,of,4,RFC,V2] localrepo: extend "changeid in repo" to return True for workingctx revision

login
register
mail settings
Submitter Yuya Nishihara
Date March 16, 2015, 2:04 p.m.
Message ID <193f5a309da2beea925f.1426514670@mimosa>
Download mbox | patch
Permalink /patch/8092/
State Accepted
Commit b9f7f3eeb99c206897beacc0eb323ab9c178e599
Headers show

Comments

Yuya Nishihara - March 16, 2015, 2:04 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1408242931 -32400
#      Sun Aug 17 11:35:31 2014 +0900
# Node ID 193f5a309da2beea925fd22a6e039bb2dcee7a81
# Parent  15afda349b11b531edd1ea6ec02847e01fe35615
localrepo: extend "changeid in repo" to return True for workingctx revision

This is necessary to implement "wc" symbol for workingctx, that will be used
as follows:

    $ hg annotate -r wc FILE

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

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

Behavior of "changeid in repo":

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

    (*original: ea3acaae25bb)

Patch

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