changeset 1135:5a0da3bab8a2

util: try to load data using json Currently, this will do nothing since no part of hgsubversion writes json but that will happen in a future patch. The goal of this is to move away from pickle completely but fallback to reading pickle if json fails.
author Sean Farley <sean.michael.farley@gmail.com>
date Sat, 15 Feb 2014 01:50:14 -0600
parents a9b6e38d6dc9
children 6e4892b6628a
files hgsubversion/util.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/util.py
+++ b/hgsubversion/util.py
@@ -3,6 +3,7 @@ import errno
 import re
 import os
 import urllib
+import json
 
 from mercurial import cmdutil
 from mercurial import error
@@ -179,13 +180,20 @@ def dump(data, file_path):
     f.close()
 
 def load(file_path):
-    """pickle load some data from a path.
+    """Deserialize some data from a path.
     """
     data = None
-    if os.path.exists(file_path):
-        f = open(file_path)
+    if not os.path.exists(file_path):
+        return data
+
+    f = open(file_path)
+    try:
+        data = _convert(json.load(f), _descrub)
+    except ValueError:
+        # Ok, JSON couldn't be loaded, so we'll try the old way of using pickle
+        f.seek(0)
         data = pickle.load(f)
-        f.close()
+    f.close()
     return data
 
 def parseurl(url, heads=[]):