@@ -101,30 +101,8 @@ def summary(self):
101101 """
102102 return self .message .split ('\n ' , 1 )[0 ]
103103
104- def iter_parents (self , paths = '' , ** kwargs ):
105- """
106- Iterate _all_ parents of this commit.
107-
108- ``paths``
109- Optional path or list of paths limiting the Commits to those that
110- contain at least one of the paths
111-
112- ``kwargs``
113- All arguments allowed by git-rev-list
114-
115- Return:
116- Iterator yielding Commit objects which are parents of self
117- """
118- # skip ourselves
119- skip = kwargs .get ("skip" , 1 )
120- if skip == 0 : # skip ourselves
121- skip = 1
122- kwargs ['skip' ] = skip
123-
124- return self .iter_items ( self .repo , self , paths , ** kwargs )
125-
126104 @classmethod
127- def count (cls , repo , rev , paths = '' ):
105+ def count (cls , repo , rev , paths = '' , ** kwargs ):
128106 """
129107 Count the number of commits reachable from this revision
130108
@@ -138,10 +116,12 @@ def count(cls, repo, rev, paths=''):
138116 is an optinal path or a list of paths restricting the return value
139117 to commits actually containing the paths
140118
119+ ``kwargs``
120+ Additional options to be passed to git-rev-list
141121 Returns
142122 int
143123 """
144- return len (repo .git .rev_list (rev , '--' , paths ).strip ().splitlines ())
124+ return len (repo .git .rev_list (rev , '--' , paths , ** kwargs ).strip ().splitlines ())
145125
146126 @classmethod
147127 def iter_items (cls , repo , rev , paths = '' , ** kwargs ):
@@ -173,59 +153,28 @@ def iter_items(cls, repo, rev, paths='', **kwargs):
173153 # the test system might confront us with string values -
174154 proc = repo .git .rev_list (rev , '--' , paths , ** options )
175155 return cls ._iter_from_process_or_stream (repo , proc )
176-
177- @classmethod
178- def _iter_from_process_or_stream (cls , repo , proc_or_stream ):
179- """
180- Parse out commit information into a list of Commit objects
181-
182- ``repo``
183- is the Repo
184-
185- ``proc``
186- git-rev-list process instance (raw format)
187-
188- Returns
189- iterator returning Commit objects
156+
157+ def iter_parents (self , paths = '' , ** kwargs ):
190158 """
191- stream = proc_or_stream
192- if not hasattr (stream ,'next' ):
193- stream = proc_or_stream .stdout
194-
195- for line in stream :
196- id = line .split ()[1 ]
197- assert line .split ()[0 ] == "commit"
198- tree = stream .next ().split ()[1 ]
199-
200- parents = []
201- next_line = None
202- for parent_line in stream :
203- if not parent_line .startswith ('parent' ):
204- next_line = parent_line
205- break
206- # END abort reading parents
207- parents .append (parent_line .split ()[- 1 ])
208- # END for each parent line
209-
210- author , authored_date = utils .parse_actor_and_date (next_line )
211- committer , committed_date = utils .parse_actor_and_date (stream .next ())
212-
213- # empty line
214- stream .next ()
215-
216- message_lines = []
217- next_line = None
218- for msg_line in stream :
219- if not msg_line .startswith (' ' ):
220- break
221- # END abort message reading
222- message_lines .append (msg_line .strip ())
223- # END while there are message lines
224- message = '\n ' .join (message_lines )
159+ Iterate _all_ parents of this commit.
160+
161+ ``paths``
162+ Optional path or list of paths limiting the Commits to those that
163+ contain at least one of the paths
164+
165+ ``kwargs``
166+ All arguments allowed by git-rev-list
225167
226- yield Commit (repo , id = id , parents = tuple (parents ), tree = tree , author = author , authored_date = authored_date ,
227- committer = committer , committed_date = committed_date , message = message )
228- # END for each line in stream
168+ Return:
169+ Iterator yielding Commit objects which are parents of self
170+ """
171+ # skip ourselves
172+ skip = kwargs .get ("skip" , 1 )
173+ if skip == 0 : # skip ourselves
174+ skip = 1
175+ kwargs ['skip' ] = skip
176+
177+ return self .iter_items ( self .repo , self , paths , ** kwargs )
229178
230179 @classmethod
231180 def diff (cls , repo , a , b = None , paths = None ):
@@ -301,6 +250,60 @@ def stats(self):
301250 text = self .repo .git .diff (self .parents [0 ].id , self .id , '--' , numstat = True )
302251 return stats .Stats ._list_from_string (self .repo , text )
303252
253+ @classmethod
254+ def _iter_from_process_or_stream (cls , repo , proc_or_stream ):
255+ """
256+ Parse out commit information into a list of Commit objects
257+
258+ ``repo``
259+ is the Repo
260+
261+ ``proc``
262+ git-rev-list process instance (raw format)
263+
264+ Returns
265+ iterator returning Commit objects
266+ """
267+ stream = proc_or_stream
268+ if not hasattr (stream ,'next' ):
269+ stream = proc_or_stream .stdout
270+
271+ for line in stream :
272+ id = line .split ()[1 ]
273+ assert line .split ()[0 ] == "commit"
274+ tree = stream .next ().split ()[1 ]
275+
276+ parents = []
277+ next_line = None
278+ for parent_line in stream :
279+ if not parent_line .startswith ('parent' ):
280+ next_line = parent_line
281+ break
282+ # END abort reading parents
283+ parents .append (parent_line .split ()[- 1 ])
284+ # END for each parent line
285+
286+ author , authored_date = utils .parse_actor_and_date (next_line )
287+ committer , committed_date = utils .parse_actor_and_date (stream .next ())
288+
289+ # empty line
290+ stream .next ()
291+
292+ message_lines = []
293+ next_line = None
294+ for msg_line in stream :
295+ if not msg_line .startswith (' ' ):
296+ break
297+ # END abort message reading
298+ message_lines .append (msg_line .strip ())
299+ # END while there are message lines
300+ message = '\n ' .join (message_lines )
301+
302+ yield Commit (repo , id = id , parents = tuple (parents ), tree = tree , author = author , authored_date = authored_date ,
303+ committer = committer , committed_date = committed_date , message = message )
304+ # END for each line in stream
305+
306+
304307 def __str__ (self ):
305308 """ Convert commit to string which is SHA1 """
306309 return self .id
0 commit comments