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

# Suppose there is a BUP repository such that
#
#     bup ls
#
# outputs
#
#     error: refs/heads/master does not point to a valid object!
#
# This script -- when run inside the BUP repo -- will point refs/heads/master
# to the previous commit, which should fix this problem.
# If bup ls doesn't yield an error, this script won't change anything.
# The entire point of this script is to fix some past snapshot repos that
# have this problem, probably due to a bug in the rollback functionality
# of snap.coffee.


import os, sys

def cmd(s):
    print s
    t = os.popen3(s)
    return t[1].read() + t[2].read()

def fix(path):
    print "Checking '%s'"%path
    os.environ['BUP_DIR'] = path
    os.chdir(path)

    # Check to see if the repo is working
    def repo_is_working():
        return 'error: refs/heads/master does not point to a valid object!' not in cmd("bup ls")

    # Move the head back up to 3 times, which should be enough to fix the repo.
    def move_head_back():
        if os.path.exists('logs/HEAD'):
            log = open('logs/HEAD').readlines()
            i = -1
            while not repo_is_working() and i >= -3 and abs(i) >= len(log):
                print "Trying head %s"%i<commit_msg>snap_fix script -- fix a wrong equality<commit_after>#!/usr/bin/env python

# Suppose there is a BUP repository such that
#
#     bup ls
#
# outputs
#
#     error: refs/heads/master does not point to a valid object!
#
# This script -- when run inside the BUP repo -- will point refs/heads/master
# to the previous commit, which should fix this problem.
# If bup ls doesn't yield an error, this script won't change anything.
# The entire point of this script is to fix some past snapshot repos that
# have this problem, probably due to a bug in the rollback functionality
# of snap.coffee.


import os, sys

def cmd(s):
    print s
    t = os.popen3(s)
    return t[1].read() + t[2].read()

def fix(path):
    print "Checking '%s'"%path
    os.environ['BUP_DIR'] = path
    os.chdir(path)

    # Check to see if the repo is working
    def repo_is_working():
        c = cmd("bup ls")
        if 'error: refs/heads/master does not point to a valid object!' in c:
            return False
        if 'is far too short to be a pack' in c:
            return False
        return True

    # Move the head back up to 3 times, which should be enough to fix the repo.
    def move_head_back():
        print "Moving head back"
        if os.path.exists('logs/HEAD'):
            log = open('logs/HEAD').readlines()
            print "log exists and has length %s"%(len(log))
            i = -1
            while not repo_is_working() and i >= -4 and abs(i) <= len(log):
                print "Trying head %s"%i
{'fraction_non_alphanumeric': 0.10242490047050308, 'fraction_numerical': 0.004343105320304018, 'mean_word_length': 2.5120711562897076, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '1536573', 'n_tokens_mistral': 870, 'n_tokens_neox': 846, 'n_words': 359}