summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2023-08-10 10:22:02 +0200
committerJean Delvare <jdelvare@suse.de>2023-08-10 10:22:02 +0200
commitcff443d3d151b61b412e6c4fb6e5aa8619348efa (patch)
tree032ae187dff27f60ca4e00e954f3778e38612335
parent855fb4b6adb554d55b5266e36973691b6335bc71 (diff)
downloadquilt-cff443d3d151b61b412e6c4fb6e5aa8619348efa.tar.gz
diff/refresh: Quote file names which contain a space
GNU diff quotes file names which contain a space, and GNU patch expects that as well (oddly enough, only when the patch header does not include timestamps). Do the same so that the patches we generate can always be applied. Signed-off-by: Jean Delvare <jdelvare@suse.de>
-rw-r--r--quilt/scripts/patchfns.in7
-rw-r--r--test/space-in-filenames.test18
2 files changed, 15 insertions, 10 deletions
diff --git a/quilt/scripts/patchfns.in b/quilt/scripts/patchfns.in
index 1fbf0d8..0c6739a 100644
--- a/quilt/scripts/patchfns.in
+++ b/quilt/scripts/patchfns.in
@@ -692,7 +692,7 @@ files_in_patch_ordered()
diff_file()
{
local file=$1 old_file=$2 new_file=$3
- local index old_hdr old_date new_hdr new_date line
+ local index old_hdr old_date new_hdr new_date line regexp
: ${opt_strip_level:=1}
if [ $opt_strip_level = ab ]
@@ -735,6 +735,11 @@ diff_file()
|| new_date=$'\t'"1970-01-01 00:00:00.000000000 +0000"
fi
+ # If a header contains a space character, it must be quoted
+ regexp="[[:space:]]"
+ [[ "$old_hdr" =~ $regexp ]] && old_hdr=\"$old_hdr\"
+ [[ "$new_hdr" =~ $regexp ]] && new_hdr=\"$new_hdr\"
+
diff $QUILT_DIFF_OPTS \
--label "$old_hdr$old_date" --label "$new_hdr$new_date" \
"$old_file" "$new_file" \
diff --git a/test/space-in-filenames.test b/test/space-in-filenames.test
index 2005d00..e7dc0cf 100644
--- a/test/space-in-filenames.test
+++ b/test/space-in-filenames.test
@@ -44,13 +44,13 @@ $ quilt diff -p ab
> Index: b/a: b [c]
> ===================================================================
> --- /dev/null
-> +++ b/a: b [c]
+> +++ "b/a: b [c]"
> @@ -0,0 +1 @@
> +new line
> Index: b/foo bar
> ===================================================================
-> --- a/foo bar
-> +++ b/foo bar
+> --- "a/foo bar"
+> +++ "b/foo bar"
> @@ -1 +1 @@
> -foo
> +bar
@@ -61,13 +61,13 @@ $ cat patches/test.diff
> Index: b/a: b [c]
> ===================================================================
> --- /dev/null
-> +++ b/a: b [c]
+> +++ "b/a: b [c]"
> @@ -0,0 +1 @@
> +new line
> Index: b/foo bar
> ===================================================================
-> --- a/foo bar
-> +++ b/foo bar
+> --- "a/foo bar"
+> +++ "b/foo bar"
> @@ -1 +1 @@
> -foo
> +bar
@@ -78,13 +78,13 @@ $ cat patches/test.diff
> Index: b/a: b [c]
> ===================================================================
> --- /dev/null
-> +++ b/a: b [c]
+> +++ "b/a: b [c]"
> @@ -0,0 +1 @@
> +new line
> Index: b/foo bar
> ===================================================================
-> --- a/foo bar
-> +++ b/foo bar
+> --- "a/foo bar"
+> +++ "b/foo bar"
> @@ -1 +1 @@
> -foo
> +bar