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.
--- a/hgext/mq.py Mon Mar 06 17:34:49 2006 +0100
+++ b/hgext/mq.py Mon Mar 06 17:47:41 2006 +0100
@@ -852,7 +852,7 @@
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)
--- a/mercurial/commands.py Mon Mar 06 17:34:49 2006 +0100
+++ b/mercurial/commands.py Mon Mar 06 17:47:41 2006 +0100
@@ -780,7 +780,7 @@
f.close()
if not opts['noupdate']:
- update(ui, repo)
+ update(repo.ui, repo)
d.close()
@@ -1067,6 +1067,7 @@
"""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 @@
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 @@
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)
--- a/mercurial/localrepo.py Mon Mar 06 17:34:49 2006 +0100
+++ b/mercurial/localrepo.py Mon Mar 06 17:47:41 2006 +0100
@@ -10,12 +10,12 @@
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 @@
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 @@
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:
--- a/mercurial/ui.py Mon Mar 06 17:34:49 2006 +0100
+++ b/mercurial/ui.py Mon Mar 06 17:47:41 2006 +0100
@@ -12,18 +12,23 @@
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 @@
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 @@
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 @@
os.unlink(name)
return t
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-push-hook-lock Mon Mar 06 17:47:41 2006 +0100
@@ -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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-push-hook-lock.out Mon Mar 06 17:47:41 2006 +0100
@@ -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