changeset 993:b62fff7832c3

buildmeta: only write the uuid file if needed We used to write it unconditionally.
author Bryan O'Sullivan <bryano@fb.com>
date Mon, 04 Feb 2013 13:10:23 -0800
parents 110794582448
children e90c31a68eb9
files hgsubversion/svncommands.py
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -38,6 +38,20 @@ 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
+        fp.close()
+    except IOError, err:
+        if err.errno != errno.ENOENT:
+            raise
+        mustwrite = True
+    if mustwrite:
+        fp = open(path, 'w')
+        fp.write(content)
+        fp.close()
+
 def _buildmeta(ui, repo, args, partial=False, skipuuid=False):
 
     if repo is None:
@@ -195,9 +209,7 @@ def _buildmeta(ui, repo, args, partial=F
                 if uuid != svn.uuid:
                     raise hgutil.Abort('remote svn repository identifier '
                                        'does not match')
-            uuidfile = open(os.path.join(svnmetadir, 'uuid'), 'w')
-            uuidfile.write(svn.uuid)
-            uuidfile.close()
+            write_if_needed(os.path.join(svnmetadir, 'uuid'), uuid)
 
         # don't reflect closed branches
         if (ctx.extra().get('close') and not ctx.files() or