11"""This module contains code for git operations"""
22import re
33import subprocess
4- from typing import Dict , List
4+ from typing import Dict , List , Set
55
66from pydriller import GitRepository
77
@@ -23,7 +23,7 @@ def get_file_diff_dict_current(files: List[str]) -> Dict[str, str]:
2323 return {file_path : get_file_diff_data_current (file_path ) for file_path in files }
2424
2525
26- def get_changed_lines (diff : str ) -> List [int ]:
26+ def get_changed_lines (diff : str ) -> Set [int ]:
2727 """Parse changed lines from git diff -U0 output.
2828 - Change data according to git diff output:
2929 - @@ -old0,old1 +new0,new1 @@
@@ -32,7 +32,7 @@ def get_changed_lines(diff: str) -> List[int]:
3232 """
3333 regex = r"[@][@]\s+[-][0-9]+(?:,[0-9]+)?\s+[+][0-9]+(?:,[0-9]+)?\s+[@][@]"
3434 line_changes = re .findall (regex , diff )
35- changed_lines = []
35+ changed_lines : Set [ int ] = set ()
3636 for change in line_changes :
3737 changed_line = change .strip ("@" ).split ()
3838
@@ -45,9 +45,9 @@ def get_changed_lines(diff: str) -> List[int]:
4545 old [0 ] = old [0 ].strip ("-" )
4646
4747 if int (old [1 ]) == 0 :
48- changed_lines .append (int (old [0 ]))
48+ changed_lines .add (int (old [0 ]))
4949 else :
50- changed_lines .extend (range (int (old [0 ]), int (old [0 ]) + int (old [1 ])))
50+ changed_lines .update (range (int (old [0 ]), int (old [0 ]) + int (old [1 ])))
5151
5252 return changed_lines
5353
0 commit comments