2652 |
2652 |
2653 def addresult(): |
2653 def addresult(): |
2654 if filename: |
2654 if filename: |
2655 results.append((filename, adds, removes, isbinary)) |
2655 results.append((filename, adds, removes, isbinary)) |
2656 |
2656 |
|
2657 # inheader is used to track if a line is in the |
|
2658 # header portion of the diff. This helps properly account |
|
2659 # for lines that start with '--' or '++' |
|
2660 inheader = False |
|
2661 |
2657 for line in lines: |
2662 for line in lines: |
2658 if line.startswith('diff'): |
2663 if line.startswith('diff'): |
2659 addresult() |
2664 addresult() |
2660 # set numbers to 0 anyway when starting new file |
2665 # starting a new file diff |
|
2666 # set numbers to 0 and reset inheader |
|
2667 inheader = True |
2661 adds, removes, isbinary = 0, 0, False |
2668 adds, removes, isbinary = 0, 0, False |
2662 if line.startswith('diff --git a/'): |
2669 if line.startswith('diff --git a/'): |
2663 filename = gitre.search(line).group(2) |
2670 filename = gitre.search(line).group(2) |
2664 elif line.startswith('diff -r'): |
2671 elif line.startswith('diff -r'): |
2665 # format: "diff -r ... -r ... filename" |
2672 # format: "diff -r ... -r ... filename" |
2666 filename = diffre.search(line).group(1) |
2673 filename = diffre.search(line).group(1) |
2667 elif line.startswith('+') and not line.startswith('+++ '): |
2674 elif line.startswith('@@'): |
|
2675 inheader = False |
|
2676 elif line.startswith('+') and not inheader: |
2668 adds += 1 |
2677 adds += 1 |
2669 elif line.startswith('-') and not line.startswith('--- '): |
2678 elif line.startswith('-') and not inheader: |
2670 removes += 1 |
2679 removes += 1 |
2671 elif (line.startswith('GIT binary patch') or |
2680 elif (line.startswith('GIT binary patch') or |
2672 line.startswith('Binary file')): |
2681 line.startswith('Binary file')): |
2673 isbinary = True |
2682 isbinary = True |
2674 addresult() |
2683 addresult() |