Patchwork [3,of,3] remove: add progress support

login
register
mail settings
Submitter timeless@mozdev.org
Date March 21, 2016, 4:25 a.m.
Message ID <1d7704a6d5dfd1a1a09c.1458534312@waste.org>
Download mbox | patch
Permalink /patch/14015/
State Superseded
Headers show

Comments

timeless@mozdev.org - March 21, 2016, 4:25 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1458248602 0
#      Thu Mar 17 21:03:22 2016 +0000
# Node ID 1d7704a6d5dfd1a1a09cc337fe57cd4c41e3a27d
# Parent  47a0e2e459081990c948408b268bd3d01e077290
remove: add progress support
Anton Shestakov - March 21, 2016, 5:01 a.m.
21.03.2016, 12:25, "timeless" <timeless@mozdev.org>:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1458248602 0
> # Thu Mar 17 21:03:22 2016 +0000
> # Node ID 1d7704a6d5dfd1a1a09cc337fe57cd4c41e3a27d
> # Parent 47a0e2e459081990c948408b268bd3d01e077290
> remove: add progress support
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -2407,7 +2407,10 @@
>      else:
>          warn = False
>
> - for subpath in sorted(wctx.substate):
> + subs = sorted(wctx.substate)
> + total = len(subs)
> + count = 0
> + for subpath in subs:
>          def matchessubrepo(matcher, subpath):
>              if matcher.exact(subpath):
>                  return True
> @@ -2416,7 +2419,10 @@
>                      return True
>              return False
>
> + count += 1
>          if subrepos or matchessubrepo(m, subpath):
> + ui.progress(_('searching'), count, total=total, unit=_('subrepos'))
> +
>              sub = wctx.sub(subpath)
>              try:
>                  submatch = matchmod.subdirmatcher(subpath, m)
> @@ -2426,16 +2432,22 @@
>              except error.LookupError:
>                  warnings.append(_("skipping missing subrepository: %s\n")
>                                 % join(subpath))
> + ui.progress(_('searching'), None)
>
>      # warn about failure to delete explicit files/dirs
>      deleteddirs = util.dirs(deleted)
> - for f in m.files():
> + files = m.files()
> + total = len(files)
> + count = 0
> + for f in files:
>          def insubrepo():
>              for subpath in wctx.substate:
>                  if f.startswith(subpath):
>                      return True
>              return False
>
> + count += 1
> + ui.progress(_('deleting'), count, total=total, unit=_('file'))

This one unit is still singular.
timeless - March 21, 2016, 8:19 p.m.
In case people are curious, check-code can't easily check for this
because it replaces the contents of strings with 'x's and thus you
can't check that side of things. And while we could add an assert or a
validator, that'd be fairly painful for not much benefit. *sigh*.
(It is possible to teach check-code to rescan a range against the
original string to see if it's a match, but even that is fairly heavy
for not much benefit...

On Mon, Mar 21, 2016 at 1:01 AM, Anton Shestakov <engored@ya.ru> wrote:
> 21.03.2016, 12:25, "timeless" <timeless@mozdev.org>:
>> # HG changeset patch
>> # User timeless <timeless@mozdev.org>
>> # Date 1458248602 0
>> # Thu Mar 17 21:03:22 2016 +0000
>> # Node ID 1d7704a6d5dfd1a1a09cc337fe57cd4c41e3a27d
>> # Parent 47a0e2e459081990c948408b268bd3d01e077290
>> remove: add progress support
>>
>> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
>> --- a/mercurial/cmdutil.py
>> +++ b/mercurial/cmdutil.py
>> @@ -2407,7 +2407,10 @@
>>      else:
>>          warn = False
>>
>> - for subpath in sorted(wctx.substate):
>> + subs = sorted(wctx.substate)
>> + total = len(subs)
>> + count = 0
>> + for subpath in subs:
>>          def matchessubrepo(matcher, subpath):
>>              if matcher.exact(subpath):
>>                  return True
>> @@ -2416,7 +2419,10 @@
>>                      return True
>>              return False
>>
>> + count += 1
>>          if subrepos or matchessubrepo(m, subpath):
>> + ui.progress(_('searching'), count, total=total, unit=_('subrepos'))
>> +
>>              sub = wctx.sub(subpath)
>>              try:
>>                  submatch = matchmod.subdirmatcher(subpath, m)
>> @@ -2426,16 +2432,22 @@
>>              except error.LookupError:
>>                  warnings.append(_("skipping missing subrepository: %s\n")
>>                                 % join(subpath))
>> + ui.progress(_('searching'), None)
>>
>>      # warn about failure to delete explicit files/dirs
>>      deleteddirs = util.dirs(deleted)
>> - for f in m.files():
>> + files = m.files()
>> + total = len(files)
>> + count = 0
>> + for f in files:
>>          def insubrepo():
>>              for subpath in wctx.substate:
>>                  if f.startswith(subpath):
>>                      return True
>>              return False
>>
>> + count += 1
>> + ui.progress(_('deleting'), count, total=total, unit=_('file'))
>
> This one unit is still singular.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2407,7 +2407,10 @@ 
     else:
         warn = False
 
-    for subpath in sorted(wctx.substate):
+    subs = sorted(wctx.substate)
+    total = len(subs)
+    count = 0
+    for subpath in subs:
         def matchessubrepo(matcher, subpath):
             if matcher.exact(subpath):
                 return True
@@ -2416,7 +2419,10 @@ 
                     return True
             return False
 
+        count += 1
         if subrepos or matchessubrepo(m, subpath):
+            ui.progress(_('searching'), count, total=total, unit=_('subrepos'))
+
             sub = wctx.sub(subpath)
             try:
                 submatch = matchmod.subdirmatcher(subpath, m)
@@ -2426,16 +2432,22 @@ 
             except error.LookupError:
                 warnings.append(_("skipping missing subrepository: %s\n")
                                % join(subpath))
+    ui.progress(_('searching'), None)
 
     # warn about failure to delete explicit files/dirs
     deleteddirs = util.dirs(deleted)
-    for f in m.files():
+    files = m.files()
+    total = len(files)
+    count = 0
+    for f in files:
         def insubrepo():
             for subpath in wctx.substate:
                 if f.startswith(subpath):
                     return True
             return False
 
+        count += 1
+        ui.progress(_('deleting'), count, total=total, unit=_('file'))
         isdir = f in deleteddirs or wctx.hasdir(f)
         if f in repo.dirstate or isdir or f == '.' or insubrepo():
             continue
@@ -2449,28 +2461,49 @@ 
                         % m.rel(f))
         # missing files will generate a warning elsewhere
         ret = 1
+    ui.progress(_('deleting'), None)
 
     if force:
         list = modified + deleted + clean + added
     elif after:
         list = deleted
-        for f in modified + added + clean:
-            warnings.append(_('not removing %s: file still exists\n') % m.rel(f))
+        remaining = modified + added + clean
+        total = len(remaining)
+        count = 0
+        for f in remaining:
+            count += 1
+            ui.progress(_('skipping'), count, total=total, unit=_('files'))
+            warnings.append(_('not removing %s: file still exists\n')
+                    % m.rel(f))
             ret = 1
+        ui.progress(_('skipping'), None)
     else:
         list = deleted + clean
+        total = len(modified) + len(added)
+        count = 0
         for f in modified:
+            count += 1
+            ui.progress(_('skipping'), count, total=total, unit=_('files'))
             warnings.append(_('not removing %s: file is modified (use -f'
                       ' to force removal)\n') % m.rel(f))
             ret = 1
         for f in added:
+            count += 1
+            ui.progress(_('skipping'), count, total=total, unit=_('files'))
             warnings.append(_('not removing %s: file has been marked for add'
                       ' (use forget to undo)\n') % m.rel(f))
             ret = 1
-
-    for f in sorted(list):
+        ui.progress(_('skipping'), None)
+
+    list = sorted(list)
+    total = len(list)
+    count = 0
+    for f in list:
+        count += 1
         if ui.verbose or not m.exact(f):
+            ui.progress(_('deleting'), count, total=total, unit=_('files'))
             ui.status(_('removing %s\n') % m.rel(f))
+    ui.progress(_('deleting'), None)
 
     with repo.wlock():
         if not after:
diff --git a/tests/test-remove.t b/tests/test-remove.t
--- a/tests/test-remove.t
+++ b/tests/test-remove.t
@@ -26,6 +26,9 @@ 
 file not managed
 
   $ remove foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   not removing foo: file is untracked
   exit code: 1
   ? foo
@@ -41,6 +44,12 @@ 
   $ echo b > bar
   $ hg add bar
   $ remove bar
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  skipping [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   not removing bar: file has been marked for add (use forget to undo)
   exit code: 1
   A bar
@@ -54,6 +63,9 @@ 
 01 state clean, options none
 
   $ remove foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   ? bar
@@ -67,6 +79,12 @@ 
 
   $ echo b >> foo
   $ remove foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  skipping [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   not removing foo: file is modified (use -f to force removal)
   exit code: 1
   M foo
@@ -82,6 +100,9 @@ 
 
   $ rm foo
   $ remove foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   ? bar
@@ -96,6 +117,9 @@ 
   $ echo b > bar
   $ hg add bar
   $ remove -f bar
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   ? bar
   ./bar
@@ -106,6 +130,9 @@ 
 11 state clean, options -f
 
   $ remove -f foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   \r (no-eol) (esc)
@@ -117,6 +144,9 @@ 
 
   $ echo b >> foo
   $ remove -f foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   \r (no-eol) (esc)
@@ -128,6 +158,9 @@ 
 
   $ rm foo
   $ remove -f foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   \r (no-eol) (esc)
@@ -140,6 +173,12 @@ 
   $ echo b > bar
   $ hg add bar
   $ remove -A bar
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  skipping [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   not removing bar: file still exists
   exit code: 1
   A bar
@@ -153,6 +192,12 @@ 
 21 state clean, options -A
 
   $ remove -A foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  skipping [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   not removing foo: file still exists
   exit code: 1
   ? bar
@@ -164,6 +209,12 @@ 
 
   $ echo b >> foo
   $ remove -A foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  skipping [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   not removing foo: file still exists
   exit code: 1
   M foo
@@ -179,6 +230,9 @@ 
 
   $ rm foo
   $ remove -A foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   ? bar
@@ -193,6 +247,9 @@ 
   $ echo b > bar
   $ hg add bar
   $ remove -Af bar
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   ? bar
   ./bar
@@ -203,6 +260,9 @@ 
 31 state clean, options -Af
 
   $ remove -Af foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   ./foo
@@ -215,6 +275,9 @@ 
 
   $ echo b >> foo
   $ remove -Af foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   ./foo
@@ -227,6 +290,9 @@ 
 
   $ rm foo
   $ remove -Af foo
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   exit code: 0
   R foo
   \r (no-eol) (esc)
@@ -247,6 +313,17 @@ 
 
   $ rm test/bar
   $ remove test
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [=====================>                      ] 1/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 2/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   removing test/bar (glob)
   removing test/foo (glob)
   exit code: 0
@@ -262,6 +339,17 @@ 
 
   $ rm test/bar
   $ remove -f test
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [=====================>                      ] 1/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 2/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   removing test/bar (glob)
   removing test/foo (glob)
   exit code: 0
@@ -277,6 +365,17 @@ 
 
   $ rm test/bar
   $ remove -A test
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  skipping [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   removing test/bar (glob)
   not removing test/foo: file still exists (glob)
   exit code: 1
@@ -292,6 +391,17 @@ 
 
   $ rm test/bar
   $ remove -Af test
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [=====================>                      ] 1/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 2/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   removing test/bar (glob)
   removing test/foo (glob)
   exit code: 0
@@ -313,6 +423,14 @@ 
   adding issue1861/b/c/y
   adding issue1861/x
   $ hg rm issue1861/b
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   removing issue1861/b/c/y (glob)
   $ hg ci -m remove
   $ ls issue1861
@@ -333,11 +451,22 @@ 
   $ mkdir d1
   $ echo a > d1/a
   $ hg rm --after d1
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   not removing d1: no tracked files
   [1]
   $ hg add d1/a
   $ rm d1/a
   $ hg rm --after d1
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   removing d1/a (glob)
 #if windows
   $ hg rm --after nosuch
@@ -346,5 +475,8 @@ 
 #else
   $ hg rm --after nosuch
   nosuch: No such file or directory
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   [1]
 #endif
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -204,6 +204,18 @@ 
 .. but first take a detour through some deep removal testing
 
   $ hg remove -S -I 're:.*.txt' .
+  \r (no-eol) (esc)
+  searching [==========================================>] 1/1\r (no-eol) (esc)
+  searching [==========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [=====================>                      ] 1/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 2/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   removing sub1/sub2/folder/test.txt (glob)
   removing sub1/sub2/test.txt (glob)
   $ hg status -S
@@ -211,9 +223,37 @@ 
   R sub1/sub2/test.txt
   $ hg update -Cq
   $ hg remove -I 're:.*.txt' sub1
+  \r (no-eol) (esc)
+  searching [==========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   $ hg status -S
   $ hg remove sub1/sub2/folder/test.txt
+  \r (no-eol) (esc)
+  searching [==========================================>] 1/1\r (no-eol) (esc)
+  searching [==========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   $ hg remove sub1/.hgsubstate
+  \r (no-eol) (esc)
+  searching [==========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   $ mv sub1/.hgsub sub1/x.hgsub
   $ hg status -S
   warning: subrepo spec file 'sub1/.hgsub' not found
@@ -247,6 +287,9 @@ 
 
 Archive wdir() with subrepos
   $ hg rm main
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   $ hg archive -S -r 'wdir()' ../wdir
   \r (no-eol) (esc)
   archiving [                                           ] 0/3\r (no-eol) (esc)
@@ -853,6 +896,10 @@ 
 Test .hgsubstate in the R state
 
   $ hg rm .hgsub .hgsubstate
+  \r (no-eol) (esc)
+  deleting [=====================>                      ] 1/2\r (no-eol) (esc)
+  deleting [===========================================>] 2/2\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
   $ hg ci -m 'trash subrepo tracking'
 
   $ hg log -r "subrepo('re:sub\d+')" --style compact