<commit_before>"""
Defines the Sumatra version control interface for Git.

Classes
-------

GitWorkingCopy
GitRepository


:copyright: Copyright 2006-2014 by the Sumatra team, see doc/authors.txt
:license: CeCILL, see LICENSE for details.
"""

import logging
import git
import os
import shutil
from ConfigParser import NoSectionError, NoOptionError
try:
    from git.errors import InvalidGitRepositoryError, NoSuchPathError
except:
    from git.exc import InvalidGitRepositoryError, NoSuchPathError
from base import Repository, WorkingCopy, VersionControlError
from ..core import registry


logger = logging.getLogger("Sumatra")


def check_version():
    if not hasattr(git, "Repo"):
        raise VersionControlError("GitPython not installed. There is a 'git' package, but it is not GitPython (https://pypi.python.org/pypi/GitPython/)")
    gitpython_version = tuple(int(x) for x in git.__version__.split("."))
    if gitpython_version[1] < 2 or gitpython_version[2] < 6:
        raise VersionControlError("Your Git Python binding is too old. You require at least version 0.2.6.")


def findrepo(path):
    check_version()
    try:
        repo = git.Repo(path, search_parent_directories=True)
    except InvalidGitRepositoryError:
        return
    else:
        return os.path.dirname(repo.git_dir)


class GitWorkingCopy(WorkingCopy):
    """
    An object which allows various operations on a Git working copy.
    """
    name = "git"<commit_msg>Use distutils.version.LooseVersion to compare versions for gitpython because the present code chokes on something like '0.3.2 RC1'.<commit_after>"""
Defines the Sumatra version control interface for Git.

Classes
-------

GitWorkingCopy
GitRepository


:copyright: Copyright 2006-2014 by the Sumatra team, see doc/authors.txt
:license: CeCILL, see LICENSE for details.
"""

import logging
import git
import os
import shutil
from distutils.version import LooseVersion
from ConfigParser import NoSectionError, NoOptionError
try:
    from git.errors import InvalidGitRepositoryError, NoSuchPathError
except:
    from git.exc import InvalidGitRepositoryError, NoSuchPathError
from base import Repository, WorkingCopy, VersionControlError
from ..core import registry


logger = logging.getLogger("Sumatra")


def check_version():
    if not hasattr(git, "Repo"):
        raise VersionControlError("GitPython not installed. There is a 'git' package, but it is not GitPython (https://pypi.python.org/pypi/GitPython/)")
    if LooseVersion(git.__version__) < LooseVersion('0.2.6'):
        raise VersionControlError("Your Git Python binding is too old. You require at least version 0.2.6.")


def findrepo(path):
    check_version()
    try:
        repo = git.Repo(path, search_parent_directories=True)
    except InvalidGitRepositoryError:
        return
    else:
        return os.path.dirname(repo.git_dir)


class GitWorkingCopy(WorkingCopy):
    """
    An object which allows various operations on a Git working copy.
    """
    name = "git"
{'fraction_non_alphanumeric': 0.08678237650200267, 'fraction_numerical': 0.011014686248331108, 'mean_word_length': 4.0625, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, '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': '3721147', 'n_tokens_mistral': 886, 'n_tokens_neox': 831, 'n_words': 288}