diff --git a/git/objects/commit.py b/git/objects/commit.py index c32bbf1a0..9a2ed81c6 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -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" @@ -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. @@ -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): @@ -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") @@ -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) diff --git a/git/test/fixtures/commit_with_gpgsig b/git/test/fixtures/commit_with_gpgsig new file mode 100644 index 000000000..f38cdabd6 --- /dev/null +++ b/git/test/fixtures/commit_with_gpgsig @@ -0,0 +1,30 @@ +tree cefbccb4843d821183ae195e70a17c9938318945 +parent 904435cf76a9bdd5eb41b1c4e049d5a64f3a8400 +author Jon Mason 1367013117 -0700 +committer Jon Mason 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 diff --git a/git/test/objects/lib.py b/git/test/objects/lib.py index fe1d9f9db..a24e1a5e0 100644 --- a/git/test/objects/lib.py +++ b/git/test/objects/lib.py @@ -7,6 +7,7 @@ assert_not_equal, with_rw_repo, StringProcessAdapter, + fixture_path, ) class TestObjectBase(TestBase): diff --git a/git/test/objects/test_commit.py b/git/test/objects/test_commit.py index 80326fe9a..3463503a8 100644 --- a/git/test/objects/test_commit.py +++ b/git/test/objects/test_commit.py @@ -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): @@ -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 = "" + assert cmt.gpgsig != fixture_sig + + cstream = StringIO() + cmt._serialize(cstream) + assert re.search(r"^gpgsig $", cstream.getvalue(), re.MULTILINE) + + cstream.seek(0) + cmt.gpgsig = None + cmt._deserialize(cstream) + assert cmt.gpgsig == "" + + cmt.gpgsig = None + cstream = StringIO() + cmt._serialize(cstream) + assert not re.search(r"^gpgsig ", cstream.getvalue(), re.MULTILINE)