From patchwork Thu Nov 16 16:16:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 2] scmutil: extra utility to display a reasonable amount of nodes From: Boris Feld X-Patchwork-Id: 25608 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Thu, 16 Nov 2017 17:16:11 +0100 # HG changeset patch # User Boris Feld # Date 1510800758 -3600 # Thu Nov 16 03:52:38 2017 +0100 # Node ID c46c0f855a64868b90260da603769c8bc1ebdcf7 # Parent 75013952d8d9608f73cd45f68405fbd6ec112bf2 # EXP-Topic single-heads # Available At https://bitbucket.org/octobus/mercurial-devel/ # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c46c0f855a64 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)