]> Untitled Git - hvutilities.git/commitdiff
hvsp: integrate with B4 tool
authorHugo Villeneuve <hugo@hugovil.com>
Mon, 23 Mar 2026 18:00:50 +0000 (14:00 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Tue, 24 Mar 2026 16:27:37 +0000 (12:27 -0400)
Signed-off-by: Hugo Villeneuve <hugo@hugovil.com>
scripts/kernel-send-patches.sh

index d2d4d64fe30da57c2e073e70e9ce0ec64a1e791f..79ca4f8064e250ef330b557bc905c26949e3f69c 100755 (executable)
@@ -55,9 +55,11 @@ compile_script=/tmp/kernel-compile-script.sh
 cover="no"
 series=""
 resend="no"
+preview="no"
 GIT_FORMAT_PATCH_SUBJECT="PATCH"
 GIT_FORMAT_PATCH_OPTS="--histogram"
 skip_compile=0
+use_b4="0"
 
 # Checkpatch options:
 # --no-summary  suppress the per-file summary
@@ -73,19 +75,27 @@ print_usage()
     echo "Usage: ${PROG_NAME} [OPTIONS...]"
     echo
     echo "Options:"
+    echo "  -a   resend patch"
+    echo "  -b   use B4 (default is no)"
     echo "  -d   debug mode"
     echo "  -e   end commit (string)"
     echo "  -f   folder containing patch infos"
     echo "  -h   display this help and exit"
     echo "  -n   dot not compile patches"
-    echo "  -p   resend patch"
+    echo "  -p   preview (send to preview_to mail address only)"
     echo "  -r   really send emails (default = dry-run)"
     echo "  -s   start commit (string)"
     echo
 }
 
-while getopts "de:f:hnprs:" flag ;do
+while getopts "abde:f:hnprs:" flag ;do
     case ${flag} in
+        a)
+            resend="yes"
+            ;;
+        b)
+            use_b4="1"
+            ;;
         d)
             debug="1"
             ;;
@@ -103,7 +113,7 @@ while getopts "de:f:hnprs:" flag ;do
             skip_compile=1
             ;;
         p)
-            resend="yes"
+            preview="yes"
             ;;
         r)
             DRY_RUN=""
@@ -255,7 +265,11 @@ add_cc_list_addresses()
     fi
 
     for address in ${cc_list}; do
-        CC_OPTS="${CC_OPTS} --cc ${address}"
+        if [ "${use_b4}" = "1" ]; then
+            echo "    Cc: ${address}" >> /tmp/cover-letter.txt
+        else
+            CC_OPTS="${CC_OPTS} --cc ${address}"
+        fi
     done
 }
 
@@ -278,15 +292,31 @@ if echo "${commit_end}" | grep -q "^end"; then
     COMMIT_END_SHA1=$(find_preceding_commit_by_log "${commit_end}")
 fi
 
+rm -f /tmp/b4-cover.patch
+rm -rf /tmp/b4-presend-${name}
 rm -rf ${srcdir}/*.patch
 
-# If the cover letter is not between start and end commits, save a copy:
-cp ${srcdir}/cover-letter.txt /tmp
+if [ x"${cover}" = x"yes" ]; then
+    echo "${subject}" > /tmp/cover-letter.txt
+    echo "" >> /tmp/cover-letter.txt
+
+    # Save cover letter to /tmp, because it may no longer be available
+    # once we switch to our patches/compile branch:
+    cat ${srcdir}/cover-letter.txt >> /tmp/cover-letter.txt
+fi
 
-patches_branch="hv_send_patches_${name}"
+if [ "${use_b4}" = "0" ]; then
+    patches_branch="hv_send_patches_${name}"
 
-if [ x"${series}" != x"" ]; then
-    patches_branch="${patches_branch}_v${series}"
+    if [ x"${series}" != x"" ]; then
+        patches_branch="${patches_branch}_v${series}"
+    fi
+else
+    patches_branch="b4/${name}"
+fi
+
+if git branch | grep -q ${patches_branch}; then
+    git branch -D ${patches_branch} 1>/dev/null
 fi
 
 orig_branch=$(git branch --show-current)
@@ -296,66 +326,95 @@ if [ x"${orig_branch}" = x"" ]; then
     exit 1
 fi
 
-if git branch | grep -q ${patches_branch}; then
-    git branch -D ${patches_branch} 1>/dev/null
-fi
-
 if [ "${debug}" = "1" ]; then
     echo "start commit: ${COMMIT_START_SHA1}"
     echo "end commit:   ${COMMIT_END_SHA1}"
 fi
 
+if [ x"${ignore_checkpatch_errors}" != x"" ]; then
+    CHECKPATCH_OPS="${CHECKPATCH_OPS} --ignore ${ignore_checkpatch_errors}"
+fi
+
+add_cc_list_addresses
+
 # Create new branch from base_branch, and apply all our patches onto it:
-git checkout -b ${patches_branch} ${base_branch}
-git branch --set-upstream-to ${base_branch}
-git cherry-pick ${COMMIT_START_SHA1}..${COMMIT_END_SHA1}
 
-GIT_FORMAT_PATCH_OPTS="${GIT_FORMAT_PATCH_OPTS} --base=${base_commit}"
+if [ "${use_b4}" = "1" ]; then
+    b4 prep -n ${name} -f ${base_branch}
+    git show --format=raw HEAD | grep -A 999999 "b4-submit-tracking" >> /tmp/cover-letter.txt
 
-if [ x"${cover}" = x"yes" ]; then
-    GIT_FORMAT_PATCH_OPTS="${GIT_FORMAT_PATCH_OPTS} --cover-letter"
-fi
+    if [ "${prereq_msg_id}" != "" ]; then
+        sed -e "s#\(.*prefixes.*\)#\1,\n  \"prerequisites\": \[\n  \"message-id: <${prereq_msg_id}>\",\n  \"base-commit: ${base_branch}\" \]#" \
+            -i /tmp/cover-letter.txt
+    fi
 
-series_prefix=""
-if [ x"${series}" != x"" -a x"${series}" != x"1" ]; then
-    series_prefix="v${series}-"
-    GIT_FORMAT_PATCH_OPTS="${GIT_FORMAT_PATCH_OPTS} -v ${series}"
-fi
+    git commit --amend --allow-empty --file=/tmp/cover-letter.txt
+
+    if [ "${prereq_msg_id}" != "" ]; then
+        # --no-signature: do not include git version at bottom of generated patch,
+        #                 because this confuses B4:
+        #     --
+        #     2.47.3
+        git format-patch --no-signature --output=/tmp/b4-cover.patch -1 HEAD
+        git reset --hard HEAD~1
+        b4 shazam ${prereq_msg_id}
+        git am --empty=keep /tmp/b4-cover.patch
+    fi
 
-if [ x"${resend}" = x"yes" ]; then
-    GIT_FORMAT_PATCH_SUBJECT="RESEND ${GIT_FORMAT_PATCH_SUBJECT}"
+    git config b4.prep-perpatch-check-cmd "./scripts/checkpatch.pl ${CHECKPATCH_OPS}"
+else
+    git checkout -b ${patches_branch} ${base_branch}
+    git branch --set-upstream-to ${base_branch}
 fi
 
-git format-patch --subject-prefix="${GIT_FORMAT_PATCH_SUBJECT}" \
-    ${GIT_FORMAT_PATCH_OPTS} --output-directory=${srcdir} ${base_branch}
+git cherry-pick ${COMMIT_START_SHA1}..${COMMIT_END_SHA1}
 
-if [ x"${cover}" = x"yes" ]; then
-    # Replace subject line in cover letter:
-    sed -i -e "s@\*\*\* SUB.*@${subject}@" ${srcdir}/${series_prefix}0000-cover-letter.patch
+if [ "${use_b4}" = "1" ]; then
+    b4 prep --check-deps
+    b4 prep --check
+    b4 prep --auto-to-cc
+    b4 send -o /tmp/b4-presend-${name}
+else
+    GIT_FORMAT_PATCH_OPTS="${GIT_FORMAT_PATCH_OPTS} --base=${base_commit}"
 
-    # Replace blurb line in cover letter:
-    sed -i -e "/.*BLURB.*/{r /tmp/cover-letter.txt" -e 'd}' ${srcdir}/${series_prefix}0000-cover-letter.patch
+    if [ x"${cover}" = x"yes" ]; then
+        GIT_FORMAT_PATCH_OPTS="${GIT_FORMAT_PATCH_OPTS} --cover-letter"
+    fi
 
-    collect_email_addresses
-fi
+    series_prefix=""
+    if [ x"${series}" != x"" -a x"${series}" != x"1" ]; then
+        series_prefix="v${series}-"
+        GIT_FORMAT_PATCH_OPTS="${GIT_FORMAT_PATCH_OPTS} -v ${series}"
+    fi
 
-add_cc_list_addresses
+    if [ x"${resend}" = x"yes" ]; then
+        GIT_FORMAT_PATCH_SUBJECT="RESEND ${GIT_FORMAT_PATCH_SUBJECT}"
+    fi
 
-# Check patches (except special case of cover letter patch):
-for p in ${srcdir}/*.patch; do
-    if [ x"$(basename ${p})" != x"${series_prefix}0000-cover-letter.patch" ]; then
-        if [ x"${ignore_checkpatch_errors}" != x"" ]; then
-            set +e
-            CHECKPATCH_OPS="${CHECKPATCH_OPS} --ignore ${ignore_checkpatch_errors}"
-        fi
+    git format-patch --subject-prefix="${GIT_FORMAT_PATCH_SUBJECT}" \
+        ${GIT_FORMAT_PATCH_OPTS} --output-directory=${srcdir} ${base_branch}
 
-        scripts/checkpatch.pl ${CHECKPATCH_OPS} ${p}
+    if [ x"${cover}" = x"yes" ]; then
+        # Replace subject line in cover letter:
+        sed -i -e "s@\*\*\* SUB.*@${subject}@" ${srcdir}/${series_prefix}0000-cover-letter.patch
 
-        if [ x"${ignore_checkpatch_errors}" != x"" ]; then
-            set -e
-        fi
+        # Replace blurb line in cover letter:
+        sed -i -e "/.*BLURB.*/{r /tmp/cover-letter.txt" -e 'd}' ${srcdir}/${series_prefix}0000-cover-letter.patch
+
+        collect_email_addresses
     fi
-done
+
+    # Check patches (except special case of cover letter patch):
+    for p in ${srcdir}/*.patch; do
+        if [ x"$(basename ${p})" != x"${series_prefix}0000-cover-letter.patch" ]; then
+            scripts/checkpatch.pl ${CHECKPATCH_OPS} ${p}
+
+            if [ x"${ignore_checkpatch_errors}" != x"" ]; then
+                set -e
+            fi
+        fi
+    done
+fi
 
 if [ ${skip_compile} -eq 0 ]; then
     cat > ${compile_script} << "EOF"
@@ -380,6 +439,8 @@ EOF
         git branch -D ${temp_compile_branch}
     fi
 
+    current_branch=$(git branch --show-current)
+
     git checkout -b ${temp_compile_branch} ${compile_branch}
 
     # Apply all of our commits to temp_compile_branch:
@@ -387,17 +448,30 @@ EOF
 
     # Compile and test each commit:
     git rebase --exec=${compile_script} ${compile_branch}
-fi
 
-git checkout ${orig_branch}
+    # Return to original branch:
+    git checkout ${current_branch}
 
-if [ ${skip_compile} -eq 0 ]; then
-    # Remove temporary branch:
+    # Remove temporary compile branch:
     git branch -D ${temp_compile_branch}
 fi
 
 # Send email(s)
-git send-email ${DRY_RUN} --annotate --thread --no-chain-reply-to \
-    ${TO_OPTS} ${CC_OPTS} \
-    --8bit-encoding=UTF-8 \
-    ${srcdir}/*.patch
+if [ "${use_b4}" = "1" ]; then
+    if [ "${preview}" = "yes" ]; then
+        if [ "${preview_to}" = "" ]; then
+            echo "Missing preview_to variable"
+            exit 1
+        fi
+
+        b4 send --preview-to ${preview_to}
+    else
+        echo "TODO B4 SEND FOR REAL......................."
+        #b4 send ${DRY_RUN}
+    fi
+else
+    git send-email ${DRY_RUN} --annotate --thread --no-chain-reply-to \
+        ${TO_OPTS} ${CC_OPTS} \
+        --8bit-encoding=UTF-8 \
+        ${srcdir}/*.patch
+fi