Patchwork [04,of,12,V2] summary: separate checking incoming/outgoing and showing remote summary

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 15, 2014, 3:52 p.m.
Message ID <162bfdc3ba21fd9fade4.1397577145@juju>
Download mbox | patch
Permalink /patch/4362/
State Accepted
Commit 7f875ed19475077e6de38631b5afd0f7b5c9bc4c
Headers show

Comments

Katsunori FUJIWARA - April 15, 2014, 3:52 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1397576244 -32400
#      Wed Apr 16 00:37:24 2014 +0900
# Node ID 162bfdc3ba21fd9fade4c997e4ad0ca6fc7e3a1e
# Parent  15a3e3a74654616426e6170c79a0f9d6cd575b22
summary: separate checking incoming/outgoing and showing remote summary

This patch separates checking incoming/outgoing and showing remote
summary, as a preparation for refactoring in succeeding patches,
because:

  - checking incoming/outgoing may be needed, even if "--remote" is
    not specified for "hg summary"

  - checking incoming/outgoing may not be needed simultaneously

"hg summary --large" without "--remote" is typical case for these.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5555,7 +5555,11 @@ 
     cmdutil.summaryhooks(ui, repo)
 
     if opts.get('remote'):
-        t = []
+        needsincoming, needsoutgoing = True, True
+    else:
+        needsincoming, needsoutgoing = False, False
+
+    def getincoming():
         source, branches = hg.parseurl(ui.expandpath('default'))
         sbranch = branches[0]
         other = hg.peer(repo, {}, source)
@@ -5565,28 +5569,48 @@ 
         ui.debug('comparing with %s\n' % util.hidepassword(source))
         repo.ui.pushbuffer()
         commoninc = discovery.findcommonincoming(repo, other, heads=revs)
-        _common, incoming, _rheads = commoninc
         repo.ui.popbuffer()
-        if incoming:
-            t.append(_('1 or more incoming'))
-
+        return source, sbranch, other, commoninc, commoninc[1]
+
+    if needsincoming:
+        source, sbranch, sother, commoninc, incoming = getincoming()
+    else:
+        source = sbranch = sother = commoninc = incoming = None
+
+    def getoutgoing():
         dest, branches = hg.parseurl(ui.expandpath('default-push', 'default'))
         dbranch = branches[0]
         revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
         if source != dest:
-            other = hg.peer(repo, {}, dest)
+            dother = hg.peer(repo, {}, dest)
             ui.debug('comparing with %s\n' % util.hidepassword(dest))
+        else:
+            dother = sother
         if (source != dest or (sbranch is not None and sbranch != dbranch)):
-            commoninc = None
+            common = None
+        else:
+            common = commoninc
         if revs:
             revs = [repo.lookup(rev) for rev in revs]
         repo.ui.pushbuffer()
-        outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs,
-                                                commoninc=commoninc)
+        outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs,
+                                                commoninc=common)
         repo.ui.popbuffer()
+        return dest, dbranch, dother, outgoing
+
+    if needsoutgoing:
+        dest, dbranch, dother, outgoing = getoutgoing()
+    else:
+        dest = dbranch = dother = outgoing = None
+
+    if opts.get('remote'):
+        t = []
+        if incoming:
+            t.append(_('1 or more incoming'))
         o = outgoing.missing
         if o:
             t.append(_('%d outgoing') % len(o))
+        other = dother or sother
         if 'bookmarks' in other.listkeys('namespaces'):
             lmarks = repo.listkeys('bookmarks')
             rmarks = other.listkeys('bookmarks')