# HG changeset patch # User Sean Farley # Date 1392769713 21600 # Node ID aa98fdccaa0e1ed0c13284862a92cc09eb056647 # Parent e5818c74d12a48eaffb5fa6b6ecd14a084ba3615 subdir: 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 subdir present in svncommands.py. We will now use the standard util.dump and util.load for writing and reading. 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 @@ -65,7 +65,7 @@ def _buildmeta(ui, repo, args, partial=F if subdir is None: svn = svnrepo.svnremoterepo(ui, url).svn subdir = svn.subdir - open(subdirpath, 'wb').write(subdir.strip('/')) + util.dump(subdir.strip('/'), subdirpath) youngest = 0 startrev = 0 diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- a/hgsubversion/svnmeta.py +++ b/hgsubversion/svnmeta.py @@ -98,19 +98,17 @@ class SVNMeta(object): subdirfile = os.path.join(self.meta_data_dir, 'subdir') if os.path.isfile(subdirfile): - stored_subdir = open(subdirfile).read() + stored_subdir = util.load(subdirfile) assert stored_subdir is not None if subdir is None: self.__subdir = stored_subdir - elif subdir != stored_subdir: + elif subdir and subdir != stored_subdir: raise hgutil.Abort('unable to work on a different path in the ' 'repository') else: self.__subdir = subdir elif subdir is not None: - f = open(subdirfile, 'w') - f.write(subdir) - f.close() + util.dump(subdir, subdirfile) self.__subdir = subdir else: raise hgutil.Abort("hgsubversion metadata unavailable; "