mirror of
https://git.yoctoproject.org/poky
synced 2026-03-19 13:49:41 +01:00
The script was sending one patch at a time, which defeats the internal confirmation mechanism of git-send-email (which would otherwise allow the user to send all patches or abort immediately). Rework the sending logic to use no more than two commands. Use two commands when the cover letter is to be sent to all recipients with the -a argument. Otherwise, send all patches via the same command. The script duplicates git's send confirmation, eliminate that. Reported-by: Khem Raj <raj.khem@gmail.com> (From OE-Core rev: 71286b32b58d4d1318b0a0a4b09ea65604d0e6fc) Signed-off-by: Darren Hart <dvhart@linux.intel.com> Acked-by: Joshua Lock <josh@linux.intel.com> Acked-by: Otavio Salvador <otavio@ossystems.com.br> Cc: Khem Raj <raj.khem@gmail.com> Cc: Joshua Lock <josh@linux.intel.com> Cc: Otavio Salvador <otavio@ossystems.com.br> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
162 lines
3.6 KiB
Bash
Executable File
162 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
AUTO=0
|
|
AUTO_CL=0
|
|
GITSOBCC=""
|
|
|
|
# Prevent environment leakage to these vars.
|
|
unset TO
|
|
unset CC
|
|
unset AUTO_CC
|
|
|
|
usage()
|
|
{
|
|
cat <<EOM
|
|
Usage: $(basename $0) [-h] [-a] [-c] [[-t email]...] -p pull-dir
|
|
-a Send the cover letter to every recipient listed in Cc and
|
|
Signed-off-by lines found in the cover letter and the patches.
|
|
This option implies -c.
|
|
-c Expand the Cc list for the individual patches using the Cc and
|
|
Signed-off-by lines from the same patch.
|
|
-p pull-dir Directory containing summary and patch files
|
|
-t email Explicitly add email to the recipients
|
|
EOM
|
|
}
|
|
|
|
# Collect addresses from a patch into AUTO_CC
|
|
# $1: a patch file
|
|
harvest_recipients()
|
|
{
|
|
PATCH=$1
|
|
export IFS=$',\n'
|
|
for REGX in "^[Cc][Cc]: *" "^[Ss]igned-[Oo]ff-[Bb]y: *"; do
|
|
for EMAIL in $(sed '/^---$/q' $PATCH | grep -e "$REGX" | sed "s/$REGX//"); do
|
|
if [ "${AUTO_CC/$EMAIL/}" == "$AUTO_CC" ] && [ -n "$EMAIL" ]; then
|
|
if [ -z "$AUTO_CC" ]; then
|
|
AUTO_CC=$EMAIL;
|
|
else
|
|
AUTO_CC="$AUTO_CC,$EMAIL";
|
|
fi
|
|
fi
|
|
done
|
|
done
|
|
unset IFS
|
|
}
|
|
|
|
check_git_sendemail_config()
|
|
{
|
|
GIT_SMTP=$(git config sendemail.smtpserver)
|
|
GIT_FROM=$(git config sendemail.from)
|
|
if [ -z "$GIT_SMTP" ] || [ -z "$GIT_FROM" ]; then
|
|
echo "ERROR: git sendemail is not configured."
|
|
echo "Please read GIT-SEND-EMAIL(1) and configure:"
|
|
echo " sendemail.smtpserver"
|
|
echo " sendemail.from"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Parse and verify arguments
|
|
while getopts "achp:t:" OPT; do
|
|
case $OPT in
|
|
a)
|
|
AUTO_CL=1
|
|
# Fall through to include -c
|
|
;&
|
|
c)
|
|
AUTO=1
|
|
GITSOBCC="--signed-off-by-cc"
|
|
;;
|
|
h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
p)
|
|
PDIR=${OPTARG%/}
|
|
if [ ! -d $PDIR ]; then
|
|
echo "ERROR: pull-dir \"$PDIR\" does not exist."
|
|
usage
|
|
exit 1
|
|
fi
|
|
;;
|
|
t)
|
|
if [ -n "$TO" ]; then
|
|
TO="$TO,$OPTARG"
|
|
else
|
|
TO="$OPTARG"
|
|
fi
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Abort early if git-send-email is not properly configured
|
|
check_git_sendemail_config
|
|
|
|
if [ -z "$PDIR" ]; then
|
|
echo "ERROR: you must specify a pull-dir."
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# Verify the cover letter is complete and free of tokens
|
|
CL="$PDIR/0000-cover-letter.patch"
|
|
for TOKEN in SUBJECT BLURB; do
|
|
grep -q "*** $TOKEN HERE ***" "$CL"
|
|
if [ $? -eq 0 ]; then
|
|
echo "ERROR: Please edit $CL and try again (Look for '*** $TOKEN HERE ***')."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
|
|
# Harvest emails from the generated patches and populate AUTO_CC.
|
|
if [ $AUTO_CL -eq 1 ]; then
|
|
for PATCH in $PDIR/*.patch; do
|
|
harvest_recipients $PATCH
|
|
done
|
|
fi
|
|
|
|
AUTO_TO="$(git config sendemail.to)"
|
|
if [ -n "$AUTO_TO" ]; then
|
|
if [ -n "$TO" ]; then
|
|
TO="$TO,$AUTO_TO"
|
|
else
|
|
TO="$AUTO_TO"
|
|
fi
|
|
fi
|
|
|
|
if [ -z "$TO" ] && [ -z "$AUTO_CC" ]; then
|
|
echo "ERROR: you have not specified any recipients."
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# Convert the collected addresses into git-send-email argument strings
|
|
export IFS=$','
|
|
GIT_TO=$(for R in $TO; do echo -n "--to='$R' "; done)
|
|
GIT_CC=$(for R in $AUTO_CC; do echo -n "--cc='$R' "; done)
|
|
unset IFS
|
|
|
|
|
|
# Handoff to git-send-email. It will perform the send confirmation.
|
|
PATCHES=$(echo $PDIR/*.patch)
|
|
if [ $AUTO_CL -eq 1 ]; then
|
|
# Send the cover letter to every recipient, both specified as well as
|
|
# harvested. Then remove it from the patches list.
|
|
eval "git send-email $GIT_TO $GIT_CC --confirm=always --no-chain-reply-to --suppress-cc=all $CL"
|
|
if [ $? -eq 1 ]; then
|
|
echo "ERROR: failed to send cover-letter with automatic recipients."
|
|
exit 1
|
|
fi
|
|
PATCHES=${PATCHES/"$CL"/}
|
|
fi
|
|
|
|
# Send the patch to the specified recipients and, if -c was specified, those git
|
|
# finds in this specific patch.
|
|
eval "git send-email $GIT_TO --confirm=always --no-chain-reply-to $GITSOBCC $PATCHES"
|
|
if [ $? -eq 1 ]; then
|
|
echo "ERROR: failed to send patches."
|
|
exit 1
|
|
fi
|