|
8 | 8 | """
|
9 | 9 | from objects.base import Object
|
10 | 10 | from objects.utils import get_object_type_by_name
|
11 |
| -from utils import LazyMixin |
| 11 | +from utils import LazyMixin, Iterable |
12 | 12 |
|
13 |
| -class Ref(LazyMixin): |
| 13 | +class Ref(LazyMixin, Iterable): |
14 | 14 | """
|
15 | 15 | Represents a named reference to any object
|
16 | 16 | """
|
@@ -73,7 +73,7 @@ def name(self):
|
73 | 73 | return '/'.join(tokens[2:])
|
74 | 74 |
|
75 | 75 | @classmethod
|
76 |
| - def list_items(cls, repo, common_path = "refs", **kwargs): |
| 76 | + def iter_items(cls, repo, common_path = "refs", **kwargs): |
77 | 77 | """
|
78 | 78 | Find all refs in the repository
|
79 | 79 |
|
@@ -102,15 +102,15 @@ def list_items(cls, repo, common_path = "refs", **kwargs):
|
102 | 102 | options.update(kwargs)
|
103 | 103 |
|
104 | 104 | output = repo.git.for_each_ref(common_path, **options)
|
105 |
| - return cls._list_from_string(repo, output) |
| 105 | + return cls._iter_from_stream(repo, iter(output.splitlines())) |
106 | 106 |
|
107 | 107 | @classmethod
|
108 |
| - def _list_from_string(cls, repo, text): |
| 108 | + def _iter_from_stream(cls, repo, stream): |
109 | 109 | """ Parse out ref information into a list of Ref compatible objects
|
110 | 110 | Returns git.Ref[] list of Ref objects """
|
111 | 111 | heads = []
|
112 | 112 |
|
113 |
| - for line in text.splitlines(): |
| 113 | + for line in stream: |
114 | 114 | heads.append(cls._from_string(repo, line))
|
115 | 115 |
|
116 | 116 | return heads
|
@@ -158,14 +158,14 @@ def commit(self):
|
158 | 158 | return self.object
|
159 | 159 |
|
160 | 160 | @classmethod
|
161 |
| - def list_items(cls, repo, common_path = "refs/heads", **kwargs): |
| 161 | + def iter_items(cls, repo, common_path = "refs/heads", **kwargs): |
162 | 162 | """
|
163 | 163 | Returns
|
164 |
| - git.Head[] |
| 164 | + Iterator yielding Head items |
165 | 165 |
|
166 | 166 | For more documentation, please refer to git.base.Ref.list_items
|
167 | 167 | """
|
168 |
| - return super(Head,cls).list_items(repo, common_path, **kwargs) |
| 168 | + return super(Head,cls).iter_items(repo, common_path, **kwargs) |
169 | 169 |
|
170 | 170 | def __repr__(self):
|
171 | 171 | return '<git.Head "%s">' % self.name
|
@@ -215,14 +215,14 @@ def tag(self):
|
215 | 215 | return None
|
216 | 216 |
|
217 | 217 | @classmethod
|
218 |
| - def list_items(cls, repo, common_path = "refs/tags", **kwargs): |
| 218 | + def iter_items(cls, repo, common_path = "refs/tags", **kwargs): |
219 | 219 | """
|
220 | 220 | Returns
|
221 |
| - git.Tag[] |
| 221 | + Iterator yielding commit items |
222 | 222 |
|
223 | 223 | For more documentation, please refer to git.base.Ref.list_items
|
224 | 224 | """
|
225 |
| - return super(TagRef,cls).list_items(repo, common_path, **kwargs) |
| 225 | + return super(TagRef,cls).iter_items(repo, common_path, **kwargs) |
226 | 226 |
|
227 | 227 |
|
228 | 228 | # provide an alias
|
|
0 commit comments