[PATCH] graphlog: fix output when both a limit and a path are provided
Martin Geisler
mg at lazybytes.net
Sat Dec 12 16:27:20 CST 2009
Nicolas Dumazet <nicdumz at gmail.com> writes:
> diff --git a/hgext/graphlog.py b/hgext/graphlog.py
> --- a/hgext/graphlog.py
> +++ b/hgext/graphlog.py
> @@ -248,7 +248,7 @@
Just before the context, we have this code:
limit = cmdutil.loglimit(opts)
start, stop = get_revs(repo, opts["rev"])
stop = max(stop, start - limit + 1)
It seems to me that the adjustment of stop is no longer needed now that
we're counting the number changesets correctly based on limit?
> if path:
> path = util.canonpath(repo.root, os.getcwd(), path)
> if path: # could be reset in canonpath
> - revdag = graphmod.filerevs(repo, path, start, stop)
> + revdag = graphmod.filerevs(repo, path, start, stop, limit)
> else:
> revdag = graphmod.revisions(repo, start, stop)
>
> diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
> --- a/mercurial/graphmod.py
> +++ b/mercurial/graphmod.py
> @@ -18,6 +18,7 @@
> """
>
> from mercurial.node import nullrev
> +import sys
>
> CHANGESET = 'C'
>
> @@ -36,20 +37,25 @@
> yield (cur, CHANGESET, ctx, sorted(parents))
> cur -= 1
>
> -def filerevs(repo, path, start, stop):
> +def filerevs(repo, path, start, stop, limit=sys.maxint):
> """file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
>
> This generator function walks through the revision history of a single
> file from revision start down to revision stop.
> """
> filerev = len(repo.file(path)) - 1
> + count = 0
> while filerev >= 0:
What about counting down to limit instead of down to 0? I tried
modifying the code to do that, but after fiddling with it for an
embarrassingly long time I gave up :-)
It just seems to me that we can do it simpler since filerev is
decremented by one in each iteration, so we should not need a separate
count variable... I also think that could get rid of sys.maxint which no
longer exists in Python 3.
> fctx = repo.filectx(path, fileid=filerev)
> parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
> rev = fctx.rev()
> if rev <= start:
> yield (rev, CHANGESET, fctx.changectx(), sorted(parents))
> - if rev <= stop:
> + if limit < sys.maxint:
> + count += 1
> + if count == limit:
> + break
> + elif rev <= stop:
> break
> filerev -= 1
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20091212/c0343601/attachment.pgp>
More information about the Mercurial-devel
mailing list