Patchwork [1,of,4] contrib/synthrepo: only generate 2 parents if model contains merges

login
register
mail settings
Submitter adgar@google.com
Date Sept. 13, 2014, 4:55 p.m.
Message ID <1b1aeb594ac261750ebf.1410627341@adgar.nyc.corp.google.com>
Download mbox | patch
Permalink /patch/5817/
State Accepted
Headers show

Comments

adgar@google.com - Sept. 13, 2014, 4:55 p.m.
# HG changeset patch
# User Mike Edgar <adgar@google.com>
# Date 1410558217 14400
#      Fri Sep 12 17:43:37 2014 -0400
# Node ID 1b1aeb594ac261750ebf95c1f92257d9c1f7d3ac
# Parent  f08b657130b9ac7cd2ad27afea6895dfde7d7722
contrib/synthrepo: only generate 2 parents if model contains merges

If `hg analyze` is run on a revision set which contains no merges, then
`hg synthesize` will raise IndexError trying to select from p2distance,
which will be empty.
Pierre-Yves David - Sept. 18, 2014, 12:52 a.m.
On 09/13/2014 09:55 AM, adgar@google.com wrote:
> # HG changeset patch
> # User Mike Edgar <adgar@google.com>
> # Date 1410558217 14400
> #      Fri Sep 12 17:43:37 2014 -0400
> # Node ID 1b1aeb594ac261750ebf95c1f92257d9c1f7d3ac
> # Parent  f08b657130b9ac7cd2ad27afea6895dfde7d7722
> contrib/synthrepo: only generate 2 parents if model contains merges

This one is pushed to the clowncopter. (with a small style fixes)

>
> If `hg analyze` is run on a revision set which contains no merges, then
> `hg synthesize` will raise IndexError trying to select from p2distance,
> which will be empty.
>
> diff -r f08b657130b9 -r 1b1aeb594ac2 contrib/synthrepo.py
> --- a/contrib/synthrepo.py	Fri Sep 05 11:37:44 2014 -0700
> +++ b/contrib/synthrepo.py	Fri Sep 12 17:43:37 2014 -0400
> @@ -307,7 +307,8 @@
>
>           # the number of heads will grow without bound if we use a pure
>           # model, so artificially constrain their proliferation
> -        if pick(parents) == 2 or len(heads) > random.randint(1, 20):
> +        if p2distance[0] and (
> +            pick(parents) == 2 or len(heads) > random.randint(1, 20)):
>               r2, p2 = pickhead(heads.difference([r1]), p2distance)
>           else:
>               r2, p2 = nullrev, nullid

I killed the ugly oneliner this way:

-        if p2distance[0] and (
-            pick(parents) == 2 or len(heads) > random.randint(1, 20)):
+        toomanyheads = len(heads) > random.randint(1, 20)
+        if p2distance[0] and (pick(parents) == 2 or toomanyheads):

Patch

diff -r f08b657130b9 -r 1b1aeb594ac2 contrib/synthrepo.py
--- a/contrib/synthrepo.py	Fri Sep 05 11:37:44 2014 -0700
+++ b/contrib/synthrepo.py	Fri Sep 12 17:43:37 2014 -0400
@@ -307,7 +307,8 @@ 
 
         # the number of heads will grow without bound if we use a pure
         # model, so artificially constrain their proliferation
-        if pick(parents) == 2 or len(heads) > random.randint(1, 20):
+        if p2distance[0] and (
+            pick(parents) == 2 or len(heads) > random.randint(1, 20)):
             r2, p2 = pickhead(heads.difference([r1]), p2distance)
         else:
             r2, p2 = nullrev, nullid