Mercurial > hg-stable
comparison mercurial/commands.py @ 17789:4cfd02c2df9a
bookmarks: check bookmark format during rename (issue3662)
author | David Soria Parra <dsp@php.net> |
---|---|
date | Wed, 17 Oct 2012 08:44:49 +0200 |
parents | 9912baaae7df |
children | 0291e122fb05 |
comparison
equal
deleted
inserted
replaced
17788:9912baaae7df | 17789:4cfd02c2df9a |
---|---|
787 ''' | 787 ''' |
788 hexfn = ui.debugflag and hex or short | 788 hexfn = ui.debugflag and hex or short |
789 marks = repo._bookmarks | 789 marks = repo._bookmarks |
790 cur = repo.changectx('.').node() | 790 cur = repo.changectx('.').node() |
791 | 791 |
792 def checkformat(mark): | |
793 if "\n" in mark: | |
794 raise util.Abort(_("bookmark name cannot contain newlines")) | |
795 mark = mark.strip() | |
796 if not mark: | |
797 raise util.Abort(_("bookmark names cannot consist entirely of " | |
798 "whitespace")) | |
799 return mark | |
800 | |
801 def checkconflict(repo, mark, force=False): | |
802 if mark in marks and not force: | |
803 raise util.Abort(_("bookmark '%s' already exists " | |
804 "(use -f to force)") % mark) | |
805 if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) | |
806 and not force): | |
807 raise util.Abort( | |
808 _("a bookmark cannot have the name of an existing branch")) | |
809 | |
792 if delete: | 810 if delete: |
793 if mark is None: | 811 if mark is None: |
794 raise util.Abort(_("bookmark name required")) | 812 raise util.Abort(_("bookmark name required")) |
795 if mark not in marks: | 813 if mark not in marks: |
796 raise util.Abort(_("bookmark '%s' does not exist") % mark) | 814 raise util.Abort(_("bookmark '%s' does not exist") % mark) |
799 del marks[mark] | 817 del marks[mark] |
800 bookmarks.write(repo) | 818 bookmarks.write(repo) |
801 return | 819 return |
802 | 820 |
803 if rename: | 821 if rename: |
822 if mark is None: | |
823 raise util.Abort(_("new bookmark name required")) | |
824 mark = checkformat(mark) | |
804 if rename not in marks: | 825 if rename not in marks: |
805 raise util.Abort(_("bookmark '%s' does not exist") % rename) | 826 raise util.Abort(_("bookmark '%s' does not exist") % rename) |
806 if mark in marks and not force: | 827 checkconflict(repo, mark, force) |
807 raise util.Abort(_("bookmark '%s' already exists " | |
808 "(use -f to force)") % mark) | |
809 if mark is None: | |
810 raise util.Abort(_("new bookmark name required")) | |
811 marks[mark] = marks[rename] | 828 marks[mark] = marks[rename] |
812 if repo._bookmarkcurrent == rename and not inactive: | 829 if repo._bookmarkcurrent == rename and not inactive: |
813 bookmarks.setcurrent(repo, mark) | 830 bookmarks.setcurrent(repo, mark) |
814 del marks[rename] | 831 del marks[rename] |
815 bookmarks.write(repo) | 832 bookmarks.write(repo) |
816 return | 833 return |
817 | 834 |
818 if mark is not None: | 835 if mark is not None: |
819 if "\n" in mark: | 836 mark = checkformat(mark) |
820 raise util.Abort(_("bookmark name cannot contain newlines")) | |
821 mark = mark.strip() | |
822 if not mark: | |
823 raise util.Abort(_("bookmark names cannot consist entirely of " | |
824 "whitespace")) | |
825 if inactive and mark == repo._bookmarkcurrent: | 837 if inactive and mark == repo._bookmarkcurrent: |
826 bookmarks.setcurrent(repo, None) | 838 bookmarks.setcurrent(repo, None) |
827 return | 839 return |
828 if mark in marks and not force: | 840 checkconflict(repo, mark, force) |
829 raise util.Abort(_("bookmark '%s' already exists " | |
830 "(use -f to force)") % mark) | |
831 if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) | |
832 and not force): | |
833 raise util.Abort( | |
834 _("a bookmark cannot have the name of an existing branch")) | |
835 if rev: | 841 if rev: |
836 marks[mark] = scmutil.revsingle(repo, rev).node() | 842 marks[mark] = scmutil.revsingle(repo, rev).node() |
837 else: | 843 else: |
838 marks[mark] = cur | 844 marks[mark] = cur |
839 if not inactive and cur == marks[mark]: | 845 if not inactive and cur == marks[mark]: |