Patchwork [03,of,11,sparse] sparse: move printing of sparse config changes function into core

login
register
mail settings
Submitter Gregory Szorc
Date July 8, 2017, 11:28 p.m.
Message ID <43da636d83fc5e4eae97.1499556538@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22128/
State Accepted
Headers show

Comments

Gregory Szorc - July 8, 2017, 11:28 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1499546059 25200
#      Sat Jul 08 13:34:19 2017 -0700
# Node ID 43da636d83fc5e4eae97a6c3b526552407a4ec77
# Parent  b54b5a5d05a19ad9d2b4b52f72a87fc4706cba3e
sparse: move printing of sparse config changes function into core

As part of the port, all arguments now have default values of 0.
Strings are now also given the i18n treatment.
via Mercurial-devel - July 9, 2017, 10:07 p.m.
On Sat, Jul 8, 2017 at 4:28 PM, Gregory Szorc <gregory.szorc@gmail.com> wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1499546059 25200
> #      Sat Jul 08 13:34:19 2017 -0700
> # Node ID 43da636d83fc5e4eae97a6c3b526552407a4ec77
> # Parent  b54b5a5d05a19ad9d2b4b52f72a87fc4706cba3e
> sparse: move printing of sparse config changes function into core

I've queued up to here for now, thanks!

Patch

diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -374,7 +374,8 @@  def debugsparse(ui, repo, *pats, **opts)
                 len,
                 sparse.refreshwdir(repo, repo.status(), sparse.matcher(repo),
                                    force=force))
-            _verbose_output(ui, opts, 0, 0, 0, *fcounts)
+            sparse.printchanges(ui, opts, added=fcounts[0], dropped=fcounts[1],
+                                conflicting=fcounts[2])
         finally:
             wlock.release()
 
@@ -437,8 +438,8 @@  def _config(ui, repo, pats, opts, includ
                             len(oldinclude - newinclude))
             excludecount = (len(newexclude - oldexclude) -
                             len(oldexclude - newexclude))
-            _verbose_output(
-                ui, opts, profilecount, includecount, excludecount, *fcounts)
+            sparse.printchanges(ui, opts, profilecount, includecount,
+                                excludecount, *fcounts)
         except Exception:
             sparse.writeconfig(repo, oldinclude, oldexclude, oldprofiles)
             raise
@@ -500,32 +501,5 @@  def _import(ui, repo, files, opts, force
                 sparse.writeconfig(repo, oincludes, oexcludes, oprofiles)
                 raise
 
-        _verbose_output(ui, opts, profilecount, includecount, excludecount,
-                        *fcounts)
-
-def _verbose_output(ui, opts, profilecount, includecount, excludecount, added,
-                    dropped, lookup):
-    """Produce --verbose and templatable output
-
-    This specifically enables -Tjson, providing machine-readable stats on how
-    the sparse profile changed.
-
-    """
-    with ui.formatter('sparse', opts) as fm:
-        fm.startitem()
-        fm.condwrite(ui.verbose, 'profiles_added', 'Profile # change: %d\n',
-                     profilecount)
-        fm.condwrite(ui.verbose, 'include_rules_added',
-                     'Include rule # change: %d\n', includecount)
-        fm.condwrite(ui.verbose, 'exclude_rules_added',
-                     'Exclude rule # change: %d\n', excludecount)
-        # In 'plain' verbose mode, mergemod.applyupdates already outputs what
-        # files are added or removed outside of the templating formatter
-        # framework. No point in repeating ourselves in that case.
-        if not fm.isplain():
-            fm.condwrite(ui.verbose, 'files_added', 'Files added: %d\n',
-                         added)
-            fm.condwrite(ui.verbose, 'files_dropped', 'Files dropped: %d\n',
-                         dropped)
-            fm.condwrite(ui.verbose, 'files_conflicting',
-                         'Files conflicting: %d\n', lookup)
+        sparse.printchanges(ui, opts, profilecount, includecount, excludecount,
+                            *fcounts)
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -512,3 +512,26 @@  def clearrules(repo, force=False):
         oldmatch = matcher(repo)
         writeconfig(repo, set(), set(), profiles)
         refreshwdir(repo, oldstatus, oldmatch, force=force)
+
+def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0,
+                 added=0, dropped=0, conflicting=0):
+    """Print output summarizing sparse config changes."""
+    with ui.formatter('sparse', opts) as fm:
+        fm.startitem()
+        fm.condwrite(ui.verbose, 'profiles_added', _('Profiles changed: %d\n'),
+                     profilecount)
+        fm.condwrite(ui.verbose, 'include_rules_added',
+                     _('Include rules changed: %d\n'), includecount)
+        fm.condwrite(ui.verbose, 'exclude_rules_added',
+                     _('Exclude rules changed: %d\n'), excludecount)
+
+        # In 'plain' verbose mode, mergemod.applyupdates already outputs what
+        # files are added or removed outside of the templating formatter
+        # framework. No point in repeating ourselves in that case.
+        if not fm.isplain():
+            fm.condwrite(ui.verbose, 'files_added', _('Files added: %d\n'),
+                         added)
+            fm.condwrite(ui.verbose, 'files_dropped', _('Files dropped: %d\n'),
+                         dropped)
+            fm.condwrite(ui.verbose, 'files_conflicting',
+                         _('Files conflicting: %d\n'), conflicting)
diff --git a/tests/test-sparse-verbose-json.t b/tests/test-sparse-verbose-json.t
--- a/tests/test-sparse-verbose-json.t
+++ b/tests/test-sparse-verbose-json.t
@@ -35,9 +35,9 @@  Verify basic --include and --reset
   $ hg debugsparse --clear-rules
   $ hg debugsparse --include 'hide' --verbose
   removing show
-  Profile # change: 0
-  Include rule # change: 1
-  Exclude rule # change: 0
+  Profiles changed: 0
+  Include rules changed: 1
+  Exclude rules changed: 0
 
   $ hg debugsparse --reset -Tjson
   [
@@ -53,9 +53,9 @@  Verify basic --include and --reset
   $ hg debugsparse --include 'hide'
   $ hg debugsparse --reset --verbose
   getting show
-  Profile # change: 0
-  Include rule # change: -1
-  Exclude rule # change: 0
+  Profiles changed: 0
+  Include rules changed: -1
+  Exclude rules changed: 0
 
 Verifying that problematic files still allow us to see the deltas when forcing:
 
@@ -77,6 +77,6 @@  Verifying that problematic files still a
   pending changes to 'hide'
   $ hg debugsparse --delete 'show*' --force --verbose
   pending changes to 'hide'
-  Profile # change: 0
-  Include rule # change: -1
-  Exclude rule # change: 0
+  Profiles changed: 0
+  Include rules changed: -1
+  Exclude rules changed: 0