Sean Farley committed 5a0da3b

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.

Comments (0)

Files changed (1)


 import re
 import os
 import urllib
+import json
 from mercurial import cmdutil
 from mercurial import error
 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
         data = pickle.load(f)
-        f.close()
+    f.close()
     return data
 def parseurl(url, heads=[]):