[PATCH 5 of 6] bookmarks: refactor code responsible for updates of bookmarks

Nicolas Dumazet nicdumz at gmail.com
Mon Dec 21 00:25:00 CST 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1261376248 -32400
# Node ID 1cdeeee6132778aa48ad83fa63c2a4e6e0d0597d
# Parent  35575c594a14b6cdd4bd0505947f7a7dd5088857
bookmarks: refactor code responsible for updates of bookmarks

introduce _bookmarksupdate for common parts from commitctx and addchangegroup

diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py
--- a/hgext/bookmarks.py
+++ b/hgext/bookmarks.py
@@ -250,44 +250,7 @@
                 key = self._bookmarks[key]
             return super(bookmark_repo, self).lookup(key)
 
-        def commitctx(self, ctx, error=False):
-            """Add a revision to the repository and
-            move the bookmark"""
-            wlock = self.wlock() # do both commit and bookmark with lock held
-            try:
-                node  = super(bookmark_repo, self).commitctx(ctx, error)
-                if node is None:
-                    return None
-                parents = self.changelog.parents(node)
-                if parents[1] == nullid:
-                    parents = (parents[0],)
-                marks = self._bookmarks
-                update = False
-                if ui.configbool('bookmarks', 'track.current'):
-                    mark = self._bookmarkcurrent
-                    if mark and marks[mark] in parents:
-                        marks[mark] = node
-                        update = True
-                else:
-                    for mark, n in marks.items():
-                        if n in parents:
-                            marks[mark] = node
-                            update = True
-                if update:
-                    write(self)
-                return node
-            finally:
-                wlock.release()
-
-        def addchangegroup(self, source, srctype, url, emptyok=False):
-            parents = self.dirstate.parents()
-
-            result = super(bookmark_repo, self).addchangegroup(
-                source, srctype, url, emptyok)
-            if result > 1:
-                # We have more heads than before
-                return result
-            node = self.changelog.tip()
+        def _bookmarksupdate(self, parents, node):
             marks = self._bookmarks
             update = False
             if ui.configbool('bookmarks', 'track.current'):
@@ -302,6 +265,35 @@
                         update = True
             if update:
                 write(self)
+
+        def commitctx(self, ctx, error=False):
+            """Add a revision to the repository and
+            move the bookmark"""
+            wlock = self.wlock() # do both commit and bookmark with lock held
+            try:
+                node  = super(bookmark_repo, self).commitctx(ctx, error)
+                if node is None:
+                    return None
+                parents = self.changelog.parents(node)
+                if parents[1] == nullid:
+                    parents = (parents[0],)
+
+                self._bookmarksupdate(parents, node)
+                return node
+            finally:
+                wlock.release()
+
+        def addchangegroup(self, source, srctype, url, emptyok=False):
+            parents = self.dirstate.parents()
+
+            result = super(bookmark_repo, self).addchangegroup(
+                source, srctype, url, emptyok)
+            if result > 1:
+                # We have more heads than before
+                return result
+            node = self.changelog.tip()
+
+            self._bookmarksupdate(parents, node)
             return result
 
         def _findtags(self):


More information about the Mercurial-devel mailing list