changeset 995:0274b75af266

svncommands: split write_if_needed into two functions
author Bryan O'Sullivan <bryano@fb.com>
date Mon, 04 Feb 2013 16:39:27 -0800
parents e90c31a68eb9
children 2c87bdc43d3c
files hgsubversion/svncommands.py
diffstat 1 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -38,17 +38,19 @@ def rebuildmeta(ui, repo, args, unsafe_s
     return _buildmeta(ui, repo, args, partial=False,
                       skipuuid=unsafe_skip_uuid_check)
 
-def write_if_needed(path, content):
-    try:
-        fp = open(path)
-        mustwrite = fp.read() != content
+def read_if_exists(path):
+     try:
+        fp = open(path, 'rb')
+        d = fp.read()
         fp.close()
-    except IOError, err:
-        if err.errno != errno.ENOENT:
-            raise
-        mustwrite = True
-    if mustwrite:
-        fp = open(path, 'w')
+        return d
+     except IOError, err:
+         if err.errno != errno.ENOENT:
+             raise
+
+def write_if_needed(path, content):
+    if read_if_exists(path) != content:
+        fp = open(path, 'wb')
         fp.write(content)
         fp.close()