<commit_before>import os
import re
import string
import sys
import logging

import oelite.util
import bb.utils


class NotAGitRepository(Exception):
    def __init__(self, path):
        self.path = path
    def __str__(self):
        print self.path


class GitRepository(object):

    COMMIT_ID_RE = re.compile("([0-9a-f]{1,40})")

    def __init__(self, path):
        self.path = oelite.util.shcmd(
            "git rev-parse --show-toplevel", dir=path,
            quiet=True, silent_errorcodes=[128])
        if self.path is None:
            raise NotAGitRepository(path)
        elif self.path == '':
            # assuming that path is top-level of a bare repository
            self.path = path
        self.path = self.path.strip()

    def git(self, cmd, quiet=True, strip=True):
        if not isinstance(cmd, basestring):
            cmd = " ".join(cmd)
        cmd = "git " + cmd
        retval = oelite.util.shcmd(
            cmd, dir=self.path, quiet=quiet, silent_errorcodes=[1, 128])
        if strip and retval:
            retval = retval.strip()
        return retval

    def has_head(self, head):
        return self.resolve_head(head) is not None

    def get_head(self, ref):
        if self.has_ref(ref, 'heads'):
            return ref
        # dereference symbolic references (such as HEAD)
        head = get_symref(ref)
        if head is None:
            return None
        if not head.startswith("refs/heads/"):
            logging.warning("ignoring non-head symbolic reference: %s", head)
            return None
        head = head[11:]
        if self.has_ref(head, 'heads'):
            return head
        return None<commit_msg>lib/oelite: Fix GitRepository error handling in quiet mode<commit_after>import os
import re
import string
import sys
import logging

import oelite.util
import bb.utils


class NotAGitRepository(Exception):
    def __init__(self, path):
        self.path = path
    def __str__(self):
        print self.path


class GitRepository(object):

    COMMIT_ID_RE = re.compile("([0-9a-f]{1,40})")

    def __init__(self, path):
        self.path = oelite.util.shcmd(
            "git rev-parse --show-toplevel", dir=path,
            quiet=True, silent_errorcodes=[128])
        if self.path is None:
            raise NotAGitRepository(path)
        elif self.path == '':
            # assuming that path is top-level of a bare repository
            self.path = path
        self.path = self.path.strip()

    def git(self, cmd, quiet=True, strip=True):
        if not isinstance(cmd, basestring):
            cmd = " ".join(cmd)
        cmd = "git " + cmd
        retval = oelite.util.shcmd(
            cmd, dir=self.path, quiet=quiet, silent_errorcodes=[1, 128])
        if not quiet:
            return retval
        if strip and retval:
            retval = retval.strip()
        return retval

    def has_head(self, head):
        return self.resolve_head(head) is not None

    def get_head(self, ref):
        if self.has_ref(ref, 'heads'):
            return ref
        # dereference symbolic references (such as HEAD)
        head = get_symref(ref)
        if head is None:
            return None
        if not head.startswith("refs/heads/"):
            logging.warning("ignoring non-head symbolic reference: %s", head)
            return None
        head = head[11:]
        if self.has_ref(head, 'heads'):
            return head
        return None
{'fraction_non_alphanumeric': 0.10276564774381368, 'fraction_numerical': 0.008151382823871907, 'mean_word_length': 2.0569395017793592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1601430', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1002, 'n_words': 291}