Patchwork [STABLE] progress: stop excessive clearing (issue4801)

login
register
mail settings
Submitter Matt Mackall
Date May 6, 2016, 10:53 p.m.
Message ID <222b8170d69e74ed6970.1462575232@ruin.waste.org>
Download mbox | patch
Permalink /patch/14956/
State Accepted
Headers show

Comments

Matt Mackall - May 6, 2016, 10:53 p.m.
# HG changeset patch
# User Matt Mackall <mpm@selenic.com>
# Date 1462575186 18000
#      Fri May 06 17:53:06 2016 -0500
# Branch stable
# Node ID 222b8170d69e74ed6970a51b73e83042a1b87b92
# Parent  77de985d7c91c67650d9fba0e4b21dfdbd894eeb
progress: stop excessive clearing (issue4801)

The progress bar was being cleared on every write(), regardless of
whether it was currently displayed. This could foul up the display of
any writes that didn't include a linebreak.

In particular, the win32 mode of the color extension was turning
single prompt string writes into two writes, and the resulting
clear/write/clear/write pattern was making the prompt invisible.

We fix this by insisting that we have shown a progress bar and haven't
just cleared it (setting lastprint to 0).

Conveniently, the test suite already had instances of duplicate
clears.. that are now cleared up.
Sean Farley - May 6, 2016, 11:07 p.m.
Matt Mackall <mpm@selenic.com> writes:

> # HG changeset patch
> # User Matt Mackall <mpm@selenic.com>
> # Date 1462575186 18000
> #      Fri May 06 17:53:06 2016 -0500
> # Branch stable
> # Node ID 222b8170d69e74ed6970a51b73e83042a1b87b92
> # Parent  77de985d7c91c67650d9fba0e4b21dfdbd894eeb
> progress: stop excessive clearing (issue4801)
>
> The progress bar was being cleared on every write(), regardless of
> whether it was currently displayed. This could foul up the display of
> any writes that didn't include a linebreak.
>
> In particular, the win32 mode of the color extension was turning
> single prompt string writes into two writes, and the resulting
> clear/write/clear/write pattern was making the prompt invisible.
>
> We fix this by insisting that we have shown a progress bar and haven't
> just cleared it (setting lastprint to 0).
>
> Conveniently, the test suite already had instances of duplicate
> clears.. that are now cleared up.

Looks awesome to me! r+
Matt Harbison - May 7, 2016, 3:43 a.m.
On Fri, 06 May 2016 18:53:52 -0400, Matt Mackall <mpm@selenic.com> wrote:

> # HG changeset patch
> # User Matt Mackall <mpm@selenic.com>
> # Date 1462575186 18000
> #      Fri May 06 17:53:06 2016 -0500
> # Branch stable
> # Node ID 222b8170d69e74ed6970a51b73e83042a1b87b92
> # Parent  77de985d7c91c67650d9fba0e4b21dfdbd894eeb
> progress: stop excessive clearing (issue4801)

I still see the issue, when this is applied to 77de985d7c91.

test:

export HGRCPATH=

rm -rf foo
hg init foo
cd foo

cat > .hg/hgrc <<EOF
[merge-tools]
foo.executable = C:\Users\Matt\Projects\hg\tests\dummy-merge.bat
foo.check = prompt
foo.priority = 1

[ui]
username = foo

[extensions]
color =

[progress]
delay = -1
changedelay = -1
EOF

hg showconfig
hg version

echo 1 > xfile.txt
hg add xfile.txt
hg commit -m commit1

echo 2 > xfile.txt
hg commit -m commit2

hg update 0
echo 3 > xfile.txt
hg commit -m commit3

hg merge 1
cd ..

----------

dummy-merge.bat:

@echo off
exit 0

----------

yields:

bundle.mainreporoot=c:\Users\Matt\Projects\hg\foo
extensions.color=
merge-tools.foo.executable=C:\Users\Matt\Projects\hg\tests\dummy-merge.bat
merge-tools.foo.check=prompt
merge-tools.foo.priority=1
progress.delay=-1
progress.changedelay=-1
ui.username=foo
Mercurial Distributed SCM (version 3.5)
(see http://mercurial.selenic.com for more information)

Copyright (C) 2005-2015 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
created new head
merging xfile.txt
  _

(The last line, the blinking caret is indented one space, waiting for the  
response.)
Matt Harbison - May 7, 2016, 3:52 a.m.
On Fri, 06 May 2016 23:43:31 -0400, Matt Harbison <mharbison72@gmail.com>  
wrote:

> On Fri, 06 May 2016 18:53:52 -0400, Matt Mackall <mpm@selenic.com> wrote:
>
>> # HG changeset patch
>> # User Matt Mackall <mpm@selenic.com>
>> # Date 1462575186 18000
>> #      Fri May 06 17:53:06 2016 -0500
>> # Branch stable
>> # Node ID 222b8170d69e74ed6970a51b73e83042a1b87b92
>> # Parent  77de985d7c91c67650d9fba0e4b21dfdbd894eeb
>> progress: stop excessive clearing (issue4801)
>
> I still see the issue, when this is applied to 77de985d7c91.

Oops, disregard this.  It works.  Thanks for chasing this down.

The cd into the repo took the source repo's hg out of $PATH, so it wasn't  
running what I thought it was.  I missed this because I originally had `hg  
version` printing at the top of the script, and didn't notice the change  
when I moved it right before hitting send.
Pierre-Yves David - May 7, 2016, 12:35 p.m.
On 05/07/2016 12:53 AM, Matt Mackall wrote:
> # HG changeset patch
> # User Matt Mackall <mpm@selenic.com>
> # Date 1462575186 18000
> #      Fri May 06 17:53:06 2016 -0500
> # Branch stable
> # Node ID 222b8170d69e74ed6970a51b73e83042a1b87b92
> # Parent  77de985d7c91c67650d9fba0e4b21dfdbd894eeb
> progress: stop excessive clearing (issue4801)

Hooray, pushed.
Thanks for tracking this down.

Patch

diff -r 77de985d7c91 -r 222b8170d69e mercurial/progress.py
--- a/mercurial/progress.py	Thu May 05 16:29:31 2016 +0200
+++ b/mercurial/progress.py	Fri May 06 17:53:06 2016 -0500
@@ -163,7 +163,7 @@ 
         sys.stderr.flush()
 
     def clear(self):
-        if not shouldprint(self.ui):
+        if not self.printed or not self.lastprint or not shouldprint(self.ui):
             return
         sys.stderr.write('\r%s\r' % (' ' * self.width()))
         if self.printed:
diff -r 77de985d7c91 -r 222b8170d69e tests/test-remove.t
--- a/tests/test-remove.t	Thu May 05 16:29:31 2016 +0200
+++ b/tests/test-remove.t	Fri May 06 17:53:06 2016 -0500
@@ -322,8 +322,6 @@ 
   \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
@@ -348,8 +346,6 @@ 
   \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
@@ -374,8 +370,6 @@ 
   \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
@@ -400,8 +394,6 @@ 
   \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
@@ -429,8 +421,6 @@ 
   \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
@@ -465,8 +455,6 @@ 
   \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)
 
   $ hg rm --after nosuch
diff -r 77de985d7c91 -r 222b8170d69e tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t	Thu May 05 16:29:31 2016 +0200
+++ b/tests/test-subrepo-deep-nested-change.t	Fri May 06 17:53:06 2016 -0500
@@ -214,8 +214,6 @@ 
   \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