From patchwork Fri Mar 22 01:20:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [08, of, 10] hg: when testing, warn if repo.ui is passed to a new peer or localrepo From: Simon Heimberg X-Patchwork-Id: 1161 Message-Id: To: Mercurial-devel Date: Fri, 22 Mar 2013 02:20:58 +0100 # HG changeset patch # User Simon Heimberg # Date 1349372803 -7200 # Node ID bc3341ad23a61fa0ad272be98cdc00cf11d4b8eb # Parent edcf5f72fdb5621bf6c1c8074ea66428932f0f96 hg: when testing, warn if repo.ui is passed to a new peer or localrepo For not getting the configuration of another repo, baseui has to be used when crating a new repository (or a new peer). Therefore we warn the programmer if the ui of a repo is passed. For not warning normal users, the warning is only printed when we are running in run-tests.py (when TESTTMP is in env), when unittest is loaded (running in a test suite of an other project) or when debugging is enabled. diff -r edcf5f72fdb5 -r bc3341ad23a6 mercurial/hg.py --- a/mercurial/hg.py Don Mär 21 18:16:49 2013 +0100 +++ b/mercurial/hg.py Don Okt 04 19:46:43 2012 +0200 @@ -609,6 +609,8 @@ src = src.ui # copy target options from repo else: # assume it's a global ui object dst = src.copy() # keep all global options + if not src.checkglobal('pass repo (not repo.ui) to hg.peer'): + dst.isglobal = True # do not repeat warning # copy ssh-specific options for o in 'ssh', 'remotecmd': diff -r edcf5f72fdb5 -r bc3341ad23a6 mercurial/localrepo.py --- a/mercurial/localrepo.py Don Mär 21 18:16:49 2013 +0100 +++ b/mercurial/localrepo.py Don Okt 04 19:46:43 2012 +0200 @@ -161,8 +161,10 @@ self.auditor = scmutil.pathauditor(self.root, self._checknested) self.vfs = scmutil.vfs(self.path) self.opener = self.vfs + baseui.checkglobal('pass a baseui (not repo.ui) when creating a repo') self.baseui = baseui self.ui = baseui.copy() + self.ui.isglobal = False # A list of callback to shape the phase if no data were found. # Callback are in the form: func(repo, roots) --> processed root. # This list it to be filled by extension during repo setup diff -r edcf5f72fdb5 -r bc3341ad23a6 mercurial/ui.py --- a/mercurial/ui.py Don Mär 21 18:16:49 2013 +0100 +++ b/mercurial/ui.py Don Okt 04 19:46:43 2012 +0200 @@ -10,6 +10,8 @@ import config, scmutil, util, error, formatter class ui(object): + isglobal = True # this is unset by the repo for its ui + def __init__(self, src=None): self._buffers = [] self.quiet = self.verbose = self.debugflag = self.tracebackflag = False @@ -34,6 +36,8 @@ self.environ = src.environ self.callhooks = src.callhooks self.fixconfig() + if not src.isglobal: + self.isglobal = False else: self.fout = sys.stdout self.ferr = sys.stderr @@ -766,3 +770,21 @@ ui.write(ui.label(s, 'label')). ''' return msg + + def checkglobal(self, warnmsg): + '''in test run, print a warning if this ui is inside a repo + + When a repo or a peer is created, it needs its own configuration. But + when it gets the ui object of another repo, the configuration from + there is copied into the new ui object. + ''' + if self.isglobal: + return True # passed + if os.environ.get('TESTTMP') or 'unittest' in sys.modules or \ + self.debugflag: + # running in a test, warn the programmer + # TESTTMP is set in mercurial test suite + # unittest is a test suite used in many projects + # debugflag is set when hg --debug was called + self.write_err('PROGRAMMER WARNING: %s\n' % warnmsg) + return False