Args: func_names: A list of function names, usually extracted from old src file, so new functions aren't included. func_ranges: A sorted list of function ranges in the same order of func_names. additions: A list of pair of integers,
(func_names, func_ranges, additions, deletions,
separate=False)
| 18 | |
| 19 | |
| 20 | def get_changed_functions(func_names, func_ranges, additions, deletions, |
| 21 | separate=False): |
| 22 | """ |
| 23 | Args: |
| 24 | func_names: A list of function names, |
| 25 | usually extracted from old src file, |
| 26 | so new functions aren't included. |
| 27 | func_ranges: A sorted list of function ranges |
| 28 | in the same order of func_names. |
| 29 | additions: A list of pair of integers, |
| 30 | deletions: A list of pair of integers, |
| 31 | separate: A boolean flag, if set to True, additions and deletions are |
| 32 | reported separately. |
| 33 | |
| 34 | Returns: |
| 35 | A dictionary where keys are function names and values are |
| 36 | number of lines edited. |
| 37 | """ |
| 38 | info = {} |
| 39 | |
| 40 | if (func_names is None or func_ranges is None or |
| 41 | additions is None or deletions is None): |
| 42 | return info |
| 43 | |
| 44 | def update_info(fn, num_lines, key): |
| 45 | """key should be one of 'adds' or 'dels'.""" |
| 46 | if fn in info: |
| 47 | info[fn][key] += num_lines |
| 48 | else: |
| 49 | info[fn] = {'adds': 0, 'dels': 0} |
| 50 | info[fn][key] = num_lines |
| 51 | |
| 52 | add_ptr, del_ptr = 0, 0 |
| 53 | num_adds, num_dels = len(additions), len(deletions) |
| 54 | for fn, fr in zip(func_names, func_ranges): |
| 55 | for i in range(add_ptr, num_adds): |
| 56 | if fr[0] <= additions[i][0] <= fr[1]: |
| 57 | update_info(fn, additions[i][1], 'adds') |
| 58 | add_ptr = i + 1 |
| 59 | |
| 60 | for j in range(del_ptr, num_dels): |
| 61 | inter_length = get_intersected_length(fr, deletions[j]) |
| 62 | if inter_length > 0: |
| 63 | update_info(fn, inter_length, 'dels') |
| 64 | del_ptr = j |
| 65 | |
| 66 | if not separate: |
| 67 | for fn in info: |
| 68 | info[fn] = info[fn]['adds'] + info[fn]['dels'] |
| 69 | |
| 70 | return info |