Skip to content

GPG signature support on commit object. #124

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 2 commits into from
Closed
Show file tree
Hide file tree
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
41 changes: 30 additions & 11 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,7 @@ 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 = gpgsig

@classmethod
def _get_intermediate_items(cls, commit):
Expand Down Expand Up @@ -399,6 +400,11 @@ 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.rstrip("\n").split("\n"):
write(" "+sigline+"\n")

write("\n")

Expand Down Expand Up @@ -435,15 +441,28 @@ 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"
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.rstrip("\n")
if is_next_header:
continue
buf = readline().strip()

# decode the authors name
try:
self.author.name = self.author.name.decode(self.encoding)
Expand Down
30 changes: 30 additions & 0 deletions git/test/fixtures/commit_with_gpgsig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
tree cefbccb4843d821183ae195e70a17c9938318945
parent 904435cf76a9bdd5eb41b1c4e049d5a64f3a8400
author Jon Mason <jon.mason@intel.com> 1367013117 -0700
committer Jon Mason <jon.mason@intel.com> 1368640702 -0700
gpgsig -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAABAgAGBQJRk8zMAAoJEG5mS6x6i9IjsTEP/0v2Wx/i7dqyKban6XMIhVdj
uI0DycfXqnCCZmejidzeao+P+cuK/ZAA/b9fU4MtwkDm2USvnIOrB00W0isxsrED
sdv6uJNa2ybGjxBolLrfQcWutxGXLZ1FGRhEvkPTLMHHvVriKoNFXcS7ewxP9MBf
NH97K2wauqA+J4BDLDHQJgADCOmLrGTAU+G1eAXHIschDqa6PZMH5nInetYZONDh
3SkOOv8VKFIF7gu8X7HC+7+Y8k8U0TW0cjlQ2icinwCc+KFoG6GwXS7u/VqIo1Yp
Tack6sxIdK7NXJhV5gAeAOMJBGhO0fHl8UUr96vGEKwtxyZhWf8cuIPOWLk06jA0
g9DpLqmy/pvyRfiPci+24YdYRBua/vta+yo/Lp85N7Hu/cpIh+q5WSLvUlv09Dmo
TTTG8Hf6s3lEej7W8z2xcNZoB6GwXd8buSDU8cu0I6mEO9sNtAuUOHp2dBvTA6cX
PuQW8jg3zofnx7CyNcd3KF3nh2z8mBcDLgh0Q84srZJCPRuxRcp9ylggvAG7iaNd
XMNvSK8IZtWLkx7k3A3QYt1cN4y1zdSHLR2S+BVCEJea1mvUE+jK5wiB9S4XNtKm
BX/otlTa8pNE3fWYBxURvfHnMY4i3HQT7Bc1QjImAhMnyo2vJk4ORBJIZ1FTNIhJ
JzJMZDRLQLFvnzqZuCjE
=przd
-----END PGP SIGNATURE-----

NTB: Multiple NTB client fix

Fix issue with adding multiple ntb client devices to the ntb virtual
bus. Previously, multiple devices would be added with the same name,
resulting in crashes. To get around this issue, add a unique number to
the device when it is added.

Signed-off-by: Jon Mason <jon.mason@intel.com>
1 change: 1 addition & 0 deletions git/test/objects/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
assert_not_equal,
with_rw_repo,
StringProcessAdapter,
fixture_path,
)

class TestObjectBase(TestBase):
Expand Down
40 changes: 40 additions & 0 deletions git/test/objects/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from cStringIO import StringIO
import time
import sys
import re


def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False):
Expand Down Expand Up @@ -277,3 +278,42 @@ def test_serialization_unicode_support(self):
# it appears
cmt.author.__repr__()

def test_gpgsig(self):
cmt = self.rorepo.commit()
cmt._deserialize(open(fixture_path('commit_with_gpgsig')))

fixture_sig = """-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAABAgAGBQJRk8zMAAoJEG5mS6x6i9IjsTEP/0v2Wx/i7dqyKban6XMIhVdj
uI0DycfXqnCCZmejidzeao+P+cuK/ZAA/b9fU4MtwkDm2USvnIOrB00W0isxsrED
sdv6uJNa2ybGjxBolLrfQcWutxGXLZ1FGRhEvkPTLMHHvVriKoNFXcS7ewxP9MBf
NH97K2wauqA+J4BDLDHQJgADCOmLrGTAU+G1eAXHIschDqa6PZMH5nInetYZONDh
3SkOOv8VKFIF7gu8X7HC+7+Y8k8U0TW0cjlQ2icinwCc+KFoG6GwXS7u/VqIo1Yp
Tack6sxIdK7NXJhV5gAeAOMJBGhO0fHl8UUr96vGEKwtxyZhWf8cuIPOWLk06jA0
g9DpLqmy/pvyRfiPci+24YdYRBua/vta+yo/Lp85N7Hu/cpIh+q5WSLvUlv09Dmo
TTTG8Hf6s3lEej7W8z2xcNZoB6GwXd8buSDU8cu0I6mEO9sNtAuUOHp2dBvTA6cX
PuQW8jg3zofnx7CyNcd3KF3nh2z8mBcDLgh0Q84srZJCPRuxRcp9ylggvAG7iaNd
XMNvSK8IZtWLkx7k3A3QYt1cN4y1zdSHLR2S+BVCEJea1mvUE+jK5wiB9S4XNtKm
BX/otlTa8pNE3fWYBxURvfHnMY4i3HQT7Bc1QjImAhMnyo2vJk4ORBJIZ1FTNIhJ
JzJMZDRLQLFvnzqZuCjE
=przd
-----END PGP SIGNATURE-----"""
assert cmt.gpgsig == fixture_sig

cmt.gpgsig = "<test\ndummy\nsig>"
assert cmt.gpgsig != fixture_sig

cstream = StringIO()
cmt._serialize(cstream)
assert re.search(r"^gpgsig <test\n dummy\n sig>$", cstream.getvalue(), re.MULTILINE)

cstream.seek(0)
cmt.gpgsig = None
cmt._deserialize(cstream)
assert cmt.gpgsig == "<test\ndummy\nsig>"

cmt.gpgsig = None
cstream = StringIO()
cmt._serialize(cstream)
assert not re.search(r"^gpgsig ", cstream.getvalue(), re.MULTILINE)