diff options
author | Jean Delvare <jdelvare@suse.de> | 2018-11-05 17:01:28 +0100 |
---|---|---|
committer | Jean Delvare <jdelvare@suse.de> | 2018-11-05 17:01:28 +0100 |
commit | a03035f8f2bdc1466d5aa79b7b43dafaabc05295 (patch) | |
tree | 63543a9326a5219f2174683e3a8e045ed808bdc9 | |
parent | cbde26f240a64bf6b4bd58951113e3524fc8db88 (diff) | |
download | quilt-a03035f8f2bdc1466d5aa79b7b43dafaabc05295.tar.gz |
New helper function ensure_trailing_newline
As we now have the need to check for the presence of a trailing
newline twice, move the code to a function to avoid redundancy.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
-rw-r--r-- | quilt/header.in | 6 | ||||
-rw-r--r-- | quilt/scripts/patchfns.in | 18 |
2 files changed, 14 insertions, 10 deletions
diff --git a/quilt/header.in b/quilt/header.in index c01778f..734ed6b 100644 --- a/quilt/header.in +++ b/quilt/header.in @@ -155,11 +155,7 @@ else fi # Ensure there is a trailing newline before we append the rest - last_char=$(tail -c 1 "$tmp") - if ! [ -z "$last_char" -o "$last_char" = $'\n' -o "$last_char" = $'\r' ] - then - echo "" >> $tmp - fi + ensure_trailing_newline $tmp maybe_strip_diffstat < $tmp \ | maybe_strip_trailing_whitespace > $tmp2 diff --git a/quilt/scripts/patchfns.in b/quilt/scripts/patchfns.in index 902faf3..15ffa98 100644 --- a/quilt/scripts/patchfns.in +++ b/quilt/scripts/patchfns.in @@ -108,6 +108,18 @@ quote_glob() echo "$1" | sed -e 's:\([][*?\\]\):\\\1:g' } +# Ensure there is a trailing newline at the end of a file +ensure_trailing_newline() +{ + local last_char + + last_char=$(tail -c 1 "$1") + if ! [ -z "$last_char" -o "$last_char" = $'\n' -o "$last_char" = $'\r' ] + then + echo "" >> "$1" + fi +} + patch_file_name() { echo "$QUILT_PATCHES/$1" @@ -260,11 +272,7 @@ insert_in_series() cat "$SERIES" > $tmpfile # Ensure there is a trailing newline before we append the rest - last_char=$(tail -c 1 "$tmpfile") - if ! [ -z "$last_char" -o "$last_char" = $'\n' -o "$last_char" = $'\r' ] - then - echo "" >> $tmpfile - fi + ensure_trailing_newline $tmpfile fi echo "$patch$patch_args" >> $tmpfile fi |