How to use the pydriller.GitRepository function in PyDriller

To help you get started, we’ve selected a few PyDriller examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ishepard / pydriller / tests / test_diff.py View on Github external
def test_diff_no_newline():
    """
    If a file ends without a newline git represents this with the additional line
        \\ No newline at end of file
    in diffs. This test asserts these additional lines are parsed correctly.
    """
    gr = GitRepository('test-repos/test9')

    diff = gr.get_commit('52a78c1ee5d100528eccba0a3d67371dbd22d898').modifications[0].diff
    parsed_lines = gr.parse_diff(diff)

    added = parsed_lines['added']
    deleted = parsed_lines['deleted']

    assert (1, 'test1') in deleted  # is considered as deleted as a 'newline' command is added
    assert (1, 'test1') in added  # now with added 'newline'
    assert (2, 'test2') in added
github ishepard / pydriller / tests / test_diff.py View on Github external
def test_additions():
    diff = '@@ -2,6 +2,7 @@ aa\r\n' + \
           ' bb\r\n' + \
           ' cc\r\n' + \
           ' log.info(\"aa\")\r\n' + \
           '+log.debug(\"b\")\r\n' + \
           ' dd\r\n' + \
           ' ee\r\n' + \
           ' ff'

    gr = GitRepository('test-repos/test1')
    parsed_lines = gr.parse_diff(diff)

    added = parsed_lines['added']
    deleted = parsed_lines['deleted']

    assert (5, 'log.debug("b")') in added
    assert len(deleted) == 0
    assert len(added) == 1
github ishepard / pydriller / tests / test_diff.py View on Github external
"-a\r\n" + \
           "-b\r\n" + \
           "-c\r\n" + \
           "-log.info(\"a\")\r\n" + \
           "-d\r\n" + \
           "-e\r\n" + \
           "-f\r\n" + \
           "+aa\r\n" + \
           "+bb\r\n" + \
           "+cc\r\n" + \
           "+log.info(\"aa\")\r\n" + \
           "+dd\r\n" + \
           "+ee\r\n" + \
           "+ff\r\n" + \
           " "
    gr = GitRepository('test-repos/test1')
    parsed_lines = gr.parse_diff(diff)

    added = parsed_lines['added']
    deleted = parsed_lines['deleted']

    assert (1, 'a') in deleted
    assert (2, 'b') in deleted
    assert (3, 'c') in deleted
    assert (4, 'log.info(\"a\")') in deleted
    assert (5, 'd') in deleted
    assert (6, 'e') in deleted
    assert (7, 'f') in deleted

    assert (1, 'aa') in added
    assert (2, 'bb') in added
    assert (3, 'cc') in added
github ishepard / pydriller / tests / test_diff.py View on Github external
' \r\n' + \
           '-       public ChangeSet getHead() {\r\n' + \
           '+       public ChangeSet getHead2() {\r\n' + \
           '                Git git = null;\r\n' + \
           '                try {\r\n' + \
           '                        git = openRepository();\r\n' + \
           '@@ -320,6 +320,7 @@ public class GitRepository implements SCM {\r\n' + \
           ' \r\n' + \
           '                return diffs;\r\n' + \
           '        }\r\n' + \
           '+       newline\r\n' + \
           ' \r\n' + \
           '        private void setContext(DiffFormatter df) {\r\n' + \
           '                String context = System.getProperty(\"git.diffcontext\");'

    gr = GitRepository('test-repos/test1')
    parsed_lines = gr.parse_diff(diff)

    added = parsed_lines['added']
    deleted = parsed_lines['deleted']

    assert (75, '       public GitRepository(String path) {') in deleted
    assert (158, '       public ChangeSet getHead() {') in deleted
    assert len(deleted) == 2

    assert (75, '       public GitRepository2(String path) {') in added
    assert (158, '       public ChangeSet getHead2() {') in added
    assert (323, '       newline') in added
    assert len(added) == 3
github ishepard / pydriller / tests / test_repository_mining.py View on Github external
assert len(diff['deleted']) == 7
    assert (3, '    java.net.URL imgURL = GuiImporter.class.getResource(path);') in diff['deleted']
    assert (4, '') in diff['deleted']
    assert (5, '    if (imgURL != null)') in diff['deleted']
    assert (7, '        return new ImageIcon(imgURL);') in diff['deleted']
    assert (9, '    else') in diff['deleted']
    assert (10, '    {') in diff['deleted']
    assert (13, '    return null;') in diff['deleted']

    # with histogram
    commit = list(RepositoryMining('test-repos/test13',
                                   single="93df8676e6fab70d9677e94fd0f6b17db095e890",
                                   histogram_diff=True).traverse_commits())[0]
    mod = commit.modifications[0]
    gr = GitRepository('test-repos/test13')
    diff = gr.parse_diff(mod.diff)
    assert (4, '    {') in diff["added"]
    assert (5, '        log.error("Icon path is null");') in diff["added"]
    assert (6, '        return null;') in diff["added"]
    assert (7, '    }') in diff["added"]
    assert (8, '') in diff["added"]
    assert (11, '    if (imgURL == null)') in diff["added"]
    assert (12, '    {') in diff["added"]
    assert (13, '        log.error("Couldn\'t find icon: " + imgURL);') in diff["added"]
    assert (14, '        return null;') in diff["added"]
    assert (17, '        return new ImageIcon(imgURL);') in diff["added"]

    assert (6, '    {') in diff["deleted"]
    assert (7, '        return new ImageIcon(imgURL);') in diff["deleted"]
    assert (10, '    {') in diff["deleted"]
    assert (11, '        log.error("Couldn\'t find icon: " + imgURL);') in diff["deleted"]
github ishepard / pydriller / tests / test_repository_mining.py View on Github external
def test_diff_histogram():
    # without histogram
    commit = list(RepositoryMining('test-repos/test13',
                                   single="93df8676e6fab70d9677e94fd0f6b17db095e890").traverse_commits())[0]
    mod = commit.modifications[0]
    gr = GitRepository('test-repos/test13')
    diff = gr.parse_diff(mod.diff)
    assert len(diff['added']) == 11
    assert (3, '    if (path == null)') in diff['added']
    assert (5, '        log.error("Icon path is null");') in diff['added']
    assert (6, '        return null;') in diff['added']
    assert (8, '') in diff['added']
    assert (9, '    java.net.URL imgURL = GuiImporter.class.getResource(path);') in diff['added']
    assert (10, '') in diff['added']
    assert (11, '    if (imgURL == null)') in diff['added']
    assert (12, '    {') in diff['added']
    assert (14, '        return null;') in diff['added']
    assert (16, '    else') in diff['added']
    assert (17, '        return new ImageIcon(imgURL);') in diff['added']

    assert len(diff['deleted']) == 7
    assert (3, '    java.net.URL imgURL = GuiImporter.class.getResource(path);') in diff['deleted']
github ishepard / pydriller / tests / test_repository_mining.py View on Github external
def test_ignore_add_whitespaces_and_modified_normal_line():
    gr = GitRepository('test-repos/test14')
    commit = list(RepositoryMining('test-repos/test14',
                                   single="52716ef1f11e07308b5df1b313aec5496d5e91ce").traverse_commits())[0]
    assert len(commit.modifications) == 1
    parsed_normal_diff = gr.parse_diff(commit.modifications[0].diff)
    commit = list(RepositoryMining('test-repos/test14',
                                   skip_whitespaces=True,
                                   single="52716ef1f11e07308b5df1b313aec5496d5e91ce").traverse_commits())[0]
    assert len(commit.modifications) == 1
    parsed_wo_whitespaces_diff = gr.parse_diff(commit.modifications[0].diff)
    assert len(parsed_normal_diff['added']) == 2
    assert len(parsed_wo_whitespaces_diff['added']) == 1

    assert len(parsed_normal_diff['deleted']) == 1
    assert len(parsed_wo_whitespaces_diff['deleted']) == 0
github mozilla / bugbug / scripts / regressor_finder.py View on Github external
def _init(git_repo_dir):
            thread_local.git = GitRepository(git_repo_dir)
github crossminer / scava / crossflow / org.eclipse.scava.crossflow.examples.projectsanalysis / py / projectanalysis / python_repository_analyzer.py View on Github external
firstCommitDate = commit.committer_date
                else:
                    lastCommitDate = commit.committer_date

                if commit.committer not in committerList:
                    committerList.append(commit.committer)

                for modification in commit.modifications:
                    noOfModifications += 1
                    if modification.new_path != None:
                        visitedFile.append(modification.new_path)  # add file to list of visited files
                        if modification.nloc != None:
                            totalLOC += modification.nloc
                            fileLocCache.update({modification.new_path: modification.nloc})

                        gr = GitRepository(java_repository_analysis_result.path)
                        parsed_lines = gr.parse_diff(modification.diff)
                        for item in parsed_lines['added']:
                            totalAddedLOC += item[0]
                        for item in parsed_lines['deleted']:
                            totalDeletedLOC += item[0]

                    else:
                        fileLocCache.update({modification.new_path: 0})

            # remove visited files from cache (already added to totalLOC)
            for file in list(fileLocCache):
                if file in visitedFile:
                    del fileLocCache[file]

            # add remaining to totalLOC
            for file, fileLoc in fileLocCache.items():