diff mbox

[2/2] retag: Properly display the final count

Message ID 1446914966-24803-2-git-send-email-damien.lespiau@intel.com
State Accepted
Headers show

Commit Message

Damien Lespiau Nov. 7, 2015, 4:49 p.m. UTC
i == count cannot happen in the loop as i will vary from 0 to count - 1.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 patchwork/management/commands/retag.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stephen Finucane Nov. 9, 2015, 2:37 a.m. UTC | #1
> i == count cannot happen in the loop as i will vary from 0 to count - 1.

> 

> Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>

> ---

>  patchwork/management/commands/retag.py | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/patchwork/management/commands/retag.py

> b/patchwork/management/commands/retag.py

> index e67d099..cb95398 100644

> --- a/patchwork/management/commands/retag.py

> +++ b/patchwork/management/commands/retag.py

> @@ -38,7 +38,8 @@ class Command(BaseCommand):

> 

>          for i, patch in enumerate(query.iterator()):

>              patch.refresh_tag_counts()

> -            if (i % 10) == 0 or i == count:

> +            if (i % 10) == 0:


What happens if count == 11?
 
>                  sys.stdout.write('%06d/%06d\r' % (i, count))

>                  sys.stdout.flush()

> +        sys.stdout.write('%06d/%06d\r' % (count, count))

>          sys.stdout.write('\ndone\n')

> --

> 2.4.3

> 

> _______________________________________________

> Patchwork mailing list

> Patchwork@lists.ozlabs.org

> https://lists.ozlabs.org/listinfo/patchwork
Damien Lespiau Nov. 9, 2015, 10:51 a.m. UTC | #2
On Mon, Nov 09, 2015 at 02:37:54AM +0000, Finucane, Stephen wrote:
> > i == count cannot happen in the loop as i will vary from 0 to count - 1.
> > 
> > Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
> > ---
> >  patchwork/management/commands/retag.py | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/patchwork/management/commands/retag.py
> > b/patchwork/management/commands/retag.py
> > index e67d099..cb95398 100644
> > --- a/patchwork/management/commands/retag.py
> > +++ b/patchwork/management/commands/retag.py
> > @@ -38,7 +38,8 @@ class Command(BaseCommand):
> > 
> >          for i, patch in enumerate(query.iterator()):
> >              patch.refresh_tag_counts()
> > -            if (i % 10) == 0 or i == count:
> > +            if (i % 10) == 0:
> 
> What happens if count == 11?

I don't where you are going with this question. In the loop we'll print
something out when i is 0, then 10. Out of the loop we'll print out
11/11. But that cannot be what you were asking, am I missing a question
behind the question?
Stephen Finucane Nov. 9, 2015, 2:59 p.m. UTC | #3
> On Mon, Nov 09, 2015 at 02:37:54AM +0000, Finucane, Stephen wrote:
> > > i == count cannot happen in the loop as i will vary from 0 to count -
> 1.
> > >
> > > Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
> > > ---
> > >  patchwork/management/commands/retag.py | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/patchwork/management/commands/retag.py
> > > b/patchwork/management/commands/retag.py
> > > index e67d099..cb95398 100644
> > > --- a/patchwork/management/commands/retag.py
> > > +++ b/patchwork/management/commands/retag.py
> > > @@ -38,7 +38,8 @@ class Command(BaseCommand):
> > >
> > >          for i, patch in enumerate(query.iterator()):
> > >              patch.refresh_tag_counts()
> > > -            if (i % 10) == 0 or i == count:
> > > +            if (i % 10) == 0:
> >
> > What happens if count == 11?
> 
> I don't where you are going with this question. In the loop we'll print
> something out when i is 0, then 10. Out of the loop we'll print out
> 11/11. But that cannot be what you were asking, am I missing a question
> behind the question?

That's what I get for trying to be less prescriptive heh. It doesn't help
when I give the wrong value also. I meant what happens if count == 12? From
what I can see, it should have looked like this:

    if (i % 10) == 0 or i == count - 1:

i.e. every 10th iteration, or on the last iteration. However, the presence of
the print on the line after this loop handles that last iteration case making
this statement, as you say, unnecessary. Therefore:

Acked-by: Stephen Finucane <stephen.finucane@intel.com>
Damien Lespiau Nov. 9, 2015, 3:19 p.m. UTC | #4
On Mon, Nov 09, 2015 at 02:59:49PM +0000, Finucane, Stephen wrote:
> > On Mon, Nov 09, 2015 at 02:37:54AM +0000, Finucane, Stephen wrote:
> > > > i == count cannot happen in the loop as i will vary from 0 to count -
> > 1.
> > > >
> > > > Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
> > > > ---
> > > >  patchwork/management/commands/retag.py | 3 ++-
> > > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/patchwork/management/commands/retag.py
> > > > b/patchwork/management/commands/retag.py
> > > > index e67d099..cb95398 100644
> > > > --- a/patchwork/management/commands/retag.py
> > > > +++ b/patchwork/management/commands/retag.py
> > > > @@ -38,7 +38,8 @@ class Command(BaseCommand):
> > > >
> > > >          for i, patch in enumerate(query.iterator()):
> > > >              patch.refresh_tag_counts()
> > > > -            if (i % 10) == 0 or i == count:
> > > > +            if (i % 10) == 0:
> > >
> > > What happens if count == 11?
> > 
> > I don't where you are going with this question. In the loop we'll print
> > something out when i is 0, then 10. Out of the loop we'll print out
> > 11/11. But that cannot be what you were asking, am I missing a question
> > behind the question?
> 
> That's what I get for trying to be less prescriptive heh. It doesn't help
> when I give the wrong value also. I meant what happens if count == 12? From
> what I can see, it should have looked like this:
> 
>     if (i % 10) == 0 or i == count - 1:
> 
> i.e. every 10th iteration, or on the last iteration. However, the presence of
> the print on the line after this loop handles that last iteration case making
> this statement, as you say, unnecessary. Therefore:

That wouldn't work either. On the last iteration (count - 1)/count would
be printed and count/count would never be printed.
Stephen Finucane Nov. 9, 2015, 3:20 p.m. UTC | #5
> On Mon, Nov 09, 2015 at 02:59:49PM +0000, Finucane, Stephen wrote:
> > > On Mon, Nov 09, 2015 at 02:37:54AM +0000, Finucane, Stephen wrote:
> > > > > i == count cannot happen in the loop as i will vary from 0 to count
> -
> > > 1.
> > > > >
> > > > > Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
> > > > > ---
> > > > >  patchwork/management/commands/retag.py | 3 ++-
> > > > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/patchwork/management/commands/retag.py
> > > > > b/patchwork/management/commands/retag.py
> > > > > index e67d099..cb95398 100644
> > > > > --- a/patchwork/management/commands/retag.py
> > > > > +++ b/patchwork/management/commands/retag.py
> > > > > @@ -38,7 +38,8 @@ class Command(BaseCommand):
> > > > >
> > > > >          for i, patch in enumerate(query.iterator()):
> > > > >              patch.refresh_tag_counts()
> > > > > -            if (i % 10) == 0 or i == count:
> > > > > +            if (i % 10) == 0:
> > > >
> > > > What happens if count == 11?
> > >
> > > I don't where you are going with this question. In the loop we'll print
> > > something out when i is 0, then 10. Out of the loop we'll print out
> > > 11/11. But that cannot be what you were asking, am I missing a question
> > > behind the question?
> >
> > That's what I get for trying to be less prescriptive heh. It doesn't help
> > when I give the wrong value also. I meant what happens if count == 12?
> From
> > what I can see, it should have looked like this:
> >
> >     if (i % 10) == 0 or i == count - 1:
> >
> > i.e. every 10th iteration, or on the last iteration. However, the
> presence of
> > the print on the line after this loop handles that last iteration case
> making
> > this statement, as you say, unnecessary. Therefore:
> 
> That wouldn't work either. On the last iteration (count - 1)/count would
> be printed and count/count would never be printed.

Right you are. What on earth was that code doing there at all? :)
Damien Lespiau Nov. 9, 2015, 3:26 p.m. UTC | #6
On Mon, Nov 09, 2015 at 03:20:39PM +0000, Finucane, Stephen wrote:
> > That wouldn't work either. On the last iteration (count - 1)/count would
> > be printed and count/count would never be printed.
> 
> Right you are. What on earth was that code doing there at all? :)

Actually, because i goes from 0 to count - 1, another option is to print
(i + 1)/count, and the i == count - 1 condition could then ben used.
Stephen Finucane Nov. 9, 2015, 3:30 p.m. UTC | #7
> On Mon, Nov 09, 2015 at 03:20:39PM +0000, Finucane, Stephen wrote:
> > > That wouldn't work either. On the last iteration (count - 1)/count
> would
> > > be printed and count/count would never be printed.
> >
> > Right you are. What on earth was that code doing there at all? :)
> 
> Actually, because i goes from 0 to count - 1, another option is to print
> (i + 1)/count, and the i == count - 1 condition could then ben used.

Which option would you prefer?

Stephen
Damien Lespiau Nov. 9, 2015, 3:38 p.m. UTC | #8
On Mon, Nov 09, 2015 at 03:30:22PM +0000, Finucane, Stephen wrote:
> > On Mon, Nov 09, 2015 at 03:20:39PM +0000, Finucane, Stephen wrote:
> > > > That wouldn't work either. On the last iteration (count - 1)/count
> > would
> > > > be printed and count/count would never be printed.
> > >
> > > Right you are. What on earth was that code doing there at all? :)
> > 
> > Actually, because i goes from 0 to count - 1, another option is to print
> > (i + 1)/count, and the i == count - 1 condition could then ben used.
> 
> Which option would you prefer?

counting from from 1 to count is probably better.
Stephen Finucane Nov. 12, 2015, 4:11 a.m. UTC | #9
On 07 Nov 16:49, Damien Lespiau wrote:
> i == count cannot happen in the loop as i will vary from 0 to count - 1.
> 
> Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>

Merged.
diff mbox

Patch

diff --git a/patchwork/management/commands/retag.py b/patchwork/management/commands/retag.py
index e67d099..cb95398 100644
--- a/patchwork/management/commands/retag.py
+++ b/patchwork/management/commands/retag.py
@@ -38,7 +38,8 @@  class Command(BaseCommand):
 
         for i, patch in enumerate(query.iterator()):
             patch.refresh_tag_counts()
-            if (i % 10) == 0 or i == count:
+            if (i % 10) == 0:
                 sys.stdout.write('%06d/%06d\r' % (i, count))
                 sys.stdout.flush()
+        sys.stdout.write('%06d/%06d\r' % (count, count))
         sys.stdout.write('\ndone\n')