Patchwork [06,of,12,V2] summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 15, 2014, 3:52 p.m.
Message ID <3bab5cfe2a9d218851b8.1397577147@juju>
Download mbox | patch
Permalink /patch/4363/
State Accepted
Commit f0003f989e724af21ece0f7d79d633c5d9fef3c8
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 3bab5cfe2a9d218851b80786d69634e88eb77972
# Parent  8b4ee4203f00b80ed8fb2d07886d296ca8010008
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check

This patch introduces "summaryremotehooks" to avoid redundant
incoming/outgoing check for "hg summary" in other than
"commands.summary".

Only if "--remote" is not specified for "hg summary", hooks registered
in "summaryremotehooks" are invoked with "None" as "changes" argument
at first, and they should return tuple of two booleans meaning
"whether incomings are needed" and "whether outgoings are needed".

If no hooks return tuple containing "True", "hg summary" does nothing
any more, because incoming/outgoing check is not needed.

Otherwise, hooks are invoked again: at this time, "changes" argument
refers the result of incoming/outgoing check.

This patch also prevents RepoError from being raised if "--remote" is
not specified for "hg summary", because of backward compatibility for
"hg summary --large" without "--remote".

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2327,6 +2327,16 @@ 
 # a list of (ui, repo) functions called by commands.summary
 summaryhooks = util.hooks()
 
+# a list of (ui, repo, opts, changes) functions called by commands.summary.
+#
+# functions should return tuple of booleans below, if 'changes' is None:
+#  (whether-incomings-are-needed, whether-outgoings-are-needed)
+#
+# otherwise, 'changes' is a tuple of tuples below:
+#  - (sourceurl, sourcebranch, sourcepeer, incoming)
+#  - (desturl,   destbranch,   destpeer,   outgoing)
+summaryremotehooks = util.hooks()
+
 # A list of state files kept by multistep operations like graft.
 # Since graft cannot be aborted, it is considered 'clearable' by update.
 # note: bisect is intentionally excluded
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5558,11 +5558,23 @@ 
         needsincoming, needsoutgoing = True, True
     else:
         needsincoming, needsoutgoing = False, False
+        for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None):
+            if i:
+                needsincoming = True
+            if o:
+                needsoutgoing = True
+        if not needsincoming and not needsoutgoing:
+            return
 
     def getincoming():
         source, branches = hg.parseurl(ui.expandpath('default'))
         sbranch = branches[0]
-        other = hg.peer(repo, {}, source)
+        try:
+            other = hg.peer(repo, {}, source)
+        except error.RepoError:
+            if opts.get('remote'):
+                raise
+            return source, sbranch, None, None, None
         revs, checkout = hg.addbranchrevs(repo, other, branches, None)
         if revs:
             revs = [other.lookup(rev) for rev in revs]
@@ -5582,8 +5594,16 @@ 
         dbranch = branches[0]
         revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
         if source != dest:
-            dother = hg.peer(repo, {}, dest)
+            try:
+                dother = hg.peer(repo, {}, dest)
+            except error.RepoError:
+                if opts.get('remote'):
+                    raise
+                return dest, dbranch, None, None
             ui.debug('comparing with %s\n' % util.hidepassword(dest))
+        elif sother is None:
+            # there is no explicit destination peer, but source one is invalid
+            return dest, dbranch, None, None
         else:
             dother = sother
         if (source != dest or (sbranch is not None and sbranch != dbranch)):
@@ -5628,6 +5648,10 @@ 
             # i18n: column positioning for "hg summary"
             ui.status(_('remote: (synced)\n'))
 
+    cmdutil.summaryremotehooks(ui, repo, opts,
+                               ((source, sbranch, sother, commoninc),
+                                (dest, dbranch, dother, outgoing)))
+
 @command('tag',
     [('f', 'force', None, _('force tag')),
     ('l', 'local', None, _('make the tag local')),