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

Peter Arrenbrecht peter.arrenbrecht at gmail.com
Mon Nov 17 12:40:43 CST 2008


On Mon, Nov 17, 2008 at 6:20 PM, David Soria Parra <sn_ at gmx.net> wrote:
> 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.

No, it does what --only-branch does in log. :)  But log currently has
no --except-branch, which I want to add, too.

The difference is that --only-branch only shows nodes committed to a
given branch (as in `hg branch`), whereas --follow only shows nodes
which are either ancestors or descendants of the main rev. So --follow
is more like --only-head than --only-branch.

Glog, on the other hand, has no --follow. So this all seems to
indicate we should try to use the same cset walking code in both log
and glog.

-parren

>
> 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]')),
>>  }
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>


More information about the Mercurial-devel mailing list