示例#1
0
def get_diff_range(diff_range=None, patches_branch=None, branch=None):
    vtag_from, vtag_to = None, None
    if diff_range:
        n = len(diff_range)
        if n > 2:
            raise exception.InvalidUsage(why="diff only supports one or two "
                                             "positional parameters.")
        if n == 2:
            vtag_from, vtag_to = diff_range
        else:
            vtag_to = diff_range[0]
    if not vtag_from:
        if not patches_branch:
            if not branch:
                branch = guess.current_branch()
            patches_branch = guess.patches_branch(branch)
        if not git.ref_exists('refs/remotes/%s' % patches_branch):
            msg = ("Patches branch not found: %s\n"
                   "Can't guess current version.\n\n"
                   "a) provide git tags/refs yourself a la:\n"
                   "   $ rdopkg reqdiff 1.1.1 2.2.2\n\n"
                   "b) add git remote with expected patches branch"
                   % patches_branch)
            raise exception.CantGuess(msg=msg)
        vtag_from = git.get_latest_tag(branch=patches_branch)
    if not vtag_to:
        upstream_branch = guess.upstream_branch()
        vtag_to = git.get_latest_tag(branch=upstream_branch)
    return {
        'version_tag_from': vtag_from,
        'version_tag_to': vtag_to
    }
示例#2
0
def get_diff_range(diff_range=None, patches_branch=None, branch=None):
    vtag_from, vtag_to = None, None
    if diff_range:
        n = len(diff_range)
        if n > 2:
            raise exception.InvalidUsage(why="diff only supports one or two "
                                             "positional parameters.")
        if n == 2:
            vtag_from, vtag_to = diff_range
        else:
            vtag_to = diff_range[0]
    if not vtag_from:
        if not patches_branch:
            if not branch:
                branch = guess.current_branch()
            patches_branch = guess.patches_branch(branch)
        if not git.ref_exists('refs/remotes/%s' % patches_branch):
            msg = ("Patches branch not found: %s\n"
                   "Can't guess current version.\n\n"
                   "a) provide git tags/refs yourself a la:\n"
                   "   $ rdopkg reqdiff 1.1.1 2.2.2\n\n"
                   "b) add git remote with expected patches branch"
                   % patches_branch)
            raise exception.CantGuess(msg=msg)
        vtag_from = git.get_latest_tag(branch=patches_branch)
    if not vtag_to:
        upstream_branch = guess.upstream_branch()
        vtag_to = git.get_latest_tag(branch=upstream_branch)
    return {
        'version_tag_from': vtag_from,
        'version_tag_to': vtag_to
    }
示例#3
0
def review_patch(local_patches_branch=None):
    if not local_patches_branch:
        local_patches_branch = git.current_branch()
        if not local_patches_branch.endswith('-patches'):
            br = guess.patches_branch(local_patches_branch)
            if br:
                local_patches_branch = br.partition('/')[2]
    rpmfactory.review_patch(local_patches_branch)
示例#4
0
def review_patch(local_patches_branch=None):
    if not local_patches_branch:
        local_patches_branch = git.current_branch()
        if not local_patches_branch.endswith('-patches'):
            br = guess.patches_branch(local_patches_branch)
            if br:
                local_patches_branch = br.partition('/')[2]
    rpmfactory.review_patch(local_patches_branch)
示例#5
0
def get_package_env(version=None,
                    release=None,
                    dist=None,
                    branch=None,
                    patches_branch=None,
                    local_patches_branch=None,
                    patches_style=None,
                    gerrit_patches_chain=None,
                    release_bump_index=None):
    if not branch:
        branch = git.current_branch()
    if branch.endswith('-patches'):
        branch = branch[:-8]
        if git.branch_exists(branch):
            log.info(
                "This looks like -patches branch. Assuming distgit branch: "
                "%s" % branch)
            git.checkout(branch)
        else:
            raise exception.InvalidUsage(
                why="This action must be run on a distgit branch.")
    args = {
        'package': guess.package(),
        'branch': branch,
    }
    osdist = guess.osdist()
    if osdist.startswith('RH'):
        log.info("RH package detected.")
        args['fedpkg'] = ['rhpkg']
    if not patches_branch:
        patches_branch = guess.patches_branch(branch,
                                              pkg=args['package'],
                                              osdist=osdist)
    if not patches_style:
        patches_style = guess.patches_style(gerrit_patches_chain)
    args['patches_style'] = patches_style
    args['patches_branch'] = patches_branch
    if release_bump_index is None:
        args['release_bump_index'] = guess.release_bump_index()
    if not local_patches_branch:
        args['local_patches_branch'] = patches_branch.partition('/')[2]
    if not version:
        base_ref = guess.patches_base_ref()
        version, _ = guess.tag2version(base_ref)
        args['version'] = version
    args['version_tag_style'] = guess.version_tag_style(version=version)

    return args
示例#6
0
def get_package_env(version=None, release=None, dist=None, branch=None,
                    patches_branch=None, local_patches_branch=None,
                    patches_style=None, gerrit_patches_chain=None):
    if not branch:
        branch = git.current_branch()
    if branch.endswith('-patches'):
        branch = branch[:-8]
        if git.branch_exists(branch):
            log.info(
                "This looks like -patches branch. Assuming distgit branch: "
                "%s" % branch)
            git.checkout(branch)
        else:
            raise exception.InvalidUsage(
                why="This action must be run on a distgit branch.")
    args = {
        'package': guess.package(),
        'branch': branch,
    }
    if not release or not dist:
        _release, _dist = guess.osreleasedist(branch, default=(None, None))
        if not release and _release:
            args['release'] = _release
        if not dist and _dist:
            args['dist'] = _dist
    osdist = guess.osdist()
    if osdist == 'RHOS':
        log.info("RHOS package detected.")
        args['fedpkg'] = ['rhpkg']
    if not patches_branch:
        patches_branch = guess.patches_branch(branch, pkg=args['package'],
                                              osdist=osdist)
    if not patches_style:
        patches_style = guess.patches_style(gerrit_patches_chain)
    args['patches_style'] = patches_style
    args['patches_branch'] = patches_branch
    if not local_patches_branch:
        args['local_patches_branch'] = patches_branch.partition('/')[2]
    if not version:
        version = guess.current_version()
        args['version'] = version
    args['version_tag_style'] = guess.version_tag_style(version=version)

    return args
示例#7
0
def get_package_env(version=None, release=None, dist=None, branch=None,
                    patches_branch=None, local_patches_branch=None,
                    patches_style=None, gerrit_patches_chain=None,
                    release_bump_index=None):
    if not branch:
        branch = git.current_branch()
    if branch.endswith('-patches'):
        branch = branch[:-8]
        if git.branch_exists(branch):
            log.info(
                "This looks like -patches branch. Assuming distgit branch: "
                "%s" % branch)
            git.checkout(branch)
        else:
            raise exception.InvalidUsage(
                why="This action must be run on a distgit branch.")
    args = {
        'package': guess.package(),
        'branch': branch,
    }
    osdist = guess.osdist()
    if osdist.startswith('RH'):
        log.info("RH package detected.")
        args['fedpkg'] = ['rhpkg']
    if not patches_branch:
        patches_branch = guess.patches_branch(branch, pkg=args['package'],
                                              osdist=osdist)
    if not patches_style:
        patches_style = guess.patches_style(gerrit_patches_chain)
    args['patches_style'] = patches_style
    args['patches_branch'] = patches_branch
    if release_bump_index is None:
        args['release_bump_index'] = guess.release_bump_index()
    if not local_patches_branch:
        args['local_patches_branch'] = patches_branch.partition('/')[2]
    if not version:
        base_ref = guess.patches_base_ref()
        version, _ = guess.tag2version(base_ref)
        args['version'] = version
    args['version_tag_style'] = guess.version_tag_style(version=version)

    return args
示例#8
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument(
        '--patches-branch',
        help='Specify another local "patches" branch, like "ceph-5.0-rhel-patches-bz12345"',
    )
    args = parser.parse_args()
    spec = specfile.Spec()

    name = spec.get_tag('Name', expand_macros=True)  # "ceph"
    version = spec.get_tag('Version', expand_macros=True)  # "12.2.8"
    orig_commit = spec.get_macro('commit')  # "9e20ef1b14ac70dea53123"

    branch = git.current_branch()  # "ceph-3.2-rhel-7"
    tag_style = guess.version_tag_style(version=version)  # "vX.Y.Z"
    base_tag = guess.version2tag(version, tag_style)  # "v12.2.8"
    osdist = guess.osdist()

    # "ceph-3.2-rhel-patches"
    if args.patches_branch:
        patches_branch = args.patches_branch
    else:
        remote_patches_branch = guess.patches_branch(branch, pkg=name,
                                                     osdist=osdist)
        patches_branch = remote_patches_branch.partition('/')[2]

    patches_sha = git('rev-parse', patches_branch)  # "9e20ef1b14ac70dea53123"

    archive_basename = '%s-%s' % (name, version)  # "ceph-12.2.8"
    patches_base, patches_base_commits = spec.get_patches_base()
    if patches_base_commits != 0:
        # We don't yet support the "+n_commits" syntax for patches_base.
        raise NotImplementedError('use a plain ref in patches_base')
    if patches_base is None:
        patches_base = base_tag
    filenames = diff_filenames(patches_base, patches_branch)
    if not filenames:
        # todo: make this a silent no-op eventually
        log.warning('%s identical to %s' % (patches_branch, patches_base))
        raise RuntimeError(patches_base)

    tarball = archive_files(archive_basename, patches_sha, filenames)
    log.info('wrote %s' % tarball)

    # Ensure our spec file will reference this tarball.
    spec.set_macro('commit', patches_sha)
    set_source1(spec)
    spec.save()

    # Find the changelog entries from the Git -patches branch.
    changes = check_new_commits(patches_base, orig_commit, patches_sha)

    if not changes:
        log.info('no changes. exiting')
        raise SystemExit(1)

    # Bump the release and add the %changelog entries.

    # Insert %changelog.
    rdopkg.actions.distgit.actions.update_spec(branch=branch, changes=changes)

    # add + upload this new tarball.
    if guess.new_sources():
        fedpkg = 'fedpkg'
        if osdist.startswith('RH'):
            fedpkg = 'rhpkg'
        clear_old_changes_sources()
        run(fedpkg, 'upload', tarball, direct=True)

    # Commit everything to dist-git
    rdopkg.actions.distgit.actions.commit_distgit_update(branch=branch,
                                                         local_patches_branch=patches_branch)
    # Show the final commit
    rdopkg.actions.distgit.actions.final_spec_diff(branch=branch)