Skip to content

Commit

Permalink
Merge pull request #106 from marxin/binary-patch
Browse files Browse the repository at this point in the history
support binary patch format
  • Loading branch information
matiasb authored Jan 13, 2023
2 parents a840305 + 7eb7da9 commit 6e81b9d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/samples/binary.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From 62ea0eaf7e00170a8fca79f665442f9f44725956 Mon Sep 17 00:00:00 2001
From: Martin Liska <[email protected]>
Date: Fri, 9 Dec 2022 12:05:32 +0100
Subject: [PATCH] add pixel

---
1x1.png | Bin 0 -> 95 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 1x1.png

diff --git a/1x1.png b/1x1.png
new file mode 100644
index 0000000000000000000000000000000000000000..1914264c08781d1f30ee0b8482bccf44586f2dc1
GIT binary patch
literal 95
zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)ga%mF?ju0VQumF+E%TuG2$FoVOh
l8)-lem#2$k2*>s01R$G<f$@>z9%CSj!PC{xWt~$(697H@6ZHT9

literal 0
HcmV?d00001

--
2.38.1
10 changes: 10 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ def do_test_diff_hunk_positions(self, res):

self.assertEqual(hunk_positions, expected_hunk_positions)

def test_binary_patch(self):
utf8_file = os.path.join(self.samples_dir, 'samples/binary.diff')
with open(utf8_file, 'r') as diff_file:
res = PatchSet(diff_file)
self.assertEqual(len(res), 1)
patch = res[0]
self.assertEqual(patch.source_file, '/dev/null')
self.assertEqual(patch.target_file, 'b/1x1.png')
self.assertTrue(patch.is_binary_file)
self.assertTrue(patch.is_added_file)

class TestVCSSamples(unittest.TestCase):
"""Tests for real examples from VCS."""
Expand Down
6 changes: 6 additions & 0 deletions unidiff/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ def _parse(self, diff, encoding, metadata_only):
current_file = None
continue

if line == 'GIT binary patch\n':
current_file.is_binary_file = True
patch_info = None
current_file = None
continue

patch_info.append(line)

@classmethod
Expand Down

0 comments on commit 6e81b9d

Please sign in to comment.