On Fri, Jan 30, 2026 at 10:00 AM Joe Lawrence <[email protected]> wrote: > > The klp-build script is currently very strict with input patches, > requiring them to apply cleanly via `git apply --recount`. This > prevents the use of patches with minor contextual fuzz relative to the > target kernel sources. > > Add an optional -z/--fuzz option to allow klp-build to "rebase" input > patches within its klp-tmp/ scratch space. When enabled, the script > utilizes GNU patch's fuzzy matching to apply changes to a temporary > directory and then creates a normalized version of the patch using `git > diff --no-index`. > > This rebased patch contains the exact line counts and context required > for the subsequent klp-build fixup and build steps, allowing users to > reuse a patch across similar kernel streams. > > Signed-off-by: Joe Lawrence <[email protected]>
LTGM. Acked-by: Song Liu <[email protected]> With one nitpick below. [...] > > +# Rebase a patch using GNU patch with fuzz > +# Outputs path to rebased patch on success, non-zero on failure > +rebase_patch() { > + local idx="$1" > + local input_patch="$2" > + local patch_name="$(basename "$input_patch" .patch)" > + local work_dir="$REBASE_DIR/$idx-$patch_name" > + local output_patch="$work_dir/rebased.patch" > + local files=() > + local file > + > + rm -rf "$work_dir" > + mkdir -p "$work_dir/orig" "$work_dir/patched" > + > + get_patch_files "$input_patch" | mapfile -t files > + > + # Copy original files (before patch) > + for file in "${files[@]}"; do > + [[ "$file" == "dev/null" ]] && continue > + if [[ -f "$SRC/$file" ]]; then > + mkdir -p "$work_dir/orig/$(dirname "$file")" > + cp -f "$SRC/$file" "$work_dir/orig/$file" > + fi > + done > + > + # Apply with fuzz > + ( > + cd "$SRC" > + sed -n '/^-- /q;p' "$input_patch" | \ > + patch -p1 \ I think we should add -s here, and. > + -F"$FUZZ_FACTOR" \ > + --no-backup-if-mismatch \ > + -r /dev/null \ > + --forward >&2 > + ) || return 1 > + > + # Copy patched files (after patch) > + for file in "${files[@]}"; do > + [[ "$file" == "dev/null" ]] && continue > + if [[ -f "$SRC/$file" ]]; then > + mkdir -p "$work_dir/patched/$(dirname "$file")" > + cp -f "$SRC/$file" "$work_dir/patched/$file" > + fi > + done > + > + # Revert with fuzz > + ( > + cd "$SRC" > + sed -n '/^-- /q;p' "$input_patch" | \ > + patch -p1 -R \ .. here, so that we can avoid a bunch of "patching file" messages. > + -F"$FUZZ_FACTOR" \ > + --no-backup-if-mismatch \ > + -r /dev/null >&2 > + ) || { > + warn "fuzzy revert failed; source tree may be corrupted" > + return 1 > + }
