[PATCH 4 of 6] bookmarks: repo._bookmarkcurrent should be a propertycache

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


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1261371640 -32400
# Node ID 35575c594a14b6cdd4bd0505947f7a7dd5088857
# Parent  449f9a2356777e12a06b07dcdc2536215c687d02
bookmarks: repo._bookmarkcurrent should be a propertycache

replace all current() calls by an attribute access

diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py
--- a/hgext/bookmarks.py
+++ b/hgext/bookmarks.py
@@ -61,7 +61,7 @@
     refs = repo._bookmarks
     if os.path.exists(repo.join('bookmarks')):
         util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
-    if current(repo) not in refs:
+    if repo._bookmarkcurrent not in refs:
         setcurrent(repo, None)
     wlock = repo.wlock()
     try:
@@ -79,8 +79,6 @@
     we are on. This function returns the name of the bookmark. It
     is stored in .hg/bookmarks.current
     '''
-    if repo._bookmarkcurrent:
-        return repo._bookmarkcurrent
     mark = None
     if os.path.exists(repo.join('bookmarks.current')):
         file = repo.opener('bookmarks.current')
@@ -89,7 +87,6 @@
         if mark == '':
             mark = None
         file.close()
-    repo._bookmarkcurrent = mark
     return mark
 
 def setcurrent(repo, mark):
@@ -98,14 +95,15 @@
     Set the name of the bookmark that we are on (hg update <bookmark>).
     The name is recorded in .hg/bookmarks.current
     '''
-    if current(repo) == mark:
+    current = repo._bookmarkcurrent
+    if current == mark:
         return
 
     refs = repo._bookmarks
 
     # do not update if we do update to a rev equal to the current bookmark
     if (mark and mark not in refs and
-        current(repo) and refs[current(repo)] == repo.changectx('.').node()):
+        current and refs[current] == repo.changectx('.').node()):
         return
     if mark not in refs:
         mark = ''
@@ -144,7 +142,7 @@
             raise util.Abort(_("new bookmark name required"))
         marks[mark] = marks[rename]
         del marks[rename]
-        if current(repo) == rename:
+        if repo._bookmarkcurrent == rename:
             setcurrent(repo, mark)
         write(repo)
         return
@@ -154,7 +152,7 @@
             raise util.Abort(_("bookmark name required"))
         if mark not in marks:
             raise util.Abort(_("a bookmark of this name does not exist"))
-        if mark == current(repo):
+        if mark == repo._bookmarkcurrent:
             setcurrent(repo, None)
         del marks[mark]
         write(repo)
@@ -186,7 +184,8 @@
         else:
             for bmark, n in marks.iteritems():
                 if ui.configbool('bookmarks', 'track.current'):
-                    prefix = (bmark == current(repo) and n == cur) and '*' or ' '
+                    current = repo._bookmarkcurrent
+                    prefix = (bmark == current and n == cur) and '*' or ' '
                 else:
                     prefix = (n == cur) and '*' or ' '
 
@@ -231,14 +230,16 @@
     if not repo.local():
         return
 
-    repo._bookmarkcurrent = None
-
     class bookmark_repo(repo.__class__):
 
         @util.propertycache
         def _bookmarks(self):
             return parse(self)
 
+        @util.propertycache
+        def _bookmarkcurrent(self):
+            return current(self)
+
         def rollback(self):
             if os.path.exists(self.join('undo.bookmarks')):
                 util.rename(self.join('undo.bookmarks'), self.join('bookmarks'))
@@ -263,7 +264,7 @@
                 marks = self._bookmarks
                 update = False
                 if ui.configbool('bookmarks', 'track.current'):
-                    mark = current(self)
+                    mark = self._bookmarkcurrent
                     if mark and marks[mark] in parents:
                         marks[mark] = node
                         update = True
@@ -290,7 +291,7 @@
             marks = self._bookmarks
             update = False
             if ui.configbool('bookmarks', 'track.current'):
-                mark = current(self)
+                mark = self._bookmarkcurrent
                 if mark and marks[mark] in parents:
                     marks[mark] = node
                     update = True


More information about the Mercurial-devel mailing list