From 007bd4b8190a6e85831c145e0aed5c68594db556 Mon Sep 17 00:00:00 2001 From: Igor Bondarenko Date: Thu, 14 Feb 2013 15:01:39 +0200 Subject: Fixed parse_actor_and_date with mangled tags --- git/objects/util.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'git') diff --git a/git/objects/util.py b/git/objects/util.py index 4c9323b8..af46f3c6 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -167,6 +167,7 @@ def parse_date(string_date): # precompiled regex _re_actor_epoch = re.compile(r'^.+? (.*) (\d+) ([+-]\d+).*$') +_re_only_actor = re.compile(r'^.+? (.*)$') def parse_actor_and_date(line): """Parse out the actor (author or committer) info from a line like:: @@ -174,8 +175,13 @@ def parse_actor_and_date(line): author Tom Preston-Werner 1191999972 -0700 :return: [Actor, int_seconds_since_epoch, int_timezone_offset]""" + actor, epoch, offset = '', 0, 0 m = _re_actor_epoch.search(line) - actor, epoch, offset = m.groups() + if m: + actor, epoch, offset = m.groups() + else: + m = _re_only_actor.search(line) + actor = m.group(1) if m else line or '' return (Actor._from_string(actor), int(epoch), utctz_to_altz(offset)) -- cgit v1.2.1 From db82455bd91ce00c22f6ee2b0dc622f117f07137 Mon Sep 17 00:00:00 2001 From: Cory Johns Date: Thu, 11 Apr 2013 18:39:03 +0000 Subject: [#6078] #102 Work-around mergetag blocks by ignoring them --- git/objects/commit.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'git') diff --git a/git/objects/commit.py b/git/objects/commit.py index fd4187b0..8e74f8bf 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -426,11 +426,18 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): self.committer, self.committed_date, self.committer_tz_offset = parse_actor_and_date(readline()) + # we might run into one or more mergetag blocks, skip those for now + next_line = readline() + while next_line.startswith('mergetag '): + next_line = readline() + while next_line.startswith(' '): + next_line = readline() + # 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 = next_line enc = enc.strip() if enc: self.encoding = enc[enc.find(' ')+1:] -- cgit v1.2.1 From f122a6aa3eb386914faa58ef3bf336f27b02fab0 Mon Sep 17 00:00:00 2001 From: Tim Van Steenburgh Date: Wed, 17 Apr 2013 18:21:53 +0000 Subject: Return bytes if object name can't be utf8-decoded Signed-off-by: Tim Van Steenburgh --- git/objects/fun.py | 10 +++++++--- git/test/test_fun.py | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'git') diff --git a/git/objects/fun.py b/git/objects/fun.py index 9b0a377c..8c380644 100644 --- a/git/objects/fun.py +++ b/git/objects/fun.py @@ -70,9 +70,13 @@ def tree_entries_from_data(data): # default encoding for strings in git is utf8 # Only use the respective unicode object if the byte stream was encoded name = data[ns:i] - name_enc = name.decode("utf-8") - if len(name) > len(name_enc): - name = name_enc + try: + name_enc = name.decode("utf-8") + except UnicodeDecodeError: + pass + else: + if len(name) > len(name_enc): + name = name_enc # END handle encoding # byte is NULL, get next 20 diff --git a/git/test/test_fun.py b/git/test/test_fun.py index b7991cdb..36435ae4 100644 --- a/git/test/test_fun.py +++ b/git/test/test_fun.py @@ -249,3 +249,8 @@ class TestFun(TestBase): entries = traverse_tree_recursive(odb, commit.tree.binsha, '') assert entries # END for each commit + +def test_tree_entries_from_data(): + from git.objects.fun import tree_entries_from_data + r = tree_entries_from_data(b'100644 \x9f\0aaa') + assert r == [('aaa', 33188, '\x9f')], r -- cgit v1.2.1 From 5869c5c1a51d448a411ae0d51d888793c35db9c0 Mon Sep 17 00:00:00 2001 From: Tim Van Steenburgh Date: Wed, 17 Apr 2013 18:43:19 +0000 Subject: Fix whacky indentation Signed-off-by: Tim Van Steenburgh --- git/objects/fun.py | 14 +++++++------- git/test/test_fun.py | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'git') diff --git a/git/objects/fun.py b/git/objects/fun.py index 8c380644..e2d4df55 100644 --- a/git/objects/fun.py +++ b/git/objects/fun.py @@ -70,13 +70,13 @@ def tree_entries_from_data(data): # default encoding for strings in git is utf8 # Only use the respective unicode object if the byte stream was encoded name = data[ns:i] - try: - name_enc = name.decode("utf-8") - except UnicodeDecodeError: - pass - else: - if len(name) > len(name_enc): - name = name_enc + try: + name_enc = name.decode("utf-8") + except UnicodeDecodeError: + pass + else: + if len(name) > len(name_enc): + name = name_enc # END handle encoding # byte is NULL, get next 20 diff --git a/git/test/test_fun.py b/git/test/test_fun.py index 36435ae4..bbd5d159 100644 --- a/git/test/test_fun.py +++ b/git/test/test_fun.py @@ -251,6 +251,6 @@ class TestFun(TestBase): # END for each commit def test_tree_entries_from_data(): - from git.objects.fun import tree_entries_from_data - r = tree_entries_from_data(b'100644 \x9f\0aaa') - assert r == [('aaa', 33188, '\x9f')], r + from git.objects.fun import tree_entries_from_data + r = tree_entries_from_data(b'100644 \x9f\0aaa') + assert r == [('aaa', 33188, '\x9f')], r -- cgit v1.2.1 From d3a728277877924e889e9fef42501127f48a4e77 Mon Sep 17 00:00:00 2001 From: Cory Johns Date: Wed, 9 Oct 2013 19:02:56 +0000 Subject: [#5330] Ensure wait() is called on git processes --- git/cmd.py | 1 + git/objects/commit.py | 3 +++ git/remote.py | 17 ++++------------- git/repo/base.py | 7 +++++-- git/util.py | 12 ++++++++++++ 5 files changed, 25 insertions(+), 15 deletions(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index 63a7134e..75687a41 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -80,6 +80,7 @@ class Git(LazyMixin): # try to kill it try: os.kill(self.proc.pid, 2) # interrupt signal + self.proc.wait() # ensure process goes away except AttributeError: # try windows # for some reason, providing None for stdout/stderr still prints something. This is why diff --git a/git/objects/commit.py b/git/objects/commit.py index 8e74f8bf..0565b2c0 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -8,6 +8,7 @@ from git.util import ( Actor, Iterable, Stats, + finalize_process ) from git.diff import Diffable from tree import Tree @@ -251,6 +252,8 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): assert len(hexsha) == 40, "Invalid line: %s" % hexsha yield Commit(repo, hex_to_bin(hexsha)) # END for each line in stream + if has_attr(proc_or_stream, 'wait'): + finalize_process(proc_or_stream) @classmethod diff --git a/git/remote.py b/git/remote.py index 5e4439fb..e38b3540 100644 --- a/git/remote.py +++ b/git/remote.py @@ -24,7 +24,10 @@ from refs import ( TagReference ) -from git.util import join_path +from git.util import ( + join_path, + finalize_process + ) from gitdb.util import join import re @@ -58,18 +61,6 @@ def digest_process_messages(fh, progress): # END while file is not done reading return dropped_lines -def finalize_process(proc): - """Wait for the process (clone, fetch, pull or push) and handle its errors accordingly""" - try: - proc.wait() - except GitCommandError,e: - # if a push has rejected items, the command has non-zero return status - # a return status of 128 indicates a connection error - reraise the previous one - if proc.poll() == 128: - raise - pass - # END exception handling - def add_progress(kwargs, git, progress): """Add the --progress flag to the given kwargs dict if supported by the git command. If the actual progress in the given progress instance is not diff --git a/git/repo/base.py b/git/repo/base.py index 14efabdc..0bc3c12c 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -6,7 +6,10 @@ from git.exc import InvalidGitRepositoryError, NoSuchPathError from git.cmd import Git -from git.util import Actor +from git.util import ( + Actor, + finalize_process + ) from git.refs import * from git.index import IndexFile from git.objects import * @@ -14,7 +17,6 @@ from git.config import GitConfigParser from git.remote import ( Remote, digest_process_messages, - finalize_process, add_progress ) @@ -541,6 +543,7 @@ class Repo(object): untracked_files.append(untracked_info.replace("#\t", "").rstrip()) # END for each utracked info line # END for each line + finalize_process(proc) return untracked_files @property diff --git a/git/util.py b/git/util.py index a9e87d6f..130d7762 100644 --- a/git/util.py +++ b/git/util.py @@ -121,6 +121,18 @@ def get_user_id(): # END get username from login return "%s@%s" % (username, platform.node()) +def finalize_process(proc): + """Wait for the process (clone, fetch, pull or push) and handle its errors accordingly""" + try: + proc.wait() + except GitCommandError,e: + # if a push has rejected items, the command has non-zero return status + # a return status of 128 indicates a connection error - reraise the previous one + if proc.poll() == 128: + raise + pass + # END exception handling + #} END utilities #{ Classes -- cgit v1.2.1 From c6b08c27a031f8b8b0bb6c41747ca1bc62b72706 Mon Sep 17 00:00:00 2001 From: Cory Johns Date: Thu, 17 Oct 2013 15:33:59 +0000 Subject: [#5330] Fixed has_attr typo --- git/objects/commit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git') diff --git a/git/objects/commit.py b/git/objects/commit.py index 0565b2c0..4ccd9d75 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -252,7 +252,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): assert len(hexsha) == 40, "Invalid line: %s" % hexsha yield Commit(repo, hex_to_bin(hexsha)) # END for each line in stream - if has_attr(proc_or_stream, 'wait'): + if hasattr(proc_or_stream, 'wait'): finalize_process(proc_or_stream) -- cgit v1.2.1 From 2e6957abf8cd88824282a19b74497872fe676a46 Mon Sep 17 00:00:00 2001 From: Dave Brondsema Date: Tue, 28 Jan 2014 21:07:31 -0500 Subject: Fix missed import from d3a7282 The `finalize_process` method was moved but this import wasn't carried with it. --- git/util.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'git') diff --git a/git/util.py b/git/util.py index 130d7762..0a533e50 100644 --- a/git/util.py +++ b/git/util.py @@ -13,6 +13,8 @@ import shutil import tempfile import platform +from exc import GitCommandError + from gitdb.util import ( make_sha, LockedFD, -- cgit v1.2.1 From 56d7a9b64b6d768dd118a02c1ed2afb38265c8b9 Mon Sep 17 00:00:00 2001 From: Yuriy Arhipov Date: Mon, 24 Feb 2014 02:08:58 +0400 Subject: [#7021] ticket:533 fixed error with pgp signed commits --- git/objects/commit.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'git') diff --git a/git/objects/commit.py b/git/objects/commit.py index 4ccd9d75..34ae15bf 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 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): 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 @@ 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 + + # 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) -- cgit v1.2.1 From 8005591231c8ae329f0ff320385b190d2ea81df0 Mon Sep 17 00:00:00 2001 From: Cory Johns Date: Mon, 3 Mar 2014 23:09:39 +0000 Subject: [#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 (limited to 'git') diff --git a/git/objects/commit.py b/git/objects/commit.py index 34ae15bf..035ce004 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -398,6 +398,11 @@ 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") diff --git a/git/test/fixtures/commit_with_gpgsig b/git/test/fixtures/commit_with_gpgsig new file mode 100644 index 00000000..f38cdabd --- /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/lib/helper.py b/git/test/lib/helper.py index 3a60d116..5790a858 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 4a8d8b87..0b7ed9ff 100644 --- a/git/test/test_commit.py +++ b/git/test/test_commit.py @@ -13,6 +13,7 @@ from gitdb.util import hex_to_bin 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 @@ class TestCommit(TestBase): # 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 = "" + self.assertNotEqual(cmt.gpgsig, fixture_sig) + + cstream = StringIO() + cmt._serialize(cstream) + value = cstream.getvalue() + self.assertRegexpMatches(value, re.compile(r"^gpgsig $", re.MULTILINE)) + + cstream.seek(0) + cmt.gpgsig = None + cmt._deserialize(cstream) + self.assertEqual(cmt.gpgsig, "") + + cmt.gpgsig = None + cstream = StringIO() + cmt._serialize(cstream) + value = cstream.getvalue() + self.assertNotRegexpMatches(value, re.compile(r"^gpgsig ", re.MULTILINE)) -- cgit v1.2.1 From f7ed51ba4c8416888f5744ddb84726316c461051 Mon Sep 17 00:00:00 2001 From: Cory Johns Date: Tue, 4 Mar 2014 18:33:13 +0000 Subject: [#7021] Fixed error serializing programmatically created commits --- git/objects/commit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git') diff --git a/git/objects/commit.py b/git/objects/commit.py index 035ce004..edbdf038 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -121,7 +121,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): 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 -- cgit v1.2.1