def patch_analysis(self, patch): info = {'size': 0, 'test_size': 0, 'addlines': 0, 'rmlines': 0} for diff in whatthepatch.parse_patch(patch): if diff.header and diff.changes: h = diff.header new_path = h.new_path[2:] if h.new_path.startswith( 'b/') else h.new_path # Calc changes additions & deletions counts = [(old is None and new is not None, new is None and old is not None) for old, new, _ in diff.changes] counts = list(zip(*counts)) # inverse zip info['addlines'] += sum(counts[0]) info['rmlines'] += sum(counts[1]) if utils.is_test_file(new_path): info['test_size'] += len(diff.changes) else: info['size'] += len(diff.changes) return info
def patch_analysis(self, patch): info = {'size': 0, 'test_size': 0, 'addlines': 0, 'rmlines': 0} for diff in whatthepatch.parse_patch(patch): if diff.header and diff.changes: h = diff.header new_path = h.new_path[2:] if h.new_path.startswith('b/') else h.new_path # Calc changes additions & deletions counts = [ (old is None and new is not None, new is None and old is not None) for old, new, _ in diff.changes ] counts = list(zip(*counts)) # inverse zip info['addlines'] += sum(counts[0]) info['rmlines'] += sum(counts[1]) if utils.is_test_file(new_path): info['test_size'] += len(diff.changes) else: info['size'] += len(diff.changes) return info