@@ -100,45 +100,49 @@ def summary(self):
100100 First line of the commit message.
101101 """
102102 return self .message .split ('\n ' , 1 )[0 ]
103-
103+
104104 @classmethod
105- def count (cls , repo , ref , path = '' ):
105+ def count (cls , repo , rev , paths = '' , ** kwargs ):
106106 """
107- Count the number of commits reachable from this ref
107+ Count the number of commits reachable from this revision
108108
109109 ``repo``
110110 is the Repo
111111
112- ``ref ``
113- is the ref from which to begin (SHA1 or name)
112+ ``rev ``
113+ revision specifier, see git-rev-parse for viable options
114114
115- ``path``
116- is an optinal path
115+ ``paths``
116+ is an optinal path or a list of paths restricting the return value
117+ to commits actually containing the paths
117118
119+ ``kwargs``
120+ Additional options to be passed to git-rev-list
118121 Returns
119122 int
120123 """
121- return len (repo .git .rev_list (ref , '--' , path ).strip ().splitlines ())
124+ return len (repo .git .rev_list (rev , '--' , paths , ** kwargs ).strip ().splitlines ())
122125
123126 @classmethod
124- def iter_items (cls , repo , ref , path = '' , ** kwargs ):
127+ def iter_items (cls , repo , rev , paths = '' , ** kwargs ):
125128 """
126129 Find all commits matching the given criteria.
127130
128131 ``repo``
129132 is the Repo
130133
131- ``ref ``
132- is the ref from which to begin (SHA1, Head or name)
134+ ``rev ``
135+ revision specifier, see git-rev-parse for viable options
133136
134- ``path ``
135- is an optinal path, if set only Commits that include the path
136- will be considered
137+ ``paths ``
138+ is an optinal path or list of paths , if set only Commits that include the path
139+ or paths will be considered
137140
138141 ``kwargs``
139- optional keyword arguments to git where
142+ optional keyword arguments to git rev-list where
140143 ``max_count`` is the maximum number of commits to fetch
141144 ``skip`` is the number of commits to skip
145+ ``since`` all commits since i.e. '1970-01-01'
142146
143147 Returns
144148 iterator yielding Commit items
@@ -147,61 +151,30 @@ def iter_items(cls, repo, ref, path='', **kwargs):
147151 options .update (kwargs )
148152
149153 # the test system might confront us with string values -
150- proc = repo .git .rev_list (ref , '--' , path , ** options )
154+ proc = repo .git .rev_list (rev , '--' , paths , ** options )
151155 return cls ._iter_from_process_or_stream (repo , proc )
152-
153- @classmethod
154- def _iter_from_process_or_stream (cls , repo , proc_or_stream ):
155- """
156- Parse out commit information into a list of Commit objects
157-
158- ``repo``
159- is the Repo
160-
161- ``proc``
162- git-rev-list process instance (raw format)
163-
164- Returns
165- iterator returning Commit objects
156+
157+ def iter_parents (self , paths = '' , ** kwargs ):
166158 """
167- stream = proc_or_stream
168- if not hasattr (stream ,'next' ):
169- stream = proc_or_stream .stdout
170-
171- for line in stream :
172- id = line .split ()[1 ]
173- assert line .split ()[0 ] == "commit"
174- tree = stream .next ().split ()[1 ]
175-
176- parents = []
177- next_line = None
178- for parent_line in stream :
179- if not parent_line .startswith ('parent' ):
180- next_line = parent_line
181- break
182- # END abort reading parents
183- parents .append (parent_line .split ()[- 1 ])
184- # END for each parent line
185-
186- author , authored_date = utils .parse_actor_and_date (next_line )
187- committer , committed_date = utils .parse_actor_and_date (stream .next ())
188-
189- # empty line
190- stream .next ()
191-
192- message_lines = []
193- next_line = None
194- for msg_line in stream :
195- if not msg_line .startswith (' ' ):
196- break
197- # END abort message reading
198- message_lines .append (msg_line .strip ())
199- # END while there are message lines
200- 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
201167
202- yield Commit (repo , id = id , parents = parents , tree = tree , author = author , authored_date = authored_date ,
203- committer = committer , committed_date = committed_date , message = message )
204- # 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 )
205178
206179 @classmethod
207180 def diff (cls , repo , a , b = None , paths = None ):
@@ -277,6 +250,60 @@ def stats(self):
277250 text = self .repo .git .diff (self .parents [0 ].id , self .id , '--' , numstat = True )
278251 return stats .Stats ._list_from_string (self .repo , text )
279252
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+
280307 def __str__ (self ):
281308 """ Convert commit to string which is SHA1 """
282309 return self .id
0 commit comments