##// END OF EJS Templates
diff parser: more correct detection and reporting of binary git diffs...
Mads Kiilerich -
r3818:0d22458b beta
parent child Browse files
Show More
@@ -354,10 +354,12 b' class DiffProcessor(object):'
354
354
355 ##split the diff in chunks of separate --git a/file b/file chunks
355 ##split the diff in chunks of separate --git a/file b/file chunks
356 for raw_diff in ('\n' + self._diff).split('\ndiff --git')[1:]:
356 for raw_diff in ('\n' + self._diff).split('\ndiff --git')[1:]:
357 binary = False
358 binary_msg = 'unknown binary'
359 head, diff = self._get_header(raw_diff)
357 head, diff = self._get_header(raw_diff)
360
358
359 op = None
360 stats = None
361 msg = None
362
361 if not head['a_file'] and head['b_file']:
363 if not head['a_file'] and head['b_file']:
362 op = 'A'
364 op = 'A'
363 elif head['a_file'] and head['b_file']:
365 elif head['a_file'] and head['b_file']:
@@ -365,34 +367,32 b' class DiffProcessor(object):'
365 elif head['a_file'] and not head['b_file']:
367 elif head['a_file'] and not head['b_file']:
366 op = 'D'
368 op = 'D'
367 else:
369 else:
368 #probably we're dealing with a binary file 1
369 binary = True
370 if head['deleted_file_mode']:
370 if head['deleted_file_mode']:
371 op = 'D'
371 op = 'D'
372 stats = ['b', DEL_FILENODE]
372 stats = ['b', DEL_FILENODE]
373 binary_msg = 'deleted binary file'
373 msg = 'deleted file'
374 elif head['new_file_mode']:
374 elif head['new_file_mode']:
375 op = 'A'
375 op = 'A'
376 stats = ['b', NEW_FILENODE]
376 stats = ['b', NEW_FILENODE]
377 binary_msg = 'new binary file %s' % head['new_file_mode']
377 msg = 'new file %s' % head['new_file_mode']
378 else:
378 else:
379 if head['new_mode'] and head['old_mode']:
379 if head['new_mode'] and head['old_mode']:
380 stats = ['b', CHMOD_FILENODE]
380 stats = ['b', CHMOD_FILENODE]
381 op = 'M'
381 op = 'M'
382 binary_msg = ('modified binary file chmod %s => %s'
382 msg = ('modified file chmod %s => %s'
383 % (head['old_mode'], head['new_mode']))
383 % (head['old_mode'], head['new_mode']))
384 elif (head['rename_from'] and head['rename_to']
384 elif (head['rename_from'] and head['rename_to']
385 and head['rename_from'] != head['rename_to']):
385 and head['rename_from'] != head['rename_to']):
386 stats = ['b', RENAMED_FILENODE]
386 stats = ['b', RENAMED_FILENODE]
387 op = 'M'
387 op = 'M'
388 binary_msg = ('file renamed from %s to %s'
388 msg = ('file renamed from %s to %s'
389 % (head['rename_from'], head['rename_to']))
389 % (head['rename_from'], head['rename_to']))
390 else:
390 else:
391 stats = ['b', MOD_FILENODE]
391 stats = ['b', MOD_FILENODE]
392 op = 'M'
392 op = 'M'
393 binary_msg = 'modified binary file'
393 msg = 'modified file'
394
394
395 if not binary:
395 if head['a_file'] or head['b_file']: # a real diff
396 try:
396 try:
397 chunks, stats = self._parse_lines(diff)
397 chunks, stats = self._parse_lines(diff)
398 except DiffLimitExceeded:
398 except DiffLimitExceeded:
@@ -401,13 +401,17 b' class DiffProcessor(object):'
401 self.cur_diff_size,
401 self.cur_diff_size,
402 _diff)
402 _diff)
403 break
403 break
404 else:
404 else: # GIT binary patch (or empty diff)
405 chunks = []
405 chunks = []
406 chunks.append([{
406 if not msg: # don't overwrite more important message
407 msg = 'binary diff not shown'
408
409 if msg:
410 chunks.insert(0, [{
407 'old_lineno': '',
411 'old_lineno': '',
408 'new_lineno': '',
412 'new_lineno': '',
409 'action': 'binary',
413 'action': 'binary',
410 'line': binary_msg,
414 'line': msg,
411 }])
415 }])
412
416
413 _files.append({
417 _files.append({
General Comments 0
You need to be logged in to leave comments. Login now