[PATCH 3 of 9 (38 total)] push: ease access to current ui object

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Sat Feb 1 19:32:59 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1391129190 28800
#      Thu Jan 30 16:46:30 2014 -0800
# Node ID 912430e402d6b3ddf6c2a85247a6127f2fe852a0
# Parent  70e5daae7c52156584ee20eccc2a13e1e0752483
push: ease access to current ui object

The `pushoperation.repo.ui` attribute is very commonly used. we offer a faster way
to access it directly through the push operation object.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -22,10 +22,11 @@ class pushoperation(object):
     """
 
     def __init__(self, repo):
         # repo we push from
         self.repo = repo
+        self.ui = repo.ui
 
 def push(repo, remote, force=False, revs=None, newbranch=False):
     '''Push outgoing changesets (limited by revs) from a local
     repository to remote. Return an integer:
       - None means nothing to push
@@ -63,12 +64,12 @@ def push(repo, remote, force=False, revs
             # Informs the user that phases should have been moved when
             # applicable.
             actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()]
             phasestr = phases.phasenames[phase]
             if actualmoves:
-                pushop.repo.ui.status(_('cannot lock source repo, skipping '
-                                        'local %s phase update\n') % phasestr)
+                pushop.ui.status(_('cannot lock source repo, skipping '
+                                   'local %s phase update\n') % phasestr)
     # get local lock as we might write phase data
     locallock = None
     try:
         locallock = pushop.repo.lock()
     except IOError, err:
@@ -76,11 +77,11 @@ def push(repo, remote, force=False, revs
             raise
         # source repo cannot be locked.
         # We do not abort the push, but just disable the local phase
         # synchronisation.
         msg = 'cannot lock source repository: %s\n' % err
-        pushop.repo.ui.debug(msg)
+        pushop.ui.debug(msg)
     try:
         pushop.repo.checkpush(force, revs)
         lock = None
         unbundle = remote.capable('unbundle')
         if not unbundle:
@@ -122,11 +123,11 @@ def push(repo, remote, force=False, revs
                                 raise util.Abort(mso % ctx)
                             elif ctx.troubled():
                                 raise util.Abort(_(mst)
                                                  % (ctx.troubles()[0],
                                                     ctx))
-                    newbm = pushop.repo.ui.configlist('bookmarks', 'pushing')
+                    newbm = pushop.ui.configlist('bookmarks', 'pushing')
                     discovery.checkheads(unfi, remote, outgoing,
                                          remoteheads, newbranch,
                                          bool(inc), newbm)
 
                 # TODO: get bundlecaps from remote
@@ -190,11 +191,11 @@ def push(repo, remote, force=False, revs
                                  outgoing.commonheads,
                                  outgoing.missing)
                 cheads.extend(c.node() for c in revset)
             # even when we don't push, exchanging phase data is useful
             remotephases = remote.listkeys('phases')
-            if (pushop.repo.ui.configbool('ui', '_usedassubrepo', False)
+            if (pushop.ui.configbool('ui', '_usedassubrepo', False)
                 and remotephases    # server supports phases
                 and ret is None # nothing was pushed
                 and remotephases.get('publishing', False)):
                 # When:
                 # - this is a subrepo push
@@ -230,18 +231,18 @@ def push(repo, remote, force=False, revs
                     r = remote.pushkey('phases',
                                        newremotehead.hex(),
                                        str(phases.draft),
                                        str(phases.public))
                     if not r:
-                        pushop.repo.ui.warn(_('updating %s to public failed!\n')
-                                        % newremotehead)
-            pushop.repo.ui.debug('try to push obsolete markers to remote\n')
+                        pushop.ui.warn(_('updating %s to public failed!\n')
+                                       % newremotehead)
+            pushop.ui.debug('try to push obsolete markers to remote\n')
             obsolete.syncpush(pushop.repo, remote)
         finally:
             if lock is not None:
                 lock.release()
     finally:
         if locallock is not None:
             locallock.release()
 
-    bookmarks.updateremote(pushop.repo.ui, unfi, remote, revs)
+    bookmarks.updateremote(pushop.ui, unfi, remote, revs)
     return ret


More information about the Mercurial-devel mailing list