Skip to content

Commit d5e28c0

Browse files
committed
Merge remote-tracking branch 'cholin/features/diff_line_origin'
2 parents c3a5a36 + f572a8f commit d5e28c0

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

src/diff.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ diff_get_patch_byindex(git_diff_list* list, size_t idx)
6262
if (py_patch != NULL) {
6363
py_patch->old_file_path = delta->old_file.path;
6464
py_patch->new_file_path = delta->new_file.path;
65-
py_patch->status = delta->status;
65+
py_patch->status = git_diff_status_char(delta->status);
6666
py_patch->similarity = delta->similarity;
6767
py_patch->old_oid = git_oid_allocfmt(&delta->old_file.oid);
6868
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)
8888
PyList_SetItem(py_hunk->lines, 0,
8989
to_unicode_n(header, header_len, NULL, NULL));
9090
for (j=1; j < lines_in_hunk + 1; ++j) {
91-
err = git_diff_patch_get_line_in_hunk(NULL, &line,
92-
&line_len, NULL, NULL, patch, i, j - 1);
91+
err = git_diff_patch_get_line_in_hunk(&py_hunk->origin,
92+
&line, &line_len, NULL, NULL, patch, i, j - 1);
9393

9494
if (err < 0)
9595
goto cleanup;
@@ -126,7 +126,7 @@ PyMemberDef Patch_members[] = {
126126
MEMBER(Patch, new_file_path, T_STRING, "new file path"),
127127
MEMBER(Patch, old_oid, T_STRING, "old oid"),
128128
MEMBER(Patch, new_oid, T_STRING, "new oid"),
129-
MEMBER(Patch, status, T_INT, "status"),
129+
MEMBER(Patch, status, T_CHAR, "status"),
130130
MEMBER(Patch, similarity, T_INT, "similarity"),
131131
MEMBER(Patch, hunks, T_OBJECT, "hunks"),
132132
{NULL}
@@ -279,6 +279,7 @@ Hunk_dealloc(Hunk *self)
279279
}
280280

281281
PyMemberDef Hunk_members[] = {
282+
MEMBER(Hunk, origin, T_CHAR, "origin."),
282283
MEMBER(Hunk, old_start, T_INT, "Old start."),
283284
MEMBER(Hunk, old_lines, T_INT, "Old lines."),
284285
MEMBER(Hunk, new_start, T_INT, "New start."),

src/pygit2.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -329,24 +329,6 @@ moduleinit(PyObject* m)
329329
ADD_CONSTANT_INT(m, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED)
330330
/* --break-rewrites=/M */
331331
ADD_CONSTANT_INT(m, GIT_DIFF_FIND_AND_BREAK_REWRITES)
332-
/* Flags for diff deltas */
333-
ADD_CONSTANT_INT(m, GIT_DELTA_UNMODIFIED)
334-
ADD_CONSTANT_INT(m, GIT_DELTA_ADDED)
335-
ADD_CONSTANT_INT(m, GIT_DELTA_DELETED)
336-
ADD_CONSTANT_INT(m, GIT_DELTA_MODIFIED)
337-
ADD_CONSTANT_INT(m, GIT_DELTA_RENAMED)
338-
ADD_CONSTANT_INT(m, GIT_DELTA_COPIED)
339-
ADD_CONSTANT_INT(m, GIT_DELTA_IGNORED)
340-
ADD_CONSTANT_INT(m, GIT_DELTA_UNTRACKED)
341-
/* Flags for diffed lines origin */
342-
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_CONTEXT)
343-
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_ADDITION)
344-
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_DELETION)
345-
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_ADD_EOFNL)
346-
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_DEL_EOFNL)
347-
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_FILE_HDR)
348-
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_HUNK_HDR)
349-
ADD_CONSTANT_INT(m, GIT_DIFF_LINE_BINARY)
350332

351333
/* Config */
352334
INIT_TYPE(ConfigType, NULL, PyType_GenericNew)

src/types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,14 @@ typedef struct {
111111
const char * new_file_path;
112112
char* old_oid;
113113
char* new_oid;
114-
unsigned status;
114+
char status;
115115
unsigned similarity;
116116
} Patch;
117117

118118
typedef struct {
119119
PyObject_HEAD
120120
PyObject* lines;
121+
char origin;
121122
int old_start;
122123
int old_lines;
123124
int new_start;

test/test_diff.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def test_diff_tree(self):
134134

135135
patch = diff[0]
136136
hunk = patch.hunks[0]
137+
self.assertEqual(hunk.origin, '+')
137138
self.assertEqual(hunk.old_start, 1)
138139
self.assertEqual(hunk.old_lines, 1)
139140
self.assertEqual(hunk.new_start, 1)
@@ -224,9 +225,9 @@ def test_find_similar(self):
224225
#~ Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate
225226
#~ --find-copies-harder during rename transformion...
226227
diff = commit_a.tree.diff(commit_b.tree, GIT_DIFF_INCLUDE_UNMODIFIED)
227-
self.assertAll(lambda x: x.status is not pygit2.GIT_DELTA_RENAMED, diff)
228+
self.assertAll(lambda x: x.status != 'R', diff)
228229
diff.find_similar()
229-
self.assertAny(lambda x: x.status is pygit2.GIT_DELTA_RENAMED, diff)
230+
self.assertAny(lambda x: x.status == 'R', diff)
230231

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

0 commit comments

Comments
 (0)