[PATCH] branches: avoid unnecessary changectx.branch() calls

Brodie Rao brodie at sf.io
Fri Nov 15 20:21:02 CST 2013


On Thu, Nov 14, 2013 at 5:50 PM, Brodie Rao <brodie at sf.io> wrote:
> # HG changeset patch
> # User Brodie Rao <brodie at sf.io>
> # Date 1384467366 18000
> #      Thu Nov 14 17:16:06 2013 -0500
> # Node ID 5ad83b0804e366b79d1bde8b897b1dbbc1dd2d7a
> # Parent  c38c3fdc8b9317ba09e03ab09364c3800da7c50c
> branches: avoid unnecessary changectx.branch() calls
>
> This requires reading from the changelog, which can be costly over NFS.
>
> Note that this does not totally remove reading from the changelog; we
> still do that when calling changectx.closesbranch(). That call will be
> removed in a later patch.

Please ignore this patch. I'm sending a longer series that contains an
updated version of it.

> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1008,7 +1008,7 @@ def branches(ui, repo, active=False, clo
>
>      hexfunc = ui.debugflag and hex or short
>
> -    activebranches = set([repo[n].branch() for n in repo.heads()])
> +    allheads = set(repo.heads())
>      branches = []
>      for tag, heads in repo.branchmap().iteritems():
>          for h in reversed(heads):
> @@ -1019,12 +1019,12 @@ def branches(ui, repo, active=False, clo
>                  break
>          else:
>              tip = repo[heads[-1]]
> -        isactive = tag in activebranches and isopen
> -        branches.append((tip, isactive, isopen))
> -    branches.sort(key=lambda i: (i[1], i[0].rev(), i[0].branch(), i[2]),
> +        isactive = isopen and bool(set(heads) & allheads)
> +        branches.append((tag, tip, isactive, isopen))
> +    branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]),
>                    reverse=True)
>
> -    for ctx, isactive, isopen in branches:
> +    for tag, ctx, isactive, isopen in branches:
>          if (not active) or isactive:
>              if isactive:
>                  label = 'branches.active'
> @@ -1037,16 +1037,16 @@ def branches(ui, repo, active=False, clo
>              else:
>                  label = 'branches.inactive'
>                  notice = _(' (inactive)')
> -            if ctx.branch() == repo.dirstate.branch():
> +            if tag == repo.dirstate.branch():
>                  label = 'branches.current'
> -            rev = str(ctx.rev()).rjust(31 - encoding.colwidth(ctx.branch()))
> +            rev = str(ctx.rev()).rjust(31 - encoding.colwidth(tag))
>              rev = ui.label('%s:%s' % (rev, hexfunc(ctx.node())),
>                             'log.changeset changeset.%s' % ctx.phasestr())
> -            tag = ui.label(ctx.branch(), label)
> +            labeledtag = ui.label(tag, label)
>              if ui.quiet:
> -                ui.write("%s\n" % tag)
> +                ui.write("%s\n" % labeledtag)
>              else:
> -                ui.write("%s %s%s\n" % (tag, rev, notice))
> +                ui.write("%s %s%s\n" % (labeledtag, rev, notice))
>
>  @command('bundle',
>      [('f', 'force', None, _('run even when the destination is unrelated')),


More information about the Mercurial-devel mailing list