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.)."""
50 """If ref does not exist, yield (None, None, None). Otherwise yield
51 (oidx, type, size), and then all of the data associated with
55 it = self._cp.get(ref)
56 oidx, typ, size = info = next(it)
61 assert not next(it, None)
64 return self._cp.join(ref)
66 def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False):
67 for ref in git.list_refs(patterns=patterns,
68 limit_to_heads=limit_to_heads,
69 limit_to_tags=limit_to_tags,
70 repo_dir=self.repo_dir):
74 def __init__(self, address):
75 self.address = address
76 self.client = client.Client(address)
77 self.rev_list = self.client.rev_list
78 self._id = _repo_id(self.address)
91 def __exit__(self, type, value, traceback):
95 """Return an identifier that differs from any other repository that
96 doesn't share the same repository-specific information
97 (e.g. refs, tags, etc.)."""
104 """If ref does not exist, yield (None, None, None). Otherwise yield
105 (oidx, type, size), and then all of the data associated with
109 # Yield all the data here so that we don't finish the
110 # cat_batch iterator (triggering its cleanup) until all of the
111 # data has been read. Otherwise we'd be out of sync with the
113 items = self.client.cat_batch((ref,))
114 oidx, typ, size, it = info = next(items)
119 assert not next(items, None)
122 return self.client.join(ref)
124 def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False):
125 for ref in self.client.refs(patterns=patterns,
126 limit_to_heads=limit_to_heads,
127 limit_to_tags=limit_to_tags):