<commit_before>#!/usr/bin/python

# Remap each CraftBukkit commit

import subprocess
import os
import shutil
import xml.dom.minidom

inOriginalDir = "CraftBukkit"       # original source
inRemappedDir = "CraftBukkit"       # output of remapper
outDirGitRepo = "/tmp/MCPBukkit"    # git repository to build
srcComponent = "src"            # common directory name for source (in inOriginalDir and outDirGitRepo)

shouldCloneRepo = True
shouldPullLatestChanges = True
shouldCheckoutMaster = True
remoteSource = "origin" # 'git remote' name
repoURL = "https://github.com/Bukkit/CraftBukkit/commit/"
masterBranch = "master"
defaultStartCommit = "2<PASSWORD>" # Updated version to 1.4.7-R1.0 in pom.xml for RB.


def runRemap():
    print "Starting remap script..."
    run("python remap-craftbukkit.py --cb-dir "+inOriginalDir+" --fml-dir fml --skip-output-archive")
    print "Remap script finished"

def run(cmd):
    print ">",cmd
    #raw_input()
    status = os.system(cmd)
    assert status == 0, "Failed to run '%s' status=%s" % (cmd, status)

def runOutput(cmd):
    return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.read()

DIR_STACK = []
def pushd(newDir):
    print "cd",newDir
    DIR_STACK.append(os.getcwd())
    os.chdir(newDir)

def popd():
    print "cd",DIR_STACK[-1]
    os.chdir(DIR_STACK.pop())

"""Clean out even non-repository or moved files."""
def clean():
    run("rm -rf src")
    run("git reset --hard HEAD")

"""Get commit IDs and short messages after the starting commit, in reverse chronological order."""
def readCommitLog(startCommit):
    commits = []
    for line in runOutput(("git", "log", "--format=oneline")).split("\n"):
        assert len(line) != 0, "Reached end of commit log without finding starting commit "+startCommit
        commit, message = line.split(" ", 1)
        if commit == startCommit: break
        print commit, message
        commits.append((commit, message))
    commits.reverse()
    return commits

"""Get detailed information on a commit."""
def getCommitInfo(commit):
    out = runOutput(("git", "show", commit, "--format=format:%an <%ae>%n%aD%n%B%n---END---"))
    lines = out.split("\n")
    author = lines[0]
    date = lines[1]
    messageLines = []
    for i in range(2,len(lines)):
        if lines[i] == "---END---": break
        messageLines.append(lines[i])
    message = "\n".join(messageLines)

    return author, date, message

CREDIT_MESSAGE_PREFIX = "\n\nRemapped by Srg2Source from "+repoURL

"""Get the last remapped commit, if any"""
def getStartCommit():
    if not os.path.exists(outDirGitRepo):
        print "Creating",outDirGitRepo
        os.mkdir(outDirGitRepo)

    pushd(outDirGitRepo)

    if not os.path.exists(".git"):
        print "No git repository found in "+outDirGitRepo
        print "Initializing new repository"
        run("git init")
        popd()
        print "Starting at default "+defaultStartCommit
        return defaultStartCommit

    message = runOutput(("git", "show", "--format=%b"))
    if CREDIT_MESSAGE_PREFIX not in message:
        print "Unrecognized commit message: >>>\n"+message+"\n<<< - no match for '"+CREDIT_MESSAGE_PREFIX+"'"
        print "Starting at default "+defaultStartCommit
        popd()
        return defaultStartCommit

    n = message.index(CREDIT_MESSAGE_PREFIX)
    commit = message[CREDIT_MESSAGE_PREFIX:]
    print "C1",commit
    commit = commit[:commit.index("\n")]
    print "C2",commit
    popd()

    return commit<commit_msg>Add support for resuming commit remapping where you left off<commit_after>#!/usr/bin/python

# Remap each CraftBukkit commit

import subprocess
import os
import shutil
import xml.dom.minidom
import re

inOriginalDir = "CraftBukkit"       # original source
inRemappedDir = "CraftBukkit"       # output of remapper
outDirGitRepo = "/tmp/MCPBukkit"    # git repository to build
srcComponent = "src"            # common directory name for source (in inOriginalDir and outDirGitRepo)

shouldCloneRepo = True
shouldPullLatestChanges = True
shouldCheckoutMaster = True
remoteSource = "origin" # 'git remote' name
repoURL = "https://github.com/Bukkit/CraftBukkit/commit/"
masterBranch = "master"
defaultStartCommit = "2<PASSWORD>" # Updated version to 1.4.7-R1.0 in pom.xml for RB.


def runRemap():
    print "Starting remap script..."
    run("python remap-craftbukkit.py --cb-dir "+inOriginalDir+" --fml-dir fml --skip-output-archive")
    print "Remap script finished"

def run(cmd):
    print ">",cmd
    #raw_input()
    status = os.system(cmd)
    assert status == 0, "Failed to run '%s' status=%s" % (cmd, status)

def runOutput(cmd):
    return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.read()

DIR_STACK = []
def pushd(newDir):
    print "cd",newDir
    DIR_STACK.append(os.getcwd())
    os.chdir(newDir)

def popd():
    print "cd",DIR_STACK[-1]
    os.chdir(DIR_STACK.pop())

"""Clean out even non-repository or moved files."""
def clean():
    run("rm -rf src")
    run("git reset --hard HEAD")

"""Get commit IDs and short messages after the starting commit, in reverse chronological order."""
def readCommitLog(startCommit):
    commits = []
    for line in runOutput(("git", "log", "--format=oneline")).split("\n"):
        assert len(line) != 0, "Reached end of commit log without finding starting commit "+startCommit
        commit, message = line.split(" ", 1)
        if commit == startCommit: break
        print commit, message
        commits.append((commit, message))
    commits.reverse()
    return commits

"""Get detailed information on a commit."""
def getCommitInfo(commit):
    out = runOutput(("git", "show", commit, "--format=format:%an <%ae>%n%aD%n%B%n---END---"))
    lines = out.split("\n")
    author = lines[0]
    date = lines[1]
    messageLines = []
    for i in range(2,len(lines)):
        if lines[i] == "---END---": break
        messageLines.append(lines[i])
    message = "\n".join(messageLines)

    return author, date, message

CREDIT_MESSAGE_PREFIX = "\n\nRemapped by Srg2Source from "+repoURL

"""Get the last remapped commit, if any"""
def getStartCommit():
    if not os.path.exists(outDirGitRepo):
        print "Creating",outDirGitRepo
        os.mkdir(outDirGitRepo)

    pushd(outDirGitRepo)

    if not os.path.exists(".git"):
        print "No git repository found in "+outDirGitRepo
        print "Initializing new repository"
        run("git init")
        popd()
        print "Starting at default "+defaultStartCommit
        return defaultStartCommit

    message = runOutput(("git", "show", "--format=%B"))

    r = re.compile(CREDIT_MESSAGE_PREFIX.strip() + "([0-9a-f]+)")
    match = r.search(message)
    if not match:
        print "Unrecognized commit message: >>>\n"+message+"\n<<< - no match for '"+CREDIT_MESSAGE_PREFIX+"'"
        print "Starting at default "+defaultStartCommit
        popd()
        return defaultStartCommit

    commit = match.group(1)
    popd()

    print "Resuming from upstream commit",repoURL+commit
    return commit
{'fraction_non_alphanumeric': 0.13504321949837042, 'fraction_numerical': 0.0046762080204052715, 'mean_word_length': 3.386575512740833, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2087315', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2236, 'n_words': 620}