]> www.infradead.org Git - users/dedekind/aiaiai.git/commitdiff
email-lda: introduce the 'queue_series' helper
authorJacob Keller <jacob.e.keller@intel.com>
Thu, 6 Feb 2014 09:16:31 +0000 (11:16 +0200)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Fri, 7 Feb 2014 08:56:26 +0000 (10:56 +0200)
Artem: this is part of a bigger patch from Jacob, which I made to be a separate
patch. So Jacob is the author, but I am writing the commit message.

Introduce a separate function for queueing a patch series. This is a bit more
readable, and also this is a preparation for further changes.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
email/aiaiai-email-lda

index 446b32a1004ada13c59485e468fadcb7493b896a..f00c718251e2af253bebc4f89ba09499dd983ef7 100755 (executable)
@@ -175,6 +175,48 @@ series_is_complete()
        fi
 }
 
+queue_series()
+{
+       local dir="$1"; shift
+       local n="$1"; shift
+
+       message "Patch-set at \"$dir\" is complete, queue it"
+       # Don't add the 0th patch to the final mbox, as it is just the
+       # cover letter and does not contain any patch
+       for fname in $(ls --ignore=0 -A -- "$dir" | sort -n); do
+               cat -- "$dir/$fname" >> "$mbox"
+               printf "\n" >> "$mbox"
+       done
+
+       if [ -f "$dir/0" ]; then
+               # Save the subject and message ID of the cover letter in the
+               # final mbox in order to be able to reply to the cover letter
+               # later.
+               local subj="$(fetch_header "Subject" < "$dir/0")"
+               subj="X-Aiaiai-Cover-Letter-Subject: $subj"
+
+               local id="$(fetch_header "Message-Id" < "$dir/0")"
+               id="X-Aiaiai-Cover-Letter-Message-Id: $id"
+
+               # The below trick allows us to avoid creating a separate
+               # temporary file: open the "$mbox" file, unlink, use the open
+               # file descriptor for reading and redirect the output to the
+               # new version of the "$mbox" file. We could instead use the
+               # "sponge" tool, though.
+               exec 3<$mbox
+               rm $verbose "$mbox" >&2
+               message "Adding \"$subj\""
+               formail -s formail -I "$subj" <&3 > "$mbox"
+
+               exec 3<$mbox
+               rm $verbose "$mbox" >&2
+               message "Adding \"$id\""
+               formail -s formail -I "$id" <&3 > "$mbox"
+       fi
+       queue_mboxfile
+       rm $verbose -rf -- "$dir" >&2
+}
+
 move_to_series()
 {
        local file="$1"; shift
@@ -275,41 +317,7 @@ EOF
 
        # If the series is complete - queue it
        if series_is_complete "$dir" "$n"; then
-               message "Patch-set at \"$dir\" is complete, queue it"
-               # Don't add the 0th patch to the final mbox, as it is just the
-               # cover letter and does not contain any patch
-               for fname in $(ls --ignore=0 -A -- "$dir" | sort -n); do
-                       cat -- "$dir/$fname" >> "$mbox"
-                       echo >> "$mbox"
-               done
-
-               if [ -f "$dir/0" ]; then
-                       # Save the subject and message ID of the cover letter
-                       # in the final mbox in order to be able to reply to the
-                       # cover letter later.
-                       local subj="$(fetch_header "Subject" < "$dir/0")"
-                       subj="X-Aiaiai-Cover-Letter-Subject: $subj"
-
-                       local id="$(fetch_header "Message-Id" < "$dir/0")"
-                       id="X-Aiaiai-Cover-Letter-Message-Id: $id"
-
-                       # The below trick allows us to avoid creating a
-                       # separate temporary file: open the "$mbox" file,
-                       # unlink, use the open file descriptor for reading and
-                       # redirect the output to the new version of the "$mbox"
-                       # file. We could instead use the "sponge" tool, though.
-                       exec 3<$mbox
-                       rm $verbose "$mbox" >&2
-                       message "Adding \"$subj\""
-                       formail -s formail -I "$subj" <&3 > "$mbox"
-
-                       exec 3<$mbox
-                       rm $verbose "$mbox" >&2
-                       message "Adding \"$id\""
-                       formail -s formail -I "$id" <&3 > "$mbox"
-               fi
-               queue_mboxfile
-               rm $verbose -rf -- "$dir" >&2
+               queue_series "$dir" "$n"
        fi
 }