Patchwork [3,of,3] bookmarks: port to generic templater

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 4, 2014, 12:40 a.m.
Message ID <2fd6a371c4af15b547e1.1412383235@mimosa>
Download mbox | patch
Permalink /patch/6101/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 4, 2014, 12:40 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1412264602 -32400
#      Fri Oct 03 00:43:22 2014 +0900
# Node ID 2fd6a371c4af15b547e105fb79b633694edec8b7
# Parent  997ce0e10273d6b379a7a0190cbce31b97977b45
bookmarks: port to generic templater
Matt Mackall - Oct. 6, 2014, 7:48 p.m.
On Sat, 2014-10-04 at 09:40 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1412264602 -32400
> #      Fri Oct 03 00:43:22 2014 +0900
> # Node ID 2fd6a371c4af15b547e105fb79b633694edec8b7
> # Parent  997ce0e10273d6b379a7a0190cbce31b97977b45
> bookmarks: port to generic templater

These are queued for default, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -833,7 +833,8 @@  def bisect(ui, repo, rev=None, extra=Non
     ('r', 'rev', '', _('revision'), _('REV')),
     ('d', 'delete', False, _('delete a given bookmark')),
     ('m', 'rename', '', _('rename a given bookmark'), _('NAME')),
-    ('i', 'inactive', False, _('mark a bookmark inactive'))],
+    ('i', 'inactive', False, _('mark a bookmark inactive')),
+    ] + formatteropts,
     _('hg bookmarks [OPTIONS]... [NAME]...'))
 def bookmark(ui, repo, *names, **opts):
     '''create a new bookmark or list existing bookmarks
@@ -991,9 +992,10 @@  def bookmark(ui, repo, *names, **opts):
         finally:
             wlock.release()
     else: # show bookmarks
-        hexfn = ui.debugflag and hex or short
+        fm = ui.formatter('bookmarks', opts)
+        hexfn = fm.hexfunc
         marks = repo._bookmarks
-        if len(marks) == 0:
+        if len(marks) == 0 and not fm:
             ui.status(_("no bookmarks set\n"))
         for bmark, n in sorted(marks.iteritems()):
             current = repo._bookmarkcurrent
@@ -1002,15 +1004,16 @@  def bookmark(ui, repo, *names, **opts):
             else:
                 prefix, label = ' ', ''
 
+            fm.startitem()
             if not ui.quiet:
-                ui.write(' %s ' % prefix, label=label)
-            ui.write(bmark, label=label)
+                fm.plain(' %s ' % prefix, label=label)
+            fm.write('bookmark', '%s', bmark, label=label)
             pad = " " * (25 - encoding.colwidth(bmark))
-            if not ui.quiet:
-                ui.write('%s %d:%s' % (
-                    pad, repo.changelog.rev(n), hexfn(n)),
-                    label=label)
-            ui.write('\n')
+            fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s',
+                         repo.changelog.rev(n), hexfn(n), label=label)
+            fm.data(active=(bmark == current))
+            fm.plain('\n')
+        fm.end()
 
 @command('branch',
     [('f', 'force', None,
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -5,6 +5,10 @@  no bookmarks
   $ hg bookmarks
   no bookmarks set
 
+  $ hg bookmarks -Tjson
+  [
+  ]
+
 bookmark rev -1
 
   $ hg bookmark X
@@ -59,6 +63,28 @@  list bookmarks
   $ hg add b
   $ hg commit -m 1
 
+  $ hg bookmarks -Tjson
+  [
+   {
+    "active": false,
+    "bookmark": "X",
+    "node": "f7b1eb17ad24730a1651fccd46c43826d1bbc2ac",
+    "rev": 0
+   },
+   {
+    "active": true,
+    "bookmark": "X2",
+    "node": "925d80f479bb026b0fb3deb27503780b13f74123",
+    "rev": 1
+   },
+   {
+    "active": false,
+    "bookmark": "Y",
+    "node": "0000000000000000000000000000000000000000",
+    "rev": -1
+   }
+  ]
+
 bookmarks revset
 
   $ hg log -r 'bookmark()'
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -219,7 +219,7 @@  Show all commands + options
   archive: no-decode, prefix, rev, type, subrepos, include, exclude
   backout: merge, parent, rev, edit, tool, include, exclude, message, logfile, date, user
   bisect: reset, good, bad, skip, extend, command, noupdate
-  bookmarks: force, rev, delete, rename, inactive
+  bookmarks: force, rev, delete, rename, inactive, template
   branch: force, clean
   branches: active, closed, template
   bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure