[PATCH 1 of 2 stable] bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile

Brodie Rao brodie at bitheap.org
Tue Dec 7 03:04:01 CST 2010


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1291712584 -39600
# Branch stable
# Node ID 0590493fe86b3b2d0a6dca7d554d77d4849b898e
# Parent  5e51254ad4d4c80669f462e310b2677f2b3c54a7
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile

This more closely matches how the other undo files are created, and we
don't care about settings permissions or times on the file, which can
fail if the user running hg doesn't own the file.

diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py
--- a/hgext/bookmarks.py
+++ b/hgext/bookmarks.py
@@ -44,8 +44,14 @@ def write(repo):
     can be copied back on rollback.
     '''
     refs = repo._bookmarks
-    if os.path.exists(repo.join('bookmarks')):
-        util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
+
+    try:
+        bms = repo.opener('bookmarks').read()
+    except IOError:
+        bms = None
+    if bms is not None:
+        repo.opener('undo.bookmarks', 'w').write(bms)
+
     if repo._bookmarkcurrent not in refs:
         setcurrent(repo, None)
     wlock = repo.wlock()


More information about the Mercurial-devel mailing list