Skip to content

Commit c61acaf

Browse files
committed
New DiffLine.raw_content
Fixes libgit2#610
1 parent bbf4b79 commit c61acaf

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/diff.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,21 @@ DiffLine_content__get__(DiffLine *self)
377377
return to_unicode_n(self->line->content, self->line->content_len, NULL, NULL);
378378
}
379379

380+
PyDoc_STRVAR(DiffLine_raw_content__doc__, "Content of the diff line (byte string)");
381+
PyObject *
382+
DiffLine_raw_content__get__(DiffLine *self)
383+
{
384+
return PyBytes_FromStringAndSize(self->line->content, self->line->content_len);
385+
}
386+
380387
PyGetSetDef DiffLine_getsetters[] = {
381388
GETTER(DiffLine, origin),
382389
GETTER(DiffLine, old_lineno),
383390
GETTER(DiffLine, new_lineno),
384391
GETTER(DiffLine, num_lines),
385392
GETTER(DiffLine, content_offset),
386393
GETTER(DiffLine, content),
394+
GETTER(DiffLine, raw_content),
387395
{NULL}
388396
};
389397

test/test_diff.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ def test_diff_tree(self):
185185
commit_b = self.repo[COMMIT_SHA1_2]
186186

187187
def _test(diff):
188-
# self.assertIsNotNone is 2.7 only
189-
self.assertTrue(diff is not None)
188+
self.assertIsNotNone(diff)
190189
# self.assertIn is 2.7 only
191190
self.assertEqual(2, sum(map(lambda x: len(x.hunks), diff)))
192191

@@ -247,21 +246,15 @@ def test_diff_merge(self):
247246
commit_c = self.repo[COMMIT_SHA1_3]
248247

249248
diff_b = commit_a.tree.diff_to_tree(commit_b.tree)
250-
# self.assertIsNotNone is 2.7 only
251-
self.assertTrue(diff_b is not None)
249+
self.assertIsNotNone(diff_b)
252250

253251
diff_c = commit_b.tree.diff_to_tree(commit_c.tree)
254-
# self.assertIsNotNone is 2.7 only
255-
self.assertTrue(diff_c is not None)
256-
257-
# assertIn / assertNotIn are 2.7 only
258-
self.assertFalse('b' in [patch.delta.new_file.path for patch in diff_b])
259-
self.assertTrue('b' in [patch.delta.new_file.path for patch in diff_c])
252+
self.assertIsNotNone(diff_c)
253+
self.assertNotIn('b', [patch.delta.new_file.path for patch in diff_b])
254+
self.assertIn('b', [patch.delta.new_file.path for patch in diff_c])
260255

261256
diff_b.merge(diff_c)
262-
263-
# assertIn is 2.7 only
264-
self.assertTrue('b' in [patch.delta.new_file.path for patch in diff_b])
257+
self.assertIn('b', [patch.delta.new_file.path for patch in diff_b])
265258

266259
patch = diff_b[0]
267260
hunk = patch.hunks[0]
@@ -297,6 +290,8 @@ def test_hunk_content(self):
297290
hunk = patch.hunks[0]
298291
lines = ('{0} {1}'.format(x.origin, x.content) for x in hunk.lines)
299292
self.assertEqual(HUNK_EXPECTED, ''.join(lines))
293+
for line in hunk.lines:
294+
self.assertEqual(line.content, line.raw_content.decode())
300295

301296
def test_find_similar(self):
302297
commit_a = self.repo[COMMIT_SHA1_6]

0 commit comments

Comments
 (0)