@@ -106,13 +106,12 @@ def _get_intermediate_items(cls, commit):
106
106
return commit .parents
107
107
108
108
def _set_cache_ (self , attr ):
109
- """
110
- Called by LazyMixin superclass when the given uninitialized member needs
109
+ """ Called by LazyMixin superclass when the given uninitialized member needs
111
110
to be set.
112
- We set all values at once.
113
- """
111
+ We set all values at once. """
114
112
if attr in Commit .__slots__ :
115
113
# read the data in a chunk, its faster - then provide a file wrapper
114
+ # Could use self.data, but lets try to get it with less calls
116
115
hexsha , typename , size , data = self .repo .git .get_object_data (self )
117
116
self ._deserialize (StringIO (data ))
118
117
else :
@@ -181,16 +180,16 @@ def iter_items(cls, repo, rev, paths='', **kwargs):
181
180
Returns
182
181
iterator yielding Commit items
183
182
"""
184
- options = { 'pretty' : 'raw' , 'as_process' : True }
185
- options . update ( kwargs )
186
-
183
+ if 'pretty' in kwargs :
184
+ raise ValueError ( "--pretty cannot be used as parsing expects single sha's only" )
185
+ # END handle pretty
187
186
args = list ()
188
187
if paths :
189
188
args .extend (('--' , paths ))
190
189
# END if paths
191
190
192
- proc = repo .git .rev_list (rev , args , ** options )
193
- return cls ._iter_from_process_or_stream (repo , proc , True )
191
+ proc = repo .git .rev_list (rev , args , as_process = True , ** kwargs )
192
+ return cls ._iter_from_process_or_stream (repo , proc )
194
193
195
194
def iter_parents (self , paths = '' , ** kwargs ):
196
195
"""
@@ -235,35 +234,30 @@ def stats(self):
235
234
return stats .Stats ._list_from_string (self .repo , text )
236
235
237
236
@classmethod
238
- def _iter_from_process_or_stream (cls , repo , proc_or_stream , from_rev_list ):
239
- """
240
- Parse out commit information into a list of Commit objects
241
-
242
- ``repo``
243
- is the Repo
244
-
245
- ``proc``
246
- git-rev-list process instance (raw format)
237
+ def _iter_from_process_or_stream (cls , repo , proc_or_stream ):
238
+ """Parse out commit information into a list of Commit objects
239
+ We expect one-line per commit, and parse the actual commit information directly
240
+ from our lighting fast object database
247
241
248
- ``from_rev_list``
249
- If True, the stream was created by rev-list in which case we parse
250
- the message differently
251
- Returns
252
- iterator returning Commit objects
253
- """
242
+ :param proc: git-rev-list process instance - one sha per line
243
+ :return: iterator returning Commit objects"""
254
244
stream = proc_or_stream
255
245
if not hasattr (stream ,'readline' ):
256
246
stream = proc_or_stream .stdout
257
247
248
+ readline = stream .readline
258
249
while True :
259
- line = stream . readline ()
250
+ line = readline ()
260
251
if not line :
261
252
break
262
- commit_tokens = line .split ()
263
- id = commit_tokens [1 ]
264
- assert commit_tokens [0 ] == "commit"
253
+ sha = line .strip ()
254
+ if len (sha ) > 40 :
255
+ # split additional information, as returned by bisect for instance
256
+ sha , rest = line .split (None , 1 )
257
+ # END handle extra info
265
258
266
- yield Commit (repo , id )._deserialize (stream , from_rev_list )
259
+ assert len (sha ) == 40 , "Invalid line: %s" % sha
260
+ yield Commit (repo , sha )
267
261
# END for each line in stream
268
262
269
263
@@ -386,15 +380,16 @@ def _serialize(self, stream):
386
380
# for now, this is very inefficient and in fact shouldn't be used like this
387
381
return super (Commit , self )._serialize (stream )
388
382
389
- def _deserialize (self , stream , from_rev_list = False ):
383
+ def _deserialize (self , stream ):
390
384
""":param from_rev_list: if true, the stream format is coming from the rev-list command
391
385
Otherwise it is assumed to be a plain data stream from our object"""
392
- self .tree = Tree (self .repo , stream .readline ().split ()[1 ], 0 , '' )
386
+ readline = stream .readline
387
+ self .tree = Tree (self .repo , readline ().split ()[1 ], 0 , '' )
393
388
394
389
self .parents = list ()
395
390
next_line = None
396
391
while True :
397
- parent_line = stream . readline ()
392
+ parent_line = readline ()
398
393
if not parent_line .startswith ('parent' ):
399
394
next_line = parent_line
400
395
break
@@ -404,37 +399,24 @@ def _deserialize(self, stream, from_rev_list=False):
404
399
self .parents = tuple (self .parents )
405
400
406
401
self .author , self .authored_date , self .author_tz_offset = utils .parse_actor_and_date (next_line )
407
- self .committer , self .committed_date , self .committer_tz_offset = utils .parse_actor_and_date (stream . readline ())
402
+ self .committer , self .committed_date , self .committer_tz_offset = utils .parse_actor_and_date (readline ())
408
403
409
404
410
- # empty line
405
+ # now we can have the encoding line, or an empty line followed by the optional
406
+ # message.
411
407
self .encoding = self .default_encoding
412
- enc = stream .readline ()
413
- enc .strip ()
408
+ # read encoding or empty line to separate message
409
+ enc = readline ()
410
+ enc = enc .strip ()
414
411
if enc :
415
412
self .encoding = enc [enc .find (' ' )+ 1 :]
416
- # END parse encoding
417
-
418
- message_lines = list ()
419
- if from_rev_list :
420
- while True :
421
- msg_line = stream .readline ()
422
- if not msg_line .startswith (' ' ):
423
- # and forget about this empty marker
424
- # cut the last newline to get rid of the artificial newline added
425
- # by rev-list command. Lets hope its just linux style \n
426
- message_lines [- 1 ] = message_lines [- 1 ][:- 1 ]
427
- break
428
- # END abort message reading
429
- # strip leading 4 spaces
430
- message_lines .append (msg_line [4 :])
431
- # END while there are message lines
432
- self .message = '' .join (message_lines )
433
- else :
434
- # a stream from our data simply gives us the plain message
435
- # The end of our message stream is marked with a newline that we strip
436
- self .message = stream .read ()[:- 1 ]
437
- # END message parsing
413
+ # now comes the message separator
414
+ readline ()
415
+ # END handle encoding
416
+
417
+ # a stream from our data simply gives us the plain message
418
+ # The end of our message stream is marked with a newline that we strip
419
+ self .message = stream .read ()[:- 1 ]
438
420
return self
439
421
440
422
#} END serializable implementation
0 commit comments