bookmarks: split bookmark serialization and file handling
authorPierre-Yves David <pierre-yves.david@fb.com>
Sat, 27 Sep 2014 03:10:33 -0700
changeset 22664 6bd685d2a2de
parent 22663 4c6198737ad8
child 22665 8319f7e78395
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.
mercurial/bookmarks.py
--- 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