Skip to content

git-import-srpm: script to create branches in source repos from sRPMs revision.#781

Closed
casasnovas wants to merge 4 commits intomasterfrom
quentin-git-import-srpm
Closed

git-import-srpm: script to create branches in source repos from sRPMs revision.#781
casasnovas wants to merge 4 commits intomasterfrom
quentin-git-import-srpm

Conversation

@casasnovas
Copy link
Copy Markdown

@casasnovas casasnovas commented Feb 3, 2026

On Debian derivatives, you'll need:
sudo apt-get install rpm

Simply run it inside a SRPM git repository and give it a revision (can be
tag, branch, sha1, ...), e.g.:

CODE_REPO_PATH=/path/to/linux/repo SRPM_REPO_PATH=/path/kernel/srpm/repo git-import-srpm XS-8.2.1

To import all releases as branches, just pass --all:

git-import-srpm --all

By default, the SRPM_REPO_PATH is the current working directory. If no
CODE_REPO_PATH is given, a default path is inferred that is
${SRPM_REPO_PATH}/../(linux|xen|qemu) (depending on the product).

The script was used import all branches of qemu, xen and the Linux kernel
released in current and prior XCP versions, e.g.:

The script gives idempotent runs, reconstructed git sha1 will stay the same
across runs for a given srpm revision. The script will not touch any of your
repository worktrees or indexes, so it is safe to run any time even if you are
working in the source repo (patches are applied separately in a temporary worktree).

Note that for each srpm revision, the script will create two branches in the source
repository, in the form:

<product>/(xcpng|xenserver)-<version>/(pre-base|base)

The pre-base ref will point to the upstream commit that was used as basis by
the source RPM before applying patches. Effectively, the patch-set applied by
a source rpm can be rev-listed with git log .../pre-base../base which allows
see-ing how the patchset evolved over time.

Signed-off-by: Quentin Casasnovas quentin.casasnovas@vates.tech

@casasnovas casasnovas requested a review from fallen February 3, 2026 16:01
Comment thread scripts/git-import-srpm Outdated
Comment thread scripts/git-import-srpm Outdated
Comment thread scripts/git-import-srpm Outdated
Comment thread scripts/git-import-srpm Outdated
Comment thread scripts/git-import-srpm Outdated
@fallen
Copy link
Copy Markdown
Contributor

fallen commented Feb 3, 2026

I don't have time for a full review today but I'll get back to this PR in the next days :)
It looks good anyway! Thanks!

… revisions.

Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
@casasnovas casasnovas force-pushed the quentin-git-import-srpm branch from ea15c23 to 06ab679 Compare February 3, 2026 16:40
Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
@casasnovas casasnovas force-pushed the quentin-git-import-srpm branch from 06ab679 to 2ac523b Compare February 4, 2026 07:51
Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
Comment thread scripts/git-import-srpm Outdated
@fallen
Copy link
Copy Markdown
Contributor

fallen commented Feb 4, 2026

I would generally encourage to run shellcheck on your script, it seems there are a few issues :)

Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
@casasnovas casasnovas force-pushed the quentin-git-import-srpm branch from 7fa6737 to 2d8f5e6 Compare February 5, 2026 07:46
@casasnovas
Copy link
Copy Markdown
Author

casasnovas commented Feb 5, 2026

Oops that's embarassing, I thought my lsp-mode would run it in my editor, but I didn't have shellcheck installed so it silently didn't warn me about anything...

I should have fixed all shellcheck warnings/style/errors and info checks, and I've re-imported all qemu branches locally to make sure there was no breakage in functionality.

Let me know if there is anything else you'd like me to change, and thanks for the review!

If you're happy with it I'll squash the intermediate commits, I just did them to facilitate iterative reviews.

@casasnovas casasnovas requested a review from fallen February 9, 2026 11:03
@rzr
Copy link
Copy Markdown
Contributor

rzr commented Feb 12, 2026

This tool seems very similar to:

gbp import-srpm  --help
Usage: gbp import-srpm [options] /path/to/package.src.rpm [target]

https://honk.sigxcpu.org/piki/projects/git-buildpackage/

It works to some extends with RPM on my system, I can make a demo if curious.

@casasnovas
Copy link
Copy Markdown
Author

This tool seems very similar to:

gbp import-srpm  --help
Usage: gbp import-srpm [options] /path/to/package.src.rpm [target]

https://honk.sigxcpu.org/piki/projects/git-buildpackage/

It works to some extends with RPM on my system, I can make a demo if curious.

That looks nice, I didn't know it existed :)

Trying it on qemu isn't really successful here though:

quentin@laptop-tuxedo repos/qemu-rpms $ gbp import-srpm -v ./                                                                                                                                                                                                                                                                                         1
gbp:debug: Trying to import an unpacked srpm from './'
gbp:debug: Found spec file ./SPECS/qemu.spec
gbp:debug: ['git', 'rev-parse', '--show-cdup']
gbp:debug: ['git', 'rev-parse', '--is-bare-repository']
gbp:debug: ['git', 'rev-parse', '--git-dir']
gbp:debug: ['git', 'for-each-ref', '--format=%(refname:short)', 'refs/heads/']
gbp:debug: ['git', 'status', '--porcelain']
gbp:error: File '0001-usb-fix-setup_len-init-CVE-2020-14364.patch' listed in spec not found

The file is present inside SOURCES/ and I didn't find any options to make it look at the right place.

My main worry is that we'd still need to wrap it into something that does branch deduplication, branch name creation, git history stitching to upstream tags and likely it doesn't support idempotency (creating same git sha1 for same starting point + patch). I'm happy to use it as the backend instead of the apply_patch function here if it does work though and we see any advantages.

Another tiny cons is the sheer amount of dependencies installing git-buildpackage brought in, here it's a tiny self-contained script.

@rzr
Copy link
Copy Markdown
Contributor

rzr commented Feb 13, 2026

https://honk.sigxcpu.org/piki/projects/git-buildpackage/
That looks nice, I didn't know it existed :)

It's coming from debian world and has been adapted to RPMs

I have been using it along gbs long time ago it was a great experience, see in action:

https://youtu.be/DLaD0hHY_F8?t=106#

Trying it on qemu isn't really successful here though:

Let me give a try, I should be manageable.

My main worry is that we'd still need to wrap it into something that does branch deduplication

unsure

Another tiny cons is the sheer amount of dependencies installing git-buildpackage brought in, here it's a tiny self-contained script.

yes, It would requires extra distro integration (i am on it, in my idle time).

@casasnovas
Copy link
Copy Markdown
Author

@fallen any other comments? I'm hoping to move forwards with this PR and potentially add automatic branch importing later. If there are already existing tools that do the job better, I'm happy to use them in a future step.

@rzr
Copy link
Copy Markdown
Contributor

rzr commented Feb 18, 2026

If there are already existing tools that do the job better, I'm happy to use them in a future step.

Well better has to be defined but I managed to use gbp along qemu (need some teaks on my f43), feel free to call me if you want to reproduce, meanwhile here is the overall flow:

import

1st I run:

       gbp import-srpm \
            --create-missing-branches \
            --packaging-branch="${packaging_branch}" \
            --packaging-dir="${packaging_dir}" \
            --upstream-branch="${upstream_branch}" \
            --upstream-vcs-tag="$tag" \
            --vendor="$vendor" \
            --pristine-tar \
            --verbose \
            "${srpm_file}"

See history of:

Patch queue

From this we can generate a patch queue:

gbp pq-rpm --spec-file="${spec_file}"  import

See patches applied on upstream:

Refresh patches (And spec)

And export the serie of patches back to packaging branch (with git context):

gbp pq-rpm --spec-file="${spec_file}" export --no-patch-numbers --verbose

Build again

Check, it will generate files again in SOURCES and SPECS

    gbp buildpackage-rpm \
        --packaging-dir="${packaging_dir}" \
        --git-packaging-branch="${packaging_branch}" \
        --git-upstream-branch="${upstream_branch}" \
        --git-spec-file="${spec_file}" \
        --git-native=no \
        --git-pristine-tar \
        --git-pristine-tar-commit \
        --git-force-create \
        --git-ignore-new \
        --git-no-build \
        --verbose \

Which is same inputs used in xcp-ng-rpm

In theory a srpm should be rebuildable from git too (WIP)

cc: @stormi @ydirson

@fallen
Copy link
Copy Markdown
Contributor

fallen commented Feb 18, 2026

Thanks @rzr for sharing this other possible workflow.
@ydirson has created a meeting so that we can discuss further the topic of those two PRs.

@casasnovas
Copy link
Copy Markdown
Author

Thanks @rzr for going through with this! From what I can tell, there is indeed a lack of idempotency when creating the branches, although maybe that could be work-arounded in the tool itself.

My take on this is that git-import-srpm is small, self-contained, without external dependencies, so easier to maintain overall, and provides a simpler interface while supporting idempotent runs and stitching of history in one single operation. It also work in temporary worktrees so does not affect your local repos. For all these reasons I'd go for KISS approach and keep git-import-srpm.

@casasnovas
Copy link
Copy Markdown
Author

Would it be acceptable if I moved this script into https://github.com/xcp-ng/hypervisor-dev, and just add some hooks to some github workflows to run it automatically for the packages we (Hypervisor&Kernel) support/maintain?

This way we (H&K team) can work on our own automation and explore ways to improve our developer experience without this being perceived as a shared process impacting any other teams. And when the platform team works on this topic in the future, there won't be things in the way, and we can simply remove our hooks.

What do you guys think?

@stormi
Copy link
Copy Markdown
Member

stormi commented Mar 3, 2026

Would it be acceptable if I moved this script into https://github.com/xcp-ng/hypervisor-dev, and just add some hooks to some github workflows to run it automatically for the packages we (Hypervisor&Kernel) support/maintain?

This way we (H&K team) can work on our own automation and explore ways to improve our developer experience without this being perceived as a shared process impacting any other teams. And when the platform team works on this topic in the future, there won't be things in the way, and we can simply remove our hooks.

What do you guys think?

I think that's consistent with the outcome of the discussions we had on the topic all together.

@ydirson
Copy link
Copy Markdown
Contributor

ydirson commented Mar 11, 2026

Maybe the script should be renamed, today its name is quite close to existing import_srpm.py so the difference between them is not obvious to a fresh eye.

What about aligning with similar "import to git" scripts like git-(arch|cvs|quilt)import and go with git-srpmimport? That does not change much, but at least the naming convention can help those familiar with it.

casasnovas added a commit to xcp-ng/hypervisor-dev that referenced this pull request Mar 13, 2026
…itory.

On Debian derivatives, you'll need:
  sudo apt-get install rpm

Simply run it inside a SRPM git repository and give it a revision (can be
tag, branch, sha1, ...), e.g.:

```bash
CODE_REPO_PATH=/path/to/linux/repo SRPM_REPO_PATH=/path/kernel/srpm/repo git-import-srpm XS-8.2.1
```

To import all releases as branches, just pass --all:

```bash
git-import-srpm --all
```

By default, the `SRPM_REPO_PATH` is the current working directory. If no
`CODE_REPO_PATH` is given, a default path is inferred that is
`${SRPM_REPO_PATH}/../(linux|xen|qemu)` (depending on the package being
imported).

The script was used import all branches of qemu, xen and the Linux kernel
released in current and prior XCP versions, e.g.:

- xen branch example: https://github.com/xcp-ng/xen/tree/xen/xcpng-4.17.5-23.1/base
- qemu branch example: https://github.com/xcp-ng/qemu-dp/tree/qemu/xcpng-4.2.1-5.2.15.2/base
- linux branch example: https://github.com/xcp-ng/linux/tree/linux/xcpng-4.19.19-8.0.32.1/base

The script gives idempotent runs, reconstructed git sha1 will stay the same
across runs for a given srpm revision. The script will not touch any of your
repository worktrees or indexes, so it is safe to run any time even if you are
working in the source repo (patches are applied separately in a temporary worktree).

Note that for each srpm revision, the script will create two branches in the source
repository, in the form:

<product>/(xcpng|xenserver)-<version>/(pre-base|base)

The pre-base ref will point to the upstream commit that was used as basis
by the source RPM before applying patches. Effectively, the patch-set
applied by a source rpm can be rev-listed with `git log /pre-base../base`
which allows see-ing how the patchset evolved over time.

You can use `git-review-rebase` easily on two imports to see the changes in
the patch-queues.

Original pull-request was on the
[xcp](xcp-ng/xcp#781) repository but after
discussion with the OS&Platform team, it was agreed it is better to have it
here.  Sub-sequent work could try and add github workflows to run this
script automatically when we notice new SRPMs from XenServer, but right now
it is a manual process (so is running [import_srpm.py](https://github.com/xcp-ng/xcp/blob/master/scripts/import_srpm.py)).

Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
@casasnovas
Copy link
Copy Markdown
Author

PR moved to the hypervisor-dev repository:
xcp-ng/hypervisor-dev#7

@casasnovas casasnovas closed this Mar 13, 2026
casasnovas added a commit to xcp-ng/hypervisor-dev that referenced this pull request Mar 16, 2026
…itory.

On Debian derivatives, you'll need:
  sudo apt-get install rpm

Simply run it inside a SRPM git repository and give it a revision (can be
tag, branch, sha1, ...), e.g.:

```bash
CODE_REPO_PATH=/path/to/linux/repo SRPM_REPO_PATH=/path/kernel/srpm/repo git-import-srpm XS-8.2.1
```

To import all releases as branches, just pass --all:

```bash
git-import-srpm --all
```

By default, the `SRPM_REPO_PATH` is the current working directory. If no
`CODE_REPO_PATH` is given, a default path is inferred that is
`${SRPM_REPO_PATH}/../(linux|xen|qemu)` (depending on the package being
imported).

The script was used import all branches of qemu, xen and the Linux kernel
released in current and prior XCP versions, e.g.:

- xen branch example: https://github.com/xcp-ng/xen/tree/xen/xcpng-4.17.5-23.1/base
- qemu branch example: https://github.com/xcp-ng/qemu-dp/tree/qemu/xcpng-4.2.1-5.2.15.2/base
- linux branch example: https://github.com/xcp-ng/linux/tree/linux/xcpng-4.19.19-8.0.32.1/base

The script gives idempotent runs, reconstructed git sha1 will stay the same
across runs for a given srpm revision. The script will not touch any of your
repository worktrees or indexes, so it is safe to run any time even if you are
working in the source repo (patches are applied separately in a temporary worktree).

Note that for each srpm revision, the script will create two branches in the source
repository, in the form:

<product>/(xcpng|xenserver)-<version>/(pre-base|base)

The pre-base ref will point to the upstream commit that was used as basis
by the source RPM before applying patches. Effectively, the patch-set
applied by a source rpm can be rev-listed with `git log /pre-base../base`
which allows see-ing how the patchset evolved over time.

You can use `git-review-rebase` easily on two imports to see the changes in
the patch-queues.

Original pull-request was on the
[xcp](xcp-ng/xcp#781) repository but after
discussion with the OS&Platform team, it was agreed it is better to have it
here.  Sub-sequent work could try and add github workflows to run this
script automatically when we notice new SRPMs from XenServer, but right now
it is a manual process (so is running [import_srpm.py](https://github.com/xcp-ng/xcp/blob/master/scripts/import_srpm.py)).

Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
casasnovas added a commit to xcp-ng/hypervisor-dev that referenced this pull request Mar 16, 2026
…itory.

On Debian derivatives, you'll need:
  sudo apt-get install rpm

Simply run it inside a SRPM git repository and give it a revision (can be
tag, branch, sha1, ...), e.g.:

```bash
CODE_REPO_PATH=/path/to/linux/repo SRPM_REPO_PATH=/path/kernel/srpm/repo git-import-srpm XS-8.2.1
```

To import all releases as branches, just pass --all:

```bash
git-import-srpm --all
```

By default, the `SRPM_REPO_PATH` is the current working directory. If no
`CODE_REPO_PATH` is given, a default path is inferred that is
`${SRPM_REPO_PATH}/../(linux|xen|qemu)` (depending on the package being
imported).

The script was used import all branches of qemu, xen and the Linux kernel
released in current and prior XCP versions, e.g.:

- xen branch example: https://github.com/xcp-ng/xen/tree/xen/xcpng-4.17.5-23.1/base
- qemu branch example: https://github.com/xcp-ng/qemu-dp/tree/qemu/xcpng-4.2.1-5.2.15.2/base
- linux branch example: https://github.com/xcp-ng/linux/tree/linux/xcpng-4.19.19-8.0.32.1/base

The script gives idempotent runs, reconstructed git sha1 will stay the same
across runs for a given srpm revision. The script will not touch any of your
repository worktrees or indexes, so it is safe to run any time even if you are
working in the source repo (patches are applied separately in a temporary worktree).

Note that for each srpm revision, the script will create two branches in the source
repository, in the form:

<product>/(xcpng|xenserver)-<version>/(pre-base|base)

The pre-base ref will point to the upstream commit that was used as basis
by the source RPM before applying patches. Effectively, the patch-set
applied by a source rpm can be rev-listed with `git log /pre-base../base`
which allows see-ing how the patchset evolved over time.

You can use `git-review-rebase` easily on two imports to see the changes in
the patch-queues.

Original pull-request was on the
[xcp](xcp-ng/xcp#781) repository but after
discussion with the OS&Platform team, it was agreed it is better to have it
here.  Sub-sequent work could try and add github workflows to run this
script automatically when we notice new SRPMs from XenServer, but right now
it is a manual process (so is running [import_srpm.py](https://github.com/xcp-ng/xcp/blob/master/scripts/import_srpm.py)).

Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
casasnovas added a commit to xcp-ng/hypervisor-dev that referenced this pull request Apr 7, 2026
…itory.

On Debian derivatives, you'll need:
  sudo apt-get install rpm

Simply run it inside a SRPM git repository and give it a revision (can be
tag, branch, sha1, ...), e.g.:

```bash
CODE_REPO_PATH=/path/to/linux/repo SRPM_REPO_PATH=/path/kernel/srpm/repo git-import-srpm XS-8.2.1
```

To import all releases as branches, just pass --all:

```bash
git-import-srpm --all
```

By default, the `SRPM_REPO_PATH` is the current working directory. If no
`CODE_REPO_PATH` is given, a default path is inferred that is
`${SRPM_REPO_PATH}/../(linux|xen|qemu)` (depending on the package being
imported).

The script was used import all branches of qemu, xen and the Linux kernel
released in current and prior XCP versions, e.g.:

- xen branch example: https://github.com/xcp-ng/xen/tree/xen/xcpng-4.17.5-23.1/base
- qemu branch example: https://github.com/xcp-ng/qemu-dp/tree/qemu/xcpng-4.2.1-5.2.15.2/base
- linux branch example: https://github.com/xcp-ng/linux/tree/linux/xcpng-4.19.19-8.0.32.1/base

The script gives idempotent runs, reconstructed git sha1 will stay the same
across runs for a given srpm revision. The script will not touch any of your
repository worktrees or indexes, so it is safe to run any time even if you are
working in the source repo (patches are applied separately in a temporary worktree).

Note that for each srpm revision, the script will create two branches in the source
repository, in the form:

<product>/(xcpng|xenserver)-<version>/(pre-base|base)

The pre-base ref will point to the upstream commit that was used as basis
by the source RPM before applying patches. Effectively, the patch-set
applied by a source rpm can be rev-listed with `git log /pre-base../base`
which allows see-ing how the patchset evolved over time.

You can use `git-review-rebase` easily on two imports to see the changes in
the patch-queues.

Original pull-request was on the
[xcp](xcp-ng/xcp#781) repository but after
discussion with the OS&Platform team, it was agreed it is better to have it
here.  Sub-sequent work could try and add github workflows to run this
script automatically when we notice new SRPMs from XenServer, but right now
it is a manual process (so is running [import_srpm.py](https://github.com/xcp-ng/xcp/blob/master/scripts/import_srpm.py)).

Signed-off-by: Quentin Casasnovas <quentin.casasnovas@vates.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants