Mercurial > public > mercurial-scm > hg
diff mercurial/namespaces.py @ 23561:3c2419e07df5
namespaces: remove weakref; always pass in repo
It turns out that maintaining a reference of any sort (even weak!) to the repo
when constructed doesn't work because we may at some point pass in a repoview
filtered by something other than what the initial repo was.
author | Ryan McElroy <rmcelroy@fb.com> |
---|---|
date | Sun, 14 Dec 2014 19:11:44 -0800 |
parents | 3b3a962e3677 |
children | 59e703aecaf6 |
line wrap: on
line diff
--- a/mercurial/namespaces.py Thu Oct 16 23:27:54 2014 -0700 +++ b/mercurial/namespaces.py Sun Dec 14 19:11:44 2014 -0800 @@ -1,6 +1,5 @@ from i18n import _ from mercurial import util -import weakref def tolist(val): """ @@ -32,19 +31,14 @@ _names_version = 0 - def __init__(self, repo): + def __init__(self): self._names = util.sortdict() - self._repo = weakref.ref(repo) # we need current mercurial named objects (bookmarks, tags, and # branches) to be initialized somewhere, so that place is here self.addnamespace("bookmarks", lambda repo, name: tolist(repo._bookmarks.get(name))) - @property - def repo(self): - return self._repo() - def addnamespace(self, namespace, namemap, order=None): """ register a namespace @@ -60,7 +54,7 @@ else: self._names[namespace] = val - def singlenode(self, name): + def singlenode(self, repo, name): """ Return the 'best' node for the given name. Best means the first node in the first nonempty list returned by a name-to-nodes mapping function @@ -69,11 +63,11 @@ Raises a KeyError if there is no such node. """ for ns, v in self._names.iteritems(): - n = v['namemap'](self.repo, name) + n = v['namemap'](repo, name) if n: # return max revision number if len(n) > 1: - cl = self.repo.changelog + cl = repo.changelog maxrev = max(cl.rev(node) for node in n) return cl.node(maxrev) return n[0]