Patchwork debugrevlog: cope with empty revlog files

login
register
mail settings
Submitter Augie Fackler
Date Oct. 23, 2015, 3:09 p.m.
Message ID <fc066f62eac58937b409.1445612952@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/11219/
State Accepted
Headers show

Comments

Augie Fackler - Oct. 23, 2015, 3:09 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1445612693 14400
#      Fri Oct 23 11:04:53 2015 -0400
# Branch stable
# Node ID fc066f62eac58937b40948c850cc18633d43f2cb
# Parent  27683c63f44cb58d02df2d4dc16f5ba3348d394c
debugrevlog: cope with empty revlog files

I have no idea where it came from, but my clone of Mercurial has an
empty filelog for `contrib/hgfixes/__init__.py` - it's *valid*, just
contains no nodes. Without this change, debugrevlog crashes with a
zero division error.
Sean Farley - Oct. 23, 2015, 4:06 p.m.
Augie Fackler <raf@durin42.com> writes:

> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1445612693 14400
> #      Fri Oct 23 11:04:53 2015 -0400
> # Branch stable
> # Node ID fc066f62eac58937b40948c850cc18633d43f2cb
> # Parent  27683c63f44cb58d02df2d4dc16f5ba3348d394c
> debugrevlog: cope with empty revlog files
>
> I have no idea where it came from, but my clone of Mercurial has an
> empty filelog for `contrib/hgfixes/__init__.py` - it's *valid*, just
> contains no nodes. Without this change, debugrevlog crashes with a
> zero division error.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -3037,7 +3037,10 @@ def debugrevlog(ui, repo, file_=None, **
>      totalsize = fulltotal + deltatotal
>      avgchainlen = sum(chainlengths) / numrevs
>      maxchainlen = max(chainlengths)
> -    compratio = totalrawsize / totalsize
> +    if totalsize:
> +        compratio = totalrawsize / totalsize
> +    else:
> +        compratio = 1

Minor nit: can we write this as

comratio = 1
if totalsize:
    compratio = totalrawsize / totalsize

>      basedfmtstr = '%%%dd\n'
>      basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n'
> @@ -3048,7 +3051,10 @@ def debugrevlog(ui, repo, file_=None, **
>          return basepcfmtstr % (len(str(max)), ' ' * padding)
>  
>      def pcfmt(value, total):
> -        return (value, 100 * float(value) / total)
> +        if total:
> +            return (value, 100 * float(value) / total)
> +        else:
> +            return value, 100.0

I wish the same could be done here, but (shrug).
Anton Shestakov - Oct. 23, 2015, 4:33 p.m.
24.10.2015, 00:08, "Sean Farley" <sean@farley.io>:
> Augie Fackler <raf@durin42.com> writes:
>
>>  # HG changeset patch
>>  # User Augie Fackler <augie@google.com>
>>  # Date 1445612693 14400
>>  # Fri Oct 23 11:04:53 2015 -0400
>>  # Branch stable
>>  # Node ID fc066f62eac58937b40948c850cc18633d43f2cb
>>  # Parent 27683c63f44cb58d02df2d4dc16f5ba3348d394c
>>  debugrevlog: cope with empty revlog files
>>
>>  I have no idea where it came from, but my clone of Mercurial has an
>>  empty filelog for `contrib/hgfixes/__init__.py` - it's *valid*, just
>>  contains no nodes. Without this change, debugrevlog crashes with a
>>  zero division error.
>>
>>  diff --git a/mercurial/commands.py b/mercurial/commands.py
>>  --- a/mercurial/commands.py
>>  +++ b/mercurial/commands.py
>>  @@ -3037,7 +3037,10 @@ def debugrevlog(ui, repo, file_=None, **
>>       totalsize = fulltotal + deltatotal
>>       avgchainlen = sum(chainlengths) / numrevs
>>       maxchainlen = max(chainlengths)
>>  - compratio = totalrawsize / totalsize
>>  + if totalsize:
>>  + compratio = totalrawsize / totalsize
>>  + else:
>>  + compratio = 1
>
> Minor nit: can we write this as
>
> comratio = 1
> if totalsize:
>     compratio = totalrawsize / totalsize

Even smaller nit: could be spelled as

compratio = totalrawsize / totalsize if totalsize else 1

(I mean we're bikeshedding anyway, right?)
Matt Mackall - Oct. 23, 2015, 7:56 p.m.
On Sat, 2015-10-24 at 00:33 +0800, Anton Shestakov wrote:
> 24.10.2015, 00:08, "Sean Farley" <sean@farley.io>:
> > Augie Fackler <raf@durin42.com> writes:
> > 
> > >  # HG changeset patch
> > >  # User Augie Fackler <augie@google.com>
> > >  # Date 1445612693 14400
> > >  # Fri Oct 23 11:04:53 2015 -0400
> > >  # Branch stable
> > >  # Node ID fc066f62eac58937b40948c850cc18633d43f2cb
> > >  # Parent 27683c63f44cb58d02df2d4dc16f5ba3348d394c
> > >  debugrevlog: cope with empty revlog files
> > > 
> > >  I have no idea where it came from, but my clone of Mercurial has
> > > an
> > >  empty filelog for `contrib/hgfixes/__init__.py` - it's *valid*,
> > > just
> > >  contains no nodes. Without this change, debugrevlog crashes with
> > > a
> > >  zero division error.
> > > 
> > >  diff --git a/mercurial/commands.py b/mercurial/commands.py
> > >  --- a/mercurial/commands.py
> > >  +++ b/mercurial/commands.py
> > >  @@ -3037,7 +3037,10 @@ def debugrevlog(ui, repo, file_=None, **
> > >       totalsize = fulltotal + deltatotal
> > >       avgchainlen = sum(chainlengths) / numrevs
> > >       maxchainlen = max(chainlengths)
> > >  - compratio = totalrawsize / totalsize
> > >  + if totalsize:
> > >  + compratio = totalrawsize / totalsize
> > >  + else:
> > >  + compratio = 1
> > 
> > Minor nit: can we write this as
> > 
> > comratio = 1
> > if totalsize:
> >     compratio = totalrawsize / totalsize
> 
> Even smaller nit: could be spelled as
> 
> compratio = totalrawsize / totalsize if totalsize else 1
> 
> (I mean we're bikeshedding anyway, right?)

Sean's format is our current preferred style, we haven't decided yet
whether the 2.6+ conditional format is an improvement.

-- 
Mathematics is the supreme nostalgia of our time.
Matt Mackall - Oct. 23, 2015, 7:58 p.m.
On Fri, 2015-10-23 at 11:09 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1445612693 14400
> #      Fri Oct 23 11:04:53 2015 -0400
> # Branch stable
> # Node ID fc066f62eac58937b40948c850cc18633d43f2cb
> # Parent  27683c63f44cb58d02df2d4dc16f5ba3348d394c
> debugrevlog: cope with empty revlog files

I've queued this for stable with Sean's suggested tweak, thanks.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3037,7 +3037,10 @@  def debugrevlog(ui, repo, file_=None, **
     totalsize = fulltotal + deltatotal
     avgchainlen = sum(chainlengths) / numrevs
     maxchainlen = max(chainlengths)
-    compratio = totalrawsize / totalsize
+    if totalsize:
+        compratio = totalrawsize / totalsize
+    else:
+        compratio = 1
 
     basedfmtstr = '%%%dd\n'
     basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n'
@@ -3048,7 +3051,10 @@  def debugrevlog(ui, repo, file_=None, **
         return basepcfmtstr % (len(str(max)), ' ' * padding)
 
     def pcfmt(value, total):
-        return (value, 100 * float(value) / total)
+        if total:
+            return (value, 100 * float(value) / total)
+        else:
+            return value, 100.0
 
     ui.write(('format : %d\n') % format)
     ui.write(('flags  : %s\n') % ', '.join(flags))