fixed line_origin in Hunks
every line in a hunk has a origin like '+','-' or ' '.
This commit is contained in:
17
src/diff.c
17
src/diff.c
@@ -50,6 +50,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
|
|||||||
git_diff_patch* patch = NULL;
|
git_diff_patch* patch = NULL;
|
||||||
size_t i, j, hunk_amounts, lines_in_hunk, line_len, header_len;
|
size_t i, j, hunk_amounts, lines_in_hunk, line_len, header_len;
|
||||||
const char* line, *header;
|
const char* line, *header;
|
||||||
|
char line_origin;
|
||||||
int err;
|
int err;
|
||||||
Hunk *py_hunk = NULL;
|
Hunk *py_hunk = NULL;
|
||||||
Patch *py_patch = NULL;
|
Patch *py_patch = NULL;
|
||||||
@@ -84,18 +85,19 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
|
|||||||
py_hunk->new_start = range->new_start;
|
py_hunk->new_start = range->new_start;
|
||||||
py_hunk->new_lines = range->new_lines;
|
py_hunk->new_lines = range->new_lines;
|
||||||
|
|
||||||
py_hunk->lines = PyList_New(lines_in_hunk + 1);
|
py_hunk->lines = PyList_New(lines_in_hunk);
|
||||||
PyList_SetItem(py_hunk->lines, 0,
|
for (j=0; j < lines_in_hunk; ++j) {
|
||||||
to_unicode_n(header, header_len, NULL, NULL));
|
err = git_diff_patch_get_line_in_hunk(&line_origin,
|
||||||
for (j=1; j < lines_in_hunk + 1; ++j) {
|
&line, &line_len, NULL, NULL, patch, i, j);
|
||||||
err = git_diff_patch_get_line_in_hunk(&py_hunk->origin,
|
|
||||||
&line, &line_len, NULL, NULL, patch, i, j - 1);
|
|
||||||
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
PyList_SetItem(py_hunk->lines, j,
|
PyList_SetItem(py_hunk->lines, j,
|
||||||
to_unicode_n(line, line_len, NULL, NULL));
|
Py_BuildValue("cO", line_origin,
|
||||||
|
to_unicode_n(line, line_len, NULL, NULL)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyList_SetItem((PyObject*) py_patch->hunks, i,
|
PyList_SetItem((PyObject*) py_patch->hunks, i,
|
||||||
@@ -279,7 +281,6 @@ Hunk_dealloc(Hunk *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyMemberDef Hunk_members[] = {
|
PyMemberDef Hunk_members[] = {
|
||||||
MEMBER(Hunk, origin, T_CHAR, "origin."),
|
|
||||||
MEMBER(Hunk, old_start, T_INT, "Old start."),
|
MEMBER(Hunk, old_start, T_INT, "Old start."),
|
||||||
MEMBER(Hunk, old_lines, T_INT, "Old lines."),
|
MEMBER(Hunk, old_lines, T_INT, "Old lines."),
|
||||||
MEMBER(Hunk, new_start, T_INT, "New start."),
|
MEMBER(Hunk, new_start, T_INT, "New start."),
|
||||||
|
@@ -118,7 +118,6 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
PyObject* lines;
|
PyObject* lines;
|
||||||
char origin;
|
|
||||||
int old_start;
|
int old_start;
|
||||||
int old_lines;
|
int old_lines;
|
||||||
int new_start;
|
int new_start;
|
||||||
|
@@ -83,9 +83,8 @@ DIFF_WORKDIR_EXPECTED = [
|
|||||||
'subdir/modified_file'
|
'subdir/modified_file'
|
||||||
]
|
]
|
||||||
|
|
||||||
HUNK_EXPECTED = """@@ -1 +1 @@
|
HUNK_EXPECTED = """- a contents 2
|
||||||
a contents 2
|
+ a contents
|
||||||
a contents
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class DiffDirtyTest(utils.DirtyRepoTestCase):
|
class DiffDirtyTest(utils.DirtyRepoTestCase):
|
||||||
@@ -134,7 +133,6 @@ class DiffTest(utils.BareRepoTestCase):
|
|||||||
|
|
||||||
patch = diff[0]
|
patch = diff[0]
|
||||||
hunk = patch.hunks[0]
|
hunk = patch.hunks[0]
|
||||||
self.assertEqual(hunk.origin, '+')
|
|
||||||
self.assertEqual(hunk.old_start, 1)
|
self.assertEqual(hunk.old_start, 1)
|
||||||
self.assertEqual(hunk.old_lines, 1)
|
self.assertEqual(hunk.old_lines, 1)
|
||||||
self.assertEqual(hunk.new_start, 1)
|
self.assertEqual(hunk.new_start, 1)
|
||||||
@@ -216,7 +214,8 @@ class DiffTest(utils.BareRepoTestCase):
|
|||||||
commit_b = self.repo[COMMIT_SHA1_2]
|
commit_b = self.repo[COMMIT_SHA1_2]
|
||||||
patch = commit_a.tree.diff(commit_b.tree)[0]
|
patch = commit_a.tree.diff(commit_b.tree)[0]
|
||||||
hunk = patch.hunks[0]
|
hunk = patch.hunks[0]
|
||||||
self.assertEqual(HUNK_EXPECTED, ''.join(hunk.lines))
|
lines = ('{0} {1}'.format(*x) for x in hunk.lines)
|
||||||
|
self.assertEqual(HUNK_EXPECTED, ''.join(lines))
|
||||||
|
|
||||||
def test_find_similar(self):
|
def test_find_similar(self):
|
||||||
commit_a = self.repo[COMMIT_SHA1_6]
|
commit_a = self.repo[COMMIT_SHA1_6]
|
||||||
|
Reference in New Issue
Block a user