in hgext/firefoxtree/__init__.py [0:0]
def reposetup(ui, repo):
if not repo.local():
return
class firefoxtreesrepo(repo.__class__):
# Wrap _restrictcapabilities so capabilities are exposed to local peers.
def _restrictcapabilities(self, caps):
caps = super(firefoxtreesrepo, self)._restrictcapabilities(caps)
if isfirefoxrepo(self) and self.ui.configbool(
b"firefoxtree", b"servetags", False
):
caps.add(b"firefoxtrees")
return caps
@util.propertycache
def firefoxtrees(self):
trees = {}
try:
with open(self._firefoxtreespath, "rb") as fh:
data = fh.read()
except IOError as e:
if e.errno != errno.ENOENT:
raise
data = None
if not data:
return trees
cl = self.changelog
for line in data.splitlines():
line = line.strip()
if not line:
continue
tree, hexnode = line.split()
# Filter out try repos because they are special.
if tree in TRY_TREES:
continue
binnode = bin(hexnode)
# Filter out unknown nodes. Since this function is used as part
# of writing, it means that unknown nodes will silently be
# dropped on next write.
try:
if cl.rev(binnode) == nullrev:
continue
except error.LookupError:
continue
trees[tree] = binnode
return trees
@property
def _firefoxtreespath(self):
shared = {s.strip() for s in repo.vfs.tryread(b"shared").splitlines()}
if b"firefoxtrees" in shared and repo.sharedpath != repo.path:
return os.path.join(repo.sharedpath, b"firefoxtrees")
else:
return self.vfs.join(b"firefoxtrees")
repo.__class__ = firefoxtreesrepo
# Only change behavior on repositories that are clones of a Firefox
# repository.
if not isfirefoxrepo(repo):
return
repo.prepushoutgoinghooks.add(b"firefoxtree", prepushoutgoinghook)
def listnames(r):
return r.firefoxtrees.keys()
def namemap(r, name):
node = r.firefoxtrees.get(name)
if node:
return [node]
return []
def nodemap(r, node):
return [name for name, n in r.firefoxtrees.items() if n == node]
n = namespaces.namespace(
b"fxtrees",
templatename=b"fxtree",
listnames=listnames,
namemap=namemap,
nodemap=nodemap,
)
repo.names.addnamespace(n)