[PATCH 1 of 2 V2] scmutil: extra utility to display a reasonable amount of nodes

Boris Feld boris.feld at octobus.net
Mon Nov 20 17:15:21 UTC 2017


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1510800758 -3600
#      Thu Nov 16 03:52:38 2017 +0100
# Node ID 5312b5738172718b868c1ecfd28ada8d4d7e85de
# Parent  69ea10d5b00c499f14f9b8f285a09163a592ef3e
# EXP-Topic single-heads
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 5312b5738172
scmutil: extra utility to display a reasonable amount of nodes

Push have some logic to display a reasonable amount nodes. We extract it to an
utility function to make it reusable.

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -21,6 +21,7 @@ from . import (
     branchmap,
     error,
     phases,
+    scmutil,
     setdiscovery,
     treediscovery,
     util,
@@ -365,11 +366,8 @@ def checkheads(pushop):
             if None in unsyncedheads:
                 # old remote, no heads data
                 heads = None
-            elif len(unsyncedheads) <= 4 or repo.ui.verbose:
-                heads = ' '.join(short(h) for h in unsyncedheads)
             else:
-                heads = (' '.join(short(h) for h in unsyncedheads[:4]) +
-                         ' ' + _("and %s others") % (len(unsyncedheads) - 4))
+                heads = scmutil.nodesummaries(repo, unsyncedheads)
             if heads is None:
                 repo.ui.status(_("remote has heads that are "
                                  "not known locally\n"))
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1271,3 +1271,9 @@ def registersummarycallback(repo, otr, t
             else:
                 revrange = '%s:%s' % (minrev, maxrev)
             repo.ui.status(_('new changesets %s\n') % revrange)
+
+def nodesummaries(repo, nodes, maxnumnodes=4):
+    if len(nodes) <= maxnumnodes or repo.ui.verbose:
+        return ' '.join(short(h) for h in nodes)
+    first = ' '.join(short(h) for h in nodes[:maxnumnodes])
+    return _("%s and %s others") % (first, len(nodes) - maxnumnodes)


More information about the Mercurial-devel mailing list