Skip to content

Commit ac1cec7

Browse files
committed
added Iterable interface to Ref type
1 parent 6acec35 commit ac1cec7

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Diff for: lib/git/objects/commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def iter_items(cls, repo, ref, path='', **kwargs):
140140
``skip`` is the number of commits to skip
141141
142142
Returns
143-
git.Commit[]
143+
iterator yielding Commit items
144144
"""
145145
options = {'pretty': 'raw'}
146146
options.update(kwargs)

Diff for: lib/git/refs.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"""
99
from objects.base import Object
1010
from objects.utils import get_object_type_by_name
11-
from utils import LazyMixin
11+
from utils import LazyMixin, Iterable
1212

13-
class Ref(LazyMixin):
13+
class Ref(LazyMixin, Iterable):
1414
"""
1515
Represents a named reference to any object
1616
"""
@@ -73,7 +73,7 @@ def name(self):
7373
return '/'.join(tokens[2:])
7474

7575
@classmethod
76-
def list_items(cls, repo, common_path = "refs", **kwargs):
76+
def iter_items(cls, repo, common_path = "refs", **kwargs):
7777
"""
7878
Find all refs in the repository
7979
@@ -102,15 +102,15 @@ def list_items(cls, repo, common_path = "refs", **kwargs):
102102
options.update(kwargs)
103103

104104
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()))
106106

107107
@classmethod
108-
def _list_from_string(cls, repo, text):
108+
def _iter_from_stream(cls, repo, stream):
109109
""" Parse out ref information into a list of Ref compatible objects
110110
Returns git.Ref[] list of Ref objects """
111111
heads = []
112112

113-
for line in text.splitlines():
113+
for line in stream:
114114
heads.append(cls._from_string(repo, line))
115115

116116
return heads
@@ -158,14 +158,14 @@ def commit(self):
158158
return self.object
159159

160160
@classmethod
161-
def list_items(cls, repo, common_path = "refs/heads", **kwargs):
161+
def iter_items(cls, repo, common_path = "refs/heads", **kwargs):
162162
"""
163163
Returns
164-
git.Head[]
164+
Iterator yielding Head items
165165
166166
For more documentation, please refer to git.base.Ref.list_items
167167
"""
168-
return super(Head,cls).list_items(repo, common_path, **kwargs)
168+
return super(Head,cls).iter_items(repo, common_path, **kwargs)
169169

170170
def __repr__(self):
171171
return '<git.Head "%s">' % self.name
@@ -215,14 +215,14 @@ def tag(self):
215215
return None
216216

217217
@classmethod
218-
def list_items(cls, repo, common_path = "refs/tags", **kwargs):
218+
def iter_items(cls, repo, common_path = "refs/tags", **kwargs):
219219
"""
220220
Returns
221-
git.Tag[]
221+
Iterator yielding commit items
222222
223223
For more documentation, please refer to git.base.Ref.list_items
224224
"""
225-
return super(TagRef,cls).list_items(repo, common_path, **kwargs)
225+
return super(TagRef,cls).iter_items(repo, common_path, **kwargs)
226226

227227

228228
# provide an alias

0 commit comments

Comments
 (0)