[PATCH] debugrevlog: cope with empty revlog files
Sean Farley
sean at farley.io
Fri Oct 23 11:06:50 CDT 2015
Augie Fackler <raf at durin42.com> writes:
> # HG changeset patch
> # User Augie Fackler <augie at 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).
More information about the Mercurial-devel
mailing list