changeset 1150:510fa46caf9c

uuid: use util.dump and util.load for writing and reading We need to change both svnmeta and svncommands at the same time since they are heavily tied together. The reason for this change is to remove the duplicate code for reading and writing uuid present in svncommands.py. We will now use the standard util.dump and util.load for writing and reading. This presents a slight change in file format. Previously, the uuid file had the format: d073be05-634f-4543-b044-5fe20cf6d1d6[no newline] and after this change, it is: "d073be05-634f-4543-b044-5fe20cf6d1d6"[newline optional] Due to the way json reads a string, the old format is still valid for use and will be read correctly.
author Sean Farley <sean.michael.farley@gmail.com>
date Fri, 14 Mar 2014 19:44:35 -0500
parents 34173bbd3b8e
children e5818c74d12a
files hgsubversion/svncommands.py hgsubversion/svnmeta.py
diffstat 2 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -73,10 +73,10 @@ def _buildmeta(ui, repo, args, partial=F
     if not os.path.exists(svnmetadir):
         os.makedirs(svnmetadir)
     uuidpath = os.path.join(svnmetadir, 'uuid')
-    uuid = read_if_exists(uuidpath)
+    uuid = util.load(uuidpath)
 
     subdirpath = os.path.join(svnmetadir, 'subdir')
-    subdir = read_if_exists(subdirpath)
+    subdir = util.load(subdirpath)
     svn = None
     if subdir is None:
         svn = svnrepo.svnremoterepo(ui, url).svn
@@ -228,7 +228,7 @@ def _buildmeta(ui, repo, args, partial=F
                 if uuid != svn.uuid:
                     raise hgutil.Abort('remote svn repository identifier '
                                        'does not match')
-            write_if_needed(uuidpath, uuid)
+            util.dump(uuid, uuidpath)
 
         # don't reflect closed branches
         if (ctx.extra().get('close') and not ctx.files() or
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -126,15 +126,13 @@ class SVNMeta(object):
     def _set_uuid(self, uuid):
         uuidfile = os.path.join(self.meta_data_dir, 'uuid')
         if os.path.isfile(uuidfile):
-            stored_uuid = open(uuidfile).read()
+            stored_uuid = util.load(uuidfile)
             assert stored_uuid
             if uuid and uuid != stored_uuid:
                 raise hgutil.Abort('unable to operate on unrelated repository')
             self.__uuid = uuid or stored_uuid
         elif uuid:
-            f = open(uuidfile, 'w')
-            f.write(uuid)
-            f.close()
+            util.dump(uuid, uuidfile)
             self.__uuid = uuid
         else:
             raise hgutil.Abort("hgsubversion metadata unavailable; "