##// END OF EJS Templates
bookmarks: add explicit option to list bookmarks of the given names...
Yuya Nishihara -
r39789:b05b4b91 default
parent child Browse files
Show More
@@ -936,21 +936,23 b' def _printbookmarks(ui, repo, fm, bmarks'
936 fm.data(active=(activebookmarklabel in label))
936 fm.data(active=(activebookmarklabel in label))
937 fm.plain('\n')
937 fm.plain('\n')
938
938
939 def printbookmarks(ui, repo, fm):
939 def printbookmarks(ui, repo, fm, names=None):
940 """print bookmarks by the given formatter
940 """print bookmarks by the given formatter
941
941
942 Provides a way for extensions to control how bookmarks are printed.
942 Provides a way for extensions to control how bookmarks are printed.
943 """
943 """
944 marks = repo._bookmarks
944 marks = repo._bookmarks
945 bmarks = {}
945 bmarks = {}
946 for bmark, n in sorted(marks.iteritems()):
946 for bmark in (names or marks):
947 if bmark not in marks:
948 raise error.Abort(_("bookmark '%s' does not exist") % bmark)
947 active = repo._activebookmark
949 active = repo._activebookmark
948 if bmark == active:
950 if bmark == active:
949 prefix, label = '*', activebookmarklabel
951 prefix, label = '*', activebookmarklabel
950 else:
952 else:
951 prefix, label = ' ', ''
953 prefix, label = ' ', ''
952
954
953 bmarks[bmark] = (n, prefix, label)
955 bmarks[bmark] = (marks[bmark], prefix, label)
954 _printbookmarks(ui, repo, fm, bmarks)
956 _printbookmarks(ui, repo, fm, bmarks)
955
957
956 def preparehookargs(name, old, new):
958 def preparehookargs(name, old, new):
@@ -903,6 +903,7 b' def bisect(ui, repo, rev=None, extra=Non'
903 ('d', 'delete', False, _('delete a given bookmark')),
903 ('d', 'delete', False, _('delete a given bookmark')),
904 ('m', 'rename', '', _('rename a given bookmark'), _('OLD')),
904 ('m', 'rename', '', _('rename a given bookmark'), _('OLD')),
905 ('i', 'inactive', False, _('mark a bookmark inactive')),
905 ('i', 'inactive', False, _('mark a bookmark inactive')),
906 ('l', 'list', False, _('list existing bookmarks')),
906 ('', 'active', False, _('display the active bookmark')),
907 ('', 'active', False, _('display the active bookmark')),
907 ] + formatteropts,
908 ] + formatteropts,
908 _('hg bookmarks [OPTIONS]... [NAME]...'))
909 _('hg bookmarks [OPTIONS]... [NAME]...'))
@@ -924,7 +925,7 b' def bookmark(ui, repo, *names, **opts):'
924 diverged, a new 'divergent bookmark' of the form 'name@path' will
925 diverged, a new 'divergent bookmark' of the form 'name@path' will
925 be created. Using :hg:`merge` will resolve the divergence.
926 be created. Using :hg:`merge` will resolve the divergence.
926
927
927 Specifying bookmark as '.' to -m or -d options is equivalent to specifying
928 Specifying bookmark as '.' to -m/-d/-l options is equivalent to specifying
928 the active bookmark's name.
929 the active bookmark's name.
929
930
930 A bookmark named '@' has the special property that :hg:`clone` will
931 A bookmark named '@' has the special property that :hg:`clone` will
@@ -963,7 +964,8 b' def bookmark(ui, repo, *names, **opts):'
963 rev = opts.get('rev')
964 rev = opts.get('rev')
964 inactive = opts.get('inactive') # meaning add/rename to inactive bookmark
965 inactive = opts.get('inactive') # meaning add/rename to inactive bookmark
965
966
966 selactions = [k for k in ['delete', 'rename', 'active'] if opts.get(k)]
967 selactions = [k for k in ['delete', 'rename', 'active', 'list']
968 if opts.get(k)]
967 if len(selactions) > 1:
969 if len(selactions) > 1:
968 raise error.Abort(_('--%s and --%s are incompatible')
970 raise error.Abort(_('--%s and --%s are incompatible')
969 % tuple(selactions[:2]))
971 % tuple(selactions[:2]))
@@ -974,13 +976,13 b' def bookmark(ui, repo, *names, **opts):'
974 elif inactive:
976 elif inactive:
975 action = 'inactive' # meaning deactivate
977 action = 'inactive' # meaning deactivate
976 else:
978 else:
977 action = None
979 action = 'list'
978
980
979 if rev and action in {'delete', 'rename', 'active'}:
981 if rev and action in {'delete', 'rename', 'active', 'list'}:
980 raise error.Abort(_("--rev is incompatible with --%s") % action)
982 raise error.Abort(_("--rev is incompatible with --%s") % action)
981 if names and action == 'active':
983 if names and action == 'active':
982 raise error.Abort(_("NAMES is incompatible with --active"))
984 raise error.Abort(_("NAMES is incompatible with --active"))
983 if inactive and action in {'delete', 'active'}:
985 if inactive and action in {'delete', 'active', 'list'}:
984 raise error.Abort(_("--inactive is incompatible with --%s") % action)
986 raise error.Abort(_("--inactive is incompatible with --%s") % action)
985 if not names and action in {'add', 'delete'}:
987 if not names and action in {'add', 'delete'}:
986 raise error.Abort(_("bookmark name required"))
988 raise error.Abort(_("bookmark name required"))
@@ -1011,9 +1013,12 b' def bookmark(ui, repo, *names, **opts):'
1011 if book is None:
1013 if book is None:
1012 return 1
1014 return 1
1013 ui.write("%s\n" % book, label=bookmarks.activebookmarklabel)
1015 ui.write("%s\n" % book, label=bookmarks.activebookmarklabel)
1014 else: # show bookmarks
1016 elif action == 'list':
1017 names = pycompat.maplist(repo._bookmarks.expandname, names)
1015 with ui.formatter('bookmarks', opts) as fm:
1018 with ui.formatter('bookmarks', opts) as fm:
1016 bookmarks.printbookmarks(ui, repo, fm)
1019 bookmarks.printbookmarks(ui, repo, fm, names)
1020 else:
1021 raise error.ProgrammingError('invalid action: %s' % action)
1017
1022
1018 @command('branch',
1023 @command('branch',
1019 [('f', 'force', None,
1024 [('f', 'force', None,
@@ -68,6 +68,25 b' list bookmarks'
68 X 0:f7b1eb17ad24
68 X 0:f7b1eb17ad24
69 * X2 0:f7b1eb17ad24
69 * X2 0:f7b1eb17ad24
70 Y -1:000000000000
70 Y -1:000000000000
71 $ hg bookmarks -l
72 X 0:f7b1eb17ad24
73 * X2 0:f7b1eb17ad24
74 Y -1:000000000000
75 $ hg bookmarks -l X Y
76 X 0:f7b1eb17ad24
77 Y -1:000000000000
78 $ hg bookmarks -l .
79 * X2 0:f7b1eb17ad24
80 $ hg bookmarks -l X A Y
81 abort: bookmark 'A' does not exist
82 [255]
83 $ hg bookmarks -l -r0
84 abort: --rev is incompatible with --list
85 [255]
86 $ hg bookmarks -l --inactive
87 abort: --inactive is incompatible with --list
88 [255]
89
71 $ hg log -T '{bookmarks % "{rev} {bookmark}\n"}'
90 $ hg log -T '{bookmarks % "{rev} {bookmark}\n"}'
72 0 X
91 0 X
73 0 X2
92 0 X2
@@ -250,7 +250,7 b' Show all commands + options'
250 archive: no-decode, prefix, rev, type, subrepos, include, exclude
250 archive: no-decode, prefix, rev, type, subrepos, include, exclude
251 backout: merge, commit, no-commit, parent, rev, edit, tool, include, exclude, message, logfile, date, user
251 backout: merge, commit, no-commit, parent, rev, edit, tool, include, exclude, message, logfile, date, user
252 bisect: reset, good, bad, skip, extend, command, noupdate
252 bisect: reset, good, bad, skip, extend, command, noupdate
253 bookmarks: force, rev, delete, rename, inactive, active, template
253 bookmarks: force, rev, delete, rename, inactive, list, active, template
254 branch: force, clean, rev
254 branch: force, clean, rev
255 branches: active, closed, template
255 branches: active, closed, template
256 bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
256 bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
General Comments 0
You need to be logged in to leave comments. Login now