955 rev = opts.get('rev') |
955 rev = opts.get('rev') |
956 delete = opts.get('delete') |
956 delete = opts.get('delete') |
957 rename = opts.get('rename') |
957 rename = opts.get('rename') |
958 inactive = opts.get('inactive') |
958 inactive = opts.get('inactive') |
959 |
959 |
960 def checkconflict(repo, mark, cur, force=False, target=None): |
|
961 if mark in marks and not force: |
|
962 if target: |
|
963 if marks[mark] == target and target == cur: |
|
964 # re-activating a bookmark |
|
965 return |
|
966 anc = repo.changelog.ancestors([repo[target].rev()]) |
|
967 bmctx = repo[marks[mark]] |
|
968 divs = [repo[b].node() for b in marks |
|
969 if b.split('@', 1)[0] == mark.split('@', 1)[0]] |
|
970 |
|
971 # allow resolving a single divergent bookmark even if moving |
|
972 # the bookmark across branches when a revision is specified |
|
973 # that contains a divergent bookmark |
|
974 if bmctx.rev() not in anc and target in divs: |
|
975 bookmarks.deletedivergent(repo, [target], mark) |
|
976 return |
|
977 |
|
978 deletefrom = [b for b in divs |
|
979 if repo[b].rev() in anc or b == target] |
|
980 bookmarks.deletedivergent(repo, deletefrom, mark) |
|
981 if bookmarks.validdest(repo, bmctx, repo[target]): |
|
982 ui.status(_("moving bookmark '%s' forward from %s\n") % |
|
983 (mark, short(bmctx.node()))) |
|
984 return |
|
985 raise error.Abort(_("bookmark '%s' already exists " |
|
986 "(use -f to force)") % mark) |
|
987 if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) |
|
988 and not force): |
|
989 raise error.Abort( |
|
990 _("a bookmark cannot have the name of an existing branch")) |
|
991 if len(mark) > 3 and not force: |
|
992 try: |
|
993 shadowhash = (mark in repo) |
|
994 except error.LookupError: # ambiguous identifier |
|
995 shadowhash = False |
|
996 if shadowhash: |
|
997 repo.ui.warn( |
|
998 _("bookmark %s matches a changeset hash\n" |
|
999 "(did you leave a -r out of an 'hg bookmark' command?)\n") |
|
1000 % mark) |
|
1001 |
|
1002 if delete and rename: |
960 if delete and rename: |
1003 raise error.Abort(_("--delete and --rename are incompatible")) |
961 raise error.Abort(_("--delete and --rename are incompatible")) |
1004 if delete and rev: |
962 if delete and rev: |
1005 raise error.Abort(_("--rev is incompatible with --delete")) |
963 raise error.Abort(_("--rev is incompatible with --delete")) |
1006 if rename and rev: |
964 if rename and rev: |
1033 raise error.Abort(_("only one new bookmark name allowed")) |
991 raise error.Abort(_("only one new bookmark name allowed")) |
1034 mark = bookmarks.checkformat(repo, names[0]) |
992 mark = bookmarks.checkformat(repo, names[0]) |
1035 if rename not in marks: |
993 if rename not in marks: |
1036 raise error.Abort(_("bookmark '%s' does not exist") |
994 raise error.Abort(_("bookmark '%s' does not exist") |
1037 % rename) |
995 % rename) |
1038 checkconflict(repo, mark, cur, force) |
996 marks.checkconflict(mark, force) |
1039 marks[mark] = marks[rename] |
997 marks[mark] = marks[rename] |
1040 if repo._activebookmark == rename and not inactive: |
998 if repo._activebookmark == rename and not inactive: |
1041 bookmarks.activate(repo, mark) |
999 bookmarks.activate(repo, mark) |
1042 del marks[rename] |
1000 del marks[rename] |
1043 elif names: |
1001 elif names: |
1051 bookmarks.deactivate(repo) |
1009 bookmarks.deactivate(repo) |
1052 return |
1010 return |
1053 tgt = cur |
1011 tgt = cur |
1054 if rev: |
1012 if rev: |
1055 tgt = scmutil.revsingle(repo, rev).node() |
1013 tgt = scmutil.revsingle(repo, rev).node() |
1056 checkconflict(repo, mark, cur, force, tgt) |
1014 marks.checkconflict(mark, force, tgt) |
1057 marks[mark] = tgt |
1015 marks[mark] = tgt |
1058 if not inactive and cur == marks[newact] and not rev: |
1016 if not inactive and cur == marks[newact] and not rev: |
1059 bookmarks.activate(repo, newact) |
1017 bookmarks.activate(repo, newact) |
1060 elif cur != tgt and newact == repo._activebookmark: |
1018 elif cur != tgt and newact == repo._activebookmark: |
1061 bookmarks.deactivate(repo) |
1019 bookmarks.deactivate(repo) |