[PATCH] graphlog: add --only-branch and --except-branch options to glog

David Soria Parra sn_ at gmx.net
Mon Nov 17 11:20:45 CST 2008


Hi Peter,

I'm not sure about what the patch does (and the commit message is really 
not enough explanation), but guessing from the oneliner: Does 
--only-branch is more or less what --follow is in log ? If it is so, we 
should try to use the same names for the flags. Otherwise sorry for the 
noise.

David

Peter Arrenbrecht wrote:
> # HG changeset patch
> # User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
> # Date 1226938976 -3600
> # Node ID ab6a3d686136261beb4623583ddce5edb9b0edd0
> # Parent  de304148dfd96f03226ff201819a2a5bbe072121
> graphlog: add --only-branch and --except-branch options to glog
> 
> diff --git a/hgext/graphlog.py b/hgext/graphlog.py
> --- a/hgext/graphlog.py
> +++ b/hgext/graphlog.py
> @@ -14,7 +14,10 @@
>  from mercurial.node import nullrev
>  from mercurial.util import Abort, canonpath
>  
> -def revisions(repo, start, stop):
> +def nofilter(ctx):
> +    return True
> +
> +def revisions(repo, start, stop, filterctxfn=nofilter):
>      """cset DAG generator yielding (rev, node, [parents]) tuples
>  
>      This generator function walks through the revision history from revision
> @@ -24,12 +27,14 @@
>      cur = start
>      while cur >= stop:
>          ctx = repo[cur]
> -        parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev]
> -        parents.sort()
> -        yield (ctx, parents)
> +        if filterctxfn(ctx):
> +            parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev
> +                       and filterctxfn(p)]
> +            parents.sort()
> +            yield (ctx, parents)
>          cur -= 1
>  
> -def filerevs(repo, path, start, stop):
> +def filerevs(repo, path, start, stop, filterctxfn=nofilter):
>      """file cset DAG generator yielding (rev, node, [parents]) tuples
>  
>      This generator function walks through the revision history of a single
> @@ -40,10 +45,12 @@
>      filerev = len(repo.file(path)) - 1
>      while filerev >= 0:
>          fctx = repo.filectx(path, fileid=filerev)
> -        parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
> -        parents.sort()
> -        if fctx.rev() <= start:
> -            yield (fctx, parents)
> +        if filterctxfn(fctx):
> +            parents = [f.linkrev() for f in fctx.parents() if f.path() == path
> +                       and filterctxfn(f)]
> +            parents.sort()
> +            if fctx.rev() <= start:
> +                yield (fctx, parents)
>          if fctx.rev() <= stop:
>              break
>          filerev -= 1
> @@ -273,12 +280,29 @@
>      if start == nullrev:
>          return
>  
> +    def branchdict(optname):
> +        branches = opts.get(optname)
> +        if branches:
> +            return dict.fromkeys(branches)
> +        return None
> +    onlybranches = branchdict("only_branch")
> +    exceptbranches = branchdict("except_branch")
> +
> +    filter = nofilter
> +    if onlybranches:
> +        def filter(ctx):
> +            return ctx.branch() in onlybranches
> +    if exceptbranches:
> +        oldfilter = filter
> +        def filter(ctx):
> +            return oldfilter(ctx) and ctx.branch() not in exceptbranches
> +
>      if path:
>          path = canonpath(repo.root, os.getcwd(), path)
>      if path: # could be reset in canonpath
> -        revdag = filerevs(repo, path, start, stop)
> +        revdag = filerevs(repo, path, start, stop, filterctxfn=filter)
>      else:
> -        revdag = revisions(repo, start, stop)
> +        revdag = revisions(repo, start, stop, filterctxfn=filter)
>  
>      repo_parents = repo.dirstate.parents()
>      displayer = show_changeset(ui, repo, opts, buffered=True)
> @@ -299,6 +323,8 @@
>           [('l', 'limit', '', _('limit number of changes displayed')),
>            ('p', 'patch', False, _('show patch')),
>            ('r', 'rev', [], _('show the specified revision or range')),
> +          ('b', 'only-branch', [], _('show the specified branch only')),
> +          ('B', 'except-branch', [], _('do not show the specified branch')),
>           ] + templateopts,
>           _('hg glog [OPTION]... [FILE]')),
>  }



More information about the Mercurial-devel mailing list