45
45
git_header_old_line = re .compile ('^--- (.+)$' )
46
46
git_header_new_line = re .compile ('^\+\+\+ (.+)$' )
47
47
git_header_file_mode = re .compile ('^(new|deleted) file mode \d{6}$' )
48
+ git_header_binary_file = re .compile ('^Binary files (.+) and (.+) differ' )
48
49
49
50
bzr_header_index = re .compile ("=== (.+)" )
50
51
bzr_header_old_line = unified_header_old_line
@@ -89,7 +90,7 @@ def parse_patch(text):
89
90
difftext = '\n ' .join (diff ) + '\n '
90
91
h = parse_header (diff )
91
92
d = parse_diff (diff )
92
- if d :
93
+ if h or d :
93
94
yield diffobj (header = h , changes = d , text = difftext )
94
95
95
96
def parse_header (text ):
@@ -189,12 +190,11 @@ def parse_git_header(text):
189
190
except AttributeError :
190
191
lines = text
191
192
192
- headers = findall_regex (lines , git_header_old_line )
193
- if len (headers ) == 0 :
194
- return None
193
+ # headers = findall_regex(lines, git_header_old_line)
194
+ # if len(headers) == 0:
195
+ # return None
195
196
196
- over = None
197
- nver = None
197
+ over = nver = old_path = new_path = None
198
198
while len (lines ) > 1 :
199
199
g = git_header_index .match (lines [0 ])
200
200
# git always has it's own special headers
@@ -210,18 +210,22 @@ def parse_git_header(text):
210
210
if n :
211
211
old_path = o .group (1 )
212
212
new_path = n .group (1 )
213
- if old_path .startswith ('a/' ):
214
- old_path = old_path [2 :]
215
-
216
- if new_path .startswith ('b/' ):
217
- new_path = new_path [2 :]
218
-
219
- return header (
220
- index_path = None ,
221
- old_path = old_path ,
222
- old_version = over ,
223
- new_path = new_path ,
224
- new_version = nver )
213
+ binary = git_header_binary_file .match (lines [0 ])
214
+ if binary :
215
+ old_path = binary .group (1 )
216
+ new_path = binary .group (2 )
217
+ if old_path and new_path :
218
+ if old_path .startswith ('a/' ):
219
+ old_path = old_path [2 :]
220
+
221
+ if new_path .startswith ('b/' ):
222
+ new_path = new_path [2 :]
223
+ return header (
224
+ index_path = None ,
225
+ old_path = old_path ,
226
+ old_version = over ,
227
+ new_path = new_path ,
228
+ new_version = nver )
225
229
226
230
return None
227
231
0 commit comments