From 56d7a9b64b6d768dd118a02c1ed2afb38265c8b9 Mon Sep 17 00:00:00 2001
From: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Date: Mon, 24 Feb 2014 02:08:58 +0400
Subject: [PATCH 1/3] [#7021] ticket:533 fixed error with pgp signed commits

---
 git/objects/commit.py | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/git/objects/commit.py b/git/objects/commit.py
index 4ccd9d755..34ae15bf7 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -58,12 +58,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. 
 		
@@ -121,6 +121,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
+		if gpgsig is not None:
+			self.gpgsig = gpgsig
 		
 	@classmethod
 	def _get_intermediate_items(cls, commit):
@@ -439,15 +441,29 @@ 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
+
+		# read headers
 		enc = next_line
-		enc = enc.strip()
-		if enc:
-			self.encoding = enc[enc.find(' ')+1:]
-			# now comes the message separator 
-			readline()
-		# END handle encoding
-		
+		buf = enc.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) 

From 8005591231c8ae329f0ff320385b190d2ea81df0 Mon Sep 17 00:00:00 2001
From: Cory Johns <johnsca@gmail.com>
Date: Mon, 3 Mar 2014 23:09:39 +0000
Subject: [PATCH 2/3] [#7021] Added serialization and test from upstream and
 fixed test issues

---
 git/objects/commit.py                |  5 ++++
 git/test/fixtures/commit_with_gpgsig | 30 ++++++++++++++++++++
 git/test/lib/helper.py               |  2 +-
 git/test/test_commit.py              | 42 ++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 git/test/fixtures/commit_with_gpgsig

diff --git a/git/objects/commit.py b/git/objects/commit.py
index 34ae15bf7..035ce004e 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -398,6 +398,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")
 		
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 <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>
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 3a60d116c..5790a8589 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -227,7 +227,7 @@ class TestBase(TestCase):
 	"""
 	
 	@classmethod
-	def setUpAll(cls):
+	def setUpClass(cls):
 		"""
 		Dynamically add a read-only repository to our actual type. This way 
 		each test type has its own repository
diff --git a/git/test/test_commit.py b/git/test/test_commit.py
index 4a8d8b878..0b7ed9ffb 100644
--- a/git/test/test_commit.py
+++ b/git/test/test_commit.py
@@ -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):
@@ -273,3 +274,44 @@ 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-----"""
+		self.assertEqual(cmt.gpgsig, fixture_sig)
+		self.assertIn('NTB: Multiple NTB client fix', cmt.message)
+		cmt.gpgsig = "<test\ndummy\nsig>"
+		self.assertNotEqual(cmt.gpgsig, fixture_sig)
+
+		cstream = StringIO()
+		cmt._serialize(cstream)
+		value = cstream.getvalue()
+		self.assertRegexpMatches(value, re.compile(r"^gpgsig <test\n dummy\n sig>$", re.MULTILINE))
+
+		cstream.seek(0)
+		cmt.gpgsig = None
+		cmt._deserialize(cstream)
+		self.assertEqual(cmt.gpgsig, "<test\ndummy\nsig>")
+
+		cmt.gpgsig = None
+		cstream = StringIO()
+		cmt._serialize(cstream)
+		value = cstream.getvalue()
+		self.assertNotRegexpMatches(value, re.compile(r"^gpgsig ", re.MULTILINE))

From f7ed51ba4c8416888f5744ddb84726316c461051 Mon Sep 17 00:00:00 2001
From: Cory Johns <johnsca@gmail.com>
Date: Tue, 4 Mar 2014 18:33:13 +0000
Subject: [PATCH 3/3] [#7021] Fixed error serializing programmatically created
 commits

---
 git/objects/commit.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git/objects/commit.py b/git/objects/commit.py
index 035ce004e..edbdf038c 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -121,7 +121,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
-		if gpgsig is not None:
+		if binsha == '\x00'*20 or gpgsig is not None:
 			self.gpgsig = gpgsig
 		
 	@classmethod