<commit_before>from __future__ import unicode_literals
import os.path
import subprocess

from .exceptions import CommandError


def get_git_rootdir():
    cmd = ['git', 'rev-parse', '--show-toplevel']
    dirpath = subprocess.check_output(cmd).rstrip()
    if not os.path.exists(dirpath):
        raise ValueError('git directory {} does not exists'.format(dirpath))
    return dirpath


def get_git_config(config_name):
    cmd = ['git', 'config', config_name]
    try:
        data = subprocess.check_output(cmd)
    except subprocess.CalledProcessError:
        raise CommandError(
            'Value for {name} is not specified. '
            'Please specify it using the command:\n'
            'git config {name} <value>'.format(
                name=config_name,
            )
        )
    return data.decode('utf-8').rstrip()


def set_git_config(config_name, value):
    cmd = ['git', 'config', config_name, value]
    try:
        subprocess.check_output(cmd)
    except subprocess.CalledProcessError:
        raise CommandError('git config failed')


def get_email():
    return get_git_config('user.email')


def get_project_name():
    return get_git_config('jiraworklog.projectname')


def get_current_branch():
    cmd = ['git', 'branch']
    try:
        data = subprocess.check_output(cmd)
    except subprocess.CalledProcessError:
        raise ValueError('git branch failed')
    for line in data.decode('utf-8').split('\n'):
        if line.startswith('*'):
            return line[1:].strip()
    raise ValueError('current branch not found')


def set_jira_issue(issue):
    branch = get_current_branch()
    set_git_config('branch.{}.jiraissue'.format(branch), issue)


def get_git_log_file():
    pipe = subprocess.Popen(
        ['git', 'log', '--format=%H %at %ae %s'],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        close_fds=True,
    )
    return pipe.stdout
<commit_msg>set_issue, set_project_name<commit_after>from __future__ import unicode_literals
import os.path
import subprocess

from .exceptions import CommandError


def get_git_rootdir():
    cmd = ['git', 'rev-parse', '--show-toplevel']
    dirpath = subprocess.check_output(cmd).rstrip()
    if not os.path.exists(dirpath):
        raise ValueError('git directory {} does not exists'.format(dirpath))
    return dirpath


def get_git_config(config_name):
    cmd = ['git', 'config', config_name]
    try:
        data = subprocess.check_output(cmd)
    except subprocess.CalledProcessError:
        raise CommandError(
            'Value for {name} is not specified. '
            'Please specify it using the command:\n'
            'git config {name} <value>'.format(
                name=config_name,
            )
        )
    return data.decode('utf-8').rstrip()


def set_git_config(config_name, value):
    cmd = ['git', 'config', config_name, value]
    try:
        subprocess.check_output(cmd)
    except subprocess.CalledProcessError:
        raise CommandError('git config failed')


def get_email():
    return get_git_config('user.email')


def get_project_name():
    return get_git_config('jiraworklog.projectname')


def set_project_name(project):
    set_git_config('jiraworklog.projectname', project)


def get_current_branch():
    cmd = ['git', 'branch']
    try:
        data = subprocess.check_output(cmd)
    except subprocess.CalledProcessError:
        raise ValueError('git branch failed')
    for line in data.decode('utf-8').split('\n'):
        if line.startswith('*'):
            return line[1:].strip()
    raise ValueError('current branch not found')


def get_issue():
    branch = get_current_branch()
    return get_git_config('branch.{}.issue'.format(branch))


def set_issue(issue):
    branch = get_current_branch()
    # TODO: test pattern
    set_git_config('branch.{}.issue'.format(branch), issue)


def get_git_log_file():
    pipe = subprocess.Popen(
        ['git', 'log', '--format=%H %at %ae %s'],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        close_fds=True,
    )
    return pipe.stdout

{'fraction_non_alphanumeric': 0.12386558744174639, 'fraction_numerical': 0.0014716703458425313, 'mean_word_length': 3.090270812437312, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7277427', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1260, 'n_words': 284}