Mercurial > hg-stable
changeset 19147:5b1835485442
bookmarks: allow bookmark command to take multiple arguments
This change allows setting or deleting multiple bookmarks at once. If more than
one is being set and --inactive is not given, the first one is made active.
author | Kevin Bullock <kbullock@ringworld.org> |
---|---|
date | Thu, 02 May 2013 21:28:18 -0500 |
parents | a718a0ba6787 |
children | 3bda242bf244 |
files | mercurial/commands.py tests/test-bookmarks-current.t tests/test-bookmarks.t |
diffstat | 3 files changed, 48 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Sun May 05 18:51:34 2013 -0500 +++ b/mercurial/commands.py Thu May 02 21:28:18 2013 -0500 @@ -767,9 +767,8 @@ ('d', 'delete', False, _('delete a given bookmark')), ('m', 'rename', '', _('rename a given bookmark'), _('NAME')), ('i', 'inactive', False, _('mark a bookmark inactive'))], - _('hg bookmarks [-f] [-d] [-i] [-m NAME] [-r REV] [NAME]')) -def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, - rename=None, inactive=False): + _('hg bookmarks [OPTIONS]... [NAME]...')) +def bookmark(ui, repo, *names, **opts): '''track a line of development with movable markers Bookmarks are pointers to certain commits that move when committing. @@ -796,6 +795,12 @@ active even if -i/--inactive is not given. If no NAME is given, the current active bookmark will be marked inactive. ''' + force = opts.get('force') + rev = opts.get('rev') + delete = opts.get('delete') + rename = opts.get('rename') + inactive = opts.get('inactive') + hexfn = ui.debugflag and hex or short marks = repo._bookmarks cur = repo.changectx('.').node() @@ -846,21 +851,24 @@ raise util.Abort(_("--rev is incompatible with --delete")) if rename and rev: raise util.Abort(_("--rev is incompatible with --rename")) - if mark is None and (delete or rev): + if not names and (delete or rev): raise util.Abort(_("bookmark name required")) if delete: - if mark not in marks: - raise util.Abort(_("bookmark '%s' does not exist") % mark) - if mark == repo._bookmarkcurrent: - bookmarks.setcurrent(repo, None) - del marks[mark] + for mark in names: + if mark not in marks: + raise util.Abort(_("bookmark '%s' does not exist") % mark) + if mark == repo._bookmarkcurrent: + bookmarks.setcurrent(repo, None) + del marks[mark] marks.write() elif rename: - if mark is None: + if not names: raise util.Abort(_("new bookmark name required")) - mark = checkformat(mark) + elif len(names) > 1: + raise util.Abort(_("only one new bookmark name allowed")) + mark = checkformat(names[0]) if rename not in marks: raise util.Abort(_("bookmark '%s' does not exist") % rename) checkconflict(repo, mark, force) @@ -870,19 +878,23 @@ del marks[rename] marks.write() - elif mark is not None: - mark = checkformat(mark) - if inactive and mark == repo._bookmarkcurrent: - bookmarks.setcurrent(repo, None) - return - tgt = cur - if rev: - tgt = scmutil.revsingle(repo, rev).node() - checkconflict(repo, mark, force, tgt) - marks[mark] = tgt - if not inactive and cur == marks[mark] and not rev: - bookmarks.setcurrent(repo, mark) - elif cur != tgt and mark == repo._bookmarkcurrent: + elif names: + newact = None + for mark in names: + mark = checkformat(mark) + if newact is None: + newact = mark + if inactive and mark == repo._bookmarkcurrent: + bookmarks.setcurrent(repo, None) + return + tgt = cur + if rev: + tgt = scmutil.revsingle(repo, rev).node() + checkconflict(repo, mark, force, tgt) + marks[mark] = tgt + if not inactive and cur == marks[newact] and not rev: + bookmarks.setcurrent(repo, newact) + elif cur != tgt and newact == repo._bookmarkcurrent: bookmarks.setcurrent(repo, None) marks.write()
--- a/tests/test-bookmarks-current.t Sun May 05 18:51:34 2013 -0500 +++ b/tests/test-bookmarks-current.t Thu May 02 21:28:18 2013 -0500 @@ -43,16 +43,19 @@ $ hg bookmarks * Z -1:000000000000 -new bookmark Y +new bookmarks X and Y, first one made active - $ hg bookmark Y + $ hg bookmark Y X list bookmarks $ hg bookmark + X -1:000000000000 * Y -1:000000000000 Z -1:000000000000 + $ hg bookmark -d X + commit $ echo 'b' > b
--- a/tests/test-bookmarks.t Sun May 05 18:51:34 2013 -0500 +++ b/tests/test-bookmarks.t Thu May 02 21:28:18 2013 -0500 @@ -168,11 +168,14 @@ $ hg bookmark -d REVSET $ hg bookmark -d TIP -rename without new name +rename without new name or multiple names $ hg bookmark -m Y abort: new bookmark name required [255] + $ hg bookmark -m Y Y2 Y3 + abort: only one new bookmark name allowed + [255] delete without name @@ -417,8 +420,9 @@ a@ 2:db815d6d32e6 x y 2:db815d6d32e6 - $ hg bookmark -d @ - $ hg bookmark -d a@ +delete multiple bookmarks at once + + $ hg bookmark -d @ a@ test clone with a bookmark named "default" (issue3677)