Commits

Bryan O'Sullivan committed 0274b75

svncommands: split write_if_needed into two functions

  • Participants
  • Parent commits e90c31a

Comments (0)

Files changed (1)

File hgsubversion/svncommands.py

     return _buildmeta(ui, repo, args, partial=False,
                       skipuuid=unsafe_skip_uuid_check)
 
+def read_if_exists(path):
+     try:
+        fp = open(path, 'rb')
+        d = fp.read()
+        fp.close()
+        return d
+     except IOError, err:
+         if err.errno != errno.ENOENT:
+             raise
+
 def write_if_needed(path, content):
-    try:
-        fp = open(path)
-        mustwrite = fp.read() != content
-        fp.close()
-    except IOError, err:
-        if err.errno != errno.ENOENT:
-            raise
-        mustwrite = True
-    if mustwrite:
-        fp = open(path, 'w')
+    if read_if_exists(path) != content:
+        fp = open(path, 'wb')
         fp.write(content)
         fp.close()