diff --git a/git/objects/commit.py b/git/objects/commit.py index fd4187b08..8ffe84767 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -57,12 +57,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): __slots__ = ("tree", "author", "authored_date", "author_tz_offset", "committer", "committed_date", "committer_tz_offset", - "message", "parents", "encoding") + "message", "parents", "encoding", "gpgsig") _id_attribute_ = "binsha" def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None, committer=None, committed_date=None, committer_tz_offset=None, - message=None, parents=None, encoding=None): + message=None, parents=None, encoding=None, gpgsig=None): """Instantiate a new Commit. All keyword arguments taking None as default will be implicitly set on first query. @@ -120,6 +120,7 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut self.parents = parents if encoding is not None: self.encoding = encoding + self.gpgsig = gpgsig @classmethod def _get_intermediate_items(cls, commit): @@ -393,6 +394,12 @@ def _serialize(self, stream): if self.encoding != self.default_encoding: write("encoding %s\n" % self.encoding) + + if self.gpgsig: + write("gpgsig") + for sigline in self.gpgsig.split("\n"): + write(" " + sigline + "\n") + write("\n") @@ -430,13 +437,28 @@ def _deserialize(self, stream): # message. self.encoding = self.default_encoding # read encoding or empty line to separate message - enc = readline() - enc = enc.strip() - if enc: - self.encoding = enc[enc.find(' ')+1:] - # now comes the message separator - readline() - # END handle encoding + + # read headers + buf = readline().strip() + while buf != "": + if buf[0:10] == "encoding ": + self.encoding = buf[buf.find(' ')+1:] + elif buf[0:7] == "gpgsig ": + sig = buf[buf.find(' ')+1:] + "\n" + is_next_header = False + while True: + sigbuf = readline() + if sigbuf == "": break + if sigbuf[0:1] != " ": + buf = sigbuf.strip() + is_next_header = True + break + sig += sigbuf[1:] + self.gpgsig = sig + if is_next_header: + continue + buf = readline().strip() + # decode the authors name try: