[PATCH 08 of 10] hg: when testing, warn if repo.ui is passed to a new peer or localrepo

Matt Mackall mpm at selenic.com
Thu Apr 18 00:36:38 CDT 2013


On Fri, 2013-03-22 at 02:20 +0100, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe at besonet.ch>
> # 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.

Well, I still am not thrilled about this approach, and I don't think the
changes you've made have made it more palatable. Having the code know
when it's running inside the test environment is not great.

Perhaps something like this:

diff -r 7d31f2e42a8a mercurial/commandserver.py
--- a/mercurial/commandserver.py	Mon Apr 15 18:57:04 2013 -0300
+++ b/mercurial/commandserver.py	Thu Apr 18 00:34:21 2013 -0500
@@ -147,6 +147,7 @@
         self.ui = repo.baseui
         self.repo = repo
         self.repoui = repo.ui
+        del self.repoui.copy # defeat copy protection
 
         if mode == 'pipe':
             self.cerr = channeledoutput(sys.stderr, sys.stdout, 'e')
diff -r 7d31f2e42a8a mercurial/localrepo.py
--- a/mercurial/localrepo.py	Mon Apr 15 18:57:04 2013 -0300
+++ b/mercurial/localrepo.py	Thu Apr 18 00:34:21 2013 -0500
@@ -163,6 +163,8 @@
         self.opener = self.vfs
         self.baseui = baseui
         self.ui = baseui.copy()
+        self.ui.copy = baseui.copy # prevent copying
+
         # 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


This mostly passes tests, though there's an interaction between mq and
color I'm sure you've noticed. Let's talk about this post-2.6.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list