# HG changeset patch # User Sean Farley # Date 1394844275 18000 # Node ID 510fa46caf9cc099d0a511af988c23b8bcceafa5 # Parent 34173bbd3b8ea75d1c27f482d547d743819bfa6a 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. diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- 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 diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- 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; "