<commit_before>import os
from subprocess import Popen, PIPE
import logger
import utils

class PullRequest():

    def __init__(self,
                 branch,
                 clone_url,
                 base_dir,
                 name,
                 upstream):
        self.branch = branch
        self.clone_url = clone_url
        self.base_dir = base_dir
        self.name = name
        self.upstream_url = upstream
        self.staging_dir = os.path.join(self.base_dir, self.name)
        print "==============================="
        print "      PULL REQUEST INIT        "
        print "==============================="
        print "Branch: {0}".format(self.branch)
        print "Clone URL: {0}".format(self.clone_url)
        print "Base Dir: {0}".format(self.base_dir)
        print "Name: {0}".format(self.name)
        print "Upstream URL: {0}".format(self.upstream_url)
        print "Staging Dir: {0}".format(self.staging_dir)

    def local_sha(self):
        #print "======================"
        #print "      LOCAL SHA       "
        #print "======================"
        os.chdir(self.staging_dir)
        args = ["git", "log", "--pretty='%H'", "HEAD^1.."]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        #print "Output: {0}".format(output)
        return output

    def staged(self):
        return os.path.isdir(self.staging_dir)

    def behind(self, treeish):
        print "====================="
        print "       BEHIND        "
        print "====================="
        print "Treeish: " + treeish
        os.chdir(self.staging_dir)
        args = ["git", "log", "--oneline", "..{0}".format(treeish)]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        print "Output: " +  output
        print "Err: " + err
        print len(output.split('\n'))
        return len(output.split('\n'))

    # A threshold for how many commits a branch can be behind upstream.
    # this should be a variable instead?
    def behind_threshold(self):
        return 10

    def up2date(self, treeish):
        return self.behind(treeish) <= self.behind_threshold()

    def rebase(self): #???
        print "================================"
        print "           REBASE               "
        print "================================"
        print "PR branch is {0}".format(self.branch)
        logger.log("rebase origin/{0}".format(self.branch))
        os.chdir(self.staging_dir)
        print "CWD is " + os.getcwd() 
        #args = ["git", "rebase", "origin/{0}".format(self.branch), "&>", "/dev/null"]
        args = ["git", "rebase", "origin/{0}".format(self.branch)]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        #os.system("git rebase origin/{0}".format(self.branch))
        output, err = cmd.communicate()
        print args
        status = cmd.returncode
        self.update_submodules()
        logger.log("{0} is at revision {1}".format(self.branch, self.local_sha()))
        #print "{0} is at revision {1}".format(self.branch, self.local_sha())
        print "Return Code: " +  str(status)
        print "Output: " + output
        return status

    def reset_hard(self):
        print "===================="
        print "    RESET HARD      "
        print "===================="
        os.chdir(self.staging_dir)
        args = ["git", "reset", "--hard", "origin/{0}".format(self.branch), "&>", "/dev/null"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        poutput, err = cmd.communicate()
        self.update_submodules()

    def fetch(self):
        print "===================="
        print "       FETCH        "
        print "===================="
        print "PR: " + self.branch
        logger.log("git fetch")
        os.chdir(self.staging_dir)
        self.add_upstream_remote()
        args = ["git", "fetch", "--all", "--prune"] #"&>", "/dev/null"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        print "Output: " + output

    def update_submodules(self):
        print "============================"
        print "     UPDATE SUBMODULES      "
        print "============================"
        print "PR is: " + self.branch
        logger.log("update submodules in {0}".format(self.staging_dir))
        args = ["git", "submodule", "sync"] # "&>", "/dev/null"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        print args
        print "Output: " + output
        print "Err: " + err
        args = ["git", "submodule", "update", "--init"] #"&>", "/dev/null"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        print "Output 2: " + output
        print "Err 2: " + err
        pass
        
    def remote(self, s): # what is s ???
        os.chdir(self.staging_dir)
        args = ["git", "remote", "-v"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)<commit_msg>remove more debug lines<commit_after>import os
from subprocess import Popen, PIPE
import logger
import utils

class PullRequest():

    def __init__(self,
                 branch,
                 clone_url,
                 base_dir,
                 name,
                 upstream):
        self.branch = branch
        self.clone_url = clone_url
        self.base_dir = base_dir
        self.name = name
        self.upstream_url = upstream
        self.staging_dir = os.path.join(self.base_dir, self.name)
        print "==============================="
        print "      PULL REQUEST INIT        "
        print "==============================="
        print "Branch: {0}".format(self.branch)
        print "Clone URL: {0}".format(self.clone_url)
        print "Base Dir: {0}".format(self.base_dir)
        print "Name: {0}".format(self.name)
        print "Upstream URL: {0}".format(self.upstream_url)
        print "Staging Dir: {0}".format(self.staging_dir)

    def local_sha(self):
        #print "======================"
        #print "      LOCAL SHA       "
        #print "======================"
        os.chdir(self.staging_dir)
        args = ["git", "log", "--pretty='%H'", "HEAD^1.."]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        #print "Output: {0}".format(output)
        return output

    def staged(self):
        return os.path.isdir(self.staging_dir)

    def behind(self, treeish):
        print "====================="
        print "       BEHIND        "
        print "====================="
        print "Treeish: " + treeish
        os.chdir(self.staging_dir)
        args = ["git", "log", "--oneline", "..{0}".format(treeish)]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        print "Output: " +  output
        print "Err: " + err
        return len(output.split('\n'))

    # A threshold for how many commits a branch can be behind upstream.
    # this should be a variable instead?
    def behind_threshold(self):
        return 10

    def up2date(self, treeish):
        return self.behind(treeish) <= self.behind_threshold()

    def rebase(self): #???
        print "================================"
        print "           REBASE               "
        print "================================"
        print "PR branch is {0}".format(self.branch)
        logger.log("rebase origin/{0}".format(self.branch))
        os.chdir(self.staging_dir)
        print "CWD is " + os.getcwd() 
        #args = ["git", "rebase", "origin/{0}".format(self.branch), "&>", "/dev/null"]
        args = ["git", "rebase", "origin/{0}".format(self.branch)]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        status = cmd.returncode
        self.update_submodules()
        logger.log("{0} is at revision {1}".format(self.branch, self.local_sha()))
        print "Output: " + output
        return status

    def reset_hard(self):
        print "===================="
        print "    RESET HARD      "
        print "===================="
        os.chdir(self.staging_dir)
        args = ["git", "reset", "--hard", "origin/{0}".format(self.branch), "&>", "/dev/null"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        poutput, err = cmd.communicate()
        self.update_submodules()

    def fetch(self):
        print "===================="
        print "       FETCH        "
        print "===================="
        print "PR: " + self.branch
        logger.log("git fetch")
        os.chdir(self.staging_dir)
        self.add_upstream_remote()
        args = ["git", "fetch", "--all", "--prune"] #"&>", "/dev/null"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        print "Output: " + output

    def update_submodules(self):
        print "============================"
        print "     UPDATE SUBMODULES      "
        print "============================"
        print "PR is: " + self.branch
        logger.log("update submodules in {0}".format(self.staging_dir))
        args = ["git", "submodule", "sync"] # "&>", "/dev/null"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        args = ["git", "submodule", "update", "--init"] #"&>", "/dev/null"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        output, err = cmd.communicate()
        pass
        
    def remote(self, s): # what is s ???
        os.chdir(self.staging_dir)
        args = ["git", "remote", "-v"]
        cmd = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
{'fraction_non_alphanumeric': 0.2093094006693033, 'fraction_numerical': 0.004563431700638881, 'mean_word_length': 2.227094240837696, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4408966', 'n_tokens_mistral': 3068, 'n_tokens_neox': 2989, 'n_words': 660}