[PATCH 1 of 2] graphmod: make revisionsand filerevs yield parents or children

Benoit Boissinot benoit.boissinot at ens-lyon.org
Sun Apr 4 18:41:25 CDT 2010


On Sun, Apr 04, 2010 at 11:39:52PM +0530, Vishakh wrote:
> # HG changeset patch
> # User Vishakh <vsh426 at gmail.com>
> # Date 1270404024 -19800
> # Node ID 8f5646c4358358a4249273285793544f6e466443
> # Parent  cd0c49bdbfd9edab18c3656d8a8a0bd27a9aa82a
> graphmod: make revisionsand filerevs yield parents or children
> 
> diff -r cd0c49bdbfd9 -r 8f5646c43583 mercurial/graphmod.py
> --- a/mercurial/graphmod.py	Thu Apr 01 17:51:59 2010 -0500
> +++ b/mercurial/graphmod.py	Sun Apr 04 23:30:24 2010 +0530
> @@ -25,16 +25,23 @@
>  
> -    cur = start
> -    while cur >= stop:
> +    if start < 0 :
> +        return

Why this test? (should it test for nullrev instead?)
> +
> +    step = start >= stop and -1 or 1

This should probably be folded into the test below, that would be
cleaner.

> +    if start >= stop:
> +        relation = lambda c: [r.rev() for r in c.parents() if r.rev() != nullrev]
> +    else:
> +        relation = lambda c: [r.rev() for r in c.children()]

calling children() lots of time will be expensive, it will walk the DAG
each time.

> +
> +    for cur in xrange(start, stop + step, step):
>          ctx = repo[cur]
> -        parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev]
> -        yield (cur, CHANGESET, ctx, sorted(parents))
> -        cur -= 1
> +        relatives = relation(ctx)
> +        yield (cur, CHANGESET, ctx, sorted(relatives))
>  
>  def filerevs(repo, path, start, stop, limit=None):
>      """file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
> @@ -43,6 +50,7 @@
>      file from revision start down to revision stop.
>      """
>      filerev = len(repo.file(path)) - 1
> +    start, stop = max(start, stop), min(start, stop)
>      rev = stop + 1
>      count = 0
>      while filerev >= 0 and rev > stop:
> @@ -56,6 +64,7 @@
>                  break
>          filerev -= 1
>  
> +

We usually try not to add whitespace, is there a reason why you added
it?

Benoit

-- 
:wq


More information about the Mercurial-devel mailing list