Patchwork D6206: branchmap: implement __contains__()

login
register
mail settings
Submitter phabricator
Date April 5, 2019, 1:31 p.m.
Message ID <differential-rev-PHID-DREV-drahw2cdfedv2js43ojm-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/39503/
State Superseded
Headers show

Comments

phabricator - April 5, 2019, 1:31 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We have good occurences of `if branch in branchmap()` in our code. If
  __contains__() is not implemented then it will use __iter__() to find whether
  the element exists or not which is not good.
  
  I am bit confused that whether I should move existing callers to hasbranch() or
  this patch is a good way.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6206

AFFECTED FILES
  mercurial/branchmap.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -182,6 +182,9 @@ 
     def __getitem__(self, key):
         return self._entries[key]
 
+    def __contains__(self, key):
+        return key in self._entries
+
     def iteritems(self):
         return self._entries.iteritems()