Exemplo n.º 1
0
Arquivo: ohm.py Projeto: cscorley/ohm
def dual_speed_run(project1, project2):
    # This does not work as expectedy yet. When given a git repo, it
    # stops on some commits.

    UserRepository = project1.repo
    project_repo1 = UserRepository(project1)
    print(project_repo1)
    p1_gen = project_repo1.get_revisions()

    UserRepository = project2.repo
    project_repo2 = UserRepository(project2)
    print(project_repo2)
    p2_gen = project_repo2.get_revisions()

    n1, n2, p1_log, p1_results, p2_log, p2_results = None, None, None, None, None, None
    while True:
        try:
            n1, p1_log, p1_results = accumulate(p1_gen, p1_log, p1_results)
            n2, p2_log, p2_results = accumulate(p2_gen, p2_log, p2_results)
        except StopIteration:
            break

        if n1 == n2:
            print('Success: ', short(p1_log.commit_id), short(p2_log.commit_id))
        else:
            print('Failure: ', short(p1_log.commit_id), short(p2_log.commit_id))
Exemplo n.º 2
0
    def __init__(self, project, starting_revision=None, ending_revision=None,
            username='******', password=''):
        self._project = project
        self.username = username
        self.password = password
        self.count = 0

        self.repo = dulwich.repo.Repo(self.project.url)
        self.revList = [short(x.commit.id) for x in iter(self.repo.get_walker(reverse=True))]
        self.total_revs = len(self.revList)

        if starting_revision is None:
            self.revStart = self.revList[0]
        else:
            self.revStart = short(starting_revision)

        # get the head revision number
        if ending_revision is None:
            self.revEnd = self.revList[-1]
        else:
            self.revEnd = short(ending_revision)

        # after init, please use _move_next_revision to change these
        self.revCurr = None

        self.changes = None
        self.log = None

        self.default_lexer = None
        self.default_parser = None

        # sort out lexer and parser lists
        self.lexers = dict()
        for ext, lexers in self.project.lexers.iteritems():
            self.lexers[ext] = list()
            for lexer in lexers:
                if lexer[0] is None:
                    self.default_lexer = lexer[1]
                else:
                    sl = short(lexer[0])
                    if sl in self.revList:
                        i = self.revList.index(sl)
                        self.lexers[ext].append((i,lexer[0],lexer[1]))

        print(self.lexers)

        self.parsers = dict()
        for ext, parsers in self.project.parsers.iteritems():
            self.parsers[ext] = list()
            for parser in parsers:
                if parser[0] is None:
                    self.default_parser = parser[1]
                else:
                    sl = short(parser[0])
                    if sl in self.revList:
                        i = self.revList.index(sl)
                        self.parsers[ext].append((i,parser[0],parser[1]))

        print(self.parsers)
Exemplo n.º 3
0
    def _process_ch(self):
        # This in combination with the for loops calling it replaces
        # the need for a GitPatch(Patch) class
        patch_file = StringIO()

        dulwich.patch.write_object_diff(patch_file, self.repo.object_store,
                (self.changes.old.path, self.changes.old.mode, self.changes.old.sha),
                (self.changes.new.path, self.changes.new.mode, self.changes.new.sha))
        patch_lines = patch_file.getvalue()
        patch_lines = patch_lines.split('\n')

        # parse for the changes
        diff = GitDiff(self, patch_lines)
        diff.old_source = self.changes.old.path
        diff.new_source = self.changes.new.path
        if self.changes.old.sha is not None:
            diff.old_revision_id = short(self.log.parent_commit_id)

        if self.changes.new.sha is not None:
            diff.new_revision_id = short(self.log.commit_id)

        af = diff.get_affected()

        return af
Exemplo n.º 4
0
    def get_lexer(self, revision_number, file_ext):
        if file_ext not in self.lexers:
            return None

        lexers = sorted(self.lexers[file_ext], key=lambda l: l[0],
                reverse=True)

        # lexer list is now in descending order, so we can just return on
        # first lexer revision number is greater than
        for index, old_id, lexer in lexers:
            sl = short(revision_number)
            if sl in self.revList:
                i = self.revList.index(sl)
                if i > index:
                    return lexer

        return self.default_lexer
Exemplo n.º 5
0
 def print_status(self):
     self.count += 1
     print('%f complete (%d/%d) -- git Revision %s..%s' % (
         (float(self.count)/float(self.total_revs))*100,
         self.count, self.total_revs,
         short(self.log.parent_commit_id), short(self.log.commit_id)))