# HG changeset patch # User Sean Farley # Date 1392450614 21600 # Node ID 5a0da3bab8a2bec41655f8ff875ed9e187372e21 # Parent a9b6e38d6dc960fe33ad817223fc50d2cc876556 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. diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- 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=[]):