changeset 2907:d617128279f6

converbookmark: split target computation from actual update This will allow for further refactoring helping consistency.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 01 Sep 2017 18:33:08 +0200
parents 92566275be77
children 95bb27b8918c
files hgext3rd/topic/__init__.py
diffstat 1 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Fri Sep 01 17:09:17 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Sep 01 18:33:08 2017 +0200
@@ -488,7 +488,8 @@
             wlock = repo.wlock()
             lock = repo.lock()
             tr = repo.transaction('debugconvertbookmark')
-            _convertbmarktopic(ui, repo, revnum, bookmark, tr)
+            targetrevs = _findconvertbmarktopic(repo, bookmark)
+            _applyconvertbmarktopic(ui, repo, targetrevs, revnum, bookmark, tr)
             tr.close()
         finally:
             lockmod.release(tr, lock, wlock)
@@ -512,7 +513,8 @@
                     continue
                 if bmark == '@':
                     continue
-                _convertbmarktopic(ui, repo, revnum, bmark, tr)
+                targetrevs = _findconvertbmarktopic(repo, bmark)
+                _applyconvertbmarktopic(ui, repo, targetrevs, revnum, bmark, tr)
             tr.close()
         finally:
             lockmod.release(tr, lock, wlock)
@@ -534,15 +536,23 @@
 )
 """
 
-def _convertbmarktopic(ui, repo, rev, bmark, tr):
-    """Sets a topic as same as bname to all the changesets under the bookmark
+def _findconvertbmarktopic(repo, bmark):
+    """find revisions unambigiously defined by a bookmark
+
+    find all changesets under the bookmark and under that bookmark only.
+    """
+    return repo.revs(CONVERTBOOKREVSET, bmark, bmark, bmark)
+
+def _applyconvertbmarktopic(ui, repo, revs, old, bmark, tr):
+    """apply bookmark convertion to topic
+
+    Sets a topic as same as bname to all the changesets under the bookmark
     and delete the bookmark, if topic is set to any changeset
 
-    rev is the revision on which bookmark bmark is and tr is transaction object.
+    old is the revision on which bookmark bmark is and tr is transaction object.
     """
 
-    touchedrevs = repo.revs(CONVERTBOOKREVSET, bmark, bmark, bmark)
-    rewrote = _changetopics(ui, repo, touchedrevs, bmark)
+    rewrote = _changetopics(ui, repo, revs, bmark)
     # We didn't changed topic to any changesets because the revset
     # returned an empty set of revisions, so let's skip deleting the
     # bookmark corresponding to which we didn't put a topic on any
@@ -551,7 +561,7 @@
         return
     ui.status(_('changed topic to "%s" on %d revisions\n') % (bmark,
               rewrote))
-    ui.debug('removing bookmark "%s" from "%d"' % (bmark, rev))
+    ui.debug('removing bookmark "%s" from "%d"' % (bmark, old))
     bookmarks.delete(repo, tr, [bmark])
 
 def _changecurrenttopic(repo, newtopic):