예제 #1
0
def greatest_lesser_change_for_branch(ctx, branch, change_num):
    """Find the change for the branch that is no higher than change_num.

    :param ctx: Git Fusion context
    :param branch: branch for which to find highest change
    :param change_num: the high water mark of changes to find

    :return: ObjectType or None

    """
    results = None
    pattern = p4gf_const.P4GF_P4KEY_INDEX_OT.format(
        repo_name=ctx.config.repo_name, change_num='*', branch_id=branch.branch_id)
    LOG.debug("greatest_lesser_change_for_branch() pattern %s", pattern)
    d = p4gf_p4key.get_all(ctx.p4gf, pattern)
    if d:
        for key, value in d.items():
            mk = p4gf_object_type_util.KEY_BRANCH_REGEX.search(key)
            if not mk:
                LOG.debug("ignoring unexpected p4key: %s", key)
                continue
            branch_id = mk.group('branch_id')
            cl = int(mk.group('change_num'))
            if cl <= int(change_num):
                # Ensure we keep the highest change found so far for this branch.
                if results and int(results.change_num) > cl:
                    continue
                LOG.debug("greatest_lesser_change_for_branch() candidate %s, %s, %s",
                          branch_id, cl, value)
                results = ObjectType.create_commit(sha1=value, repo_name=ctx.config.repo_name,
                                                   change_num=cl, branch_id=branch_id)
    LOG.debug("greatest_lesser_change_for_branch() returning %s", results)
    return results
예제 #2
0
    def _create_ot_to_delete_git_ref(self, branch):
        """Return a fake ObjectType instance that tells us to delete this
        branch's Git reference later.

        Use _is_ot_to_delete_git_ref() to detect these fake instances.
        """
        return ObjectType.create_commit(
                  sha1       = p4gf_const.NULL_COMMIT_SHA1
                , repo_name  = self.ctx.config.repo_name
                , change_num = 0
                , branch_id  = branch.branch_id )