From 29c44e1f1e505071df35335b144e2d8bef7219c9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 16 May 2016 17:01:12 +0200 Subject: [PATCH] SCRIPTS: make git-show-backports capable of limiting its history When comparing very different branches, it can take a very long time to scan all commits from the very old common ancestor (eg: haproxy 1.4 to 1.7). Now it is possible to specify a range of commits instead of a specific branch, and the analysis will be limited to this range for all commits. The user is responsible for ensuring that the range covers all possible backports from base to ref, otherwise some of them may be reported missing while they are not. This also works with linux kernels, for example : git-show-backports -u -q -m -r v3.14.69 -b v3.14.65 v3.10.101..HEAD --- scripts/git-show-backports | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/git-show-backports b/scripts/git-show-backports index d8854bf82..cbe40bbc2 100755 --- a/scripts/git-show-backports +++ b/scripts/git-show-backports @@ -28,7 +28,8 @@ # show-backports -q -m -r hapee-r2 hapee-r1 -USAGE="Usage: ${0##*/} [-q] [-m] [-u] [-r reference] [-l logexpr] [-s subject] [-b base] branch [...]" +USAGE="Usage: ${0##*/} [-q] [-m] [-u] [-r reference] [-l logexpr] [-s subject] [-b base] {branch|range} [...]" +BASES=( ) BRANCHES=( ) REF=master BASE= @@ -140,7 +141,22 @@ while [ -n "$1" -a -z "${1##-*}" ]; do esac done -BRANCHES=( "$@" ) +# branches may also appear as id1..id2 to limit the history instead of looking +# back to the common base. The field is left empty if not set. +BRANCHES=( ) +BASES=( ) +while [ $# -gt 0 ]; do + branch="${1##*..}" + if [ "$branch" == "$1" ]; then + base="" + else + base="${1%%..*}" + fi + BASES[${#BRANCHES[@]}]="$base" + BRANCHES[${#BRANCHES[@]}]="$branch" + shift +done + if [ ${#BRANCHES[@]} = 0 ]; then die "$USAGE" fi @@ -170,12 +186,18 @@ rm -f "$WORK/${REF//\//_}" git log --reverse ${LOGEXPR:+--grep $LOGEXPR} --pretty="%H %s" "$BASE".."$REF" | grep "${SUBJECT}" > "$WORK/${branch//\//_}" > "$WORK/${REF//\//_}" # for each branch, enumerate all commits and their ancestry -for branch in "${BRANCHES[@]}"; do + +branch_num=0; +while [ $branch_num -lt "${#BRANCHES[@]}" ]; do + branch="${BRANCHES[$branch_num]}" + base="${BASES[$branch_num]}" + base="${base:-$BASE}" rm -f "$WORK/${branch//\//_}" - git log --reverse --pretty="%H %s" "$BASE".."$branch" | grep "${SUBJECT}" | while read h subject; do + git log --reverse --pretty="%H %s" "$base".."$branch" | grep "${SUBJECT}" | while read h subject; do echo "$h" $(git log -1 --pretty --format=%B "$h" | \ sed -n 's/^commit \([^)]*\) upstream\.$/\1/p;s/^(cherry picked from commit \([^)]*\))/\1/p') done > "$WORK/${branch//\//_}" + (( branch_num++ )) done count=0