@@ -57,15 +57,15 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
5757 __slots__ = ("tree" ,
5858 "author" , "authored_date" , "author_tz_offset" ,
5959 "committer" , "committed_date" , "committer_tz_offset" ,
60- "message" , "parents" , "encoding" )
60+ "message" , "parents" , "encoding" , "gpgsig" )
6161 _id_attribute_ = "binsha"
6262
6363 def __init__ (self , repo , binsha , tree = None , author = None , authored_date = None , author_tz_offset = None ,
64- committer = None , committed_date = None , committer_tz_offset = None ,
65- message = None , parents = None , encoding = None ):
66- """Instantiate a new Commit. All keyword arguments taking None as default will
67- be implicitly set on first query.
68-
64+ committer = None , committed_date = None , committer_tz_offset = None ,
65+ message = None , parents = None , encoding = None , gpgsig = None ):
66+ """Instantiate a new Commit. All keyword arguments taking None as default will
67+ be implicitly set on first query.
68+
6969 :param binsha: 20 byte sha1
7070 :param parents: tuple( Commit, ... )
7171 is a tuple of commit ids or actual Commits
@@ -120,7 +120,8 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
120120 self .parents = parents
121121 if encoding is not None :
122122 self .encoding = encoding
123-
123+ self .gpgsig = gpgsig
124+
124125 @classmethod
125126 def _get_intermediate_items (cls , commit ):
126127 return commit .parents
@@ -393,7 +394,12 @@ def _serialize(self, stream):
393394
394395 if self .encoding != self .default_encoding :
395396 write ("encoding %s\n " % self .encoding )
396-
397+
398+ if self .gpgsig :
399+ write ("gpgsig" )
400+ for sigline in self .gpgsig .rstrip ("\n " ).split ("\n " ):
401+ write (" " + sigline + "\n " )
402+
397403 write ("\n " )
398404
399405 # write plain bytes, be sure its encoded according to our encoding
@@ -429,15 +435,28 @@ def _deserialize(self, stream):
429435 # now we can have the encoding line, or an empty line followed by the optional
430436 # message.
431437 self .encoding = self .default_encoding
432- # read encoding or empty line to separate message
433- enc = readline ()
434- enc = enc .strip ()
435- if enc :
436- self .encoding = enc [enc .find (' ' )+ 1 :]
437- # now comes the message separator
438- readline ()
439- # END handle encoding
440-
438+
439+ # read headers
440+ buf = readline ().strip ()
441+ while buf != "" :
442+ if buf [0 :10 ] == "encoding " :
443+ self .encoding = buf [buf .find (' ' )+ 1 :]
444+ elif buf [0 :7 ] == "gpgsig " :
445+ sig = buf [buf .find (' ' )+ 1 :] + "\n "
446+ is_next_header = False
447+ while True :
448+ sigbuf = readline ()
449+ if sigbuf == "" : break
450+ if sigbuf [0 :1 ] != " " :
451+ buf = sigbuf .strip ()
452+ is_next_header = True
453+ break
454+ sig += sigbuf [1 :]
455+ self .gpgsig = sig .rstrip ("\n " )
456+ if is_next_header :
457+ continue
458+ buf = readline ().strip ()
459+
441460 # decode the authors name
442461 try :
443462 self .author .name = self .author .name .decode (self .encoding )
0 commit comments