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

Simon Heimberg simohe at besonet.ch
Mon Oct 22 04:55:56 CDT 2012


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1349372803 -7200
# Node ID a20a8a4dd3c5dc4d25cb38d04bff96e75b50e95f
# Parent  75053afab605dfef2f51075550fcebf6e10f80db
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 75053afab605 -r a20a8a4dd3c5 mercurial/hg.py
--- a/mercurial/hg.py	Don Okt 04 19:46:42 2012 +0200
+++ b/mercurial/hg.py	Don Okt 04 19:46:43 2012 +0200
@@ -587,6 +587,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.notinrepo('pass repo (not repo.ui) to hg.peer')
 
     # copy ssh-specific options
     for o in 'ssh', 'remotecmd':
diff -r 75053afab605 -r a20a8a4dd3c5 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Don Okt 04 19:46:42 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.notinrepo('pass a baseui (not repo.ui) when creating a repo')
         self.baseui = baseui
         self.ui = baseui.copy()
+        self.ui.isinrepo = True
         # 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 75053afab605 -r a20a8a4dd3c5 mercurial/ui.py
--- a/mercurial/ui.py	Don Okt 04 19:46:42 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):
+    isinrepo = False # this is set 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 notinrepo(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 self.isinrepo:
+            src.write_err(' PROGRAMMER WARNING: %s\n' % warnmsg)
+


More information about the Mercurial-devel mailing list