changeset 22776:564ae7d2ec9b

bookmarks: port to generic templater
author Yuya Nishihara <yuya@tcha.org>
date Fri, 03 Oct 2014 00:43:22 +0900
parents b59c2c8c45df
children bbb2f8b0459e
files mercurial/commands.py tests/test-bookmarks.t tests/test-completion.t
diffstat 3 files changed, 41 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Oct 03 00:36:36 2014 +0900
+++ b/mercurial/commands.py	Fri Oct 03 00:43:22 2014 +0900
@@ -833,7 +833,8 @@
     ('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 @@
         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 @@
             else:
                 prefix, label = ' ', ''
 
-            if not ui.quiet:
-                ui.write(' %s ' % prefix, label=label)
-            ui.write(bmark, label=label)
-            pad = " " * (25 - encoding.colwidth(bmark))
+            fm.startitem()
             if not ui.quiet:
-                ui.write('%s %d:%s' % (
-                    pad, repo.changelog.rev(n), hexfn(n)),
-                    label=label)
-            ui.write('\n')
+                fm.plain(' %s ' % prefix, label=label)
+            fm.write('bookmark', '%s', bmark, label=label)
+            pad = " " * (25 - encoding.colwidth(bmark))
+            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,
--- a/tests/test-bookmarks.t	Fri Oct 03 00:36:36 2014 +0900
+++ b/tests/test-bookmarks.t	Fri Oct 03 00:43:22 2014 +0900
@@ -5,6 +5,10 @@
   $ hg bookmarks
   no bookmarks set
 
+  $ hg bookmarks -Tjson
+  [
+  ]
+
 bookmark rev -1
 
   $ hg bookmark X
@@ -59,6 +63,28 @@
   $ 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()'
--- a/tests/test-completion.t	Fri Oct 03 00:36:36 2014 +0900
+++ b/tests/test-completion.t	Fri Oct 03 00:43:22 2014 +0900
@@ -219,7 +219,7 @@
   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