Skip to content

GPG signature support on commit object. #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Commit(Diffable, Iterable, RepoAliasMixin, base.Object, Traversable, Seria
__slots__ = ("tree",
"author", "authored_date", "author_tz_offset",
"committer", "committed_date", "committer_tz_offset",
"message", "parents", "encoding")
"message", "parents", "encoding", "gpgsig")
_id_attribute_ = "binsha"


Expand Down Expand Up @@ -264,7 +264,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):

def __init__(self, odb, 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.

Expand Down Expand Up @@ -322,6 +322,9 @@ def __init__(self, odb, binsha, tree=None, author=None, authored_date=None, auth
self.parents = parents
if encoding is not None:
self.encoding = encoding
self.gpgsig = None
if gpgsig is not None:
self.gpgsig = gpgsig

@classmethod
def _get_intermediate_items(cls, commit):
Expand Down Expand Up @@ -399,6 +402,9 @@ def _serialize(self, stream):

if self.encoding != self.default_encoding:
write("encoding %s\n" % self.encoding)

if self.gpgsig:
write("gpgsig %s" % self.gpgsig)

write("\n")

Expand All @@ -407,7 +413,7 @@ def _serialize(self, stream):
write(self.message.encode(self.encoding))
else:
write(self.message)
# END handle encoding
# END handle encoding
return self

def _deserialize(self, stream):
Expand Down Expand Up @@ -435,15 +441,20 @@ def _deserialize(self, stream):
# now we can have the encoding line, or an empty line followed by the optional
# 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"
while True:
sig += readline()
if sig.find("END PGP SIGNATURE") > -1: break
self.gpgsig = sig
buf = readline().strip()

# decode the authors name
try:
self.author.name = self.author.name.decode(self.encoding)
Expand Down