2021-11-03 07:06:31 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# mfprep tag1 [tag2]
|
|
|
|
#
|
2022-06-03 23:50:20 -05:00
|
|
|
# Find commits in bugfix-2.1.x that are not yet in 2.0.x.
|
2022-05-07 14:58:39 -05:00
|
|
|
#
|
|
|
|
# Specify a version tag to start from, and optional version tag to end at.
|
2022-06-03 23:50:20 -05:00
|
|
|
# For bugfix-2.1.x the tag will be prefixed by dev- to distinguish it from the version tag,
|
|
|
|
# so at every release be sure to create a dev- tag and publish it to origin.
|
2021-11-03 07:06:31 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
SED=$(which gsed sed | head -n1)
|
|
|
|
SELF=`basename "$0"`
|
2022-05-07 14:58:39 -05:00
|
|
|
DRYRUN=0
|
2021-11-03 07:06:31 -05:00
|
|
|
|
|
|
|
[[ $# < 1 || $# > 2 ]] && { echo "Usage $SELF tag1 [tag2]" ; exit 1 ; }
|
|
|
|
|
|
|
|
TAG1=$1
|
|
|
|
TAG2=${2:-"HEAD"}
|
|
|
|
|
2022-05-22 18:42:25 -05:00
|
|
|
DEST=2.1.x
|
|
|
|
|
2021-11-03 07:06:31 -05:00
|
|
|
# Validate that the required tags exist
|
|
|
|
|
2022-06-03 23:50:20 -05:00
|
|
|
MTAG=`git tag | grep -e "^dev-$TAG1\$"`
|
|
|
|
[[ -n "$MTAG" ]] || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
|
2021-11-03 07:06:31 -05:00
|
|
|
MTAG=`git tag | grep -e "^$TAG1\$"`
|
2022-05-22 18:42:25 -05:00
|
|
|
[[ -n "$MTAG" ]] || { echo "Can't find tag $TAG1" ; exit 1 ; }
|
2021-11-03 07:06:31 -05:00
|
|
|
|
2022-06-03 23:50:20 -05:00
|
|
|
# Generate log of recent commits for bugfix-2.1.x and DEST
|
2021-11-03 07:06:31 -05:00
|
|
|
|
|
|
|
TMPDIR=`mktemp -d`
|
|
|
|
LOGB="$TMPDIR/log-bf.txt"
|
2022-05-22 18:42:25 -05:00
|
|
|
LOG2="$TMPDIR/log-2x.txt"
|
2021-11-03 07:06:31 -05:00
|
|
|
TMPF="$TMPDIR/tmp.txt"
|
2022-05-22 18:42:25 -05:00
|
|
|
SCRF="$TMPDIR/update-$DEST.sh"
|
2021-11-03 07:06:31 -05:00
|
|
|
|
2022-06-03 23:50:20 -05:00
|
|
|
git checkout bugfix-2.1.x
|
|
|
|
git log --pretty="[%h] %s" dev-$TAG1..$TAG2 | grep -v '\[cron\]' | $SED '1!G;h;$!d' >"$LOGB"
|
2021-11-03 07:06:31 -05:00
|
|
|
|
2022-05-22 18:42:25 -05:00
|
|
|
git checkout $DEST
|
2022-06-03 23:50:20 -05:00
|
|
|
git log --pretty="[%h] %s" $TAG1..$TAG2 | $SED '1!G;h;$!d' >"$LOG2" || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
|
2021-11-03 07:06:31 -05:00
|
|
|
|
2022-05-22 18:42:25 -05:00
|
|
|
# Go through commit text from DEST removing all matches from the bugfix log
|
2021-11-03 07:06:31 -05:00
|
|
|
|
|
|
|
cat "$LOG2" | while read line; do
|
2022-05-22 18:42:25 -05:00
|
|
|
if [[ $line =~ \(((#[0-9]{5}),* *)((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?\)$ ]]; then
|
2022-05-07 14:58:39 -05:00
|
|
|
PATT=""
|
|
|
|
for i in ${!BASH_REMATCH[@]}; do
|
|
|
|
if ((i > 0 && (i % 2 == 0))); then
|
|
|
|
if [[ -n "${BASH_REMATCH[i]}" ]]; then
|
|
|
|
[[ -n "$PATT" ]] && PATT="$PATT|"
|
|
|
|
PATT="$PATT${BASH_REMATCH[i]}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2021-11-03 07:06:31 -05:00
|
|
|
#echo "... $PATT"
|
2022-05-22 18:42:25 -05:00
|
|
|
[[ -n "$PATT" ]] && { grep -vE "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
|
2021-11-03 07:06:31 -05:00
|
|
|
else
|
|
|
|
PATT=$( $SED -E 's/^\[[0-9a-f]{10}\]( . )?(.+)$/\2/' <<<"$line" )
|
2022-05-22 18:42:25 -05:00
|
|
|
[[ -n "$PATT" ]] && { grep -v "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
|
2021-11-03 07:06:31 -05:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Convert remaining commits into git commands
|
|
|
|
|
2022-05-22 18:42:25 -05:00
|
|
|
echo -e "#!/usr/bin/env bash\nset -e\ngit checkout ${DEST}\n" >"$TMPF"
|
2021-11-03 07:06:31 -05:00
|
|
|
cat "$LOGB" | while read line; do
|
|
|
|
if [[ $line =~ ^\[([0-9a-f]{10})\]\ *(.*)$ ]]; then
|
|
|
|
CID=${BASH_REMATCH[1]}
|
|
|
|
REST=${BASH_REMATCH[2]}
|
|
|
|
echo "git cherry-pick $CID ;# $REST" >>"$TMPF"
|
|
|
|
else
|
|
|
|
echo ";# $line" >>"$TMPF"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
mv "$TMPF" "$SCRF"
|
2022-05-22 18:42:25 -05:00
|
|
|
chmod +x "$SCRF"
|
2021-11-03 07:06:31 -05:00
|
|
|
|
2022-05-07 14:58:39 -05:00
|
|
|
((DRYRUN)) && rm -r "$TMPDIR" || open "$TMPDIR"
|