hvsp: do not send version for series=1
[hvutilities.git] / scripts / kernel-send-patches.sh
index 4037d61..10d93ef 100755 (executable)
@@ -166,6 +166,22 @@ find_commit_by_log()
     echo $(git log --oneline HEAD~100..HEAD | grep "${1}" | awk {'print $1'})
 }
 
+# Remove "Name" if present in email address. Needed because of a bug in
+# get_maintainer.pl even if we specify the "--non" option.
+# Arg #1: "Name <email>" or "email"
+format_email()
+{
+    local mail="${1}"
+
+    if echo "${mail}" | grep -q '<'; then
+        mail=$(echo ${mail} | sed "s@.*<\(.*\)>@\1@")
+    else
+        mail="${mail}"
+    fi
+
+    echo "${mail}"
+}
+
 # Because the cover letter is a special case and not a real patch, running
 # get_maintainer.pl on it would not return any TO or CC addresses.
 # Therefore, manually run get_maintainer.pl on the concatenation of all the
@@ -180,10 +196,12 @@ collect_email_addresses()
     CC_MAIL="$(${CC_CMD} /tmp/all.patch)"
 
     while IFS= read -r line; do
+        line=$(format_email "${line}")
         TO_OPTS="${TO_OPTS} --to ${line}"
     done <<< "${TO_MAIL}"
 
     while IFS= read -r line; do
+        line=$(format_email "${line}")
         CC_OPTS="${CC_OPTS} --cc ${line}"
     done <<< "${CC_MAIL}"
 }
@@ -214,10 +232,6 @@ 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"${init_cmd}" != x"" ]; then
-    ${init_cmd}
-fi
-
 patches_branch="kernel_send_patches"
 
 if [ x"${series}" != x"" ]; then
@@ -237,8 +251,10 @@ if git branch | grep -q ${patches_branch}; then
     git branch -D ${patches_branch}
 fi
 
-git checkout -b ${patches_branch} ${COMMIT_END_SHA1}
+# 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="--base=${base_commit}"
 
@@ -246,18 +262,20 @@ if [ x"${cover}" = x"yes" ]; then
     GIT_FORMAT_PATCH_OPTS="${GIT_FORMAT_PATCH_OPTS} --cover-letter"
 fi
 
-if [ x"${series}" != x"" ]; then
+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 format-patch ${GIT_FORMAT_PATCH_OPTS} --output-directory=${srcdir} ${COMMIT_START_SHA1}..${COMMIT_END_SHA1}
+git format-patch ${GIT_FORMAT_PATCH_OPTS} --output-directory=${srcdir} ${base_branch}
 
 if [ x"${cover}" = x"yes" ]; then
     # Replace subject line in cover letter:
-    sed -i -e "s/\*\*\* SUB.*/${subject}/" ${srcdir}/v${series}-0000-cover-letter.patch
+    sed -i -e "s/\*\*\* SUB.*/${subject}/" ${srcdir}/${series_prefix}0000-cover-letter.patch
 
     # Replace blurb line in cover letter:
-    sed -i -e "/.*BLURB.*/{r /tmp/cover-letter.txt" -e 'd}' ${srcdir}/v${series}-0000-cover-letter.patch
+    sed -i -e "/.*BLURB.*/{r /tmp/cover-letter.txt" -e 'd}' ${srcdir}/${series_prefix}0000-cover-letter.patch
 
     collect_email_addresses
 fi
@@ -266,7 +284,7 @@ add_cc_list_addresses
 
 # Check patches (except special case of cover letter patch):
 for p in ${srcdir}/*.patch; do
-    if [ x"$(basename ${p})" != x"v${series}-0000-cover-letter.patch" ]; then
+    if [ x"$(basename ${p})" != x"${series_prefix}0000-cover-letter.patch" ]; then
         if [ x"${ignore_checkpatch_errors}" != x"" ]; then
             set +e
             CHECKPATCH_OPS="--ignore ${ignore_checkpatch_errors}"
@@ -285,15 +303,19 @@ cat > ${compile_script} << "EOF"
 # Do not edit, auto-generated script
 echo
 echo "Testing commit: $(git log --oneline | head -n 1)"
+#INIT_CMD
 COMPILE_CMD
 EOF
 
+if [ x"${init_cmd}" != x"" ]; then
+    sed -i -e "s@.*INIT_CMD@${init_cmd}@" ${compile_script}
+fi
 sed -i -e "s@COMPILE_CMD@${compile_cmd}@" ${compile_script}
 chmod u+x ${compile_script}
 
 # Compile each commit. Create branch to avoid "detached HEAD" state, and also to
 # keep a record of what was sent:
-git rebase --exec=${compile_script} ${COMMIT_START_SHA1}
+git rebase --exec=${compile_script} ${base_branch}
 git checkout ${orig_branch}
 
 # Send email(s)