journal: use tryread helper to backup files (issue3375)
authorMatt Mackall <mpm@selenic.com>
Tue, 17 Apr 2012 11:13:38 -0500
changeset 16456 42862d64aa8f
parent 16455 154219f3a6a4
child 16457 91196ebcaeed
journal: use tryread helper to backup files (issue3375)
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Tue Apr 17 11:11:59 2012 -0500
+++ b/mercurial/localrepo.py	Tue Apr 17 11:13:38 2012 -0500
@@ -743,28 +743,16 @@
         return [undoname(x) for x in self._journalfiles()]
 
     def _writejournal(self, desc):
-        # save dirstate for rollback
-        try:
-            ds = self.opener.read("dirstate")
-        except IOError:
-            ds = ""
-        self.opener.write("journal.dirstate", ds)
+        self.opener.write("journal.dirstate",
+                          self.opener.tryread("dirstate"))
         self.opener.write("journal.branch",
                           encoding.fromlocal(self.dirstate.branch()))
         self.opener.write("journal.desc",
                           "%d\n%s\n" % (len(self), desc))
-
-        try:
-            bk = self.opener.read("bookmarks")
-        except IOError:
-            bk = ""
-        self.opener.write("journal.bookmarks", bk)
-
-        phasesname = self.sjoin('phaseroots')
-        if os.path.exists(phasesname):
-            util.copyfile(phasesname, self.sjoin('journal.phaseroots'))
-        else:
-            self.sopener.write('journal.phaseroots', '')
+        self.opener.write("journal.bookmarks",
+                          self.opener.tryread("bookmarks"))
+        self.sopener.write("journal.phaseroots",
+                           self.sopener.tryread("phaseroots"))
 
     def recover(self):
         lock = self.lock()