ishepard / pydriller

Python Framework to analyse Git repositories

Home Page:http://pydriller.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

want to get source_code of modified_files

320010ly opened this issue · comments

Describe the bug
For a commit which modified single file,I want to get the source_code and source_code_before from the modified_files[0],but I meet with a RecursionError:maximum recursion depth exceeded while calling a Python object

To Reproduce

for commit in Repository('https://github.com/AUTOMATIC1111/stable-diffusion-webui').traverse_commits():
    #print('Hash {}, message {}'.format(commit.hash, commit.msg))
    if not commit_filter(commit):
        continue
    num += 1
    print('Hash {} Code {}'.format(commit.hash, commit.modified_files[0].source_code))
    #print('Hash {}'.format(commit.hash))
    source = ""
    if commit.modified_files[0].source_code is not None:
        source = commit.modified_files[0].source_code
    else:
        source = "None"
    # for mod in commit.modified_files:
    #     print('File {} has been {}ed'.format(mod.filename, mod.change_type))
    chosen_commit.append({
            'hash': commit.hash,
            'msg': commit.msg,
            'source_code': source
            #'source_code_before': source_code_before,
            #'changed_methods': changed_methods
        })

running above code,I can see hash and code printed in the console.But after some time,it give RecursionError.I am confused that if I doesn't mention modified_files[0].source_code,for example,only record hash and msg into chosen_commit,it can finished successfully.I am appreciated if anyone can give me some advice,Thanks
OS Version:
Windows

Hi! I tried it on my laptop but couldn't repro:

from pydriller import Repository

chosen_commit = []
num_commits = 0
for commit in Repository('https://github.com/AUTOMATIC1111/stable-diffusion-webui').traverse_commits():
    try:
        num_commits += 1
        print('{} Hash {}'.format(num_commits, commit.hash))
        source = ""
        if len(commit.modified_files) == 0:
            continue

        if commit.modified_files[0].source_code is not None:
            source = commit.modified_files[0].source_code
        else:
            source = "None"
        chosen_commit.append({
                'hash': commit.hash,
                'msg': commit.msg,
                'source_code': source
            })
    except ValueError as e:
        print(e)

This will run until the end:

...
7367 Hash 6c7c176dc9b2808fa897a8f52f445b48312b61bd
7368 Hash a183ea4ba773da5144e9f6b99fa48bff13078d2a
7369 Hash e4aa0c362e440cef6a6f728b2d4d695086f8cd3a
7370 Hash e84703b2539c21d68881852f7e9738d76e7de26f
7371 Hash 61f6479ea9a85fd12b830be2dfe71a51db34b121
7372 Hash e9809de6512160501e34c54e9c8c5e5e493e306f
7373 Hash 3fdc3cfbbf50814d9609fb03e9730d16d6d20bb6
7374 Hash e837124f4b1b9dcf3caccd8d2fa5730cf3df099a
7375 Hash e2b177c508447cd3068993c67e165880348ff0d8

Also, in your code there are some issues (for example, you always analize only 1 file per commit, and not all commits have files).