2 from __future__ import absolute_import
3 from os.path import realpath
4 from functools import partial
6 from bup import client, git
13 global _next_repo_id, _repo_ids
14 repo_id = _repo_ids.get(key)
17 next_id = _next_repo_id = _next_repo_id + 1
18 _repo_ids[key] = next_id
22 def __init__(self, repo_dir=None):
23 self.repo_dir = realpath(repo_dir or git.repo())
24 self._cp = git.cp(self.repo_dir)
25 self.rev_list = partial(git.rev_list, repo_dir=self.repo_dir)
26 self._id = _repo_id(self.repo_dir)
37 def __exit__(self, type, value, traceback):
41 """Return an identifier that differs from any other repository that
42 doesn't share the same repository-specific information
43 (e.g. refs, tags, etc.)."""
47 """If ref does not exist, yield (None, None, None). Otherwise yield
48 (oidx, type, size), and then all of the data associated with
52 it = self._cp.get(ref)
53 oidx, typ, size = info = next(it)
58 assert not next(it, None)
61 return self._cp.join(ref)
63 def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False):
64 for ref in git.list_refs(patterns=patterns,
65 limit_to_heads=limit_to_heads,
66 limit_to_tags=limit_to_tags,
67 repo_dir=self.repo_dir):
71 def __init__(self, address):
72 self.address = address
73 self.client = client.Client(address)
74 self.rev_list = self.client.rev_list
75 self._id = _repo_id(self.address)
88 def __exit__(self, type, value, traceback):
92 """Return an identifier that differs from any other repository that
93 doesn't share the same repository-specific information
94 (e.g. refs, tags, etc.)."""
98 """If ref does not exist, yield (None, None, None). Otherwise yield
99 (oidx, type, size), and then all of the data associated with
103 # Yield all the data here so that we don't finish the
104 # cat_batch iterator (triggering its cleanup) until all of the
105 # data has been read. Otherwise we'd be out of sync with the
107 items = self.client.cat_batch((ref,))
108 oidx, typ, size, it = info = next(items)
113 assert not next(items, None)
116 return self.client.join(ref)
118 def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False):
119 for ref in self.client.refs(patterns=patterns,
120 limit_to_heads=limit_to_heads,
121 limit_to_tags=limit_to_tags):