Merge remote-tracking branch 'cholin/features/diff_line_origin'
This commit is contained in:
commit
d5e28c0f96
@ -62,7 +62,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
|
||||
if (py_patch != NULL) {
|
||||
py_patch->old_file_path = delta->old_file.path;
|
||||
py_patch->new_file_path = delta->new_file.path;
|
||||
py_patch->status = delta->status;
|
||||
py_patch->status = git_diff_status_char(delta->status);
|
||||
py_patch->similarity = delta->similarity;
|
||||
py_patch->old_oid = git_oid_allocfmt(&delta->old_file.oid);
|
||||
py_patch->new_oid = git_oid_allocfmt(&delta->new_file.oid);
|
||||
@ -88,8 +88,8 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
|
||||
PyList_SetItem(py_hunk->lines, 0,
|
||||
to_unicode_n(header, header_len, NULL, NULL));
|
||||
for (j=1; j < lines_in_hunk + 1; ++j) {
|
||||
err = git_diff_patch_get_line_in_hunk(NULL, &line,
|
||||
&line_len, NULL, NULL, patch, i, j - 1);
|
||||
err = git_diff_patch_get_line_in_hunk(&py_hunk->origin,
|
||||
&line, &line_len, NULL, NULL, patch, i, j - 1);
|
||||
|
||||
if (err < 0)
|
||||
goto cleanup;
|
||||
@ -126,7 +126,7 @@ PyMemberDef Patch_members[] = {
|
||||
MEMBER(Patch, new_file_path, T_STRING, "new file path"),
|
||||
MEMBER(Patch, old_oid, T_STRING, "old oid"),
|
||||
MEMBER(Patch, new_oid, T_STRING, "new oid"),
|
||||
MEMBER(Patch, status, T_INT, "status"),
|
||||
MEMBER(Patch, status, T_CHAR, "status"),
|
||||
MEMBER(Patch, similarity, T_INT, "similarity"),
|
||||
MEMBER(Patch, hunks, T_OBJECT, "hunks"),
|
||||
{NULL}
|
||||
@ -279,6 +279,7 @@ Hunk_dealloc(Hunk *self)
|
||||
}
|
||||
|
||||
PyMemberDef Hunk_members[] = {
|
||||
MEMBER(Hunk, origin, T_CHAR, "origin."),
|
||||
MEMBER(Hunk, old_start, T_INT, "Old start."),
|
||||
MEMBER(Hunk, old_lines, T_INT, "Old lines."),
|
||||
MEMBER(Hunk, new_start, T_INT, "New start."),
|
||||
|
18
src/pygit2.c
18
src/pygit2.c
@ -329,24 +329,6 @@ moduleinit(PyObject* m)
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED)
|
||||
/* --break-rewrites=/M */
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_FIND_AND_BREAK_REWRITES)
|
||||
/* Flags for diff deltas */
|
||||
ADD_CONSTANT_INT(m, GIT_DELTA_UNMODIFIED)
|
||||
ADD_CONSTANT_INT(m, GIT_DELTA_ADDED)
|
||||
ADD_CONSTANT_INT(m, GIT_DELTA_DELETED)
|
||||
ADD_CONSTANT_INT(m, GIT_DELTA_MODIFIED)
|
||||
ADD_CONSTANT_INT(m, GIT_DELTA_RENAMED)
|
||||
ADD_CONSTANT_INT(m, GIT_DELTA_COPIED)
|
||||
ADD_CONSTANT_INT(m, GIT_DELTA_IGNORED)
|
||||
ADD_CONSTANT_INT(m, GIT_DELTA_UNTRACKED)
|
||||
/* Flags for diffed lines origin */
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_CONTEXT)
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_ADDITION)
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_DELETION)
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_ADD_EOFNL)
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_DEL_EOFNL)
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_FILE_HDR)
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_HUNK_HDR)
|
||||
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_BINARY)
|
||||
|
||||
/* Config */
|
||||
INIT_TYPE(ConfigType, NULL, PyType_GenericNew)
|
||||
|
@ -111,13 +111,14 @@ typedef struct {
|
||||
const char * new_file_path;
|
||||
char* old_oid;
|
||||
char* new_oid;
|
||||
unsigned status;
|
||||
char status;
|
||||
unsigned similarity;
|
||||
} Patch;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject* lines;
|
||||
char origin;
|
||||
int old_start;
|
||||
int old_lines;
|
||||
int new_start;
|
||||
|
@ -134,6 +134,7 @@ class DiffTest(utils.BareRepoTestCase):
|
||||
|
||||
patch = diff[0]
|
||||
hunk = patch.hunks[0]
|
||||
self.assertEqual(hunk.origin, '+')
|
||||
self.assertEqual(hunk.old_start, 1)
|
||||
self.assertEqual(hunk.old_lines, 1)
|
||||
self.assertEqual(hunk.new_start, 1)
|
||||
@ -224,9 +225,9 @@ class DiffTest(utils.BareRepoTestCase):
|
||||
#~ Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate
|
||||
#~ --find-copies-harder during rename transformion...
|
||||
diff = commit_a.tree.diff(commit_b.tree, GIT_DIFF_INCLUDE_UNMODIFIED)
|
||||
self.assertAll(lambda x: x.status is not pygit2.GIT_DELTA_RENAMED, diff)
|
||||
self.assertAll(lambda x: x.status != 'R', diff)
|
||||
diff.find_similar()
|
||||
self.assertAny(lambda x: x.status is pygit2.GIT_DELTA_RENAMED, diff)
|
||||
self.assertAny(lambda x: x.status == 'R', diff)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user