##// 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 355 ##split the diff in chunks of separate --git a/file b/file chunks
356 356 for raw_diff in ('\n' + self._diff).split('\ndiff --git')[1:]:
357 binary = False
358 binary_msg = 'unknown binary'
359 357 head, diff = self._get_header(raw_diff)
360 358
359 op = None
360 stats = None
361 msg = None
362
361 363 if not head['a_file'] and head['b_file']:
362 364 op = 'A'
363 365 elif head['a_file'] and head['b_file']:
@@ -365,34 +367,32 b' class DiffProcessor(object):'
365 367 elif head['a_file'] and not head['b_file']:
366 368 op = 'D'
367 369 else:
368 #probably we're dealing with a binary file 1
369 binary = True
370 370 if head['deleted_file_mode']:
371 371 op = 'D'
372 372 stats = ['b', DEL_FILENODE]
373 binary_msg = 'deleted binary file'
373 msg = 'deleted file'
374 374 elif head['new_file_mode']:
375 375 op = 'A'
376 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 378 else:
379 379 if head['new_mode'] and head['old_mode']:
380 380 stats = ['b', CHMOD_FILENODE]
381 381 op = 'M'
382 binary_msg = ('modified binary file chmod %s => %s'
382 msg = ('modified file chmod %s => %s'
383 383 % (head['old_mode'], head['new_mode']))
384 384 elif (head['rename_from'] and head['rename_to']
385 385 and head['rename_from'] != head['rename_to']):
386 386 stats = ['b', RENAMED_FILENODE]
387 387 op = 'M'
388 binary_msg = ('file renamed from %s to %s'
388 msg = ('file renamed from %s to %s'
389 389 % (head['rename_from'], head['rename_to']))
390 390 else:
391 391 stats = ['b', MOD_FILENODE]
392 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 396 try:
397 397 chunks, stats = self._parse_lines(diff)
398 398 except DiffLimitExceeded:
@@ -401,13 +401,17 b' class DiffProcessor(object):'
401 401 self.cur_diff_size,
402 402 _diff)
403 403 break
404 else:
404 else: # GIT binary patch (or empty diff)
405 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 411 'old_lineno': '',
408 412 'new_lineno': '',
409 413 'action': 'binary',
410 'line': binary_msg,
414 'line': msg,
411 415 }])
412 416
413 417 _files.append({
General Comments 0
You need to be logged in to leave comments. Login now