Home > front end >  How to get last touched lines in a file of a commit: PyDriller?
How to get last touched lines in a file of a commit: PyDriller?

Time:12-09

I am new to git, API and python. Currently I am using PyDriller and trying to extract the last touched lines of a modified files of a commit. [My main purpose is that I want to find out which class of the file owns these last touched lines. ]

for commit in Repository('testing').traverse_commits():
   for modified_file in commit.modified_files:
       print(modified_file.get_commits_last_modified_lines)

but it shows me an error like:

AttributeError: 'ModifiedFile' object has no attribute 'get_commits_last_modified_lines'

That "get_commits_last_modified_lines" is written in API PyDriller Reference. But I cannot use it. What should I do?

CodePudding user response:

The chapter in Git shows that Git.get_commits_last_modified_lines method being applied on the repository, and taking a commit as parameter.

# commit abc modified line 1 of file A
# commit def modified line 2 of file A
# commit ghi modified line 3 of file A
# commit lmn deleted lines 1 and 2 of file A

gr = Git('test-repos/test5')

commit = gr.get_commit('lmn')
buggy_commits = gr.get_commits_last_modified_lines(commit)
print(buggy_commits)      # result: (abc, def)

In your case:

print(gr.get_commits_last_modified_lines(commit, modified_file)

(with gr being defined as Repository('testing'))

  • Related