update_program_fw: Use multiple Cq-Depend lines

Gerrit will wrap long Cq-Depend lines, so place each Cq-Depend reference
on a separate line.

BUG=none
TEST=Run puff upgrade.

Change-Id: Ib200d949236ff00d65b23e2bb92432334cafa0c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/2395295
Commit-Queue: Andrew McRae <amcrae@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Tested-by: Andrew McRae <amcrae@chromium.org>
Auto-Submit: Andrew McRae <amcrae@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
diff --git a/contrib/update_program_fw b/contrib/update_program_fw
index ff9edfd..f956699 100755
--- a/contrib/update_program_fw
+++ b/contrib/update_program_fw
@@ -161,11 +161,11 @@
   [[ -n $(git status -s) ]]
 }
 #
-# Add a Cq-Depend line to a commit.
+# Add Cq-Depend lines from a file to a commit.
 #
-amend() {
+amend_cq_file() {
   git log -1 --pretty=%B > "${TEMPDIR}/amend-msg"
-  sed -i "/^Change-Id/ i ${1}" "${TEMPDIR}/amend-msg"
+  sed -i "/^Change-Id/e cat ${1}" "${TEMPDIR}/amend-msg"
   git commit -q --amend -F "${TEMPDIR}/amend-msg"
 }
 #
@@ -493,21 +493,20 @@
   fi
 done
 #
-# Create a Cq-Depend line with all the project CLs
+# Create a file with Cq-Depend lines for all the project CLs
 #
+CQD_FILE="${TEMPDIR}/cqd"
+touch "${CQD_FILE}"
 if [[ -n "${PROJ_CLS[*]}" ]];then
-  SEP=" "
-  PROG_CQD="Cq-Depend:"
   for CL in "${PROJ_CLS[@]}"; do
-    PROG_CQD="${PROG_CQD}${SEP}chrome-internal:${CL}"
-    SEP=", "
+    echo "Cq-Depend: chrome-internal:${CL}" >> "${CQD_FILE}"
   done
   #
   # If a program CL exists, add the Cq-Depend line to it.
   #
   if [[ -n "${PROGRAM_CL}" ]]; then
     cd "${PROGDIR}"
-    amend "${PROG_CQD}"
+    amend_cq_file "${CQD_FILE}"
     if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.amend.output" 2>&1 ;then
       cat  "${TEMPDIR}/upload.amend.output"
       abort "repo upload failed"
@@ -572,7 +571,7 @@
   NEXTVERS=$((CURVERS + 1))
   sed -i "/VERSION=REVBUMP/s/${CURVERS}$/${NEXTVERS}/" "${EB9999}"
   git add .
-  git commit -q -F - <<EOF
+  cat > "${TEMPDIR}/overlay.msg" <<EOF
 ${FLAGS_board}: Update firmware to ${FLAGS_release}
 
 Autogenerated by:
@@ -581,8 +580,8 @@
 BUG=${FLAGS_bug}
 TEST=${FLAGS_test}
 
-${PROG_CQD}
 EOF
+  cat "${TEMPDIR}/overlay.msg" "${CQD_FILE}" | git commit -q -F -
   #
   # Upload with no-verify since the file lines are too long.
   #
@@ -592,16 +591,16 @@
   fi
   OVERLAY_CL=$(getcl "overlays/overlay-${FLAGS_board}-private" "${TEMPDIR}/overlay.output")
   #
-  # Go back and amend all the project commit messages with a Cq-Depend on
+  # Go back and amend all the project commit messages with Cq-Depend lines on
   # the program and overlay CLs.
   #
-  CQD="Cq-Depend: chrome-internal:${OVERLAY_CL}"
+  echo "Cq-Depend: chrome-internal:${OVERLAY_CL}" >  "${TEMPDIR}/over_cqd"
   if [[ -n "${PROGRAM_CL}" ]]; then
-    CQD="${CQD}, chrome-internal:${PROGRAM_CL}"
+    echo "Cq-Depend: chrome-internal:${PROGRAM_CL}" >>  "${TEMPDIR}/over_cqd"
   fi
   for DIR in "${PROJ_DIRS[@]}"; do
     cd "${DIR}"
-    amend "${CQD}"
+    amend_cq_file "${TEMPDIR}/over_cqd"
     if ! repo upload -y --verify --cbr . > "${TEMPDIR}/cqd.output" 2>&1 ;then
       cat  "${TEMPDIR}/cqd.output"
       abort "repo upload failed"