aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorAndrew Robbins <contact@andrewrobbins.info>2019-03-18 14:11:47 -0400
committerAndrew Robbins <contact@andrewrobbins.info>2019-03-18 14:30:44 -0400
commit3f3d1c0437fd3dfe1cb11fc622d317daa004ea2a (patch)
tree287abd6768034c6adad72553ef523cfd36f89ab6 /libs
parent8d50c4b231ebc02f0f1b9586097a9e9a22cf906f (diff)
downloadlibrebootfr-3f3d1c0437fd3dfe1cb11fc622d317daa004ea2a.tar.gz
librebootfr-3f3d1c0437fd3dfe1cb11fc622d317daa004ea2a.zip
Rename and refactor diff_patch_file()
The previous function, diff_patch_file, was more error-prone and fragile and did not take into consideration patching of more than one file at a time(!).
Diffstat (limited to 'libs')
-rwxr-xr-xlibs/common19
-rwxr-xr-xlibs/git2
-rwxr-xr-xlibs/project2
3 files changed, 6 insertions, 17 deletions
diff --git a/libs/common b/libs/common
index a27ff785..06b411e1 100755
--- a/libs/common
+++ b/libs/common
@@ -110,22 +110,11 @@ download_wrapper() {
fi
}
-diff_patch_file() {
- local repository_path="$1"
- local patch_file_path="$2"
+diff_patch() {
+ local sources_path=$1
+ local patch_path=$2
- # TODO: Improve handling of filenames to avoid gotchas w/ \n, \t, etc.
- local filename_in_diff="$(sed -rne 's/^-{3}\s+([^ \r\n]*).*/\1/p' "$patch_file_path")"
-
- local source_file_path
-
- if ! ( grep -E '^-{3}.*/' "$patch_file_path" >/dev/null 2>&1 ); then
- source_file_path="$repository_path/$filename_in_diff"
- else
- source_file_path="$repository_path/${filename_in_diff##*/}"
- fi
-
- patch "$source_file_path" "$patch_file_path"
+ patch -fd "$sources_path" -r - < "$patch_path"
}
path_wildcard_expand() {
diff --git a/libs/git b/libs/git
index 16dd5411..998ceae7 100755
--- a/libs/git
+++ b/libs/git
@@ -249,7 +249,7 @@ git_project_patch_recursive() {
if [[ ${patch##*.} == patch ]]; then
git_patch "$repository_path" "$branch" "$patch"
else
- diff_patch_file "$repository_path" "$patch"
+ diff_patch "$repository_path" "$patch"
fi
done
}
diff --git a/libs/project b/libs/project
index f90b368e..70a76d71 100755
--- a/libs/project
+++ b/libs/project
@@ -531,7 +531,7 @@ project_sources_prepare_patch() {
local patches_path="$project_path/$PATCHES"
for patch in "$patches_path"/[!.]*.@(patch|diff); do
- diff_patch_file "$sources_path" "$patch"
+ diff_patch "$sources_path" "$patch"
done
}