Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8065d2a

Browse files
committed
GPG signature support on commit object.
1 parent 660bdca commit 8065d2a

File tree

4 files changed

+102
-11
lines changed

4 files changed

+102
-11
lines changed

git/objects/commit.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Commit(Diffable, Iterable, RepoAliasMixin, base.Object, Traversable, Seria
6262
__slots__ = ("tree",
6363
"author", "authored_date", "author_tz_offset",
6464
"committer", "committed_date", "committer_tz_offset",
65-
"message", "parents", "encoding")
65+
"message", "parents", "encoding", "gpgsig")
6666
_id_attribute_ = "binsha"
6767

6868

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

265265
def __init__(self, odb, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None,
266266
committer=None, committed_date=None, committer_tz_offset=None,
267-
message=None, parents=None, encoding=None):
267+
message=None, parents=None, encoding=None, gpgsig=None):
268268
"""Instantiate a new Commit. All keyword arguments taking None as default will
269269
be implicitly set on first query.
270270
@@ -322,6 +322,7 @@ def __init__(self, odb, binsha, tree=None, author=None, authored_date=None, auth
322322
self.parents = parents
323323
if encoding is not None:
324324
self.encoding = encoding
325+
self.gpgsig = gpgsig
325326

326327
@classmethod
327328
def _get_intermediate_items(cls, commit):
@@ -399,6 +400,11 @@ def _serialize(self, stream):
399400

400401
if self.encoding != self.default_encoding:
401402
write("encoding %s\n" % self.encoding)
403+
404+
if self.gpgsig:
405+
write("gpgsig")
406+
for sigline in self.gpgsig.split("\n"):
407+
write(" "+sigline+"\n")
402408

403409
write("\n")
404410

@@ -435,15 +441,28 @@ def _deserialize(self, stream):
435441
# now we can have the encoding line, or an empty line followed by the optional
436442
# message.
437443
self.encoding = self.default_encoding
438-
# read encoding or empty line to separate message
439-
enc = readline()
440-
enc = enc.strip()
441-
if enc:
442-
self.encoding = enc[enc.find(' ')+1:]
443-
# now comes the message separator
444-
readline()
445-
# END handle encoding
446-
444+
445+
# read headers
446+
buf = readline().strip()
447+
while buf != "":
448+
if buf[0:10] == "encoding ":
449+
self.encoding = buf[buf.find(' ')+1:]
450+
elif buf[0:7] == "gpgsig ":
451+
sig = buf[buf.find(' ')+1:] + "\n"
452+
is_next_header = False
453+
while True:
454+
sigbuf = readline()
455+
if sigbuf == "": break
456+
if sigbuf[0:1] != " ":
457+
buf = sigbuf.strip()
458+
is_next_header = True
459+
break
460+
sig += sigbuf[1:]
461+
self.gpgsig = sig
462+
if is_next_header:
463+
continue
464+
buf = readline().strip()
465+
447466
# decode the authors name
448467
try:
449468
self.author.name = self.author.name.decode(self.encoding)

git/test/fixtures/commit_with_gpgsig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
tree cefbccb4843d821183ae195e70a17c9938318945
2+
parent 904435cf76a9bdd5eb41b1c4e049d5a64f3a8400
3+
author Jon Mason <[email protected]> 1367013117 -0700
4+
committer Jon Mason <[email protected]> 1368640702 -0700
5+
gpgsig -----BEGIN PGP SIGNATURE-----
6+
Version: GnuPG v1.4.11 (GNU/Linux)
7+
8+
iQIcBAABAgAGBQJRk8zMAAoJEG5mS6x6i9IjsTEP/0v2Wx/i7dqyKban6XMIhVdj
9+
uI0DycfXqnCCZmejidzeao+P+cuK/ZAA/b9fU4MtwkDm2USvnIOrB00W0isxsrED
10+
sdv6uJNa2ybGjxBolLrfQcWutxGXLZ1FGRhEvkPTLMHHvVriKoNFXcS7ewxP9MBf
11+
NH97K2wauqA+J4BDLDHQJgADCOmLrGTAU+G1eAXHIschDqa6PZMH5nInetYZONDh
12+
3SkOOv8VKFIF7gu8X7HC+7+Y8k8U0TW0cjlQ2icinwCc+KFoG6GwXS7u/VqIo1Yp
13+
Tack6sxIdK7NXJhV5gAeAOMJBGhO0fHl8UUr96vGEKwtxyZhWf8cuIPOWLk06jA0
14+
g9DpLqmy/pvyRfiPci+24YdYRBua/vta+yo/Lp85N7Hu/cpIh+q5WSLvUlv09Dmo
15+
TTTG8Hf6s3lEej7W8z2xcNZoB6GwXd8buSDU8cu0I6mEO9sNtAuUOHp2dBvTA6cX
16+
PuQW8jg3zofnx7CyNcd3KF3nh2z8mBcDLgh0Q84srZJCPRuxRcp9ylggvAG7iaNd
17+
XMNvSK8IZtWLkx7k3A3QYt1cN4y1zdSHLR2S+BVCEJea1mvUE+jK5wiB9S4XNtKm
18+
BX/otlTa8pNE3fWYBxURvfHnMY4i3HQT7Bc1QjImAhMnyo2vJk4ORBJIZ1FTNIhJ
19+
JzJMZDRLQLFvnzqZuCjE
20+
=przd
21+
-----END PGP SIGNATURE-----
22+
23+
NTB: Multiple NTB client fix
24+
25+
Fix issue with adding multiple ntb client devices to the ntb virtual
26+
bus. Previously, multiple devices would be added with the same name,
27+
resulting in crashes. To get around this issue, add a unique number to
28+
the device when it is added.
29+
30+
Signed-off-by: Jon Mason <[email protected]>

git/test/objects/lib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
assert_not_equal,
88
with_rw_repo,
99
StringProcessAdapter,
10+
fixture_path,
1011
)
1112

1213
class TestObjectBase(TestBase):

git/test/objects/test_commit.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from cStringIO import StringIO
1818
import time
1919
import sys
20+
import re
2021

2122

2223
def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False):
@@ -277,3 +278,43 @@ def test_serialization_unicode_support(self):
277278
# it appears
278279
cmt.author.__repr__()
279280

281+
def test_gpgsig(self):
282+
cmt = self.rorepo.commit()
283+
cmt._deserialize(open(fixture_path('commit_with_gpgsig')))
284+
285+
fixture_sig = """-----BEGIN PGP SIGNATURE-----
286+
Version: GnuPG v1.4.11 (GNU/Linux)
287+
288+
iQIcBAABAgAGBQJRk8zMAAoJEG5mS6x6i9IjsTEP/0v2Wx/i7dqyKban6XMIhVdj
289+
uI0DycfXqnCCZmejidzeao+P+cuK/ZAA/b9fU4MtwkDm2USvnIOrB00W0isxsrED
290+
sdv6uJNa2ybGjxBolLrfQcWutxGXLZ1FGRhEvkPTLMHHvVriKoNFXcS7ewxP9MBf
291+
NH97K2wauqA+J4BDLDHQJgADCOmLrGTAU+G1eAXHIschDqa6PZMH5nInetYZONDh
292+
3SkOOv8VKFIF7gu8X7HC+7+Y8k8U0TW0cjlQ2icinwCc+KFoG6GwXS7u/VqIo1Yp
293+
Tack6sxIdK7NXJhV5gAeAOMJBGhO0fHl8UUr96vGEKwtxyZhWf8cuIPOWLk06jA0
294+
g9DpLqmy/pvyRfiPci+24YdYRBua/vta+yo/Lp85N7Hu/cpIh+q5WSLvUlv09Dmo
295+
TTTG8Hf6s3lEej7W8z2xcNZoB6GwXd8buSDU8cu0I6mEO9sNtAuUOHp2dBvTA6cX
296+
PuQW8jg3zofnx7CyNcd3KF3nh2z8mBcDLgh0Q84srZJCPRuxRcp9ylggvAG7iaNd
297+
XMNvSK8IZtWLkx7k3A3QYt1cN4y1zdSHLR2S+BVCEJea1mvUE+jK5wiB9S4XNtKm
298+
BX/otlTa8pNE3fWYBxURvfHnMY4i3HQT7Bc1QjImAhMnyo2vJk4ORBJIZ1FTNIhJ
299+
JzJMZDRLQLFvnzqZuCjE
300+
=przd
301+
-----END PGP SIGNATURE-----
302+
"""
303+
assert cmt.gpgsig == fixture_sig
304+
305+
cmt.gpgsig = "<test\ndummy\nsig>"
306+
assert cmt.gpgsig != sig
307+
308+
cstream = StringIO()
309+
cmt._serialize(cstream)
310+
assert re.search(r"^gpgsig <test\n dummy\n sig>$", cstream.getvalue(), re.MULTILINE)
311+
312+
cstream.seek(0)
313+
cmt.gpgsig = None
314+
cmt._deserialize(cstream)
315+
assert cmt.gpgsig == "<test\ndummy\nsig>\n"
316+
317+
cmt.gpgsig = None
318+
cstream = StringIO()
319+
cmt._serialize(cstream)
320+
assert not re.search(r"^gpgsig ", cstream.getvalue(), re.MULTILINE)

0 commit comments

Comments
 (0)