[PATCH] graphlog: fix output when both a limit and a path are provided

Patrick Mézard pmezard at gmail.com
Tue Dec 15 15:07:07 CST 2009


Le 14/12/09 01:08, Nicolas Dumazet a écrit :
> # HG changeset patch
> # User Nicolas Dumazet <nicdumz.commits at gmail.com>
> # Date 1260512733 -32400
> # Node ID 0f195e3ad08945e2bfc3c4f34be337612f946bc8
> # Parent  dfc3ed37d58d921428a6a684001e4f708c445a52
> graphlog: fix output when both a limit and a path are provided
> 
> Limit was interpreted as absolute, from the topmost revision, without
> counting the number of revisions matching a given file.
> Which caused "glog -lN file" to show sometimes less than N csets if
> the file was not modified in all of the N previous csets.
> 
> glog will now match the behavior of log.
> 
> diff --git a/hgext/graphlog.py b/hgext/graphlog.py
> --- a/hgext/graphlog.py
> +++ b/hgext/graphlog.py
> @@ -241,15 +241,15 @@
>      check_unsupported_flags(opts)
>      limit = cmdutil.loglimit(opts)
>      start, stop = get_revs(repo, opts["rev"])
> -    stop = max(stop, start - limit + 1)
>      if start == nullrev:
>          return
>  
>      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:
> +        stop = max(stop, start - limit + 1)
>          revdag = graphmod.revisions(repo, start, stop)
>  
>      displayer = show_changeset(ui, repo, opts, buffered=True)
> 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

Nitpicking: I would switch both imports. Don't need to resend for this one.

>  
>  CHANGESET = 'C'
>  
> @@ -36,21 +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
> -    while filerev >= 0:
> +    if limit < sys.maxint:
> +        lower = max(0, filerev - limit + 1)
> +    else:
> +        lower = 0

Any reason to use sys.maxint instead of None?

> +    count = 0
> +    rev = stop + 1
> +    while filerev >= lower and rev > stop:
>          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:
> -            break
>          filerev -= 1
>  
>  def nodes(repo, nodes):

Looks good to me.

--
Patrick Mézard


More information about the Mercurial-devel mailing list