gitar

FileInfo.py

1
""" FileInfo.py - Contains functionality to ask info about a given file."""
2
3
from ..models import Repository
4
from . import RepoInfo
5
import git
6
import pydriller
7
8
9
def get_changing_commits(repository, file):
10
    """ Returns a list of all commits in which the file was changed.
11
    """
12
    presented_commits = get_presented_commits(repository, file)
13
14
15
def get_presented_commits(repository, file):
16
    """ Returns a dict with all branches where the given file is present.
17
    """
18
    branches = RepoInfo.get_commits(repository)
19
    present_branches = dict()
20
    for commits in branches:
21
        pass
22
23
def last_commit(repository_name, branch, file):
24
    """ Returns the last commit in which this file occured.
25
    """
26
    repository = Repository.objects.get(directory_path__endswith=repository_name+".git")
27
    #print(repository.directory_path)
28
    repo = pydriller.Repository(repository.directory_path, only_in_branch=branch)
29
    # Because traverse_commits() is a generator, I can't reverse the order, and
30
    # since it goes from oldest to latest, I have to traverse all commits and
31
    # store the last one that mentions that particular file.
32
    latest_commit = None
33
    for commit in repo.traverse_commits():
34
        for modified_file in commit.modified_files:
35
            #print("Comparing {} with {}".format(modified_file.new_path, file))
36
            if modified_file.new_path == file:
37
                latest_commit = commit
38
    return latest_commit
39