@@ -419,23 +419,25 @@ def _deserialize(self, stream):
419419 next_line = None
420420 while True :
421421 parent_line = readline ()
422- if not parent_line .startswith ('parent' ):
422+ if not parent_line .startswith (b 'parent' ):
423423 next_line = parent_line
424424 break
425425 # END abort reading parents
426- self .parents .append (type (self )(self .repo , hex_to_bin (parent_line .split ()[- 1 ])))
426+ self .parents .append (type (self )(self .repo , hex_to_bin (parent_line .split ()[- 1 ]. decode ( 'ascii' ) )))
427427 # END for each parent line
428428 self .parents = tuple (self .parents )
429429
430- self .author , self .authored_date , self .author_tz_offset = parse_actor_and_date (next_line )
431- self .committer , self .committed_date , self .committer_tz_offset = parse_actor_and_date (readline ())
430+ # we don't know actual author encoding before we have parsed it, so keep the lines around
431+ author_line = next_line
432+ committer_line = readline ()
432433
433434 # we might run into one or more mergetag blocks, skip those for now
434435 next_line = readline ()
435- while next_line .startswith ('mergetag ' ):
436+ while next_line .startswith (b 'mergetag ' ):
436437 next_line = readline ()
437438 while next_line .startswith (' ' ):
438439 next_line = readline ()
440+ # end skip mergetags
439441
440442 # now we can have the encoding line, or an empty line followed by the optional
441443 # message.
@@ -444,39 +446,40 @@ def _deserialize(self, stream):
444446 # read headers
445447 enc = next_line
446448 buf = enc .strip ()
447- while buf != "" :
448- if buf [0 :10 ] == "encoding " :
449- self .encoding = buf [buf .find (' ' ) + 1 :]
450- elif buf [0 :7 ] == "gpgsig " :
451- sig = buf [buf .find (' ' ) + 1 :] + "\n "
449+ while buf :
450+ if buf [0 :10 ] == b "encoding " :
451+ self .encoding = buf [buf .find (' ' ) + 1 :]. decode ( 'ascii' )
452+ elif buf [0 :7 ] == b "gpgsig " :
453+ sig = buf [buf .find (b ' ' ) + 1 :] + b "\n "
452454 is_next_header = False
453455 while True :
454456 sigbuf = readline ()
455- if sigbuf == "" :
457+ if not sigbuf :
456458 break
457- if sigbuf [0 :1 ] != " " :
459+ if sigbuf [0 :1 ] != b " " :
458460 buf = sigbuf .strip ()
459461 is_next_header = True
460462 break
461463 sig += sigbuf [1 :]
462- self .gpgsig = sig .rstrip ("\n " )
464+ # end read all signature
465+ self .gpgsig = sig .rstrip (b"\n " ).decode ('ascii' )
463466 if is_next_header :
464467 continue
465468 buf = readline ().strip ()
466-
467469 # decode the authors name
470+
468471 try :
469- self .author .name = self .author .name .decode (self .encoding )
472+ self .author , self .authored_date , self .author_tz_offset = \
473+ parse_actor_and_date (author_line .decode (self .encoding ))
470474 except UnicodeDecodeError :
471- log .error ("Failed to decode author name '%s' using encoding %s" , self . author . name , self .encoding ,
475+ log .error ("Failed to decode author line '%s' using encoding %s" , author_line , self .encoding ,
472476 exc_info = True )
473- # END handle author's encoding
474477
475- # decode committer name
476478 try :
477- self .committer .name = self .committer .name .decode (self .encoding )
479+ self .committer , self .committed_date , self .committer_tz_offset = \
480+ parse_actor_and_date (committer_line .decode (self .encoding ))
478481 except UnicodeDecodeError :
479- log .error ("Failed to decode committer name '%s' using encoding %s" , self . committer . name , self .encoding ,
482+ log .error ("Failed to decode committer line '%s' using encoding %s" , committer_line , self .encoding ,
480483 exc_info = True )
481484 # END handle author's encoding
482485
@@ -488,6 +491,7 @@ def _deserialize(self, stream):
488491 except UnicodeDecodeError :
489492 log .error ("Failed to decode message '%s' using encoding %s" , self .message , self .encoding , exc_info = True )
490493 # END exception handling
494+
491495 return self
492496
493497 #} END serializable implementation
0 commit comments