# HG changeset patch # User Thomas Arendsen Hein # Date 2006-03-06 16:47:41 # Node ID 876e4e6ad82b6012daf19f99fbd17badc8c6596e # Parent 429bf036f2cbf8dbdbe66e26bdaeafa66776e7b6 Create local ui object per repository, so .hg/hgrc don't get mixed. This is needed for hooks, but may be important for other settings, too. Fixes issue113, also integrated push-hook-lock.sh as a test case for this. diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -852,7 +852,7 @@ class queue: def qrepo(self, create=False): if create or os.path.isdir(os.path.join(self.path, ".hg")): - return hg.repository(ui=self.ui, path=self.path, create=create) + return hg.repository(self.ui, path=self.path, create=create) def restore(self, repo, rev, delete=None, qupdate=None): c = repo.changelog.read(rev) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -780,7 +780,7 @@ def clone(ui, source, dest=None, **opts) f.close() if not opts['noupdate']: - update(ui, repo) + update(repo.ui, repo) d.close() @@ -1067,6 +1067,7 @@ def debugconfig(ui): """show combined config settings from all hgrc files""" try: repo = hg.repository(ui) + ui = repo.ui except hg.RepoError: pass for section, name, value in ui.walkconfig(): @@ -1777,7 +1778,8 @@ def paths(ui, search=None): and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. """ try: - repo = hg.repository(ui=ui) + repo = hg.repository(ui) + ui = repo.ui except hg.RepoError: pass @@ -2852,7 +2854,8 @@ def dispatch(args): if cmd not in norepo.split(): path = options["repository"] or "" - repo = hg.repository(ui=u, path=path) + repo = hg.repository(u, path=path) + u = repo.ui for x in external: if hasattr(x, 'reposetup'): x.reposetup(u, repo) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -10,12 +10,12 @@ import filelog, manifest, changelog, dir from node import * from i18n import gettext as _ from demandload import * -demandload(globals(), "re lock transaction tempfile stat mdiff errno") +demandload(globals(), "re lock transaction tempfile stat mdiff errno ui") class localrepository(object): def __del__(self): self.transhandle = None - def __init__(self, ui, path=None, create=0): + def __init__(self, parentui, path=None, create=0): if not path: p = os.getcwd() while not os.path.isdir(os.path.join(p, ".hg")): @@ -30,7 +30,7 @@ class localrepository(object): raise repo.RepoError(_("repository %s not found") % path) self.root = os.path.abspath(path) - self.ui = ui + self.ui = ui.ui(parentui=parentui) self.opener = util.opener(self.path) self.wopener = util.opener(self.root) self.manifest = manifest.manifest(self.opener) @@ -45,7 +45,7 @@ class localrepository(object): os.mkdir(self.path) os.mkdir(self.join("data")) - self.dirstate = dirstate.dirstate(self.opener, ui, self.root) + self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root) try: self.ui.readconfig(self.join("hgrc")) except IOError: diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -12,18 +12,23 @@ demandload(globals(), "re socket sys uti class ui(object): def __init__(self, verbose=False, debug=False, quiet=False, - interactive=True): + interactive=True, parentui=None): self.overlay = {} self.cdata = ConfigParser.SafeConfigParser() - self.readconfig(util.rcpath) + self.parentui = parentui and parentui.parentui or parentui + if parentui is None: + self.readconfig(util.rcpath) - self.quiet = self.configbool("ui", "quiet") - self.verbose = self.configbool("ui", "verbose") - self.debugflag = self.configbool("ui", "debug") - self.interactive = self.configbool("ui", "interactive", True) + self.quiet = self.configbool("ui", "quiet") + self.verbose = self.configbool("ui", "verbose") + self.debugflag = self.configbool("ui", "debug") + self.interactive = self.configbool("ui", "interactive", True) - self.updateopts(verbose, debug, quiet, interactive) - self.diffcache = None + self.updateopts(verbose, debug, quiet, interactive) + self.diffcache = None + + def __getattr__(self, key): + return getattr(self.parentui, key) def updateopts(self, verbose=False, debug=False, quiet=False, interactive=True): @@ -49,22 +54,34 @@ class ui(object): return self.overlay[(section, name)] if self.cdata.has_option(section, name): return self.cdata.get(section, name) - return default + if self.parentui is None: + return default + else: + return self.parentui.config(section, name, default) def configbool(self, section, name, default=False): if self.overlay.has_key((section, name)): return self.overlay[(section, name)] if self.cdata.has_option(section, name): return self.cdata.getboolean(section, name) - return default + if self.parentui is None: + return default + else: + return self.parentui.configbool(section, name, default) def configitems(self, section): + items = {} + if self.parentui is not None: + items = dict(self.parentui.configitems(section)) if self.cdata.has_section(section): - return self.cdata.items(section) - return [] + items.update(dict(self.cdata.items(section))) + x = items.items() + x.sort() + return x - def walkconfig(self): - seen = {} + def walkconfig(self, seen=None): + if seen is None: + seen = {} for (section, name), value in self.overlay.iteritems(): yield section, name, value seen[section, name] = 1 @@ -73,6 +90,9 @@ class ui(object): if (section, name) in seen: continue yield section, name, value.replace('\n', '\\n') seen[section, name] = 1 + if self.parentui is not None: + for parent in self.parentui.walkconfig(seen): + yield parent def extensions(self): return self.configitems("extensions") @@ -171,3 +191,4 @@ class ui(object): os.unlink(name) return t + diff --git a/tests/test-push-hook-lock b/tests/test-push-hook-lock new file mode 100755 --- /dev/null +++ b/tests/test-push-hook-lock @@ -0,0 +1,13 @@ +#!/bin/sh +hg init 1 +echo '[ui]' >> 1/.hg/hgrc +echo 'timeout = 10' >> 1/.hg/hgrc +echo foo > 1/foo +hg --cwd 1 ci -A -m foo +hg clone 1 2 +hg clone 2 3 +echo '[hooks]' >> 2/.hg/hgrc +echo 'changegroup.push = hg push -qf ../1' >> 2/.hg/hgrc +echo bar >> 3/foo +hg --cwd 3 ci -m bar +hg --cwd 3 push ../2 diff --git a/tests/test-push-hook-lock.out b/tests/test-push-hook-lock.out new file mode 100644 --- /dev/null +++ b/tests/test-push-hook-lock.out @@ -0,0 +1,7 @@ +adding foo +pushing to ../2 +searching for changes +adding changesets +adding manifests +adding file changes +added 1 changesets with 1 changes to 1 files