[PATCH 2 of 2 V2] show: new extension for displaying various repository data

Yuya Nishihara yuya at tcha.org
Wed Mar 22 11:16:16 EDT 2017


On Tue, 21 Mar 2017 23:52:42 -0700, Gregory Szorc wrote:
> On Tue, Mar 21, 2017 at 11:49 PM, Gregory Szorc <gregory.szorc at gmail.com>
> wrote:
> 
> > # HG changeset patch
> > # User Gregory Szorc <gregory.szorc at gmail.com>
> > # Date 1490165337 25200
> > #      Tue Mar 21 23:48:57 2017 -0700
> > # Node ID 80ca2bee4a06887f918e3328b3f005e4c1cb1ab1
> > # Parent  ae796e23fd42b036352b298f570af8949c2db2d9
> > show: new extension for displaying various repository data
> >
> 
> Yuya, et al:
> 
> Since the default output isn't covered by BC guarantees, we probably want
> HGPLAIN to be. I'm not sure what the preferred way to do that should be.
> Should I create a separate topic within the template for the plain view?

No idea about BC guarantees vs HGPLAIN. HGPLAIN is to disable user
configuration. If "hg show" is covered by e.g. compat version, we'll only
need to set it to the lowest version if HGPLAIN set.

> I'm still a bit confused as to how formatters work :/

[...]

> > + at showview('bookmarks', fmtopic='bookmarks')
> > +def showbookmarks(ui, repo, fm):
> > +    """bookmarks and their associated changeset"""
> > +    marks = repo._bookmarks
> > +    if not len(marks):
> > +        ui.write(_('(no bookmarks set)\n'))
> > +        return
> > +
> > +    active = repo._activebookmark
> > +    longest = max(len(b) for b in marks)
> > +
> > +    for bm, node in sorted(marks.items()):
> > +        fm.startitem()
> > +        fm.context(ctx=repo[node])
> > +        fm.write('bookmark', '%s', bm)
> > +        fm.write('node', fm.hexfunc(node), fm.hexfunc(node))
> > +        fm.data(active=bm == active,
> > +                _longestlen=longest)

I think the formatter API was designed to make hand-written output formatting
templatable, so the default (plain) output doesn't use template file.

  bookmarkfmt = '%%-%ds' % longest
  fm.write('bookmark', bookmarkfmt, bm)
  fm.write('node', '%s\n', fm.hexfunc_that_uses_shortest(node))

But 'hg show' does use template by default. That's why fm.plain() doesn't work.


More information about the Mercurial-devel mailing list