[PATCH 7 of 7] hg: warn if repo.ui is passed when creating a peer or a localrepo

Simon Heimberg simohe at besonet.ch
Wed Oct 24 17:41:19 CDT 2012


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1349372803 -7200
# Node ID 8d943dc8516b9189fbbf4c78cd2e308d691da659
# Parent  74e7ed12a586de71e527862b20587c365251255c
hg: warn if repo.ui is passed when creating a peer or a 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.
Because a user also sees this warning (when there is a programming error), the
message is short.

diff -r 74e7ed12a586 -r 8d943dc8516b mercurial/hg.py
--- a/mercurial/hg.py	Mit Okt 10 21:55:49 2012 +0200
+++ b/mercurial/hg.py	Don Okt 04 19:46:43 2012 +0200
@@ -596,6 +596,7 @@
         src = src.ui # copy target options from repo
     else: # assume it's a global ui object
         dst = src.copy() # keep all global options
+        src.checkglobal('pass repo (not repo.ui) to hg.peer')
 
     # copy ssh-specific options
     for o in 'ssh', 'remotecmd':
diff -r 74e7ed12a586 -r 8d943dc8516b mercurial/localrepo.py
--- a/mercurial/localrepo.py	Mit Okt 10 21:55:49 2012 +0200
+++ b/mercurial/localrepo.py	Don Okt 04 19:46:43 2012 +0200
@@ -125,8 +125,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 74e7ed12a586 -r 8d943dc8516b mercurial/ui.py
--- a/mercurial/ui.py	Mit Okt 10 21:55:49 2012 +0200
+++ 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
@@ -759,3 +761,14 @@
         ui.write(ui.label(s, 'label')).
         '''
         return msg
+
+    def checkglobal(self, warnmsg):
+        '''print a short 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 not self.isglobal:
+            self.write_err(' PROGRAMMER WARNING: %s\n' % warnmsg)
+


More information about the Mercurial-devel mailing list