From: "Darrick J. Wong" <djwong@kernel.org>
To: cem@kernel.org
Cc: linux-xfs@vger.kernel.org, david@fromorbit.com, sandeen@sandeen.net
Subject: [RFC PATCH 3/2] libxfs-apply: allow stgit users to force-apply a patch
Date: Mon, 20 Nov 2023 11:50:21 -0800 [thread overview]
Message-ID: <20231120195021.GF36190@frogsfrogsfrogs> (raw)
In-Reply-To: <20231120151056.710510-1-cem@kernel.org>
From: Darrick J. Wong <djwong@kernel.org>
Currently, libxfs-apply handles merge conflicts in the auto-backported
patches in a somewhat unfriendly way -- either it applies completely
cleanly, or the user has to ^Z, find the raw diff file in /tmp, apply it
by hand, resume the process, and then tell it to skip the patch.
This is annoying, and I've long worked around that by using my handy
stg-force-import script that imports the patch with --reject, undoes the
partially-complete diff, uses patch(1) to import as much of the diff as
possible, and then starts an editor so the caller can clean up the rest.
When patches are fuzzy, patch(1) is /much/ less strict about applying
changes than stg-import. Since Carlos sent in his own workaround for
guilt, I figured I might as well port stg-force-import into libxfs-apply
and contribute that.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
tools/libxfs-apply | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 61 insertions(+), 1 deletion(-)
diff --git a/tools/libxfs-apply b/tools/libxfs-apply
index 097a695f942..3ff46a8cd2b 100755
--- a/tools/libxfs-apply
+++ b/tools/libxfs-apply
@@ -297,6 +297,64 @@ fixup_header_format()
}
+editor() {
+ if [ -n "${EDITOR}" ]; then
+ ${EDITOR} "$@"
+ elif [ -n "${VISUAL}" ]; then
+ ${VISUAL} "$@"
+ elif command -v editor &>/dev/null; then
+ editor "$@"
+ elif command -v nano &>/dev/null; then
+ nano "$@"
+ else
+ echo "No editor available, aborting messily."
+ exit 1
+ fi
+}
+
+stg_force_import()
+{
+ local _patch="$1"
+ local _patch_name="$2"
+
+ # Import patch to get the metadata even though the diff application
+ # might fail due to stg import being very picky. If the patch applies
+ # cleanly, we're done.
+ stg import --reject -n "${_patch_name}" "${_patch}" && return 0
+
+ local tmpfile="${_patch}.stgit"
+ rm -f "${tmpfile}"
+
+ # Erase whatever stgit managed to apply, then use patch(1)'s more
+ # flexible heuristics. Capture the output for later use.
+ stg diff | patch -p1 -R
+ patch -p1 < "${patch}" &> "${tmpfile}"
+ cat "${tmpfile}"
+
+ # Attach any new files created by the patch
+ grep 'create mode' "${patch}" | sed -e 's/^.* mode [0-7]* //g' | while read -r f; do
+ git add "$f"
+ done
+
+ # Remove any existing files deleted by the patch
+ grep 'delete mode' "${patch}" | sed -e 's/^.* mode [0-7]* //g' | while read -r f; do
+ git rm "$f"
+ done
+
+ # Open an editor so the user can clean up the rejects. Use readarray
+ # instead of "<<<" because the latter picks up empty output as a single
+ # line and does variable expansion... stupid bash.
+ readarray -t rej_files < <(grep 'saving rejects to' "${tmpfile}" | \
+ sed -e 's/^.*saving rejects to file //g')
+ rm -f "${tmpfile}"
+ if [ "${#rej_files[@]}" -gt 0 ]; then
+ echo "Opening editor to deal with rejects. Changes commit when you close the editor."
+ editor "${rej_files[@]}"
+ fi
+
+ stg refresh
+}
+
apply_patch()
{
local _patch=$1
@@ -385,11 +443,13 @@ apply_patch()
stg import -n $_patch_name $_new_patch.2
if [ $? -ne 0 ]; then
echo "stgit push failed!"
- read -r -p "Skip or Fail [s|F]? " response
+ read -r -p "Skip, force Apply, or Fail [s|a|F]? " response
if [ -z "$response" -o "$response" != "s" ]; then
echo "Force push patch, fix and refresh."
echo "Restart from commit $_current_commit"
fail "Manual cleanup required!"
+ elif [ "$response" = "a" ]; then
+ stg_force_import "$_patch_name" "$_new_patch.2"
else
echo "Skipping. Manual series file cleanup needed!"
fi
prev parent reply other threads:[~2023-11-20 19:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 15:10 [PATCH 1/2] libxf-apply: Ignore Merge commits cem
2023-11-20 15:10 ` [PATCH 2/2] libxfs-apply: Add option to only import patches into guilt stack cem
2023-11-20 16:49 ` Darrick J. Wong
2023-11-20 18:21 ` Carlos Maiolino
2023-11-20 16:51 ` [PATCH 1/2] libxf-apply: Ignore Merge commits Darrick J. Wong
2023-11-20 18:23 ` Carlos Maiolino
2023-11-20 19:50 ` Darrick J. Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231120195021.GF36190@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=cem@kernel.org \
--cc=david@fromorbit.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox