Patchwork [05,of,10] bookmark: use 'divergent2delete' in checkconflict

login
register
mail settings
Submitter Boris Feld
Date July 15, 2017, 11:42 a.m.
Message ID <3c70ad3b3daaeb8b2386.1500118973@FB>
Download mbox | patch
Permalink /patch/22398/
State Accepted
Headers show

Comments

Boris Feld - July 15, 2017, 11:42 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1499709752 -7200
#      Mon Jul 10 20:02:32 2017 +0200
# Node ID 3c70ad3b3daaeb8b2386b9d8760ac69e6dce0ecc
# Parent  08c2a3d309e8619e0cc3ec16c4ae02722b9a1118
# EXP-Topic tr.changes.bookmarks
bookmark: use 'divergent2delete' in checkconflict

checkconflict used to also do some bookmark deletion in case of divergence. It
is a bit suspicious given the function name, but it's not the goal of this
series.

In order to unify bookmarks changing, checkconflict now return the list of
divergent bookmarks to clean up and the callers must clean them by calling
applyphases.

Patch

diff -r 08c2a3d309e8 -r 3c70ad3b3daa mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Mon Jul 10 19:12:25 2017 +0200
+++ b/mercurial/bookmarks.py	Mon Jul 10 20:02:32 2017 +0200
@@ -183,13 +183,15 @@ 
 
         If force is supplied, then forcibly move the bookmark to a new commit
         regardless if it is a move forward.
+
+        If divergent bookmark are to be deleted, they will be returned as list.
         """
         cur = self._repo.changectx('.').node()
         if mark in self and not force:
             if target:
                 if self[mark] == target and target == cur:
                     # re-activating a bookmark
-                    return
+                    return []
                 rev = self._repo[target].rev()
                 anc = self._repo.changelog.ancestors([rev])
                 bmctx = self._repo[self[mark]]
@@ -200,17 +202,16 @@ 
                 # the bookmark across branches when a revision is specified
                 # that contains a divergent bookmark
                 if bmctx.rev() not in anc and target in divs:
-                    deletedivergent(self._repo, [target], mark)
-                    return
+                    return divergent2delete(self._repo, [target], mark)
 
                 deletefrom = [b for b in divs
                               if self._repo[b].rev() in anc or b == target]
-                deletedivergent(self._repo, deletefrom, mark)
+                delbms = divergent2delete(self._repo, deletefrom, mark)
                 if validdest(self._repo, bmctx, self._repo[target]):
                     self._repo.ui.status(
                         _("moving bookmark '%s' forward from %s\n") %
                         (mark, short(bmctx.node())))
-                    return
+                    return delbms
             raise error.Abort(_("bookmark '%s' already exists "
                                 "(use -f to force)") % mark)
         if ((mark in self._repo.branchmap() or
@@ -228,6 +229,7 @@ 
                       "(did you leave a -r out of an 'hg bookmark' "
                       "command?)\n")
                     % mark)
+        return []
 
 def _readactive(repo, marks):
     """
@@ -747,8 +749,10 @@ 
     mark = checkformat(repo, new)
     if old not in marks:
         raise error.Abort(_("bookmark '%s' does not exist") % old)
-    marks.checkconflict(mark, force)
-    changes = [(mark, marks[old]), (old, None)]
+    changes = []
+    for bm in marks.checkconflict(mark, force):
+        changes.append((bm, None))
+    changes.extend([(mark, marks[old]), (old, None)])
     marks.applychanges(repo, tr, changes)
     if repo._activebookmark == old and not inactive:
         activate(repo, mark)
@@ -778,7 +782,8 @@ 
         tgt = cur
         if rev:
             tgt = scmutil.revsingle(repo, rev).node()
-        marks.checkconflict(mark, force, tgt)
+        for bm in marks.checkconflict(mark, force, tgt):
+            changes.append((bm, None))
         changes.append((mark, tgt))
     marks.applychanges(repo, tr, changes)
     if not inactive and cur == marks[newact] and not rev: