<commit_before># -*- coding: utf-8 -*-
import subprocess
import sys
import os
from urlparse import urlparse


def get_branch():
    try:
        output = subprocess.check_output(
            ["git", "rev-parse", "--abbrev-ref", "HEAD"]
        )
        output = output.replace("\n", "")
        return output
    except subprocess.CalledProcessError:
        return "unknown"


def get_commit():
    try:
        output = subprocess.check_output(
            ["git", "rev-parse", "HEAD"]
        )
        output = output.replace("\n", "")
        return output
    except subprocess.CalledProcessError:
        return "unknown"


def get_repo_url():
    cmd = 'git config --get remote.origin.url'
    origin_url = subprocess.check_output(cmd.split(' '))
    repository = ""
    if origin_url.startswith("http"):
        repository, _ = os.path.splitext(urlparse(origin_url).path)
    elif origin_url.startswith("git@"):
        repository = "/" + origin_url.split(":")[1].split(".")[0]
    else:
        raise Exception("Unknown origin url format")
    github_url = "https://github.com"
    return github_url + repository


def get_git_version():
    """Returns git version info bits in a dict, or None if there is no version
    to be found (i.e. no tag for instance).
    """
    if not os.path.isdir(".git"):
        print "This does not appear to be a Git repository."
        sys.exit(1)

    p = subprocess.Popen(
        ["git", "describe", "--tags", "--dirty", "--long"],
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT
    )
    stdout, _ = p.communicate()
    if p.returncode == 128:
        return  # No tag found, probably

    if p.returncode != 0:
        print "git command failed:", p.returncode
        sys.exit(1)

    is_dirty = False
    stdout = stdout.strip()
    canonical = stdout
    if stdout.endswith("-dirty"):
        stdout = stdout.replace("-dirty", "")
        is_dirty = True
    print stdout.rsplit("-", 2)
    tag, commits_after_tag, sha = stdout.rsplit("-", 2)
    if is_dirty or int(commits_after_tag) > 0:
        tag = canonical

    version = {
        "tag": tag,
        "commits_after_tag": int(commits_after_tag),
        "sha": sha,
        "is_dirty": is_dirty,
        "canonical": canonical,
    }

    return version


def checkout(branch_or_tag):
    """Check out a branch or tag."""
    p = subprocess.Popen(
        ["git", "checkout", branch_or_tag],
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT
    )
    stdout, _ = p.communicate()
    if p.returncode != 0:
        print "git command failed:", p.returncode
        sys.exit(1)<commit_msg>Removing a print statement in gittools module.<commit_after># -*- coding: utf-8 -*-
import subprocess
import sys
import os
from urlparse import urlparse


def get_branch():
    try:
        output = subprocess.check_output(
            ["git", "rev-parse", "--abbrev-ref", "HEAD"]
        )
        output = output.replace("\n", "")
        return output
    except subprocess.CalledProcessError:
        return "unknown"


def get_commit():
    try:
        output = subprocess.check_output(
            ["git", "rev-parse", "HEAD"]
        )
        output = output.replace("\n", "")
        return output
    except subprocess.CalledProcessError:
        return "unknown"


def get_repo_url():
    cmd = 'git config --get remote.origin.url'
    origin_url = subprocess.check_output(cmd.split(' '))
    repository = ""
    if origin_url.startswith("http"):
        repository, _ = os.path.splitext(urlparse(origin_url).path)
    elif origin_url.startswith("git@"):
        repository = "/" + origin_url.split(":")[1].split(".")[0]
    else:
        raise Exception("Unknown origin url format")
    github_url = "https://github.com"
    return github_url + repository


def get_git_version():
    """Returns git version info bits in a dict, or None if there is no version
    to be found (i.e. no tag for instance).
    """
    if not os.path.isdir(".git"):
        print "This does not appear to be a Git repository."
        sys.exit(1)

    p = subprocess.Popen(
        ["git", "describe", "--tags", "--dirty", "--long"],
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT
    )
    stdout, _ = p.communicate()
    if p.returncode == 128:
        return  # No tag found, probably

    if p.returncode != 0:
        print "git command failed:", p.returncode
        sys.exit(1)

    is_dirty = False
    stdout = stdout.strip()
    canonical = stdout
    if stdout.endswith("-dirty"):
        stdout = stdout.replace("-dirty", "")
        is_dirty = True
    tag, commits_after_tag, sha = stdout.rsplit("-", 2)
    if is_dirty or int(commits_after_tag) > 0:
        tag = canonical

    version = {
        "tag": tag,
        "commits_after_tag": int(commits_after_tag),
        "sha": sha,
        "is_dirty": is_dirty,
        "canonical": canonical,
    }

    return version


def checkout(branch_or_tag):
    """Check out a branch or tag."""
    p = subprocess.Popen(
        ["git", "checkout", branch_or_tag],
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT
    )
    stdout, _ = p.communicate()
    if p.returncode != 0:
        print "git command failed:", p.returncode
        sys.exit(1)
{'fraction_non_alphanumeric': 0.13715377268385864, 'fraction_numerical': 0.005157593123209169, 'mean_word_length': 2.4066363044892647, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5741284', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1621, 'n_words': 418}