[PATCH 6 of 6] bookmarks: move parse() and current() in the property definitions

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


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1261376588 -32400
# Node ID b030971ea7222009adf928a56ba2ffc3cd735241
# Parent  1cdeeee6132778aa48ad83fa63c2a4e6e0d0597d
bookmarks: move parse() and current() in the property definitions

They are only called once when fetching _bookmarks/_bookmarkcurrent.

diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py
--- a/hgext/bookmarks.py
+++ b/hgext/bookmarks.py
@@ -33,22 +33,6 @@
 from mercurial import util, commands, localrepo, repair, extensions
 import os
 
-def parse(repo):
-    '''Parse .hg/bookmarks file and return a dictionary
-
-    Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values
-    in the .hg/bookmarks file. They are read returned as a dictionary
-    with name => hash values.
-    '''
-    try:
-        bookmarks = {}
-        for line in repo.opener('bookmarks'):
-            sha, refspec = line.strip().split(' ', 1)
-            bookmarks[refspec] = super(bookmark_repo, repo).lookup(sha)
-    except:
-        pass
-    return bookmarks
-
 def write(repo):
     '''Write bookmarks
 
@@ -72,23 +56,6 @@
     finally:
         wlock.release()
 
-def current(repo):
-    '''Get the current bookmark
-
-    If we use gittishsh branches we have a current bookmark that
-    we are on. This function returns the name of the bookmark. It
-    is stored in .hg/bookmarks.current
-    '''
-    mark = None
-    if os.path.exists(repo.join('bookmarks.current')):
-        file = repo.opener('bookmarks.current')
-        # No readline() in posixfile_nt, reading everything is cheap
-        mark = (file.readlines() or [''])[0]
-        if mark == '':
-            mark = None
-        file.close()
-    return mark
-
 def setcurrent(repo, mark):
     '''Set the name of the bookmark that we are currently on
 
@@ -234,11 +201,38 @@
 
         @util.propertycache
         def _bookmarks(self):
-            return parse(self)
+            '''Parse .hg/bookmarks file and return a dictionary
+
+            Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values
+            in the .hg/bookmarks file. They are read returned as a dictionary
+            with name => hash values.
+            '''
+            try:
+                bookmarks = {}
+                for line in repo.opener('bookmarks'):
+                    sha, refspec = line.strip().split(' ', 1)
+                    bookmarks[refspec] = super(bookmark_repo, repo).lookup(sha)
+            except:
+                pass
+            return bookmarks
 
         @util.propertycache
         def _bookmarkcurrent(self):
-            return current(self)
+            '''Get the current bookmark
+
+            If we use gittishsh branches we have a current bookmark that
+            we are on. This function returns the name of the bookmark. It
+            is stored in .hg/bookmarks.current
+            '''
+            mark = None
+            if os.path.exists(self.join('bookmarks.current')):
+                file = self.opener('bookmarks.current')
+                # No readline() in posixfile_nt, reading everything is cheap
+                mark = (file.readlines() or [''])[0]
+                if mark == '':
+                    mark = None
+                file.close()
+            return mark
 
         def rollback(self):
             if os.path.exists(self.join('undo.bookmarks')):


More information about the Mercurial-devel mailing list