# Path: ellen/utils/process.py
# def git_with_repo(repository):
#     git_dir = repository.path
#     work_tree = repository.workdir
#     return git_with_path(git_dir, work_tree)
# 
# Path: ellen/utils/format.py
# def format_merge_analysis(analysis):
#     from pygit2 import GIT_MERGE_ANALYSIS_FASTFORWARD, GIT_MERGE_ANALYSIS_UP_TO_DATE
#     d = {}
#     d['is_uptodate'] = analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE
#     d['is_fastforward'] = analysis & GIT_MERGE_ANALYSIS_FASTFORWARD
#     return d
# 
# def format_index(merge_index):
#     d = {}
#     d['has_conflicts'] = merge_index.has_conflicts
#     return d


from ellen.utils.process import git_with_repo
from ellen.utils.format import format_merge_analysis, format_index
        git_merge = git_merge.bake(m=msg)
    if commit_msg:
        git_merge = git_merge.bake(m=commit_msg)
    return git_merge(env=_env)


def merge_tree(repository, ours, theirs):
    theirs = repository.revparse_single(theirs)
    theirs_tree = theirs.tree
    ours = repository.revparse_single(ours)
    ours_tree = ours.tree
    merge_base_oid = repository.merge_base(str(theirs.id),
                                           str(ours.id))
    merge_base_tree = repository.get(str(merge_base_oid)).tree \
        if merge_base_oid else ours_tree
    index = ours_tree.merge(theirs_tree, merge_base_tree)
    return format_index(index)


def merge_head(repository, ref):
    target = repository.revparse_single(ref)
    oid = target.id
    analysis = repository.merge_analysis(oid)
    return format_merge_analysis(analysis)


def merge_commits(repository, ours, theirs):
    theirs = repository.revparse_single(theirs)
    ours = repository.revparse_single(ours)
    merge_index = repository.merge_commits(ours, theirs)

# Path: ellen/utils/process.py
# def git_with_repo(repository):
#     git_dir = repository.path
#     work_tree = repository.workdir
#     return git_with_path(git_dir, work_tree)
# 
# Path: ellen/utils/format.py
# def format_merge_analysis(analysis):
#     from pygit2 import GIT_MERGE_ANALYSIS_FASTFORWARD, GIT_MERGE_ANALYSIS_UP_TO_DATE
#     d = {}
#     d['is_uptodate'] = analysis & GIT_MERGE_ANALYSIS_UP_TO_DATE
#     d['is_fastforward'] = analysis & GIT_MERGE_ANALYSIS_FASTFORWARD
#     return d
# 
# def format_index(merge_index):
#     d = {}
#     d['has_conflicts'] = merge_index.has_conflicts
#     return d


# Path: ellen/git/merge.py
from ellen.utils.process import git_with_repo
from ellen.utils.format import format_merge_analysis, format_index

        git_merge = git_merge.bake(m=msg)
    if commit_msg:
        git_merge = git_merge.bake(m=commit_msg)
    return git_merge(env=_env)


def merge_tree(repository, ours, theirs):
    theirs = repository.revparse_single(theirs)
    theirs_tree = theirs.tree
    ours = repository.revparse_single(ours)
    ours_tree = ours.tree
    merge_base_oid = repository.merge_base(str(theirs.id),
                                           str(ours.id))
    merge_base_tree = repository.get(str(merge_base_oid)).tree \
        if merge_base_oid else ours_tree
    index = ours_tree.merge(theirs_tree, merge_base_tree)
    return format_index(index)


def merge_head(repository, ref):
    target = repository.revparse_single(ref)
    oid = target.id
    analysis = repository.merge_analysis(oid)
    return format_merge_analysis(analysis)


def merge_commits(repository, ours, theirs):
    theirs = repository.revparse_single(theirs)
    ours = repository.revparse_single(ours)
    merge_index = repository.merge_commits(ours, theirs)

    return format_index(merge_index)