Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd38b9a9

Browse files
committed
Merge pull requestgitpython-developers#189 from mrasskazov/0.3
GPG signature support on commit object.
2 parents0f09906 +d45c76b commitd38b9a9

File tree

3 files changed

+107
-18
lines changed

3 files changed

+107
-18
lines changed

‎git/objects/commit.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
5757
__slots__= ("tree",
5858
"author","authored_date","author_tz_offset",
5959
"committer","committed_date","committer_tz_offset",
60-
"message","parents","encoding")
60+
"message","parents","encoding","gpgsig")
6161
_id_attribute_="binsha"
6262

6363
def__init__(self,repo,binsha,tree=None,author=None,authored_date=None,author_tz_offset=None,
64-
committer=None,committed_date=None,committer_tz_offset=None,
65-
message=None,parents=None,encoding=None):
66-
"""Instantiate a new Commit. All keyword arguments taking None as default will
67-
be implicitly set on first query.
68-
64+
committer=None,committed_date=None,committer_tz_offset=None,
65+
message=None,parents=None,encoding=None,gpgsig=None):
66+
"""Instantiate a new Commit. All keyword arguments taking None as default will
67+
be implicitly set on first query.
68+
6969
:param binsha: 20 byte sha1
7070
:param parents: tuple( Commit, ... )
7171
is a tuple of commit ids or actual Commits
@@ -120,7 +120,8 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
120120
self.parents=parents
121121
ifencodingisnotNone:
122122
self.encoding=encoding
123-
123+
self.gpgsig=gpgsig
124+
124125
@classmethod
125126
def_get_intermediate_items(cls,commit):
126127
returncommit.parents
@@ -393,7 +394,12 @@ def _serialize(self, stream):
393394

394395
ifself.encoding!=self.default_encoding:
395396
write("encoding %s\n"%self.encoding)
396-
397+
398+
ifself.gpgsig:
399+
write("gpgsig")
400+
forsiglineinself.gpgsig.rstrip("\n").split("\n"):
401+
write(" "+sigline+"\n")
402+
397403
write("\n")
398404

399405
# write plain bytes, be sure its encoded according to our encoding
@@ -429,15 +435,28 @@ def _deserialize(self, stream):
429435
# now we can have the encoding line, or an empty line followed by the optional
430436
# message.
431437
self.encoding=self.default_encoding
432-
# read encoding or empty line to separate message
433-
enc=readline()
434-
enc=enc.strip()
435-
ifenc:
436-
self.encoding=enc[enc.find(' ')+1:]
437-
# now comes the message separator
438-
readline()
439-
# END handle encoding
440-
438+
439+
# read headers
440+
buf=readline().strip()
441+
whilebuf!="":
442+
ifbuf[0:10]=="encoding ":
443+
self.encoding=buf[buf.find(' ')+1:]
444+
elifbuf[0:7]=="gpgsig ":
445+
sig=buf[buf.find(' ')+1:]+"\n"
446+
is_next_header=False
447+
whileTrue:
448+
sigbuf=readline()
449+
ifsigbuf=="":break
450+
ifsigbuf[0:1]!=" ":
451+
buf=sigbuf.strip()
452+
is_next_header=True
453+
break
454+
sig+=sigbuf[1:]
455+
self.gpgsig=sig.rstrip("\n")
456+
ifis_next_header:
457+
continue
458+
buf=readline().strip()
459+
441460
# decode the authors name
442461
try:
443462
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 <jon.mason@intel.com> 1367013117 -0700
4+
committer Jon Mason <jon.mason@intel.com> 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 <jon.mason@intel.com>

‎git/test/test_commit.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
fromcStringIOimportStringIO
1414
importtime
1515
importsys
16+
importre
1617

1718

1819
defassert_commit_serialization(rwrepo,commit_id,print_performance_info=False):
@@ -272,4 +273,43 @@ def test_serialization_unicode_support(self):
272273
# actually, it can't be printed in a shell as repr wants to have ascii only
273274
# it appears
274275
cmt.author.__repr__()
275-
276+
277+
deftest_gpgsig(self):
278+
cmt=self.rorepo.commit()
279+
cmt._deserialize(open(fixture_path('commit_with_gpgsig')))
280+
281+
fixture_sig="""-----BEGIN PGP SIGNATURE-----
282+
Version: GnuPG v1.4.11 (GNU/Linux)
283+
284+
iQIcBAABAgAGBQJRk8zMAAoJEG5mS6x6i9IjsTEP/0v2Wx/i7dqyKban6XMIhVdj
285+
uI0DycfXqnCCZmejidzeao+P+cuK/ZAA/b9fU4MtwkDm2USvnIOrB00W0isxsrED
286+
sdv6uJNa2ybGjxBolLrfQcWutxGXLZ1FGRhEvkPTLMHHvVriKoNFXcS7ewxP9MBf
287+
NH97K2wauqA+J4BDLDHQJgADCOmLrGTAU+G1eAXHIschDqa6PZMH5nInetYZONDh
288+
3SkOOv8VKFIF7gu8X7HC+7+Y8k8U0TW0cjlQ2icinwCc+KFoG6GwXS7u/VqIo1Yp
289+
Tack6sxIdK7NXJhV5gAeAOMJBGhO0fHl8UUr96vGEKwtxyZhWf8cuIPOWLk06jA0
290+
g9DpLqmy/pvyRfiPci+24YdYRBua/vta+yo/Lp85N7Hu/cpIh+q5WSLvUlv09Dmo
291+
TTTG8Hf6s3lEej7W8z2xcNZoB6GwXd8buSDU8cu0I6mEO9sNtAuUOHp2dBvTA6cX
292+
PuQW8jg3zofnx7CyNcd3KF3nh2z8mBcDLgh0Q84srZJCPRuxRcp9ylggvAG7iaNd
293+
XMNvSK8IZtWLkx7k3A3QYt1cN4y1zdSHLR2S+BVCEJea1mvUE+jK5wiB9S4XNtKm
294+
BX/otlTa8pNE3fWYBxURvfHnMY4i3HQT7Bc1QjImAhMnyo2vJk4ORBJIZ1FTNIhJ
295+
JzJMZDRLQLFvnzqZuCjE
296+
=przd
297+
-----END PGP SIGNATURE-----"""
298+
assertcmt.gpgsig==fixture_sig
299+
300+
cmt.gpgsig="<test\ndummy\nsig>"
301+
assertcmt.gpgsig!=fixture_sig
302+
303+
cstream=StringIO()
304+
cmt._serialize(cstream)
305+
assertre.search(r"^gpgsig <test\n dummy\n sig>$",cstream.getvalue(),re.MULTILINE)
306+
307+
cstream.seek(0)
308+
cmt.gpgsig=None
309+
cmt._deserialize(cstream)
310+
assertcmt.gpgsig=="<test\ndummy\nsig>"
311+
312+
cmt.gpgsig=None
313+
cstream=StringIO()
314+
cmt._serialize(cstream)
315+
assertnotre.search(r"^gpgsig ",cstream.getvalue(),re.MULTILINE)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp