# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1502701571 -19800 # Node ID 1928e9c802dd17ac401f91067115c1d40e65f822 # Parent 32306ee328066eb874f4dd1e0433d57062e71431 convertbookmark: add logic to skip revisions with multiple bookmarks When a user tries to converts a bookmark to topic which is on a changeset with more bookmarks we skip that. diff -r 32306ee32806 -r 1928e9c802dd hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Fri Sep 01 18:02:50 2017 +0200 +++ b/hgext3rd/topic/__init__.py Mon Aug 14 14:36:11 2017 +0530 @@ -460,12 +460,29 @@ bmstore = repo._bookmarks lock = wlock = tr = None + nodetobook = {} + for book, revnode in bmstore.iteritems(): + if nodetobook.get(revnode): + nodetobook[revnode].append(book) + else: + nodetobook[revnode] = [book] + + # a list of nodes which we have skipped so that we don't print the skip + # warning repeatedly + skipped = [] + if bookmark: try: node = bmstore[bookmark] except KeyError: raise error.Abort(_("no such bookmark exists: '%s'") % bookmark) + if len(nodetobook[node]) > 1: + revnum = repo[node].rev() + ui.status(_("skipping revision '%d' as it has multiple bookmarks " + "on it\n") % revnum) + return + revnum = repo[node].rev() try: wlock = repo.wlock() @@ -485,9 +502,17 @@ lock = repo.lock() tr = repo.transaction('debugconvertbookmark') for bmark, revnode in sorted(storecopy.iteritems()): + revnum = repo[revnode].rev() + if revnum in skipped: + continue + if len(nodetobook[revnode]) > 1: + ui.status(_("skipping '%d' as it has multiple bookmarks on" + " it\n") % revnum) + skipped.append(revnum) + continue if bmark == '@': continue - _convertbmarktopic(ui, repo, repo[revnode].rev(), bmark, tr) + _convertbmarktopic(ui, repo, revnum, bmark, tr) tr.close() finally: lockmod.release(tr, lock, wlock) diff -r 32306ee32806 -r 1928e9c802dd tests/test-topic-debugcb.t --- a/tests/test-topic-debugcb.t Fri Sep 01 18:02:50 2017 +0200 +++ b/tests/test-topic-debugcb.t Mon Aug 14 14:36:11 2017 +0530 @@ -106,26 +106,17 @@ |/ topic: hellos o [0:3caf92e45cfb] First commit -XXX: When we have multiple bookmarks on the same changeset, we should skip that -and do nothing. This should be fixed. - $ hg debugconvertbookmark --all - switching to topic book1 - changed topic to "book1" on 3 revisions - changed topic to "book2" on 3 revisions + skipping '7' as it has multiple bookmarks on it $ hg log -G - o [13:f979f772bd7d] Trying multiple bookmarks - | topic: book2 - o [12:2397fdab7b79] Fixing second - | topic: book2 - o [11:0dd194861ea1] Fixing first - | topic: book2 - | @ [10:e738ed1df4b2] Trying multiple bookmarks - | | topic: book1 - | o [9:4198fce21412] Fixing second - | | topic: book1 - | o [8:221a9ddef504] Fixing first - |/ topic: book1 + @ [7:7c46b4bbdda3] Trying multiple bookmarks + | bookmark: book1 + | bookmark:book2 + | topic: secondfix + o [6:6efc0524f97a] Fixing second + | topic: secondfix + o [5:0a4244c62a16] Fixing first + | topic: secondfix | o [4:ca8825a7eb18] Second commit |/ topic: hellos o [0:3caf92e45cfb] First commit