changeset 22664:6bd685d2a2de

bookmarks: split bookmark serialization and file handling If we want to handle bookmarks in a transaction we need to decouple the file handling and the actual production of the content. This is similar to how we handle phases in transaction.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 27 Sep 2014 03:10:33 -0700
parents 4c6198737ad8
children 8319f7e78395
files mercurial/bookmarks.py
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Sun Sep 28 00:36:42 2014 -0700
+++ b/mercurial/bookmarks.py	Sat Sep 27 03:10:33 2014 -0700
@@ -64,8 +64,7 @@
         try:
 
             file = repo.vfs('bookmarks', 'w', atomictemp=True)
-            for name, node in self.iteritems():
-                file.write("%s %s\n" % (hex(node), encoding.fromlocal(name)))
+            self._write(file)
             file.close()
 
             # touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
@@ -77,6 +76,10 @@
         finally:
             wlock.release()
 
+    def _write(self, fp):
+        for name, node in self.iteritems():
+            fp.write("%s %s\n" % (hex(node), encoding.fromlocal(name)))
+
 def readcurrent(repo):
     '''Get the current bookmark