maint: Add script to backport my pull requests from nixpkgs

Normally, ~/source/nixpkgs follows the releases, but when I contribute to
nixpkgs, it is convenient to have access to my changes in ~/source/nixpkgs
before next release, ideally even before pull request hits the master.
This commit is contained in:
Dmitry Bogatov 2024-01-01 13:22:00 -05:00
parent 91ab5402c3
commit 2c8893870f
1 changed files with 27 additions and 0 deletions

27
maint/import-commit Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python3
"""
Import commit from specified local repository into a prefix of this monorepository.
"""
import click
import os
import tempfile
from subprocess import check_output, check_call
@click.command()
@click.option("-s", "--source", default="/home/kaction/devel/nix/nixpkgs")
@click.option("-P", "--prefix", default="nixpkgs")
@click.argument("rev")
def main(source, prefix, rev):
with tempfile.TemporaryDirectory() as tempdir:
patch_filename = f"{tempdir}/out.patch"
here = check_output("git rev-parse --show-toplevel".split(), text=True).strip()
with open(patch_filename, "w") as fp:
os.chdir(source)
check_call(["git", "format-patch", "--stdout", f"{rev}~..{rev}"], stdout=fp)
with open(patch_filename) as fp:
os.chdir(here)
check_call(["./maint/prefix-patch", prefix], stdin=fp)
main()