<commit_before>#!/usr/bin/env python

# This script finds the current repository revision base on the log file
# It currently understands both local git-svn and svn repositories

import subprocess, os, sys, re


def shellCommand( command, cwd=None ):
    # The following line works with Python 2.7+
    # return subprocess.check_output( command, shell=True, stderr=subprocess.STDOUT, cwd=cwd )
    p = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd )
    p.wait()
    retcode = p.returncode
    if retcode != 0:
        raise Exception()

    return p.communicate()[0]


def gitSHA1( cwd=None ):
  try:
    # The SHA1 should always be available if we have a git repo.
    return shellCommand( 'git show -s --format=%h', cwd ).strip()
  except: # subprocess.CalledProcessError:
    return None


def gitTag( cwd=None ):
    try:
        # The tag should always be available if we have a git repo.
        return shellCommand( 'git describe --tags', cwd).strip()
    except: # subprocess.CalledProcessError:
        return None


def gitDate( cwd=None ):
    try:
        # The date should always be available if we have a git repo.
        return shellCommand( 'git show -s --format=%ci', cwd ).split()[0]<commit_msg>Ignore stderr when running git commands for repo version.<commit_after>#!/usr/bin/env python

# This script finds the current repository revision base on the log file
# It currently understands both local git-svn and svn repositories

import subprocess, os, sys, re


def shellCommand( command, cwd=None ):
    """
    Run a command in the shell.
    We can ignore anything on stderr as that can potentially mess up the output
    of an otherwise successful command.
    """
    with open(os.devnull, 'w') as devnull:
        p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=devnull, cwd=cwd)
        p.wait()
        retcode = p.returncode
        if retcode != 0:
            raise Exception()

        return p.communicate()[0]


def gitSHA1( cwd=None ):
  try:
    # The SHA1 should always be available if we have a git repo.
    return shellCommand( 'git show -s --format=%h', cwd ).strip()
  except: # subprocess.CalledProcessError:
    return None


def gitTag( cwd=None ):
    try:
        # The tag should always be available if we have a git repo.
        return shellCommand( 'git describe --tags', cwd).strip()
    except: # subprocess.CalledProcessError:
        return None


def gitDate( cwd=None ):
    try:
        # The date should always be available if we have a git repo.
        return shellCommand( 'git show -s --format=%ci', cwd ).split()[0]
{'fraction_non_alphanumeric': 0.09751506024096386, 'fraction_numerical': 0.004518072289156626, 'mean_word_length': 2.995488721804511, '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': '4654155', 'n_tokens_mistral': 801, 'n_tokens_neox': 783, 'n_words': 303}