# HG changeset patch # User Yuya Nishihara # Date 2014-10-02 15:43:22 # Node ID 564ae7d2ec9bee86b00a6ba817271ac0b19deca7 # Parent b59c2c8c45df23d96e4281967d4691d66660a786 bookmarks: port to generic templater 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 = ' ', '' - 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, 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