8000 GPG signature support on commit object. by mrasskazov · Pull Request #189 · gitpython-developers/GitPython · GitHub
[go: up one dir, main page]

Skip to content

GPG signature support on commit object. #189

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

Merged
merged 1 commit into from
Nov 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading 8000
Diff view
Diff view
53 changes: 36 additions & 17 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ 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):
"""Instantiate a new Commit. All keyword arguments taking None as default will
be implicitly set on first query.
committer=None, committed_date=None, committer_tz_offset=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.

:param binsha: 20 byte sha1
:param parents: tuple( Commit, ... )
is a tuple of commit ids or actual Commits
Expand Down Expand Up @@ -120,7 +120,8 @@ 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):
return commit.parents
Expand Down Expand Up @@ -393,7 +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.rstrip("\n").split("\n"):
write(" "+sigline+"\n")

write("\n")

# write plain bytes, be sure its encoded according to our encoding
Expand Down Expand Up @@ -429,15 +435,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>
42 changes: 41 additions & 1 deletion git/test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 @@ -272,4 +273,43 @@ def test_serialization_unicode_support(self):
# actually, it can't be printed in a shell as repr wants to have ascii only
# 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)
0