| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0cd09bd commit b999cae
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,15 @@ def __init__(self, name, email): | |||
| 18 | 18 | self.name = name | |
| 19 | 19 | self.email = email | |
| 20 | 20 | ||
| 21 | + def __eq__(self, other): | ||
| 22 | + return self.name == other.name and self.email == other.email | ||
| 23 | + | ||
| 24 | + def __ne__(self, other): | ||
| 25 | + return not (self == other) | ||
| 26 | + | ||
| 27 | + def __hash__(self): | ||
| 28 | + return hash((self.name, self.email)) | ||
| 29 | + | ||
| 21 | 30 | def __str__(self): | |
| 22 | 31 | return self.name | |
| 23 | 32 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,7 +83,7 @@ def _set_cache_(self, attr): | |||
| 83 | 83 | # prepare our data lines to match rev-list | |
| 84 | 84 | data_lines = self.data.splitlines() | |
| 85 | 85 | data_lines.insert(0, "commit %s" % self.id) | |
| 86 | - temp = self._iter_from_process_or_stream(self.repo, iter(data_lines)).next() | ||
| 86 | + temp = self._iter_from_process_or_stream(self.repo, iter(data_lines), False).next() | ||
| 87 | 87 | self.parents = temp.parents | |
| 88 | 88 | self.tree = temp.tree | |
| 89 | 89 | self.author = temp.author | |
@@ -111,7 +111,8 @@ def count(self, paths='', **kwargs): | |||
| 111 | 111 | to commits actually containing the paths | |
| 112 | 112 | ||
| 113 | 113 | ``kwargs`` | |
| 114 | - Additional options to be passed to git-rev-list | ||
| 114 | + Additional options to be passed to git-rev-list. They must not alter | ||
| 115 | + the ouput style of the command, or parsing will yield incorrect results | ||
| 115 | 116 | Returns | |
| 116 | 117 | int | |
| 117 | 118 | """ | |
@@ -144,9 +145,8 @@ def iter_items(cls, repo, rev, paths='', **kwargs): | |||
| 144 | 145 | options = {'pretty': 'raw', 'as_process' : True } | |
| 145 | 146 | options.update(kwargs) | |
| 146 | 147 | ||
| 147 | - # the test system might confront us with string values - | ||
| 148 | 148 | proc = repo.git.rev_list(rev, '--', paths, **options) | |
| 149 | - return cls._iter_from_process_or_stream(repo, proc) | ||
| 149 | + return cls._iter_from_process_or_stream(repo, proc, True) | ||
| 150 | 150 | ||
| 151 | 151 | def iter_parents(self, paths='', **kwargs): | |
| 152 | 152 | """ | |
@@ -191,7 +191,7 @@ def stats(self): | |||
| 191 | 191 | return stats.Stats._list_from_string(self.repo, text) | |
| 192 | 192 | ||
| 193 | 193 | @classmethod | |
| 194 | - def _iter_from_process_or_stream(cls, repo, proc_or_stream): | ||
| 194 | + def _iter_from_process_or_stream(cls, repo, proc_or_stream, from_rev_list): | ||
| 195 | 195 | """ | |
| 196 | 196 | Parse out commit information into a list of Commit objects | |
| 197 | 197 | ||
@@ -201,17 +201,20 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream): | |||
| 201 | 201 | ``proc`` | |
| 202 | 202 | git-rev-list process instance (raw format) | |
| 203 | 203 | ||
| 204 | + ``from_rev_list`` | ||
| 205 | + If True, the stream was created by rev-list in which case we parse | ||
| 206 | + the message differently | ||
| 204 | 207 | Returns | |
| 205 | 208 | iterator returning Commit objects | |
| 206 | 209 | """ | |
| 207 | 210 | stream = proc_or_stream | |
| 208 | 211 | if not hasattr(stream,'next'): | |
| 209 | 212 | stream = proc_or_stream.stdout | |
| 210 | 213 | ||
| 211 | - | ||
| 212 | 214 | for line in stream: | |
| 213 | - id = line.split()[1] | ||
| 214 | - assert line.split()[0] == "commit" | ||
| 215 | + commit_tokens = line.split() | ||
| 216 | + id = commit_tokens[1] | ||
| 217 | + assert commit_tokens[0] == "commit" | ||
| 215 | 218 | tree = stream.next().split()[1] | |
| 216 | 219 | ||
| 217 | 220 | parents = [] | |
@@ -231,13 +234,20 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream): | |||
| 231 | 234 | stream.next() | |
| 232 | 235 | ||
| 233 | 236 | message_lines = [] | |
| 234 | - next_line = None | ||
| 235 | - for msg_line in stream: | ||
| 236 | - if not msg_line.startswith(' '): | ||
| 237 | - break | ||
| 238 | - # END abort message reading | ||
| 239 | - message_lines.append(msg_line.strip()) | ||
| 240 | - # END while there are message lines | ||
| 237 | + if from_rev_list: | ||
| 238 | + for msg_line in stream: | ||
| 239 | + if not msg_line.startswith(' '): | ||
| 240 | + # and forget about this empty marker | ||
| 241 | + break | ||
| 242 | + # END abort message reading | ||
| 243 | + # strip leading 4 spaces | ||
| 244 | + message_lines.append(msg_line[4:]) | ||
| 245 | + # END while there are message lines | ||
| 246 | + else: | ||
| 247 | + # a stream from our data simply gives us the plain message | ||
| 248 | + for msg_line in stream: | ||
| 249 | + message_lines.append(msg_line) | ||
| 250 | + # END message parsing | ||
| 241 | 251 | message = '\n'.join(message_lines) | |
| 242 | 252 | ||
| 243 | 253 | yield Commit(repo, id=id, parents=tuple(parents), tree=tree, author=author, authored_date=authored_date, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,14 @@ def test_from_string_should_separate_name_and_email(self): | |||
| 13 | 13 | a = Actor._from_string("Michael Trier <mtrier@example.com>") | |
| 14 | 14 | assert_equal("Michael Trier", a.name) | |
| 15 | 15 | assert_equal("mtrier@example.com", a.email) | |
| 16 | + | ||
| 17 | + # base type capabilities | ||
| 18 | + assert a == a | ||
| 19 | + assert not ( a != a ) | ||
| 20 | + m = set() | ||
| 21 | + m.add(a) | ||
| 22 | + m.add(a) | ||
| 23 | + assert len(m) == 1 | ||
| 16 | 24 | ||
| 17 | 25 | def test_from_string_should_handle_just_name(self): | |
| 18 | 26 | a = Actor._from_string("Michael Trier") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,9 @@ def test_bake(self): | |||
| 16 | 16 | ||
| 17 | 17 | assert_equal("Sebastian Thiel", commit.author.name) | |
| 18 | 18 | assert_equal("byronimo@gmail.com", commit.author.email) | |
| 19 | + assert commit.author == commit.committer | ||
| 20 | + assert isinstance(commit.authored_date, int) and isinstance(commit.committed_date, int) | ||
| 21 | + assert commit.message == "Added missing information to docstrings of commit and stats module" | ||
| 19 | 22 | ||
| 20 | 23 | ||
| 21 | 24 | def test_stats(self): | |
@@ -37,6 +40,14 @@ def check_entries(d): | |||
| 37 | 40 | check_entries(d) | |
| 38 | 41 | # END for each stated file | |
| 39 | 42 | ||
| 43 | + # assure data is parsed properly | ||
| 44 | + michael = Actor._from_string("Michael Trier <mtrier@gmail.com>") | ||
| 45 | + assert commit.author == michael | ||
| 46 | + assert commit.committer == michael | ||
| 47 | + assert commit.authored_date == 1210193388 | ||
| 48 | + assert commit.committed_date == 1210193388 | ||
| 49 | + assert commit.message == "initial project" | ||
| 50 | + | ||
| 40 | 51 | @patch_object(Git, '_call_process') | |
| 41 | 52 | def test_rev_list_bisect_all(self, git): | |
| 42 | 53 | """ | |
@@ -52,7 +63,7 @@ def test_rev_list_bisect_all(self, git): | |||
| 52 | 63 | bisect_all=True) | |
| 53 | 64 | assert_true(git.called) | |
| 54 | 65 | ||
| 55 | - commits = Commit._iter_from_process_or_stream(self.rorepo, ListProcessAdapter(revs)) | ||
| 66 | + commits = Commit._iter_from_process_or_stream(self.rorepo, ListProcessAdapter(revs), True) | ||
| 56 | 67 | expected_ids = ( | |
| 57 | 68 | 'cf37099ea8d1d8c7fbf9b6d12d7ec0249d3acb8b', | |
| 58 | 69 | '33ebe7acec14b25c5f84f35a664803fcab2f7781', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments