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

login
register
mail settings
Submitter Boris Feld
Date Nov. 20, 2017, 5:15 p.m.
Message ID <5312b5738172718b868c.1511198121@FB>
Download mbox | patch
Permalink /patch/25666/
State Accepted
Headers show

Comments

Boris Feld - Nov. 20, 2017, 5:15 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@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.
Yuya Nishihara - Dec. 2, 2017, 1:45 p.m.
On Mon, 20 Nov 2017 18:15:21 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@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

> +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)

Nit: '%s and %d others'
             ^^

Please send a follow up.

Patch

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)