<commit_before>#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# change those symbols to whatever you prefer
symbols = {'ahead of': '↑', 'behind': '↓', 'staged':'♦', 'changed':'‣', 'untracked':'…', 'clean':'⚡', 'unmerged':'≠', 'sha1':':'}

from subprocess import Popen, PIPE

branch,error = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE, stderr=PIPE).communicate()

if error.find('fatal: Not a git repository') != -1:
	import sys
	sys.exit(0)

branch = branch[11:-1]

status = ''

def execute(*command):
	out, err = Popen(*command, stdout=PIPE, stderr=PIPE).communicate()
	if not err:
		nb = len(out.splitlines())
	else:
		nb = '?'
	return nb

nb = execute(['git','diff','--staged','--name-only','--diff-filter=ACDMRT'])
if nb:
	status += '%s%s' % (symbols['staged'], nb)
nb = execute(['git','diff', '--staged','--name-only', '--diff-filter=U'])
if nb:
	status += '%s%s' % (symbols['unmerged'], nb)
nb = execute(['git','diff','--name-only', '--diff-filter=ACDMRT'])
if nb:
	status += '%s%s' % (symbols['changed'], nb)
nb = len(Popen(['git','ls-files','--others','--exclude-standard'],stdout=PIPE).communicate()[0].splitlines())
if nb:
	status += symbols['untracked']
if status == '':
	status = symbols['clean']

remote = ''

if not branch: # not on any branch
	branch = symbols['sha1']+ Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0][:-1]
else:
	remote_name = Popen(['git','config','branch.%s.remote' % branch], stdout=PIPE).communicate()[0].strip()
	if remote_name:
		merge_name = Popen(['git','config','branch.%s.merge' % branch], stdout=PIPE).communicate()[0].strip()
		if remote_name == '.': # local<commit_msg>slightly faster version: one less call to git diff<commit_after>#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# change those symbols to whatever you prefer
symbols = {'ahead of': '↑', 'behind': '↓', 'staged':'♦', 'changed':'‣', 'untracked':'…', 'clean':'⚡', 'unmerged':'≠', 'sha1':':'}

from subprocess import Popen, PIPE

branch,error = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE, stderr=PIPE).communicate()

if error.find('fatal: Not a git repository') != -1:
	import sys
	sys.exit(0)

branch = branch[11:-1]

status = ''

changed = [namestat[0] for namestat in Popen(['git','diff','--name-status'], stdout=PIPE).communicate()[0].splitlines()]
staged = [namestat[0] for namestat in Popen(['git','diff', '--staged','--name-status'], stdout=PIPE).communicate()[0].splitlines()]
nb_changed = len(changed) - changed.count('U')
nb_U = staged.count('U')
nb_staged = len(staged) - nb_U
if nb_staged:
	status += '%s%s' % (symbols['staged'], nb_staged)
if nb_U:
	status += '%s%s' % (symbols['unmerged'], nb_U)
if nb_changed:
	status += '%s%s' % (symbols['changed'], nb_changed)
nb = len(Popen(['git','ls-files','--others','--exclude-standard'],stdout=PIPE).communicate()[0].splitlines())
if nb:
	status += symbols['untracked']
if status == '':
	status = symbols['clean']

remote = ''

if not branch: # not on any branch
	branch = symbols['sha1']+ Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0][:-1]
else:
	remote_name = Popen(['git','config','branch.%s.remote' % branch], stdout=PIPE).communicate()[0].strip()
	if remote_name:
		merge_name = Popen(['git','config','branch.%s.merge' % branch], stdout=PIPE).communicate()[0].strip()
		if remote_name == '.': # local
{'fraction_non_alphanumeric': 0.24865188735769922, 'fraction_numerical': 0.008987417615338526, 'mean_word_length': 5.651394422310757, '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': '5722851', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1242, 'n_words': 257}