Patchwork [1,of,8] bookmarks: add support for log-like template keywords and functions

login
register
mail settings
Submitter Yuya Nishihara
Date July 3, 2018, 1:26 p.m.
Message ID <65ebef5548276d61a95e.1530624364@mimosa>
Download mbox | patch
Permalink /patch/32580/
State Accepted
Headers show

Comments

Yuya Nishihara - July 3, 2018, 1:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1530451327 -32400
#      Sun Jul 01 22:22:07 2018 +0900
# Node ID 65ebef5548276d61a95e949d8ef2fd1b82947bc6
# Parent  c1a7bbf9984d2614bfac478d42c86377a84641ba
bookmarks: add support for log-like template keywords and functions

This is basically the same as 5d9b765dbe15 "tags: unblock log-like template
keywords and functions."
Gregory Szorc - July 4, 2018, 6:05 p.m.
On Tue, Jul 3, 2018 at 6:26 AM, Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1530451327 -32400
> #      Sun Jul 01 22:22:07 2018 +0900
> # Node ID 65ebef5548276d61a95e949d8ef2fd1b82947bc6
> # Parent  c1a7bbf9984d2614bfac478d42c86377a84641ba
> bookmarks: add support for log-like template keywords and functions
>

Queued this series.

It's great to see templates being more usable and consistent across
commands!


>
> This is basically the same as 5d9b765dbe15 "tags: unblock log-like template
> keywords and functions."
>
> diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
> --- a/mercurial/bookmarks.py
> +++ b/mercurial/bookmarks.py
> @@ -923,11 +923,14 @@ def _printbookmarks(ui, repo, bmarks, **
>      """
>      opts = pycompat.byteskwargs(opts)
>      fm = ui.formatter('bookmarks', opts)
> +    contexthint = fm.contexthint('bookmark rev node active')
>      hexfn = fm.hexfunc
>      if len(bmarks) == 0 and fm.isplain():
>          ui.status(_("no bookmarks set\n"))
>      for bmark, (n, prefix, label) in sorted(bmarks.iteritems()):
>          fm.startitem()
> +        if 'ctx' in contexthint:
> +            fm.context(ctx=repo[n])
>          if not ui.quiet:
>              fm.plain(' %s ' % prefix, label=label)
>          fm.write('bookmark', '%s', bmark, label=label)
> diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
> --- a/tests/test-bookmarks.t
> +++ b/tests/test-bookmarks.t
> @@ -77,6 +77,11 @@ list bookmarks
>    $ hg commit -m 1 --config "$TESTHOOK"
>    test-hook-bookmark: X2:  f7b1eb17ad24730a1651fccd46c43826d1bbc2ac ->
> 925d80f479bb026b0fb3deb27503780b13f74123
>
> +  $ hg bookmarks -T '{rev}:{node|shortest} {bookmark} {desc|firstline}\n'
> +  0:f7b1 X 0
> +  1:925d X2 1
> +  -1:0000 Y
> +
>    $ hg bookmarks -Tjson
>    [
>     {
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -923,11 +923,14 @@  def _printbookmarks(ui, repo, bmarks, **
     """
     opts = pycompat.byteskwargs(opts)
     fm = ui.formatter('bookmarks', opts)
+    contexthint = fm.contexthint('bookmark rev node active')
     hexfn = fm.hexfunc
     if len(bmarks) == 0 and fm.isplain():
         ui.status(_("no bookmarks set\n"))
     for bmark, (n, prefix, label) in sorted(bmarks.iteritems()):
         fm.startitem()
+        if 'ctx' in contexthint:
+            fm.context(ctx=repo[n])
         if not ui.quiet:
             fm.plain(' %s ' % prefix, label=label)
         fm.write('bookmark', '%s', bmark, label=label)
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -77,6 +77,11 @@  list bookmarks
   $ hg commit -m 1 --config "$TESTHOOK"
   test-hook-bookmark: X2:  f7b1eb17ad24730a1651fccd46c43826d1bbc2ac -> 925d80f479bb026b0fb3deb27503780b13f74123
 
+  $ hg bookmarks -T '{rev}:{node|shortest} {bookmark} {desc|firstline}\n'
+  0:f7b1 X 0
+  1:925d X2 1
+  -1:0000 Y 
+
   $ hg bookmarks -Tjson
   [
    {