[PATCH] tip: -S/--subrepos for hg tip to recurse on subrepositories

Martin Geisler mg at aragost.com
Mon Oct 4 02:10:46 CDT 2010


Erik Zielke <ez at aragost.com> writes:

> # HG changeset patch
> # User Erik Zielke <ez at aragost.com>
> # Date 1285578511 -7200
> # Node ID 71891e2de2cc1f74cd166757e1a2ff52024505da
> # Parent  234e9a63173db6eb117b952cccbc4ccc9fc297ab
> tip: -S/--subrepos for hg tip to recurse on subrepositories
>
> Option for tip to recurse on subrepositories.
>
> Shows
>   subrepo:  name of subrepo
> before a sub repository changeset
>
> And added {subrepo} as a keyword for templates to show subrepo name
> with a templatex

This needs a bit of documentation in mercurial/help/templates.txt.

> @@ -790,6 +791,9 @@
>          parents = [(p, hexfunc(log.node(p)))
>                     for p in self._meaningful_parentrevs(log, rev)]
>  
> +        if self.subpath:
> +            self.ui.write(_("subrepo:     %s\n") % self.subpath)

This should get a new kind of label -- 'log.subrepo' seems appropriate.
The color extension should then be extended with a color for that label.

> diff -r 234e9a63173d -r 71891e2de2cc mercurial/commands.py
> --- a/mercurial/commands.py	Thu Sep 30 12:46:46 2010 +0200
> +++ b/mercurial/commands.py	Mon Sep 27 11:08:31 2010 +0200
> @@ -3719,6 +3719,8 @@
>      displayer.show(repo[len(repo) - 1])
>      displayer.close()
>  
> +    hg.tip(ui, repo, **opts)
> +

I think the recursion is slightly wrong here -- the commands.tip
function now becomes

    def tip(ui, repo, **opts):
        displayer = cmdutil.show_changeset(ui, repo, opts)
        displayer.show(repo[len(repo) - 1])
        displayer.close()

        hg.tip(ui, repo, **opts)

where hg.tip is

    def tip(ui, repo, **opts):
        if opts.get('subrepos'):
            ctx = repo[None]
            for subpath in sorted(ctx.substate):
                sub = ctx.sub(subpath)
                sub.tip(ui, **opts)

and sub.hgsubreposub.tip is

    def tip(self, ui, **opts):
        repo = self._repo
        path = relpath(self)
        displayer = cmdutil.show_changeset(ui, repo, opts, subpath=path)
        displayer.show(repo[len(repo) - 1])
        displayer.close()
        hg.tip(ui, repo, **opts)

Here the latter method implements the same logic as commands.tip -- it's
just three lines, but still :) I think the code from commands.tip should
be moved to hg.tip and the hgsubrepo.tip method should then call back to
hg.tip in a similar way to how the other methods in that class does it.

I had initially thought that we should be using the same displayer for
all the changesets. That displayer would then look at each context it's
asked to show and determine if it comes from a differnet repo than the
last one -- if so, then the 'subrepo:' line should be included.

However, that would require that we can go from a context to a subrepo
object, which we cannot do via public methods and attributes. So perhaps
it's better to print the line unconditionally when we're within a
subrepo (this is with an eye to how 'hg log -S' could be implemented in
the future...).

I quite like the output, though:

> +  $ hg tip -S
> +  changeset:   2:1326fa26d0c0
> +  tag:         tip
> +  user:        test
> +  date:        Thu Jan 01 00:00:00 1970 +0000
> +  summary:     2-3-2
> +  
> +  subrepo:     foo
> +  changeset:   3:65903cebad86
> +  tag:         tip
> +  user:        test
> +  date:        Thu Jan 01 00:00:00 1970 +0000
> +  summary:     2-3-2
> +  
> +  subrepo:     foo/bar
> +  changeset:   2:31ecbdafd357
> +  tag:         tip
> +  user:        test
> +  date:        Thu Jan 01 00:00:00 1970 +0000
> +  summary:     2-3-2

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://aragost.com/mercurial/


More information about the Mercurial-devel mailing list