Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix blame argument handling #297

Merged
merged 1 commit into from
Dec 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/repository.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern PyTypeObject IndexType;
extern PyTypeObject WalkerType;
extern PyTypeObject SignatureType;
extern PyTypeObject ObjectType;
extern PyTypeObject OidType;
extern PyTypeObject CommitType;
extern PyTypeObject TreeType;
extern PyTypeObject TreeBuilderType;
Expand Down Expand Up @@ -1477,13 +1478,14 @@ Repository_blame(Repository *self, PyObject *args, PyObject *kwds)
PyObject *value1 = NULL;
PyObject *value2 = NULL;
int err;
char *keywords[] = {"flags", "min_match_characters", "newest_commit",
char *keywords[] = {"path", "flags", "min_match_characters", "newest_commit",
"oldest_commit", "min_line", "max_line", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|IHOOII", keywords,
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|IHO!O!II", keywords,
&path, &opts.flags,
&opts.min_match_characters,
&value1, &value2,
&OidType, &value1,
&OidType, &value2,
&opts.min_line, &opts.max_line))
return NULL;

Expand All @@ -1498,7 +1500,7 @@ Repository_blame(Repository *self, PyObject *args, PyObject *kwds)
return NULL;
}

err = git_blame_file(&blame, self->repo, path, NULL);
err = git_blame_file(&blame, self->repo, path, &opts);
if (err < 0)
return Error_set(err);

Expand Down
27 changes: 27 additions & 0 deletions test/test_blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,32 @@ def test():

self.assertRaises(IndexError, test)

def test_blame_newest(self):
repo = self.repo

revs = [
( 'master^2', 3 ),
( 'master^2^', 2 ),
( 'master^2^^', 1 ),
]

for rev, num_commits in revs:
commit = repo.revparse_single(rev)
blame = repo.blame(PATH, newest_commit=commit.oid)

self.assertEqual(len(blame), num_commits)

for i, hunk in enumerate(tuple(blame)[:num_commits]):
self.assertEqual(hunk.lines_in_hunk, 1)
self.assertEqual(HUNKS[i][0], hunk.final_commit_id)
self.assertEqual(HUNKS[i][1], hunk.final_start_line_number)
self.assertEqualSignature(HUNKS[i][2], hunk.final_committer)
self.assertEqual(hunk.orig_commit_id,
'0000000000000000000000000000000000000000')
self.assertEqual(hunk.orig_path, PATH)
self.assertEqual(HUNKS[i][1], hunk.orig_start_line_number)
self.assertTrue(hunk.orig_committer is None)
self.assertEqual(HUNKS[i][3], hunk.boundary)

if __name__ == '__main__':
unittest.main()