# HG changeset patch # User Sean Farley # Date 1413521368 25200 # Node ID 885c0290f7d51b86c647c8590fb24c1c1f032fdf # Parent b9537ee87961d88dea449a2fc69143c0fdaf1ae6 localrepo: add ignoremissing parameter to branchtip Previously, in the namespaces api, the only caller of branchtip was singlenode which happened to raise the same exception that branchtip raised: KeyError. This is a minor change but will allow upcoming patches to use repo.branchtip to not raise an exception if a branch doesn't exist. After that, it will be possible for extensions to use the namespace api in a stable way. diff -r b9537ee87961 -r 885c0290f7d5 mercurial/localrepo.py --- a/mercurial/localrepo.py Mon Dec 15 14:46:04 2014 -0800 +++ b/mercurial/localrepo.py Thu Oct 16 21:49:28 2014 -0700 @@ -718,12 +718,21 @@ branchmap.updatecache(self) return self._branchcaches[self.filtername] - def branchtip(self, branch): - '''return the tip node for a given branch''' + def branchtip(self, branch, ignoremissing=False): + '''return the tip node for a given branch + + If ignoremissing is True, then this method will not raise an error. + This is helpful for callers that only expect None for a missing branch + (e.g. namespace). + + ''' try: return self.branchmap().branchtip(branch) except KeyError: - raise error.RepoLookupError(_("unknown branch '%s'") % branch) + if not ignoremissing: + raise error.RepoLookupError(_("unknown branch '%s'") % branch) + else: + pass def lookup(self, key): return self[key].node() diff -r b9537ee87961 -r 885c0290f7d5 mercurial/namespaces.py --- a/mercurial/namespaces.py Mon Dec 15 14:46:04 2014 -0800 +++ b/mercurial/namespaces.py Thu Oct 16 21:49:28 2014 -0700 @@ -41,7 +41,7 @@ n = ns("branches", "branch", lambda repo: repo.branchmap().keys(), - lambda repo, name: tolist(repo.branchtip(name)), + lambda repo, name: tolist(repo.branchtip(name, True)), lambda repo, node: [repo[node].branch()]) self.addnamespace(n)