summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/actor.py9
-rw-r--r--lib/git/objects/commit.py40
-rw-r--r--test/git/test_actor.py8
-rw-r--r--test/git/test_commit.py13
4 files changed, 54 insertions, 16 deletions
diff --git a/lib/git/actor.py b/lib/git/actor.py
index fe4a47e5..04872f1c 100644
--- a/lib/git/actor.py
+++ b/lib/git/actor.py
@@ -18,6 +18,15 @@ class Actor(object):
self.name = name
self.email = email
+ def __eq__(self, other):
+ return self.name == other.name and self.email == other.email
+
+ def __ne__(self, other):
+ return not (self == other)
+
+ def __hash__(self):
+ return hash((self.name, self.email))
+
def __str__(self):
return self.name
diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py
index 4080305f..00f3d0e4 100644
--- a/lib/git/objects/commit.py
+++ b/lib/git/objects/commit.py
@@ -83,7 +83,7 @@ class Commit(base.Object, Iterable, diff.Diffable):
# prepare our data lines to match rev-list
data_lines = self.data.splitlines()
data_lines.insert(0, "commit %s" % self.id)
- temp = self._iter_from_process_or_stream(self.repo, iter(data_lines)).next()
+ temp = self._iter_from_process_or_stream(self.repo, iter(data_lines), False).next()
self.parents = temp.parents
self.tree = temp.tree
self.author = temp.author
@@ -111,7 +111,8 @@ class Commit(base.Object, Iterable, diff.Diffable):
to commits actually containing the paths
``kwargs``
- Additional options to be passed to git-rev-list
+ Additional options to be passed to git-rev-list. They must not alter
+ the ouput style of the command, or parsing will yield incorrect results
Returns
int
"""
@@ -144,9 +145,8 @@ class Commit(base.Object, Iterable, diff.Diffable):
options = {'pretty': 'raw', 'as_process' : True }
options.update(kwargs)
- # the test system might confront us with string values -
proc = repo.git.rev_list(rev, '--', paths, **options)
- return cls._iter_from_process_or_stream(repo, proc)
+ return cls._iter_from_process_or_stream(repo, proc, True)
def iter_parents(self, paths='', **kwargs):
"""
@@ -191,7 +191,7 @@ class Commit(base.Object, Iterable, diff.Diffable):
return stats.Stats._list_from_string(self.repo, text)
@classmethod
- def _iter_from_process_or_stream(cls, repo, proc_or_stream):
+ def _iter_from_process_or_stream(cls, repo, proc_or_stream, from_rev_list):
"""
Parse out commit information into a list of Commit objects
@@ -201,6 +201,9 @@ class Commit(base.Object, Iterable, diff.Diffable):
``proc``
git-rev-list process instance (raw format)
+ ``from_rev_list``
+ If True, the stream was created by rev-list in which case we parse
+ the message differently
Returns
iterator returning Commit objects
"""
@@ -208,10 +211,10 @@ class Commit(base.Object, Iterable, diff.Diffable):
if not hasattr(stream,'next'):
stream = proc_or_stream.stdout
-
for line in stream:
- id = line.split()[1]
- assert line.split()[0] == "commit"
+ commit_tokens = line.split()
+ id = commit_tokens[1]
+ assert commit_tokens[0] == "commit"
tree = stream.next().split()[1]
parents = []
@@ -231,13 +234,20 @@ class Commit(base.Object, Iterable, diff.Diffable):
stream.next()
message_lines = []
- next_line = None
- for msg_line in stream:
- if not msg_line.startswith(' '):
- break
- # END abort message reading
- message_lines.append(msg_line.strip())
- # END while there are message lines
+ if from_rev_list:
+ for msg_line in stream:
+ if not msg_line.startswith(' '):
+ # and forget about this empty marker
+ break
+ # END abort message reading
+ # strip leading 4 spaces
+ message_lines.append(msg_line[4:])
+ # END while there are message lines
+ else:
+ # a stream from our data simply gives us the plain message
+ for msg_line in stream:
+ message_lines.append(msg_line)
+ # END message parsing
message = '\n'.join(message_lines)
yield Commit(repo, id=id, parents=tuple(parents), tree=tree, author=author, authored_date=authored_date,
diff --git a/test/git/test_actor.py b/test/git/test_actor.py
index b7c2af7c..2941468d 100644
--- a/test/git/test_actor.py
+++ b/test/git/test_actor.py
@@ -13,6 +13,14 @@ class TestActor(object):
a = Actor._from_string("Michael Trier <mtrier@example.com>")
assert_equal("Michael Trier", a.name)
assert_equal("mtrier@example.com", a.email)
+
+ # base type capabilities
+ assert a == a
+ assert not ( a != a )
+ m = set()
+ m.add(a)
+ m.add(a)
+ assert len(m) == 1
def test_from_string_should_handle_just_name(self):
a = Actor._from_string("Michael Trier")
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index c4ed4b72..da636a2b 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -16,6 +16,9 @@ class TestCommit(TestBase):
assert_equal("Sebastian Thiel", commit.author.name)
assert_equal("byronimo@gmail.com", commit.author.email)
+ assert commit.author == commit.committer
+ assert isinstance(commit.authored_date, int) and isinstance(commit.committed_date, int)
+ assert commit.message == "Added missing information to docstrings of commit and stats module"
def test_stats(self):
@@ -37,6 +40,14 @@ class TestCommit(TestBase):
check_entries(d)
# END for each stated file
+ # assure data is parsed properly
+ michael = Actor._from_string("Michael Trier <mtrier@gmail.com>")
+ assert commit.author == michael
+ assert commit.committer == michael
+ assert commit.authored_date == 1210193388
+ assert commit.committed_date == 1210193388
+ assert commit.message == "initial project"
+
@patch_object(Git, '_call_process')
def test_rev_list_bisect_all(self, git):
"""
@@ -52,7 +63,7 @@ class TestCommit(TestBase):
bisect_all=True)
assert_true(git.called)
- commits = Commit._iter_from_process_or_stream(self.rorepo, ListProcessAdapter(revs))
+ commits = Commit._iter_from_process_or_stream(self.rorepo, ListProcessAdapter(revs), True)
expected_ids = (
'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b',
'33ebe7acec14b25c5f84f35a664803fcab2f7781',