ishepard / pydriller

Python Framework to analyse Git repositories
http://pydriller.readthedocs.io/en/latest/
Apache License 2.0
810 stars 138 forks source link

Saving commits in a list for later access won't give access to stats #283

Open hcwang opened 9 months ago

hcwang commented 9 months ago

Describe the bug

After upgrade from 2.5 to 2.5.1, the below code will raise exception.

To Reproduce

The below code:

commits = list(Repository(".",only_no_merge=True).traverse_commits())
commits[0].files
commits[0].lines

will raise:

AttributeError: 'NoneType' object has no attribute 'repo'

OS Version:

no-arch

ishepard commented 9 months ago

Thanks for raising the issue! I just checked and this code works:

from pydriller import Repository

for commit in Repository("test-repos/small_repo", only_no_merge=True).traverse_commits():
    print(commit.lines)
    print(commit.files)

but this code doesn't work:

commits = list(Repository("test-repos/small_repo",only_no_merge=True).traverse_commits())
commits[0].files
commits[0].lines

Not sure why, we'll have to check. I will put this issue as a bug and PR are welcome

ishepard commented 9 months ago

The reason is that the object is inside a context manager, so it will get destroyed after the loop.

I don't see a good solution to this, other than just iterating over the commits rather than putting them in a list.