diff options
| author | Anthony King <anthonydking@slimroms.net> | 2014-05-06 15:57:48 +0100 |
|---|---|---|
| committer | Anthony King <anthonydking@slimroms.net> | 2014-05-07 10:46:24 +0100 |
| commit | 85b24acd6a11af3d84cc71fc35ebdb6d3c78065f (patch) | |
| tree | ec326002ea5e985a4f1f5cd5e9f8f002dcd75236 /subcmds | |
| parent | 2cd1f0452eb746ae727218f5dbda0fd1ae0b2e34 (diff) | |
| download | git-repo-85b24acd6a11af3d84cc71fc35ebdb6d3c78065f.tar.gz | |
Use JSON instead of pickle
Use JSON as it is shown to be much faster than pickle.
Also clean up the loading and saving functions.
Change-Id: I45b3dee7b4d59a1c0e0d38d4a83b543ac5839390
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/sync.py | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index a0a68960..6f77310f 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -14,10 +14,10 @@ | |||
| 14 | # limitations under the License. | 14 | # limitations under the License. |
| 15 | 15 | ||
| 16 | from __future__ import print_function | 16 | from __future__ import print_function |
| 17 | import json | ||
| 17 | import netrc | 18 | import netrc |
| 18 | from optparse import SUPPRESS_HELP | 19 | from optparse import SUPPRESS_HELP |
| 19 | import os | 20 | import os |
| 20 | import pickle | ||
| 21 | import re | 21 | import re |
| 22 | import shutil | 22 | import shutil |
| 23 | import socket | 23 | import socket |
| @@ -760,7 +760,7 @@ class _FetchTimes(object): | |||
| 760 | _ALPHA = 0.5 | 760 | _ALPHA = 0.5 |
| 761 | 761 | ||
| 762 | def __init__(self, manifest): | 762 | def __init__(self, manifest): |
| 763 | self._path = os.path.join(manifest.repodir, '.repopickle_fetchtimes') | 763 | self._path = os.path.join(manifest.repodir, '.repo_fetchtimes.json') |
| 764 | self._times = None | 764 | self._times = None |
| 765 | self._seen = set() | 765 | self._seen = set() |
| 766 | 766 | ||
| @@ -779,22 +779,17 @@ class _FetchTimes(object): | |||
| 779 | def _Load(self): | 779 | def _Load(self): |
| 780 | if self._times is None: | 780 | if self._times is None: |
| 781 | try: | 781 | try: |
| 782 | f = open(self._path, 'rb') | 782 | f = open(self._path) |
| 783 | except IOError: | ||
| 784 | self._times = {} | ||
| 785 | return self._times | ||
| 786 | try: | ||
| 787 | try: | 783 | try: |
| 788 | self._times = pickle.load(f) | 784 | self._times = json.load(f) |
| 789 | except IOError: | 785 | finally: |
| 790 | try: | 786 | f.close() |
| 791 | os.remove(self._path) | 787 | except (IOError, ValueError): |
| 792 | except OSError: | 788 | try: |
| 793 | pass | 789 | os.remove(self._path) |
| 794 | self._times = {} | 790 | except OSError: |
| 795 | finally: | 791 | pass |
| 796 | f.close() | 792 | self._times = {} |
| 797 | return self._times | ||
| 798 | 793 | ||
| 799 | def Save(self): | 794 | def Save(self): |
| 800 | if self._times is None: | 795 | if self._times is None: |
| @@ -808,13 +803,13 @@ class _FetchTimes(object): | |||
| 808 | del self._times[name] | 803 | del self._times[name] |
| 809 | 804 | ||
| 810 | try: | 805 | try: |
| 811 | f = open(self._path, 'wb') | 806 | f = open(self._path, 'w') |
| 812 | try: | 807 | try: |
| 813 | pickle.dump(self._times, f) | 808 | json.dump(self._times, f, indent=2) |
| 814 | except (IOError, OSError, pickle.PickleError): | 809 | finally: |
| 815 | try: | 810 | f.close() |
| 816 | os.remove(self._path) | 811 | except (IOError, TypeError): |
| 817 | except OSError: | 812 | try: |
| 818 | pass | 813 | os.remove(self._path) |
| 819 | finally: | 814 | except OSError: |
| 820 | f.close() | 815 | pass |
