summaryrefslogtreecommitdiff
path: root/git/objects/commit.py
diff options
context:
space:
mode:
authorMax Rasskazov <mrasskazov@mirantis.com>2014-09-08 18:10:57 +0400
committerMax Rasskazov <mrasskazov@mirantis.com>2014-09-08 18:36:11 +0400
commitd45c76bd8cd28d05102311e9b4bc287819a51e0e (patch)
treeb8dab8aed961b0f9a90d511b03bfc1e0fc588adb /git/objects/commit.py
parent27c577dfd5c7f0fc75cd10ed6606674b56b405bd (diff)
downloadgitpython-d45c76bd8cd28d05102311e9b4bc287819a51e0e.tar.gz
GPG signature support on commit object.
Originals: Pull request "GPG signature support on commit object" #124 by Tatsuki Sugiura. https://github.com/gitpython-developers/GitPython/pull/124 commit 8065d2abdbb18e09560fc061807301b4c834d5a7 commit 62ecd6c66a84144632b045696326af503ee8cd4e
Diffstat (limited to 'git/objects/commit.py')
-rw-r--r--git/objects/commit.py53
1 files changed, 36 insertions, 17 deletions
diff --git a/git/objects/commit.py b/git/objects/commit.py
index cbfd5097..4380f472 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -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
@@ -120,7 +120,8 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
self.parents = parents
if encoding is not None:
self.encoding = encoding
-
+ self.gpgsig = gpgsig
+
@classmethod
def _get_intermediate_items(cls, commit):
return commit.parents
@@ -393,7 +394,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
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
@@ -429,15 +435,28 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# 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)