[PATCH 6 of 7 bm-refactor V2] bookmarks: factor out bookmark printing from commands
Sean Farley
sean at farley.io
Wed Jun 21 16:45:13 EDT 2017
# HG changeset patch
# User Sean Farley <sean at farley.io>
# Date 1498001785 25200
# Tue Jun 20 16:36:25 2017 -0700
# Branch bm-refactor
# Node ID 6c3528df39f51c56c8bd671538fcf570c8171170
# Parent b0332f98ac1229f5c8fd0ab2f4e52392f192aa82
bookmarks: factor out bookmark printing from commands
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
index 99c23e2..518b362 100644
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -764,5 +764,33 @@ def addbookmarks(repo, tr, names, rev=No
if not inactive and cur == marks[newact] and not rev:
activate(repo, newact)
elif cur != tgt and newact == repo._activebookmark:
deactivate(repo)
marks.recordchange(tr)
+
+def printbookmarks(ui, repo, **opts):
+ """print bookmarks to a formatter
+
+ Provides a way for extensions to control how bookmarks are printed.
+ """
+ fm = ui.formatter('bookmarks', opts)
+ hexfn = fm.hexfunc
+ marks = repo._bookmarks
+ if len(marks) == 0 and fm.isplain():
+ ui.status(_("no bookmarks set\n"))
+ for bmark, n in sorted(marks.iteritems()):
+ active = repo._activebookmark
+ if bmark == active:
+ prefix, label = '*', activebookmarklabel
+ else:
+ prefix, label = ' ', ''
+
+ fm.startitem()
+ if not ui.quiet:
+ 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 == active))
+ fm.plain('\n')
+ fm.end()
diff --git a/mercurial/commands.py b/mercurial/commands.py
index 3778095..5bee39c 100644
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -978,32 +978,11 @@ def bookmark(ui, repo, *names, **opts):
elif not repo._activebookmark:
ui.status(_("no active bookmark\n"))
else:
bookmarks.deactivate(repo)
else: # show bookmarks
- fm = ui.formatter('bookmarks', opts)
- hexfn = fm.hexfunc
- marks = repo._bookmarks
- if len(marks) == 0 and fm.isplain():
- ui.status(_("no bookmarks set\n"))
- for bmark, n in sorted(marks.iteritems()):
- active = repo._activebookmark
- if bmark == active:
- prefix, label = '*', bookmarks.activebookmarklabel
- else:
- prefix, label = ' ', ''
-
- fm.startitem()
- if not ui.quiet:
- 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 == active))
- fm.plain('\n')
- fm.end()
+ bookmarks.printbookmarks(ui, repo, **opts)
@command('branch',
[('f', 'force', None,
_('set branch name even if it shadows an existing branch')),
('C', 'clean', None, _('reset branch name to parent branch name'))],
More information about the Mercurial-devel
mailing list