sparse: move printing of sparse config changes function into core
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 08 Jul 2017 13:34:19 -0700
changeset 33355 9087f9997f42
parent 33354 4695f1829045
child 33356 ccb3e5399921
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.
hgext/sparse.py
mercurial/sparse.py
tests/test-sparse-verbose-json.t
--- a/hgext/sparse.py	Sat Jul 08 13:19:38 2017 -0700
+++ b/hgext/sparse.py	Sat Jul 08 13:34:19 2017 -0700
@@ -374,7 +374,8 @@
                 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 @@
                             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 @@
                 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)
--- a/mercurial/sparse.py	Sat Jul 08 13:19:38 2017 -0700
+++ b/mercurial/sparse.py	Sat Jul 08 13:34:19 2017 -0700
@@ -512,3 +512,26 @@
         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)
--- a/tests/test-sparse-verbose-json.t	Sat Jul 08 13:19:38 2017 -0700
+++ b/tests/test-sparse-verbose-json.t	Sat Jul 08 13:34:19 2017 -0700
@@ -35,9 +35,9 @@
   $ 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 @@
   $ 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 @@
   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