]> arthur.barton.de Git - bup.git/blob - lib/bup/repo.py
Use absolute_import from the __future__ everywhere
[bup.git] / lib / bup / repo.py
1
2 from __future__ import absolute_import
3 from functools import partial
4
5 from bup import client, git
6
7
8 class LocalRepo:
9     def __init__(self, repo_dir=None):
10         self.repo_dir = repo_dir or git.repo()
11         self._cp = git.cp(repo_dir)
12         self.rev_list = partial(git.rev_list, repo_dir=repo_dir)
13
14     def cat(self, ref):
15         """If ref does not exist, yield (None, None, None).  Otherwise yield
16         (oidx, type, size), and then all of the data associated with
17         ref.
18
19         """
20         it = self._cp.get(ref)
21         oidx, typ, size = info = next(it)
22         yield info
23         if oidx:
24             for data in it:
25                 yield data
26         assert not next(it, None)
27
28     def join(self, ref):
29         return self._cp.join(ref)
30
31     def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False):
32         for ref in git.list_refs(patterns=patterns,
33                                  limit_to_heads=limit_to_heads,
34                                  limit_to_tags=limit_to_tags,
35                                  repo_dir=self.repo_dir):
36             yield ref
37
38 class RemoteRepo:
39     def __init__(self, address):
40         self.address = address
41         self.client = client.Client(address)
42         self.rev_list = self.client.rev_list
43
44     def cat(self, ref):
45         """If ref does not exist, yield (None, None, None).  Otherwise yield
46         (oidx, type, size), and then all of the data associated with
47         ref.
48
49         """
50         # Yield all the data here so that we don't finish the
51         # cat_batch iterator (triggering its cleanup) until all of the
52         # data has been read.  Otherwise we'd be out of sync with the
53         # server.
54         items = self.client.cat_batch((ref,))
55         oidx, typ, size, it = info = next(items)
56         yield info[:-1]
57         if oidx:
58             for data in it:
59                 yield data
60         assert not next(items, None)
61
62     def join(self, ref):
63         return self.client.join(ref)
64
65     def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False):
66         for ref in self.client.refs(patterns=patterns,
67                                     limit_to_heads=limit_to_heads,
68                                     limit_to_tags=limit_to_tags):
69             yield ref