]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
SCRIPTS: git-show-backports: add a restart-from-last option
authorWilly Tarreau <w@1wt.eu>
Mon, 9 Mar 2026 14:20:35 +0000 (15:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Mar 2026 14:36:05 +0000 (15:36 +0100)
It's always a bit tricky to avoid already backported patches when they
just got a different ID (e.g. a critical fix in a topic branch). Most
often with stable topic branches we just want to pick all stable commits
since the last backported one. New option -L instead of -m does exactly
this: it enumerates only commits that were added to the reference branch
after its most recent backport.

scripts/git-show-backports

index ce2f7c73d349435fe51bc49d1486a93ec04c6ffe..10b666fc3a073a11f28d054b7e7363a414fad10e 100755 (executable)
@@ -28,7 +28,7 @@
 #   show-backports -q -m -r hapee-r2 hapee-r1
 
 
-USAGE="Usage: ${0##*/} [-q] [-H] [-m] [-u] [-r reference] [-l logexpr] [-s subject] [-b base] {branch|range} [...] [-- file*]"
+USAGE="Usage: ${0##*/} [-q] [-H] [-m] [-u] [-L] [-r reference] [-l logexpr] [-s subject] [-b base] {branch|range} [...] [-- file*]"
 BASES=( )
 BRANCHES=( )
 REF=
@@ -39,6 +39,7 @@ SUBJECT=
 MISSING=
 UPSTREAM=
 BODYHASH=
+SINCELAST=
 
 die() {
        [ "$#" -eq 0 ] || echo "$*" >&2
@@ -70,7 +71,7 @@ dump_commit_matrix() {
        count=0
        # now look up commits
        while read ref subject; do
-               if [ -n "$MISSING" -a "${subject:0:9}" = "[RELEASE]" ]; then
+               if [ -n "$MISSING" -o -n "$SINCELAST" ] && [ "${subject:0:9}" = "[RELEASE]" ]; then
                        continue
                fi
 
@@ -153,6 +154,7 @@ while [ -n "$1" -a -z "${1##-*}" ]; do
                -m)        MISSING=1      ; shift   ;;
                -u)        UPSTREAM=1     ; shift   ;;
                -H)        BODYHASH=1     ; shift   ;;
+               -L)        SINCELAST=1    ; shift   ;;
                -h|--help) quit "$USAGE" ;;
                *)         die  "$USAGE" ;;
        esac
@@ -297,9 +299,23 @@ dump_commit_matrix | column -t | \
 (
        left_commits=( )
        right_commits=( )
+       since_last=( )
+       last_bkp=$BASE
        while read line; do
                # append the subject at the end of the line
                set -- $line
+               if [ -n "$SINCELAST" ]; then
+                       if [ "${line::1}" = ":" ]; then
+                               continue
+                       fi
+                       if [ "$2" != "-" ]; then
+                               last_bkp="$1"
+                               since_last=( )
+                       else
+                               since_last[${#since_last[@]}]="$1"
+                       fi
+                       continue
+               fi
                echo -n "$line "
                if [ "${line::1}" = ":" ]; then
                        echo "---- Subject ----"
@@ -315,7 +331,14 @@ dump_commit_matrix | column -t | \
                        right_commits[${#right_commits[@]}]="$comm"
                fi
        done
-       if [ -n "$MISSING" -a ${#left_commits[@]} -eq 0 ]; then
+       if [ -n "$SINCELAST" -a ${#since_last[@]} -eq 0 ]; then
+               echo "No new commit upstream since last commit $last_bkp."
+       elif [ -n "$SINCELAST" ]; then
+               echo "Found ${#since_last[@]} commit(s) added to branch $REF since last backported commit $last_bkp:"
+               echo
+               echo "   git cherry-pick -sx ${since_last[@]}"
+               echo
+       elif [ -n "$MISSING" -a ${#left_commits[@]} -eq 0 ]; then
                echo "No missing commit to apply."
        elif [ -n "$MISSING" ]; then
                echo