2 from __future__ import absolute_import
3 from functools import partial
5 from bup import client, git
9 def __init__(self, repo_dir=None):
10 self.repo_dir = repo_dir or git.repo()
11 self._cp = git.cp(self.repo_dir)
12 self.rev_list = partial(git.rev_list, repo_dir=self.repo_dir)
23 def __exit__(self, type, value, traceback):
27 """If ref does not exist, yield (None, None, None). Otherwise yield
28 (oidx, type, size), and then all of the data associated with
32 it = self._cp.get(ref)
33 oidx, typ, size = info = next(it)
38 assert not next(it, None)
41 return self._cp.join(ref)
43 def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False):
44 for ref in git.list_refs(patterns=patterns,
45 limit_to_heads=limit_to_heads,
46 limit_to_tags=limit_to_tags,
47 repo_dir=self.repo_dir):
51 def __init__(self, address):
52 self.address = address
53 self.client = client.Client(address)
54 self.rev_list = self.client.rev_list
67 def __exit__(self, type, value, traceback):
71 """If ref does not exist, yield (None, None, None). Otherwise yield
72 (oidx, type, size), and then all of the data associated with
76 # Yield all the data here so that we don't finish the
77 # cat_batch iterator (triggering its cleanup) until all of the
78 # data has been read. Otherwise we'd be out of sync with the
80 items = self.client.cat_batch((ref,))
81 oidx, typ, size, it = info = next(items)
86 assert not next(items, None)
89 return self.client.join(ref)
91 def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False):
92 for ref in self.client.refs(patterns=patterns,
93 limit_to_heads=limit_to_heads,
94 limit_to_tags=limit_to_tags):