comparison mercurial/localrepo.py @ 23775:885c0290f7d5

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.
author Sean Farley <sean.michael.farley@gmail.com>
date Thu, 16 Oct 2014 21:49:28 -0700
parents a387b0390082
children 99e125626352
comparison
equal deleted inserted replaced
23774:b9537ee87961 23775:885c0290f7d5
716 '''returns a dictionary {branch: [branchheads]} with branchheads 716 '''returns a dictionary {branch: [branchheads]} with branchheads
717 ordered by increasing revision number''' 717 ordered by increasing revision number'''
718 branchmap.updatecache(self) 718 branchmap.updatecache(self)
719 return self._branchcaches[self.filtername] 719 return self._branchcaches[self.filtername]
720 720
721 def branchtip(self, branch): 721 def branchtip(self, branch, ignoremissing=False):
722 '''return the tip node for a given branch''' 722 '''return the tip node for a given branch
723
724 If ignoremissing is True, then this method will not raise an error.
725 This is helpful for callers that only expect None for a missing branch
726 (e.g. namespace).
727
728 '''
723 try: 729 try:
724 return self.branchmap().branchtip(branch) 730 return self.branchmap().branchtip(branch)
725 except KeyError: 731 except KeyError:
726 raise error.RepoLookupError(_("unknown branch '%s'") % branch) 732 if not ignoremissing:
733 raise error.RepoLookupError(_("unknown branch '%s'") % branch)
734 else:
735 pass
727 736
728 def lookup(self, key): 737 def lookup(self, key):
729 return self[key].node() 738 return self[key].node()
730 739
731 def lookupbranch(self, key, remote=None): 740 def lookupbranch(self, key, remote=None):