summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--git_config.py54
-rw-r--r--manifest_xml.py6
-rw-r--r--project.py9
-rwxr-xr-xrepo8
-rw-r--r--subcmds/status.py6
-rw-r--r--subcmds/sync.py47
-rw-r--r--subcmds/upload.py6
7 files changed, 61 insertions, 75 deletions
diff --git a/git_config.py b/git_config.py
index 32879ec7..380bdd24 100644
--- a/git_config.py
+++ b/git_config.py
@@ -15,8 +15,8 @@
15 15
16from __future__ import print_function 16from __future__ import print_function
17 17
18import json
18import os 19import os
19import pickle
20import re 20import re
21import subprocess 21import subprocess
22import sys 22import sys
@@ -80,7 +80,7 @@ class GitConfig(object):
80 return cls(configfile = os.path.join(gitdir, 'config'), 80 return cls(configfile = os.path.join(gitdir, 'config'),
81 defaults = defaults) 81 defaults = defaults)
82 82
83 def __init__(self, configfile, defaults=None, pickleFile=None): 83 def __init__(self, configfile, defaults=None, jsonFile=None):
84 self.file = configfile 84 self.file = configfile
85 self.defaults = defaults 85 self.defaults = defaults
86 self._cache_dict = None 86 self._cache_dict = None
@@ -88,12 +88,11 @@ class GitConfig(object):
88 self._remotes = {} 88 self._remotes = {}
89 self._branches = {} 89 self._branches = {}
90 90
91 if pickleFile is None: 91 self._json = jsonFile
92 self._pickle = os.path.join( 92 if self._json is None:
93 self._json = os.path.join(
93 os.path.dirname(self.file), 94 os.path.dirname(self.file),
94 '.repopickle_' + os.path.basename(self.file)) 95 '.repo_' + os.path.basename(self.file) + '.json')
95 else:
96 self._pickle = pickleFile
97 96
98 def Has(self, name, include_defaults = True): 97 def Has(self, name, include_defaults = True):
99 """Return true if this configuration file has the key. 98 """Return true if this configuration file has the key.
@@ -248,50 +247,41 @@ class GitConfig(object):
248 return self._cache_dict 247 return self._cache_dict
249 248
250 def _Read(self): 249 def _Read(self):
251 d = self._ReadPickle() 250 d = self._ReadJson()
252 if d is None: 251 if d is None:
253 d = self._ReadGit() 252 d = self._ReadGit()
254 self._SavePickle(d) 253 self._SaveJson(d)
255 return d 254 return d
256 255
257 def _ReadPickle(self): 256 def _ReadJson(self):
258 try: 257 try:
259 if os.path.getmtime(self._pickle) \ 258 if os.path.getmtime(self._json) \
260 <= os.path.getmtime(self.file): 259 <= os.path.getmtime(self.file):
261 os.remove(self._pickle) 260 os.remove(self._json)
262 return None 261 return None
263 except OSError: 262 except OSError:
264 return None 263 return None
265 try: 264 try:
266 Trace(': unpickle %s', self.file) 265 Trace(': parsing %s', self.file)
267 fd = open(self._pickle, 'rb') 266 fd = open(self._json)
268 try: 267 try:
269 return pickle.load(fd) 268 return json.load(fd)
270 finally: 269 finally:
271 fd.close() 270 fd.close()
272 except EOFError: 271 except (IOError, ValueError):
273 os.remove(self._pickle) 272 os.remove(self._json)
274 return None
275 except IOError:
276 os.remove(self._pickle)
277 return None
278 except pickle.PickleError:
279 os.remove(self._pickle)
280 return None 273 return None
281 274
282 def _SavePickle(self, cache): 275 def _SaveJson(self, cache):
283 try: 276 try:
284 fd = open(self._pickle, 'wb') 277 fd = open(self._json, 'w')
285 try: 278 try:
286 pickle.dump(cache, fd, pickle.HIGHEST_PROTOCOL) 279 json.dump(cache, fd, indent=2)
287 finally: 280 finally:
288 fd.close() 281 fd.close()
289 except IOError: 282 except (IOError, TypeError):
290 if os.path.exists(self._pickle): 283 if os.path.exists(self.json):
291 os.remove(self._pickle) 284 os.remove(self._json)
292 except pickle.PickleError:
293 if os.path.exists(self._pickle):
294 os.remove(self._pickle)
295 285
296 def _ReadGit(self): 286 def _ReadGit(self):
297 """ 287 """
diff --git a/manifest_xml.py b/manifest_xml.py
index 6557477c..a79f7142 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -872,10 +872,8 @@ class XmlManifest(object):
872 fromProjects = self.paths 872 fromProjects = self.paths
873 toProjects = manifest.paths 873 toProjects = manifest.paths
874 874
875 fromKeys = fromProjects.keys() 875 fromKeys = sorted(fromProjects.keys())
876 fromKeys.sort() 876 toKeys = sorted(toProjects.keys())
877 toKeys = toProjects.keys()
878 toKeys.sort()
879 877
880 diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []} 878 diff = {'added': [], 'removed': [], 'changed': [], 'unreachable': []}
881 879
diff --git a/project.py b/project.py
index 127176e5..55c188db 100644
--- a/project.py
+++ b/project.py
@@ -438,7 +438,8 @@ class RepoHook(object):
438 # and convert to a HookError w/ just the failing traceback. 438 # and convert to a HookError w/ just the failing traceback.
439 context = {} 439 context = {}
440 try: 440 try:
441 execfile(self._script_fullpath, context) 441 exec(compile(open(self._script_fullpath).read(),
442 self._script_fullpath, 'exec'), context)
442 except Exception: 443 except Exception:
443 raise HookError('%s\nFailed to import %s hook; see traceback above.' % ( 444 raise HookError('%s\nFailed to import %s hook; see traceback above.' % (
444 traceback.format_exc(), self._hook_type)) 445 traceback.format_exc(), self._hook_type))
@@ -2321,8 +2322,8 @@ class Project(object):
2321 out = iter(out[:-1].split('\0')) # pylint: disable=W1401 2322 out = iter(out[:-1].split('\0')) # pylint: disable=W1401
2322 while out: 2323 while out:
2323 try: 2324 try:
2324 info = out.next() 2325 info = next(out)
2325 path = out.next() 2326 path = next(out)
2326 except StopIteration: 2327 except StopIteration:
2327 break 2328 break
2328 2329
@@ -2348,7 +2349,7 @@ class Project(object):
2348 info = _Info(path, *info) 2349 info = _Info(path, *info)
2349 if info.status in ('R', 'C'): 2350 if info.status in ('R', 'C'):
2350 info.src_path = info.path 2351 info.src_path = info.path
2351 info.path = out.next() 2352 info.path = next(out)
2352 r[info.path] = info 2353 r[info.path] = info
2353 return r 2354 return r
2354 finally: 2355 finally:
diff --git a/repo b/repo
index b8c414be..3fd0166e 100755
--- a/repo
+++ b/repo
@@ -139,10 +139,6 @@ def _print(*objects, **kwargs):
139 139
140# Python version check 140# Python version check
141ver = sys.version_info 141ver = sys.version_info
142if ver[0] == 3:
143 _print('warning: Python 3 support is currently experimental. YMMV.\n'
144 'Please use Python 2.6 - 2.7 instead.',
145 file=sys.stderr)
146if (ver[0], ver[1]) < MIN_PYTHON_VERSION: 142if (ver[0], ver[1]) < MIN_PYTHON_VERSION:
147 _print('error: Python version %s unsupported.\n' 143 _print('error: Python version %s unsupported.\n'
148 'Please use Python 2.6 - 2.7 instead.' 144 'Please use Python 2.6 - 2.7 instead.'
@@ -768,4 +764,8 @@ def main(orig_args):
768 764
769 765
770if __name__ == '__main__': 766if __name__ == '__main__':
767 if ver[0] == 3:
768 _print('warning: Python 3 support is currently experimental. YMMV.\n'
769 'Please use Python 2.6 - 2.7 instead.',
770 file=sys.stderr)
771 main(sys.argv[1:]) 771 main(sys.argv[1:])
diff --git a/subcmds/status.py b/subcmds/status.py
index 41c4429a..b42675e0 100644
--- a/subcmds/status.py
+++ b/subcmds/status.py
@@ -113,7 +113,7 @@ the following meanings:
113 try: 113 try:
114 state = project.PrintWorkTreeStatus(output) 114 state = project.PrintWorkTreeStatus(output)
115 if state == 'CLEAN': 115 if state == 'CLEAN':
116 clean_counter.next() 116 next(clean_counter)
117 finally: 117 finally:
118 sem.release() 118 sem.release()
119 119
@@ -141,7 +141,7 @@ the following meanings:
141 for project in all_projects: 141 for project in all_projects:
142 state = project.PrintWorkTreeStatus() 142 state = project.PrintWorkTreeStatus()
143 if state == 'CLEAN': 143 if state == 'CLEAN':
144 counter.next() 144 next(counter)
145 else: 145 else:
146 sem = _threading.Semaphore(opt.jobs) 146 sem = _threading.Semaphore(opt.jobs)
147 threads_and_output = [] 147 threads_and_output = []
@@ -164,7 +164,7 @@ the following meanings:
164 t.join() 164 t.join()
165 output.dump(sys.stdout) 165 output.dump(sys.stdout)
166 output.close() 166 output.close()
167 if len(all_projects) == counter.next(): 167 if len(all_projects) == next(counter):
168 print('nothing to commit (working directory clean)') 168 print('nothing to commit (working directory clean)')
169 169
170 if opt.orphans: 170 if opt.orphans:
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
16from __future__ import print_function 16from __future__ import print_function
17import json
17import netrc 18import netrc
18from optparse import SUPPRESS_HELP 19from optparse import SUPPRESS_HELP
19import os 20import os
20import pickle
21import re 21import re
22import shutil 22import shutil
23import socket 23import 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
diff --git a/subcmds/upload.py b/subcmds/upload.py
index e2fa261e..0ee36df1 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -25,10 +25,12 @@ from git_command import GitCommand
25from project import RepoHook 25from project import RepoHook
26 26
27from pyversion import is_python3 27from pyversion import is_python3
28# pylint:disable=W0622
28if not is_python3(): 29if not is_python3():
29 # pylint:disable=W0622
30 input = raw_input 30 input = raw_input
31 # pylint:enable=W0622 31else:
32 unicode = str
33# pylint:enable=W0622
32 34
33UNUSUAL_COMMIT_THRESHOLD = 5 35UNUSUAL_COMMIT_THRESHOLD = 5
34 36