diff: expose the hunk header
We can rebuild it from the data we already have, but this will allow us to get the function headers in it once the library supports it.
This commit is contained in:
@@ -68,6 +68,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
char *header;
|
||||||
int old_start;
|
int old_start;
|
||||||
int old_lines;
|
int old_lines;
|
||||||
char* old_file;
|
char* old_file;
|
||||||
|
@@ -101,6 +101,16 @@ static int diff_hunk_cb(
|
|||||||
hunk->new_start = range->new_start;
|
hunk->new_start = range->new_start;
|
||||||
hunk->new_lines = range->new_lines;
|
hunk->new_lines = range->new_lines;
|
||||||
|
|
||||||
|
if (header) {
|
||||||
|
hunk->header = malloc(header_len+1);
|
||||||
|
|
||||||
|
if (hunk->header == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memcpy(hunk->header, header, header_len);
|
||||||
|
hunk->header[header_len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
if (delta->old_file.path != NULL) {
|
if (delta->old_file.path != NULL) {
|
||||||
len = strlen(delta->old_file.path) + 1;
|
len = strlen(delta->old_file.path) + 1;
|
||||||
old_path = malloc(sizeof(char) * len);
|
old_path = malloc(sizeof(char) * len);
|
||||||
@@ -219,6 +229,7 @@ Hunk_dealloc(Hunk *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyMemberDef Hunk_members[] = {
|
PyMemberDef Hunk_members[] = {
|
||||||
|
{"header", T_STRING, offsetof(Hunk, header), 0, "header"},
|
||||||
{"old_start", T_INT, offsetof(Hunk, old_start), 0, "old start"},
|
{"old_start", T_INT, offsetof(Hunk, old_start), 0, "old start"},
|
||||||
{"old_lines", T_INT, offsetof(Hunk, old_lines), 0, "old lines"},
|
{"old_lines", T_INT, offsetof(Hunk, old_lines), 0, "old lines"},
|
||||||
{"old_file", T_STRING, offsetof(Hunk, old_file), 0, "old file"},
|
{"old_file", T_STRING, offsetof(Hunk, old_file), 0, "old file"},
|
||||||
|
@@ -174,6 +174,12 @@ class DiffTest(utils.BareRepoTestCase):
|
|||||||
diff = commit_a.tree.diff(commit_b.tree)
|
diff = commit_a.tree.diff(commit_b.tree)
|
||||||
self.assertEqual(diff.patch, PATCH)
|
self.assertEqual(diff.patch, PATCH)
|
||||||
|
|
||||||
|
def test_diff_header(self):
|
||||||
|
commit_a = self.repo[COMMIT_SHA1_1]
|
||||||
|
commit_b = self.repo[COMMIT_SHA1_2]
|
||||||
|
diff = commit_a.tree.diff(commit_b.tree)
|
||||||
|
|
||||||
|
self.assertEqual(diff.changes['hunks'][0].header, "@@ -1 +1 @@\n")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user