def get_change_for_commit(commit, ctx):
     """Given a commit sha1, find the corresponding perforce change.
     """
     object_type = p4gf_object_type.sha1_to_object_type(
                           sha1           = commit
                         , view_name      = ctx.config.view_name
                         , p4             = ctx.p4gf
                         , raise_on_error = False)
     if not object_type:
         return None
     return object_type.view_name_to_changelist(ctx.config.view_name)
 def get_change_for_commit(commit, ctx):
     """Given a commit sha1, find the corresponding perforce change.
     """
     object_type = p4gf_object_type.sha1_to_object_type(
         sha1=commit,
         view_name=ctx.config.view_name,
         p4=ctx.p4gf,
         raise_on_error=False)
     if not object_type:
         return None
     return object_type.view_name_to_changelist(ctx.config.view_name)
Exemple #3
0
    def __init__(self, ctx,
                 testing_head_sha1=None,    # Only for testing, set to bypass
                                            # p4gf_object_type.sha1_to_object_type(),
                                            # set to -1 to leave self.good[] empty.
                 testing_head_change=None): # Only for testing
        self.ctx = ctx

        LOG.debug("checker init")
        # List of CommitChange tuples.
        #
        # As we copy from git to Perforce, record the most recent git
        # commit we just copied to Perforce, and the Perforce changelist
        # number that corresponds with that change. If we see any
        # changes other than this in our view, we know someone else has
        # submitted to our view and that we hit a conflict.
        #
        # element[0] is usally the git commit sha1 and Perforce
        # changelist number that correspond with HEAD at __init__ time.
        self.good                    = []

        # Updated by check(), point to element of good[] or None if no
        # conflict yet.
        self.first_conflict_index    = None

        # Updated by find_conflict_index() when no conflict is found.
        self.last_good_change_number = None

        # Dump out starting state.
        if LOG.isEnabledFor(logging.DEBUG):
            cmd = ['git', 'log', '--oneline', '--all', '--decorate', '-5']
            d = p4gf_util.popen_no_throw(cmd)
            LOG.debug('dumping current state:')
            LOG.debug('{}\n{}'.format(' '.join(cmd), d['out']))
            with ctx.p4.while_tagged(False):
                cmd = ['changes', '-m', '5', '-c', ctx.config.p4client]
                r = ctx.p4.run(cmd)
                LOG.debug('p4 {}\n{}'
                          .format( ' '.join(cmd)
                                 , '\n'.join(r)  ))

        if testing_head_sha1 != None or testing_head_change != None:
            # unit test hook to bypass p4gf_object_type.sha1_to_object_type()
            if testing_head_sha1 != -1:
                self.good.append(CommitChange(testing_head_sha1,
                                              testing_head_change))
        else:
            LOG.debug("checker getting head sha1")
            head_sha1 = p4gf_util.git_head_sha1()
            if head_sha1:
                object_type = p4gf_object_type.sha1_to_object_type(
                                          sha1      = p4gf_util.git_head_sha1()
                                        , view_name = ctx.config.view_name
                                        , p4        = ctx.p4)
                LOG.debug("checker got head sha1")
                if (object_type.type == 'commit'):
                    LOG.debug("checker got commit {}".format(object_type))
                    change_num = object_type.view_name_to_changelist(ctx.config.view_name)   
                    self.good.append(CommitChange(object_type.sha1, change_num))
                    self.last_good_change_number = change_num

        LOG.debug("end of __init__(): {}".format(self))