changeset 1152:aa98fdccaa0e

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.
author Sean Farley <sean.michael.farley@gmail.com>
date Tue, 18 Feb 2014 18:28:33 -0600
parents e5818c74d12a
children c3c4518e00aa
files hgsubversion/svncommands.py hgsubversion/svnmeta.py
diffstat 2 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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; "