[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH 2/2] New helper function ensure_trailing_newline
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH 2/2] New helper function ensure_trailing_newline |
Date: |
Tue, 9 Oct 2018 16:16:07 +0200 |
From: Jean Delvare <address@hidden>
Subject: 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 <address@hidden>
---
quilt/header.in | 6 +-----
quilt/scripts/patchfns.in | 18 +++++++++++++-----
2 files changed, 14 insertions(+), 10 deletions(-)
--- quilt.orig/quilt/header.in 2017-07-18 09:22:28.860617331 +0200
+++ quilt/quilt/header.in 2018-10-09 13:01:54.970565924 +0200
@@ -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
--- quilt.orig/quilt/scripts/patchfns.in 2018-10-09 10:10:02.017074824
+0200
+++ quilt/quilt/scripts/patchfns.in 2018-10-09 14:59:11.779126828 +0200
@@ -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
--
Jean Delvare
SUSE L3 Support