Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 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 | 23f785b38af3 |
children | 05390cfe678a |
comparison
equal
deleted
inserted
replaced
19146:a718a0ba6787 | 19147:5b1835485442 |
---|---|
765 [('f', 'force', False, _('force')), | 765 [('f', 'force', False, _('force')), |
766 ('r', 'rev', '', _('revision'), _('REV')), | 766 ('r', 'rev', '', _('revision'), _('REV')), |
767 ('d', 'delete', False, _('delete a given bookmark')), | 767 ('d', 'delete', False, _('delete a given bookmark')), |
768 ('m', 'rename', '', _('rename a given bookmark'), _('NAME')), | 768 ('m', 'rename', '', _('rename a given bookmark'), _('NAME')), |
769 ('i', 'inactive', False, _('mark a bookmark inactive'))], | 769 ('i', 'inactive', False, _('mark a bookmark inactive'))], |
770 _('hg bookmarks [-f] [-d] [-i] [-m NAME] [-r REV] [NAME]')) | 770 _('hg bookmarks [OPTIONS]... [NAME]...')) |
771 def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, | 771 def bookmark(ui, repo, *names, **opts): |
772 rename=None, inactive=False): | |
773 '''track a line of development with movable markers | 772 '''track a line of development with movable markers |
774 | 773 |
775 Bookmarks are pointers to certain commits that move when committing. | 774 Bookmarks are pointers to certain commits that move when committing. |
776 Bookmarks are local. They can be renamed, copied and deleted. It is | 775 Bookmarks are local. They can be renamed, copied and deleted. It is |
777 possible to use :hg:`merge NAME` to merge from a given bookmark, and | 776 possible to use :hg:`merge NAME` to merge from a given bookmark, and |
794 With -i/--inactive, the new bookmark will not be made the active | 793 With -i/--inactive, the new bookmark will not be made the active |
795 bookmark. If -r/--rev is given, the new bookmark will not be made | 794 bookmark. If -r/--rev is given, the new bookmark will not be made |
796 active even if -i/--inactive is not given. If no NAME is given, the | 795 active even if -i/--inactive is not given. If no NAME is given, the |
797 current active bookmark will be marked inactive. | 796 current active bookmark will be marked inactive. |
798 ''' | 797 ''' |
798 force = opts.get('force') | |
799 rev = opts.get('rev') | |
800 delete = opts.get('delete') | |
801 rename = opts.get('rename') | |
802 inactive = opts.get('inactive') | |
803 | |
799 hexfn = ui.debugflag and hex or short | 804 hexfn = ui.debugflag and hex or short |
800 marks = repo._bookmarks | 805 marks = repo._bookmarks |
801 cur = repo.changectx('.').node() | 806 cur = repo.changectx('.').node() |
802 | 807 |
803 def checkformat(mark): | 808 def checkformat(mark): |
844 raise util.Abort(_("--delete and --rename are incompatible")) | 849 raise util.Abort(_("--delete and --rename are incompatible")) |
845 if delete and rev: | 850 if delete and rev: |
846 raise util.Abort(_("--rev is incompatible with --delete")) | 851 raise util.Abort(_("--rev is incompatible with --delete")) |
847 if rename and rev: | 852 if rename and rev: |
848 raise util.Abort(_("--rev is incompatible with --rename")) | 853 raise util.Abort(_("--rev is incompatible with --rename")) |
849 if mark is None and (delete or rev): | 854 if not names and (delete or rev): |
850 raise util.Abort(_("bookmark name required")) | 855 raise util.Abort(_("bookmark name required")) |
851 | 856 |
852 if delete: | 857 if delete: |
853 if mark not in marks: | 858 for mark in names: |
854 raise util.Abort(_("bookmark '%s' does not exist") % mark) | 859 if mark not in marks: |
855 if mark == repo._bookmarkcurrent: | 860 raise util.Abort(_("bookmark '%s' does not exist") % mark) |
856 bookmarks.setcurrent(repo, None) | 861 if mark == repo._bookmarkcurrent: |
857 del marks[mark] | 862 bookmarks.setcurrent(repo, None) |
863 del marks[mark] | |
858 marks.write() | 864 marks.write() |
859 | 865 |
860 elif rename: | 866 elif rename: |
861 if mark is None: | 867 if not names: |
862 raise util.Abort(_("new bookmark name required")) | 868 raise util.Abort(_("new bookmark name required")) |
863 mark = checkformat(mark) | 869 elif len(names) > 1: |
870 raise util.Abort(_("only one new bookmark name allowed")) | |
871 mark = checkformat(names[0]) | |
864 if rename not in marks: | 872 if rename not in marks: |
865 raise util.Abort(_("bookmark '%s' does not exist") % rename) | 873 raise util.Abort(_("bookmark '%s' does not exist") % rename) |
866 checkconflict(repo, mark, force) | 874 checkconflict(repo, mark, force) |
867 marks[mark] = marks[rename] | 875 marks[mark] = marks[rename] |
868 if repo._bookmarkcurrent == rename and not inactive: | 876 if repo._bookmarkcurrent == rename and not inactive: |
869 bookmarks.setcurrent(repo, mark) | 877 bookmarks.setcurrent(repo, mark) |
870 del marks[rename] | 878 del marks[rename] |
871 marks.write() | 879 marks.write() |
872 | 880 |
873 elif mark is not None: | 881 elif names: |
874 mark = checkformat(mark) | 882 newact = None |
875 if inactive and mark == repo._bookmarkcurrent: | 883 for mark in names: |
876 bookmarks.setcurrent(repo, None) | 884 mark = checkformat(mark) |
877 return | 885 if newact is None: |
878 tgt = cur | 886 newact = mark |
879 if rev: | 887 if inactive and mark == repo._bookmarkcurrent: |
880 tgt = scmutil.revsingle(repo, rev).node() | 888 bookmarks.setcurrent(repo, None) |
881 checkconflict(repo, mark, force, tgt) | 889 return |
882 marks[mark] = tgt | 890 tgt = cur |
883 if not inactive and cur == marks[mark] and not rev: | 891 if rev: |
884 bookmarks.setcurrent(repo, mark) | 892 tgt = scmutil.revsingle(repo, rev).node() |
885 elif cur != tgt and mark == repo._bookmarkcurrent: | 893 checkconflict(repo, mark, force, tgt) |
894 marks[mark] = tgt | |
895 if not inactive and cur == marks[newact] and not rev: | |
896 bookmarks.setcurrent(repo, newact) | |
897 elif cur != tgt and newact == repo._bookmarkcurrent: | |
886 bookmarks.setcurrent(repo, None) | 898 bookmarks.setcurrent(repo, None) |
887 marks.write() | 899 marks.write() |
888 | 900 |
889 # Same message whether trying to deactivate the current bookmark (-i | 901 # Same message whether trying to deactivate the current bookmark (-i |
890 # with no NAME) or listing bookmarks | 902 # with no NAME) or listing bookmarks |