Skip to content

Commit 7d38b42

Browse files
committed
cli: rewrite-<uboot,kernel>-patches-needing-rebase
1 parent ab7e8c5 commit 7d38b42

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

lib/functions/cli/commands.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ function armbian_register_commands() {
4242
# Patch to git & patch rewrite, for kernel
4343
["kernel-patches-to-git"]="patch_kernel" # implemented in cli_patch_kernel_pre_run and cli_patch_kernel_run
4444
["rewrite-kernel-patches"]="patch_kernel" # implemented in cli_patch_kernel_pre_run and cli_patch_kernel_run
45+
["rewrite-kernel-patches-needing-rebase"]="patch_kernel" # implemented in cli_patch_kernel_pre_run and cli_patch_kernel_run
4546

4647
# Patch to git & patch rewrite, for u-boot
4748
["uboot-patches-to-git"]="patch_uboot" # implemented in cli_patch_uboot_pre_run and cli_patch_uboot_run
4849
["rewrite-uboot-patches"]="patch_uboot" # implemented in cli_patch_uboot_pre_run and cli_patch_uboot_run
50+
["rewrite-uboot-patches-needing-rebase"]="patch_uboot" # implemented in cli_patch_uboot_pre_run and cli_patch_uboot_run
4951

5052
["build"]="standard_build" # implemented in cli_standard_build_pre_run and cli_standard_build_run
5153
["distccd"]="distccd" # implemented in cli_distccd_pre_run and cli_distccd_run
@@ -114,8 +116,10 @@ function armbian_register_commands() {
114116
["inventory-boards"]="TARGETS_FILE='something_that_does_not_exist_so_defaults_are_used'"
115117

116118
# patching
117-
["rewrite-kernel-patches"]="REWRITE_PATCHES=yes" # rewrite the patches after round-tripping to git: "rebase patches"
118-
["rewrite-uboot-patches"]="REWRITE_PATCHES=yes" # rewrite the patches after round-tripping to git: "rebase patches"
119+
["rewrite-kernel-patches"]="REWRITE_PATCHES='yes'" # rewrite the patches after round-tripping to git: "rebase patches"
120+
["rewrite-uboot-patches"]="REWRITE_PATCHES='yes'" # rewrite the patches after round-tripping to git: "rebase patches"
121+
["rewrite-kernel-patches-needing-rebase"]="REWRITE_PATCHES='yes' REWRITE_PATCHES_NEEDING_REBASE='yes'"
122+
["rewrite-uboot-patches-needing-rebase"]="REWRITE_PATCHES='yes' REWRITE_PATCHES_NEEDING_REBASE='yes'"
119123

120124
# artifact shortcuts
121125
["rootfs"]="WHAT='rootfs' ${common_cli_artifact_vars}"

lib/functions/compilation/kernel-patching.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ function kernel_main_patching_python() {
3838
"PATH=${PATH}"
3939
"HOME=${HOME}"
4040
# What to do?
41-
"APPLY_PATCHES=yes" # Apply the patches to the filesystem. Does not imply git commiting. If no, still exports the hash.
42-
"PATCHES_TO_GIT=${PATCHES_TO_GIT:-no}" # Commit to git after applying the patches.
43-
"REWRITE_PATCHES=${REWRITE_PATCHES:-no}" # Rewrite the original patch files after git commiting.
41+
"APPLY_PATCHES=yes" # Apply the patches to the filesystem. Does not imply git commiting. If no, still exports the hash.
42+
"PATCHES_TO_GIT=${PATCHES_TO_GIT:-no}" # Commit to git after applying the patches.
43+
"REWRITE_PATCHES=${REWRITE_PATCHES:-no}" # Rewrite the original patch files after git commiting.
44+
"REWRITE_PATCHES_NEEDING_REBASE=${REWRITE_PATCHES_NEEDING_REBASE:-no}" # Only rewrite those patch files in need of a rebase.
4445
# Git dir, revision, and target branch
4546
"GIT_WORK_DIR=${kernel_work_dir}" # "Where to apply patches?"
4647
"BASE_GIT_REVISION=${kernel_git_revision}" # The revision we're building/patching. Python will reset and clean to this.

lib/functions/compilation/uboot-patching.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ function uboot_main_patching_python() {
3333
"PATH=${PATH}"
3434
"HOME=${HOME}"
3535
# What to do?
36-
"APPLY_PATCHES=yes" # Apply the patches to the filesystem. Does not imply git commiting. If no, still exports the hash.
37-
"PATCHES_TO_GIT=${PATCHES_TO_GIT:-no}" # Commit to git after applying the patches.
38-
"REWRITE_PATCHES=${REWRITE_PATCHES:-no}" # Rewrite the original patch files after git commiting.
36+
"APPLY_PATCHES=yes" # Apply the patches to the filesystem. Does not imply git commiting. If no, still exports the hash.
37+
"PATCHES_TO_GIT=${PATCHES_TO_GIT:-no}" # Commit to git after applying the patches.
38+
"REWRITE_PATCHES=${REWRITE_PATCHES:-no}" # Rewrite the original patch files after git commiting.
39+
"REWRITE_PATCHES_NEEDING_REBASE=${REWRITE_PATCHES_NEEDING_REBASE:-no}" # Only rewrite those patch files in need of a rebase.
3940
# Git dir, revision, and target branch
4041
"GIT_WORK_DIR=${uboot_work_dir}" # "Where to apply patches?"
4142
"BASE_GIT_REVISION=${uboot_git_revision}" # The revision we're building/patching. Python will reset and clean to this.

lib/tools/patching.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
APPLY_PATCHES = armbian_utils.get_from_env("APPLY_PATCHES")
4545
PATCHES_TO_GIT = armbian_utils.get_from_env("PATCHES_TO_GIT")
4646
REWRITE_PATCHES = armbian_utils.get_from_env("REWRITE_PATCHES")
47+
REWRITE_PATCHES_NEEDING_REBASE = armbian_utils.get_from_env("REWRITE_PATCHES_NEEDING_REBASE")
4748
SPLIT_PATCHES = armbian_utils.get_from_env("SPLIT_PATCHES")
4849
ALLOW_RECREATE_EXISTING_FILES = armbian_utils.get_from_env("ALLOW_RECREATE_EXISTING_FILES")
4950
GIT_ARCHEOLOGY = armbian_utils.get_from_env("GIT_ARCHEOLOGY")
@@ -53,6 +54,7 @@
5354
git_archeology = GIT_ARCHEOLOGY == "yes"
5455
fast_archeology = FAST_ARCHEOLOGY == "yes"
5556
rewrite_patches_in_place = REWRITE_PATCHES == "yes"
57+
rewrite_only_patches_needing_rebase = REWRITE_PATCHES_NEEDING_REBASE == "yes"
5658
split_patches = SPLIT_PATCHES == "yes"
5759
apply_options = {
5860
"allow_recreate_existing_files": (ALLOW_RECREATE_EXISTING_FILES == "yes"),
@@ -357,6 +359,12 @@
357359
if one_patch.rewritten_patch is None:
358360
log.warning(f"Skipping patch {one_patch} from rewrite because it was not rewritten.")
359361
continue
362+
363+
# Skip the patch if it doesn't need rebasing
364+
if rewrite_only_patches_needing_rebase:
365+
if "needs_rebase" not in one_patch.problems:
366+
log.info(f"Skipping patch {one_patch} from rewrite because it doesn't need a rebase.")
367+
continue
360368

361369
if one_patch.parent not in patch_files_by_parent:
362370
patch_files_by_parent[one_patch.parent] = []
@@ -365,8 +373,8 @@
365373
for parent in patch_files_by_parent:
366374
patches = patch_files_by_parent[parent]
367375
parent.rewrite_patch_file(patches)
368-
UNAPPLIED_PATCHES = [one_patch for one_patch in VALID_PATCHES if (not one_patch.applied_ok) or (one_patch.rewritten_patch is None)]
369-
for failed_patch in UNAPPLIED_PATCHES:
376+
FAILED_PATCHES = [one_patch for one_patch in VALID_PATCHES if (not one_patch.applied_ok) or (one_patch.rewritten_patch is None)]
377+
for failed_patch in FAILED_PATCHES:
370378
log.info(
371379
f"Consider removing {failed_patch.parent.full_file_path()}(:{failed_patch.counter}); "
372380
f"it was not applied successfully.")

0 commit comments

Comments
 (0)