# HG changeset patch # User FUJIWARA Katsunori # Date 1426584024 -32400 # Node ID ca4b89683078a7199e108799afdeb5943b8a97c3 # Parent 194e1e3ebc29b1ee8e06c680f975b3a939f78f7e bookmarks: reuse @number bookmark, if it refers changeset referred remotely Before this patch, "@number" suffixed bookmark may be newly created at each "hg pull" from the remote repository, if the bookmark in remote repository diverges from one in local one. This causes unexpected increase of "@number" suffixed bookmarks. This patch reuses "@number" suffixed bookmark, if it refers the changeset which is referred by the same bookmark in the remote repository. diff -r 194e1e3ebc29 -r ca4b89683078 mercurial/bookmarks.py --- a/mercurial/bookmarks.py Tue Mar 17 18:20:24 2015 +0900 +++ b/mercurial/bookmarks.py Tue Mar 17 18:20:24 2015 +0900 @@ -362,11 +362,14 @@ return results -def _diverge(ui, b, path, localmarks): +def _diverge(ui, b, path, localmarks, remotenode): '''Return appropriate diverged bookmark for specified ``path`` This returns None, if it is failed to assign any divergent bookmark name. + + This reuses already existing one with "@number" suffix, if it + refers ``remotenode``. ''' if b == '@': b = '' @@ -383,7 +386,7 @@ # assign a unique "@number" suffix newly for x in range(1, 100): n = '%s@%d' % (b, x) - if n not in localmarks: + if n not in localmarks or localmarks[n] == remotenode: return n return None @@ -417,9 +420,10 @@ changed.append((b, bin(scid), status, _("importing bookmark %s\n") % (b))) else: - db = _diverge(ui, b, path, localmarks) + snode = bin(scid) + db = _diverge(ui, b, path, localmarks, snode) if db: - changed.append((db, bin(scid), warn, + changed.append((db, snode, warn, _("divergent bookmark %s stored as %s\n") % (b, db))) else: diff -r 194e1e3ebc29 -r ca4b89683078 tests/test-bookmarks-pushpull.t --- a/tests/test-bookmarks-pushpull.t Tue Mar 17 18:20:24 2015 +0900 +++ b/tests/test-bookmarks-pushpull.t Tue Mar 17 18:20:24 2015 +0900 @@ -182,6 +182,24 @@ $ hg bookmarks | grep '^ X' | grep -v ':000000000000' X 1:9b140be10808 X@foo 2:0d2164f0ce0d + +(test that remotely diverged bookmarks are reused if they aren't changed) + + $ hg bookmarks | grep '^ @' + @ 1:9b140be10808 + @1 2:0d2164f0ce0d + @foo 2:0d2164f0ce0d + $ hg pull ../a + pulling from ../a + searching for changes + no changes found + warning: failed to assign numbered name to divergent bookmark X + divergent bookmark @ stored as @1 + $ hg bookmarks | grep '^ @' + @ 1:9b140be10808 + @1 2:0d2164f0ce0d + @foo 2:0d2164f0ce0d + $ python $TESTTMP/seq.py 1 100 | while read i; do hg bookmarks -d "X@${i}"; done $ hg bookmarks -d "@1"