diff mercurial/commands.py @ 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 9271630f4720
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,