Ejemplo n.º 1
0
def convert_package(repo, options):
    """Convert package to orphan-packaging model"""
    old_packaging = repo.get_branch()
    # Check if we're on pq branch, already
    err_msg_base = "Seems you're already using orphan-packaging model - "
    if is_pq_branch(old_packaging, options):
        raise GbpError(err_msg_base + "you're on patch-queue branch")
    # Check if a pq branch already exists
    spec = parse_spec(options, repo, treeish=old_packaging)
    pq_branch = pq_branch_name(old_packaging, options, spec.version)
    if repo.has_branch(pq_branch):
        pq_branch = pq_branch_name(old_packaging, options, spec.version)
        raise GbpError(err_msg_base +
                       "pq branch %s already exists" % pq_branch)
    # Check that the current branch is based on upstream
    upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
    if not is_ancestor(repo, upstream_commit, old_packaging):
        raise GbpError(err_msg_base +
                       "%s is not based on upstream version %s" %
                       (old_packaging, spec.upstreamversion))
    # Check new branch
    new_branch = old_packaging + "-orphan"
    if repo.has_branch(new_branch):
        if not options.force:
            raise GbpError("Branch '%s' already exists!" % new_branch)
        else:
            gbp.log.info("Dropping branch '%s'" % new_branch)
            repo.delete_branch(new_branch)

    # Determine "history"
    if options.retain_history:
        # Find first commit that has the spec file and list commits from there
        try:
            repo.show('%s:%s' % (upstream_commit, spec.specpath))
            history = repo.get_commits(upstream_commit, old_packaging)
        except GitRepositoryError:
            history_start = repo.get_commits(upstream_commit, old_packaging,
                                             spec.specpath)[-1]
            history = repo.get_commits('%s^' % history_start, old_packaging)
    else:
        history = [repo.rev_parse(old_packaging)]
    history.reverse()

    # Do import
    gbp.log.info("Importing packaging files from branch '%s' to '%s'" %
                 (old_packaging, new_branch))
    convert_with_history(repo, upstream_commit, history, new_branch,
                         spec.specfile, options)
    # Copy extra files
    import_extra_files(repo,
                       old_packaging,
                       options.import_files,
                       patch_ignore=False)

    gbp.log.info("Package successfully converted to orphan-packaging.")
    gbp.log.info("You're now on the new '%s' packaging branch (the old "
                 "packaging branch '%s' was left intact)." %
                 (new_branch, old_packaging))
    gbp.log.info("Please check all files and test building the package!")
Ejemplo n.º 2
0
def maybe_import_pq(repo, branch, options):
    """Import quilt patches onto pq branch if pq branch does not exist yet"""
    if not repo.has_branch(pq_branch_name(branch)):
        gbp.log.info("No pq branch found, importing patches")
        import_pq(repo, branch, options)
        return True
    return False
Ejemplo n.º 3
0
 def test_commit_dropped_patches(self):
     """Test if we commit the patch-queue branch with all patches dropped"""
     repo = self.repo
     start = repo.get_branch()
     pq_branch = os.path.join('patch-queue', start)
     opts = TestExport.Options()
     opts.commit = True
     patch_dir = os.path.join(repo.path, 'debian/patches')
     os.makedirs(patch_dir)
     with open(os.path.join(patch_dir, 'series'), 'w') as f:
         f.write("patch1.diff\n")
         f.write("patch2.diff\n")
     repo.add_files('debian/patches')
     repo.commit_all('Add series file')
     repo.create_branch(pq.pq_branch_name('master'))
     switch_pq(repo, start, opts)
     self.assertEqual(len(repo.get_commits()), 2)
     self.assertEqual(repo.get_branch(), pq_branch)
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertTrue(repo.has_branch(pq_branch))
     self.assertEqual(len(repo.get_commits()), 3,
                      "Export did not create commit")
     self.assertIn(b"Drop patch1.diff:", repo.show('HEAD'))
     self.assertIn(b"Drop patch2.diff:", repo.show('HEAD'))
Ejemplo n.º 4
0
 def test_commit_dropped_patches(self):
     """Test if we commit the patch-queue branch with all patches dropped"""
     repo = self.repo
     start = repo.get_branch()
     pq_branch = os.path.join('patch-queue', start)
     opts = TestExport.Options()
     opts.commit = True
     patch_dir = os.path.join(repo.path, 'debian/patches')
     os.makedirs(patch_dir)
     with open(os.path.join(patch_dir, 'series'), 'w') as f:
         f.write("patch1.diff\n")
         f.write("patch2.diff\n")
     repo.add_files('debian/patches')
     repo.commit_all('Add series file')
     repo.create_branch(pq.pq_branch_name('master'))
     switch_pq(repo, start, opts)
     self.assertEqual(len(repo.get_commits()), 2)
     self.assertEqual(repo.get_branch(), pq_branch)
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertTrue(repo.has_branch(pq_branch))
     self.assertEqual(len(repo.get_commits()), 3,
                      "Export did not create commit")
     self.assertIn(b"Drop patch1.diff:", repo.show('HEAD'))
     self.assertIn(b"Drop patch2.diff:", repo.show('HEAD'))
Ejemplo n.º 5
0
def maybe_import_pq(repo, branch, options):
    """Import quilt patches onto pq branch if pq branch does not exist yet"""
    if not repo.has_branch(pq_branch_name(branch)):
        gbp.log.info("No pq branch found, importing patches")
        import_pq(repo, branch, options)
        return True
    return False
Ejemplo n.º 6
0
    def test_apply_single_patch(self):
        """Test applying a single patch"""

        patch = gbp.patch_series.Patch(_patch_path('foo.patch'))

        self.repo.create_branch(pq.pq_branch_name('master'))
        pq.apply_single_patch(self.repo, 'master', patch, None)
        self.assertIn(b'foo', self.repo.list_files())
Ejemplo n.º 7
0
    def test_apply_single_patch(self):
        """Test applying a single patch"""

        patch = gbp.patch_series.Patch(_patch_path('foo.patch'))

        self.repo.create_branch(pq.pq_branch_name('master'))
        pq.apply_single_patch(self.repo, 'master', patch, None)
        self.assertIn(b'foo', self.repo.list_files())
Ejemplo n.º 8
0
def import_bb_patches(cfg, repo, options):
    """Apply a series of patches in a recipe to branch onto a pq branch"""
    current = repo.get_branch()

    if is_pq_branch(current, options):
        base = pq_branch_base(current, options)
        raise GbpError("Already on a patch-queue branch '%s' - doing "
                       "nothing." % current)
    else:
        bbfile = parse_bb(cfg, options, repo)
        base = current
    upstream_commit = find_upstream_commit(repo, bbfile, options.upstream_tag)
    pq_branch = pq_branch_name(base, options, pkg_version(bbfile))

    # Create pq-branch
    if repo.has_branch(pq_branch) and not options.force:
        raise GbpError("Patch-queue branch '%s' already exists. "
                       "Try 'rebase' instead." % pq_branch)
    try:
        if repo.get_branch() == pq_branch:
            repo.force_head(upstream_commit, hard=True)
        else:
            repo.create_branch(pq_branch, upstream_commit, force=True)
    except GitRepositoryError as err:
        raise GbpError("Cannot create patch-queue branch '%s': %s" %
                       (pq_branch, err))

    # Put patches in a safe place
    in_queue = bb_to_patch_series(bbfile)
    queue = safe_patches(in_queue, options.tmp_dir)
    # Do import
    try:
        gbp.log.info("Switching to branch '%s'" % pq_branch)
        repo.set_branch(pq_branch)
        import_extra_files(repo, base, options.import_files)

        if not queue:
            return
        gbp.log.info("Trying to apply patches from branch '%s' onto '%s'" %
                     (base, upstream_commit))
        for patch in queue:
            gbp.log.debug("Applying %s" % patch.path)
            apply_and_commit_patch(repo, patch, fallback_author=None)
    except (GbpError, GitRepositoryError) as err:
        gbp.log.err('Import failed: %s' % err)
        repo.force_head('HEAD', hard=True)
        repo.set_branch(base)
        repo.delete_branch(pq_branch)
        raise

    recipe_fn = os.path.basename(bbfile.getVar('FILE', True))
    gbp.log.info("Patches listed in '%s' imported on '%s'" %
                 (recipe_fn, pq_branch))
Ejemplo n.º 9
0
    def test_drop(self):
        """Test if we drop the patch-queue branch with --drop"""
        repo = self.repo
        start = repo.get_branch()
        pq_branch = os.path.join('patch-queue', start)
        opts = TestExport.Options()
        opts.drop = True

        repo.create_branch(pq.pq_branch_name('master'))
        switch_pq(repo, start, opts)
        self.assertEqual(repo.get_branch(), pq_branch)
        export_patches(repo, pq_branch, opts)
        self.assertEqual(repo.get_branch(), start)
        self.assertFalse(repo.has_branch(pq_branch))
Ejemplo n.º 10
0
    def test_drop(self):
        """Test if we drop the patch-queue branch with --drop"""
        repo = self.repo
        start = repo.get_branch()
        pq_branch = os.path.join('patch-queue', start)
        opts = TestExport.Options()
        opts.drop = True

        repo.create_branch(pq.pq_branch_name('master'))
        switch_pq(repo, start, opts)
        self.assertEqual(repo.get_branch(), pq_branch)
        export_patches(repo, pq_branch, opts)
        self.assertEqual(repo.get_branch(), start)
        self.assertFalse(repo.has_branch(pq_branch))
Ejemplo n.º 11
0
def export_patches(repo, branch, options):
    """Export patches from the pq branch into a patch series"""
    patch_dir = os.path.join(repo.path, PATCH_DIR)
    series_file = os.path.join(repo.path, SERIES_FILE)
    if is_pq_branch(branch):
        base = pq_branch_base(branch)
        gbp.log.info("On '%s', switching to '%s'" % (branch, base))
        branch = base
        repo.set_branch(branch)

    pq_branch = pq_branch_name(branch)
    try:
        shutil.rmtree(patch_dir)
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise GbpError("Failed to remove patch dir: %s" % e.strerror)
        else:
            gbp.log.debug("%s does not exist." % patch_dir)

    if pq_on_upstream_tag(options.pq_from):
        base = find_upstream_commit(repo, branch, options.upstream_tag)
    else:
        base = branch

    patches = generate_patches(repo, base, pq_branch, patch_dir, options)

    if patches:
        with open(series_file, 'w') as seriesfd:
            for patch in patches:
                seriesfd.write(os.path.relpath(patch, patch_dir) + '\n')
    else:
        gbp.log.info("No patches on '%s' - nothing to export." % pq_branch)

    if options.commit:
        added, removed = commit_patches(repo, branch, patches, options,
                                        patch_dir)
        if added:
            what = 'patches' if len(added) > 1 else 'patch'
            gbp.log.info("Added %s %s to patch series" %
                         (what, ', '.join(added)))
        if removed:
            what = 'patches' if len(removed) > 1 else 'patch'
            gbp.log.info("Removed %s %s from patch series" %
                         (what, ', '.join(removed)))
        else:
            gbp.log.info("Updated existing patches.")

    if options.drop:
        drop_pq(repo, branch)
Ejemplo n.º 12
0
def switch_to_pq_branch(repo, branch, options):
    """
    Switch to patch-queue branch if not already there, create it if it
    doesn't exist yet
    """
    if is_pq_branch(branch, options):
        return

    spec = parse_spec(options, repo, branch)
    pq_branch = pq_branch_name(branch, options, spec.version)
    if not repo.has_branch(pq_branch):
        raise GbpError("Branch '%s' does not exist" % pq_branch)

    gbp.log.info("Switching to branch '%s'" % pq_branch)
    repo.set_branch(pq_branch)
Ejemplo n.º 13
0
def export_patches(repo, branch, options):
    """Export patches from the pq branch into a patch series"""
    if is_pq_branch(branch):
        base = pq_branch_base(branch)
        gbp.log.info("On '%s', switching to '%s'" % (branch, base))
        branch = base
        repo.set_branch(branch)

    pq_branch = pq_branch_name(branch)
    try:
        shutil.rmtree(PATCH_DIR)
    except OSError as (e, msg):
        if e != errno.ENOENT:
            raise GbpError("Failed to remove patch dir: %s" % msg)
        else:
            gbp.log.debug("%s does not exist." % PATCH_DIR)
Ejemplo n.º 14
0
def export_patches(repo, branch, options):
    """Export patches from the pq branch into a patch series"""
    patch_dir = os.path.join(repo.path, PATCH_DIR)
    series_file = os.path.join(repo.path, SERIES_FILE)
    if is_pq_branch(branch):
        base = pq_branch_base(branch)
        gbp.log.info("On '%s', switching to '%s'" % (branch, base))
        branch = base
        repo.set_branch(branch)

    pq_branch = pq_branch_name(branch)
    try:
        shutil.rmtree(patch_dir)
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise GbpError("Failed to remove patch dir: %s" % e.strerror)
        else:
            gbp.log.debug("%s does not exist." % patch_dir)

    if pq_on_upstream_tag(options.pq_from):
        base = find_upstream_commit(repo, branch, options.upstream_tag)
    else:
        base = branch

    patches = generate_patches(repo, base, pq_branch, patch_dir, options)

    if patches:
        with open(series_file, 'w') as seriesfd:
            for patch in patches:
                seriesfd.write(os.path.relpath(patch, patch_dir) + '\n')
    else:
        gbp.log.info("No patches on '%s' - nothing to export." % pq_branch)

    if options.commit:
        added, removed = commit_patches(repo, branch, patches, options, patch_dir)
        if added:
            what = 'patches' if len(added) > 1 else 'patch'
            gbp.log.info("Added %s %s to patch series" % (what, ', '.join(added)))
        if removed:
            what = 'patches' if len(removed) > 1 else 'patch'
            gbp.log.info("Removed %s %s from patch series" % (what, ', '.join(removed)))
        else:
            gbp.log.info("Updated existing patches.")

    if options.drop:
        drop_pq(repo, branch)
Ejemplo n.º 15
0
def export_patches(repo, options):
    """Export patches from the pq branch into a packaging branch"""
    current = repo.get_branch()
    if is_pq_branch(current):
        base = pq_branch_base(current)
        gbp.log.info("On branch '%s', switching to '%s'" % (current, base))
        repo.set_branch(base)
        pq_branch = current
    else:
        pq_branch = pq_branch_name(current)
    spec = parse_spec(options, repo)
    upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
    export_treeish = pq_branch

    update_patch_series(repo, spec, upstream_commit, export_treeish, options)

    GitCommand('status')(['--', spec.specdir])
Ejemplo n.º 16
0
def export_patches(repo, options):
    """Export patches from the pq branch into a packaging branch"""
    current = repo.get_branch()
    if is_pq_branch(current):
        base = pq_branch_base(current)
        gbp.log.info("On branch '%s', switching to '%s'" % (current, base))
        repo.set_branch(base)
        pq_branch = current
    else:
        pq_branch = pq_branch_name(current)
    spec = parse_spec(options, repo)
    upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
    export_treeish = pq_branch

    update_patch_series(repo, spec, upstream_commit, export_treeish, options)

    GitCommand('status')(['--', spec.specdir])
Ejemplo n.º 17
0
def export_patches(cfg, repo, options):
    """Export patches from the pq branch into a packaging branch"""
    current = repo.get_branch()
    if is_pq_branch(current, options):
        base = pq_branch_base(current, options)
        gbp.log.info("On branch '%s', switching to '%s'" % (current, base))
        repo.set_branch(base)
        bbfile = parse_bb(cfg, options, repo)
        pq_branch = current
    else:
        bbfile = parse_bb(cfg, options, repo)
        pq_branch = pq_branch_name(current, options, pkg_version(bbfile))
    upstream_commit = find_upstream_commit(repo, bbfile, options.upstream_tag)

    export_treeish = options.export_rev if options.export_rev else pq_branch

    update_patch_series(repo, bbfile, upstream_commit, export_treeish, options)

    bb_dir = os.path.dirname(bbfile.getVar('FILE', True))
    GitCommand('status')(['--', bb_dir])
Ejemplo n.º 18
0
def export_patches(repo, options):
    """Export patches from the pq branch into a packaging branch"""
    current = repo.get_branch()
    if is_pq_branch(current, options):
        base = pq_branch_base(current, options)
        gbp.log.info("On branch '%s', switching to '%s'" % (current, base))
        repo.set_branch(base)
        spec = parse_spec(options, repo)
        pq_branch = current
    else:
        spec = parse_spec(options, repo)
        pq_branch = pq_branch_name(current, options, spec.version)
    upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)

    export_treeish = options.export_rev if options.export_rev else pq_branch
    if not repo.has_treeish(export_treeish):
        raise GbpError('Invalid treeish object %s' % export_treeish)

    update_patch_series(repo, spec, upstream_commit, export_treeish, options)

    GitCommand('status')(['--', spec.specdir])
Ejemplo n.º 19
0
 def test_commit(self):
     """Test if we commit the patch-queue branch with --commit"""
     repo = self.repo
     start = repo.get_branch()
     pq_branch = os.path.join('patch-queue', start)
     opts = TestExport.Options()
     opts.commit = True
     repo.create_branch(pq.pq_branch_name('master'))
     switch_pq(repo, start, opts)
     self.assertEqual(len(repo.get_commits()), 1)
     self.assertEqual(repo.get_branch(), pq_branch)
     self.add_file('foo', 'foo')
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertTrue(repo.has_branch(pq_branch))
     self.assertEqual(len(repo.get_commits()), 2,
                      "Export did not create commit")
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertEqual(len(repo.get_commits()), 2,
                      "Export must not create another commit")
Ejemplo n.º 20
0
 def test_commit(self):
     """Test if we commit the patch-queue branch with --commit"""
     repo = self.repo
     start = repo.get_branch()
     pq_branch = os.path.join('patch-queue', start)
     opts = TestExport.Options()
     opts.commit = True
     repo.create_branch(pq.pq_branch_name('master'))
     switch_pq(repo, start, opts)
     self.assertEqual(len(repo.get_commits()), 1)
     self.assertEqual(repo.get_branch(), pq_branch)
     self.add_file('foo', 'foo')
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertTrue(repo.has_branch(pq_branch))
     self.assertEqual(len(repo.get_commits()), 2,
                      "Export did not create commit")
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertEqual(len(repo.get_commits()), 2,
                      "Export must not create another commit")
Ejemplo n.º 21
0
def export_patches(repo, branch, options):
    """Export patches from the pq branch into a patch series"""
    if is_pq_branch(branch):
        base = pq_branch_base(branch)
        gbp.log.info("On '%s', switching to '%s'" % (branch, base))
        branch = base
        repo.set_branch(branch)

    pq_branch = pq_branch_name(branch)
    try:
        shutil.rmtree(PATCH_DIR)
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise GbpError("Failed to remove patch dir: %s" % e.strerror)
        else:
            gbp.log.debug("%s does not exist." % PATCH_DIR)

    patches = generate_patches(repo, branch, pq_branch, PATCH_DIR, options)

    if patches:
        with open(SERIES_FILE, 'w') as seriesfd:
            for patch in patches:
                seriesfd.write(os.path.relpath(patch, PATCH_DIR) + '\n')
        if options.commit:
            added, removed = commit_patches(repo, branch, patches, options)
            if added:
                what = 'patches' if len(added) > 1 else 'patch'
                gbp.log.info("Added %s %s to patch series" %
                             (what, ', '.join(added)))
            if removed:
                what = 'patches' if len(removed) > 1 else 'patch'
                gbp.log.info("Removed %s %s from patch series" %
                             (what, ', '.join(removed)))
        else:
            GitCommand('status')(['--', PATCH_DIR])
    else:
        gbp.log.info("No patches on '%s' - nothing to do." % pq_branch)

    if options.drop:
        drop_pq(repo, branch)
Ejemplo n.º 22
0
def export_patches(repo, branch, options):
    """Export patches from the pq branch into a patch series"""
    if is_pq_branch(branch):
        base = pq_branch_base(branch)
        gbp.log.info("On '%s', switching to '%s'" % (branch, base))
        branch = base
        repo.set_branch(branch)

    pq_branch = pq_branch_name(branch)
    try:
        shutil.rmtree(PATCH_DIR)
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise GbpError("Failed to remove patch dir: %s" % e.strerror)
        else:
            gbp.log.debug("%s does not exist." % PATCH_DIR)

    patches = generate_patches(repo, branch, pq_branch, PATCH_DIR, options)

    if patches:
        with open(SERIES_FILE, 'w') as seriesfd:
            for patch in patches:
                seriesfd.write(os.path.relpath(patch, PATCH_DIR) + '\n')
        if options.commit:
            added, removed = commit_patches(repo, branch, patches, options)
            if added:
                what = 'patches' if len(added) > 1 else 'patch'
                gbp.log.info("Added %s %s to patch series" % (what, ', '.join(added)))
            if removed:
                what = 'patches' if len(removed) > 1 else 'patch'
                gbp.log.info("Removed %s %s from patch series" % (what, ', '.join(removed)))
        else:
            GitCommand('status')(['--', PATCH_DIR])
    else:
        gbp.log.info("No patches on '%s' - nothing to do." % pq_branch)

    if options.drop:
        drop_pq(repo, branch)
Ejemplo n.º 23
0
def guess_export_params(repo, options):
    """Get commit and tree from where to export packaging and patches"""
    tree = None
    branch = None
    if options.export in wc_names.keys() + [index_name, 'HEAD']:
        branch = get_current_branch(repo)
    elif options.export in repo.get_local_branches():
        branch = options.export
    if branch:
        if is_pq_branch(branch, options):
            packaging_branch = pq_branch_base(branch, options)
            if repo.has_branch(packaging_branch):
                gbp.log.info("It seems you're building a development/patch-"
                             "queue branch. Export target changed to '%s' and "
                             "patch-export enabled!" % packaging_branch)
                options.patch_export = True
                if not options.patch_export_rev:
                    options.patch_export_rev = options.export
                options.export = packaging_branch
            else:
                gbp.log.warn("It seems you're building a development/patch-"
                             "queue branch. No corresponding packaging branch "
                             "found. Build may fail!")
        elif options.patch_export and not options.patch_export_rev:
            tree = get_tree(repo, options.export)
            spec = parse_spec(options, repo, treeish=tree)
            pq_branch = pq_branch_name(branch, options, spec.version)
            if repo.has_branch(pq_branch):
                gbp.log.info("Exporting patches from development/patch-queue "
                             "branch '%s'" % pq_branch)
                options.patch_export_rev = pq_branch
    if tree is None:
        tree = get_tree(repo, options.export)
        spec = parse_spec(options, repo, treeish=tree)

    # Return tree-ish object and relative spec path for for exporting packaging
    return tree, spec.specpath
Ejemplo n.º 24
0
def import_spec_patches(repo, options):
    """
    apply a series of patches in a spec/packaging dir to branch
    the patch-queue branch for 'branch'

    @param repo: git repository to work on
    @param options: command options
    """
    current = repo.get_branch()
    # Get spec and related information
    if is_pq_branch(current):
        base = pq_branch_base(current)
        if options.force:
            spec = parse_spec(options, repo, base)
            spec_treeish = base
        else:
            raise GbpError("Already on a patch-queue branch '%s' - doing "
                           "nothing." % current)
    else:
        spec = parse_spec(options, repo)
        spec_treeish = None
        base = current
    upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
    packager = get_packager(spec)
    pq_branch = pq_branch_name(base)

    # Create pq-branch
    if repo.has_branch(pq_branch) and not options.force:
        raise GbpError("Patch-queue branch '%s' already exists. "
                       "Try 'switch' instead." % pq_branch)
    try:
        if repo.get_branch() == pq_branch:
            repo.force_head(upstream_commit, hard=True)
        else:
            repo.create_branch(pq_branch, upstream_commit, force=True)
    except GitRepositoryError as err:
        raise GbpError("Cannot create patch-queue branch '%s': %s" %
                       (pq_branch, err))

    # Put patches in a safe place
    if spec_treeish:
        packaging_tmp = tempfile.mkdtemp(prefix='dump_')
        packaging_tree = '%s:%s' % (spec_treeish, options.packaging_dir)
        dump_tree(repo,
                  packaging_tmp,
                  packaging_tree,
                  with_submodules=False,
                  recursive=False)
        spec.specdir = packaging_tmp
    in_queue = spec.patchseries()
    queue = safe_patches(in_queue)
    # Do import
    try:
        gbp.log.info("Switching to branch '%s'" % pq_branch)
        repo.set_branch(pq_branch)

        if not queue:
            return
        gbp.log.info("Trying to apply patches from branch '%s' onto '%s'" %
                     (base, upstream_commit))
        for patch in queue:
            gbp.log.debug("Applying %s" % patch.path)
            apply_and_commit_patch(repo, patch, packager)
    except (GbpError, GitRepositoryError) as err:
        repo.set_branch(base)
        repo.delete_branch(pq_branch)
        raise GbpError('Import failed: %s' % err)

    gbp.log.info("%d patches listed in '%s' imported on '%s'" %
                 (len(queue), spec.specfile, pq_branch))
Ejemplo n.º 25
0
def import_quilt_patches(repo, branch, series, tries, force, pq_from,
                         upstream_tag):
    """
    apply a series of quilt patches in the series file 'series' to branch
    the patch-queue branch for 'branch'

    @param repo: git repository to work on
    @param branch: branch to base patch queue on
    @param series: series file to read patches from
    @param tries: try that many times to apply the patches going back one
                  commit in the branches history after each failure.
    @param force: import the patch series even if the branch already exists
    @param pq_from: what to use as the starting point for the pq branch.
                    DEBIAN indicates the current branch, TAG indicates that
                    the corresponding upstream tag should be used.
    @param upstream_tag: upstream tag template to use
    """
    tmpdir = None
    series = os.path.join(repo.path, series)

    if is_pq_branch(branch):
        if force:
            branch = pq_branch_base(branch)
            pq_branch = pq_branch_name(branch)
            repo.checkout(branch)
        else:
            raise GbpError(
                "Already on a patch-queue branch '%s' - doing nothing." %
                branch)
    else:
        pq_branch = pq_branch_name(branch)

    if repo.has_branch(pq_branch):
        if force:
            drop_pq(repo, branch)
        else:
            raise GbpError(
                "Patch queue branch '%s'. already exists. Try 'rebase' or 'switch' instead."
                % pq_branch)

    maintainer = get_maintainer_from_control(repo)
    if pq_on_upstream_tag(pq_from):
        commits = [find_upstream_commit(repo, branch, upstream_tag)]
    else:  # pq_from == 'DEBIAN'
        commits = repo.get_commits(num=tries, first_parent=True)
    # If we go back in history we have to safe our pq so we always try to apply
    # the latest one
    # If we are using the upstream_tag, we always need a copy of the patches
    if len(commits) > 1 or pq_on_upstream_tag(pq_from):
        if os.path.exists(series):
            tmpdir, series = safe_patches(series, repo)

    queue = PatchSeries.read_series_file(series)

    i = len(commits)
    for commit in commits:
        if len(commits) > 1:
            gbp.log.info("%d %s left" % (i, 'tries' if i > 1 else 'try'))
        try:
            gbp.log.info("Trying to apply patches at '%s'" % commit)
            repo.create_branch(pq_branch, commit)
        except GitRepositoryError:
            raise GbpError("Cannot create patch-queue branch '%s'." %
                           pq_branch)

        repo.set_branch(pq_branch)
        for patch in queue:
            gbp.log.debug("Applying %s" % patch.path)
            try:
                name = os.path.basename(patch.path)
                apply_and_commit_patch(repo, patch, maintainer, patch.topic,
                                       name)
            except (GbpError, GitRepositoryError) as e:
                gbp.log.err("Failed to apply '%s': %s" % (patch.path, e))
                repo.force_head('HEAD', hard=True)
                repo.set_branch(branch)
                repo.delete_branch(pq_branch)
                break
        else:
            # All patches applied successfully
            break
        i -= 1
    else:
        raise GbpError("Couldn't apply patches")

    if tmpdir:
        gbp.log.debug("Remove temporary patch safe '%s'" % tmpdir)
        shutil.rmtree(tmpdir)

    return len(queue)
Ejemplo n.º 26
0
def import_quilt_patches(repo, branch, series, tries, force):
    """
    apply a series of quilt patches in the series file 'series' to branch
    the patch-queue branch for 'branch'

    @param repo: git repository to work on
    @param branch: branch to base pqtch queue on
    @param series; series file to read patches from
    @param tries: try that many times to apply the patches going back one
                  commit in the branches history after each failure.
    @param force: import the patch series even if the branch already exists
    """
    tmpdir = None

    if is_pq_branch(branch):
        if force:
            branch = pq_branch_base(branch)
            pq_branch = pq_branch_name(branch)
            repo.checkout(branch)
        else:
            gbp.log.err("Already on a patch-queue branch '%s' - doing nothing." % branch)
            raise GbpError
    else:
        pq_branch = pq_branch_name(branch)

    if repo.has_branch(pq_branch):
        if force:
            drop_pq(repo, branch)
        else:
            raise GbpError("Patch queue branch '%s'. already exists. Try 'rebase' instead."
                           % pq_branch)

    maintainer = get_maintainer_from_control(repo)
    commits = repo.get_commits(num=tries, first_parent=True)
    # If we go back in history we have to safe our pq so we always try to apply
    # the latest one
    if len(commits) > 1:
        tmpdir, series = safe_patches(series)

    queue = PatchSeries.read_series_file(series)

    i = len(commits)
    for commit in commits:
        if len(commits) > 1:
            gbp.log.info("%d %s left" % (i, 'tries' if i > 1 else 'try'))
        try:
            gbp.log.info("Trying to apply patches at '%s'" % commit)
            repo.create_branch(pq_branch, commit)
        except GitRepositoryError:
            raise GbpError("Cannot create patch-queue branch '%s'." % pq_branch)

        repo.set_branch(pq_branch)
        for patch in queue:
            gbp.log.debug("Applying %s" % patch.path)
            try:
                apply_and_commit_patch(repo, patch, maintainer, patch.topic)
            except (GbpError, GitRepositoryError):
                gbp.log.err("Failed to apply '%s'" % patch.path)
                repo.set_branch(branch)
                repo.delete_branch(pq_branch)
                break
        else:
            # All patches applied successfully
            break
        i-=1
    else:
        raise GbpError("Couldn't apply patches")

    if tmpdir:
        gbp.log.debug("Remove temporary patch safe '%s'" % tmpdir)
        shutil.rmtree(tmpdir)
Ejemplo n.º 27
0
def import_quilt_patches(repo, branch, series, tries, force, pq_from,
                         upstream_tag):
    """
    apply a series of quilt patches in the series file 'series' to branch
    the patch-queue branch for 'branch'

    @param repo: git repository to work on
    @param branch: branch to base patch queue on
    @param series: series file to read patches from
    @param tries: try that many times to apply the patches going back one
                  commit in the branches history after each failure.
    @param force: import the patch series even if the branch already exists
    @param pq_from: what to use as the starting point for the pq branch.
                    DEBIAN indicates the current branch, TAG indicates that
                    the corresponding upstream tag should be used.
    @param upstream_tag: upstream tag template to use
    """
    tmpdir = None
    series = os.path.join(repo.path, series)

    if is_pq_branch(branch):
        if force:
            branch = pq_branch_base(branch)
            pq_branch = pq_branch_name(branch)
            repo.checkout(branch)
        else:
            raise GbpError("Already on a patch-queue branch '%s' - doing nothing." % branch)
    else:
        pq_branch = pq_branch_name(branch)

    if repo.has_branch(pq_branch):
        if force:
            drop_pq(repo, branch)
        else:
            raise GbpError("Patch queue branch '%s'. already exists. Try 'rebase' or 'switch' instead."
                           % pq_branch)

    maintainer = get_maintainer_from_control(repo)
    if pq_on_upstream_tag(pq_from):
        commits = [find_upstream_commit(repo, branch, upstream_tag)]
    else:  # pq_from == 'DEBIAN'
        commits = repo.get_commits(num=tries, first_parent=True)
    # If we go back in history we have to safe our pq so we always try to apply
    # the latest one
    # If we are using the upstream_tag, we always need a copy of the patches
    if len(commits) > 1 or pq_on_upstream_tag(pq_from):
        if os.path.exists(series):
            tmpdir, series = safe_patches(series, repo)

    queue = PatchSeries.read_series_file(series)

    i = len(commits)
    for commit in commits:
        if len(commits) > 1:
            gbp.log.info("%d %s left" % (i, 'tries' if i > 1 else 'try'))
        try:
            gbp.log.info("Trying to apply patches at '%s'" % commit)
            repo.create_branch(pq_branch, commit)
        except GitRepositoryError:
            raise GbpError("Cannot create patch-queue branch '%s'." % pq_branch)

        repo.set_branch(pq_branch)
        for patch in queue:
            gbp.log.debug("Applying %s" % patch.path)
            try:
                name = os.path.basename(patch.path)
                apply_and_commit_patch(repo, patch, maintainer, patch.topic, name)
            except (GbpError, GitRepositoryError) as e:
                gbp.log.err("Failed to apply '%s': %s" % (patch.path, e))
                repo.force_head('HEAD', hard=True)
                repo.set_branch(branch)
                repo.delete_branch(pq_branch)
                break
        else:
            # All patches applied successfully
            break
        i -= 1
    else:
        raise GbpError("Couldn't apply patches")

    if tmpdir:
        gbp.log.debug("Remove temporary patch safe '%s'" % tmpdir)
        shutil.rmtree(tmpdir)

    return len(queue)
Ejemplo n.º 28
0
def import_spec_patches(repo, options):
    """
    apply a series of patches in a spec/packaging dir to branch
    the patch-queue branch for 'branch'

    @param repo: git repository to work on
    @param options: command options
    """
    current = repo.get_branch()
    # Get spec and related information
    if is_pq_branch(current):
        base = pq_branch_base(current)
        if options.force:
            spec = parse_spec(options, repo, base)
            spec_treeish = base
        else:
            raise GbpError("Already on a patch-queue branch '%s' - doing "
                           "nothing." % current)
    else:
        spec = parse_spec(options, repo)
        spec_treeish = None
        base = current
    upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
    packager = get_packager(spec)
    pq_branch = pq_branch_name(base)

    # Create pq-branch
    if repo.has_branch(pq_branch) and not options.force:
        raise GbpError("Patch-queue branch '%s' already exists. "
                       "Try 'switch' instead." % pq_branch)
    try:
        if repo.get_branch() == pq_branch:
            repo.force_head(upstream_commit, hard=True)
        else:
            repo.create_branch(pq_branch, upstream_commit, force=True)
    except GitRepositoryError as err:
        raise GbpError("Cannot create patch-queue branch '%s': %s" %
                        (pq_branch, err))

    # Put patches in a safe place
    if spec_treeish:
        packaging_tmp = tempfile.mkdtemp(prefix='dump_', dir=options.tmp_dir)
        packaging_tree = '%s:%s' % (spec_treeish, options.packaging_dir)
        dump_tree(repo, packaging_tmp, packaging_tree, with_submodules=False,
                  recursive=False)
        spec.specdir = packaging_tmp
    in_queue = spec.patchseries()
    queue = safe_patches(in_queue, options.tmp_dir)
    # Do import
    try:
        gbp.log.info("Switching to branch '%s'" % pq_branch)
        repo.set_branch(pq_branch)

        if not queue:
            return
        gbp.log.info("Trying to apply patches from branch '%s' onto '%s'" %
                        (base, upstream_commit))
        for patch in queue:
            gbp.log.debug("Applying %s" % patch.path)
            apply_and_commit_patch(repo, patch, packager)
    except (GbpError, GitRepositoryError) as err:
        repo.set_branch(base)
        repo.delete_branch(pq_branch)
        raise GbpError('Import failed: %s' % err)

    gbp.log.info("Patches listed in '%s' imported on '%s'" % (spec.specfile,
                                                              pq_branch))