[PATCH STABLE] bookmarks: recreating the same bookmark should be a no-op (BC)
Patrick Mezard
patrick at mezard.eu
Mon Jul 30 08:35:29 CDT 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1343654778 -7200
# Branch stable
# Node ID 954100d6dacade7e43a794a4e248af48025938f8
# Parent 7a9246abf9febedfe00d6799bcb9a3383eb87beb
bookmarks: recreating the same bookmark should be a no-op (BC)
The following command sequences do not fail anymore:
$ hg bo abookmark
$ hg bo abookmark
$ hg bo -r . abookmark
$ hg bo --inactive abookmark
$ hg bo --inactive abookmark
$ hg bo --inactive -r . abookmark
Before this change the calls following the first one would have aborted with:
abort: bookmark 'abookmark' already exists (use -f to force)
As a side-effect, bookmarks on parent changeset can be activated without
--force.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -825,17 +825,18 @@
if inactive and mark == repo._bookmarkcurrent:
bookmarks.setcurrent(repo, None)
return
- if mark in marks and not force:
- raise util.Abort(_("bookmark '%s' already exists "
- "(use -f to force)") % mark)
if ((mark in repo.branchmap() or mark == repo.dirstate.branch())
and not force):
raise util.Abort(
_("a bookmark cannot have the name of an existing branch"))
if rev:
- marks[mark] = repo.lookup(rev)
+ target = repo.lookup(rev)
else:
- marks[mark] = cur
+ target = cur
+ if marks.get(mark, target) != target and not force:
+ raise util.Abort(_("bookmark '%s' already exists "
+ "(use -f to force)") % mark)
+ marks[mark] = target
if not inactive and cur == marks[mark]:
bookmarks.setcurrent(repo, mark)
bookmarks.write(repo)
diff --git a/tests/test-bookmarks-current.t b/tests/test-bookmarks-current.t
--- a/tests/test-bookmarks-current.t
+++ b/tests/test-bookmarks-current.t
@@ -168,3 +168,33 @@
$ hg up -q .
$ test -f .hg/bookmarks.current
[1]
+
+Creating the same bookmark on the same node should be a no-op, and could
+activate it without --force.
+
+ $ hg bookmarks
+ X 2:4f6d61883d64
+ Z 0:719295282060
+ $ hg bookmarks X
+ $ hg bookmarks
+ * X 2:4f6d61883d64
+ Z 0:719295282060
+ $ hg bookmarks -r . X
+
+Deactivating the same bookmark on the same node should be a no-op
+
+ $ hg bookmarks --inactive X
+ $ hg bookmarks
+ X 2:4f6d61883d64
+ Z 0:719295282060
+ $ hg bookmarks --inactive -r . X
+
+All this fails if the node is different
+
+ $ hg bookmarks --inactive -r 0 X
+ abort: bookmark 'X' already exists (use -f to force)
+ [255]
+ $ hg bookmarks -r 0 X
+ abort: bookmark 'X' already exists (use -f to force)
+ [255]
+
More information about the Mercurial-devel
mailing list