libreboot

my branch of libreboot
git clone git://git.hazbo.co.uk/libreboot.git
Log | Files | Refs | README

commit 834ad955ad7407b842546422c711034fe0c4ace2
parent 8d50c4b231ebc02f0f1b9586097a9e9a22cf906f
Author: Swift Geek <swiftgeek@gmail.com>
Date:   Tue, 19 Mar 2019 02:35:51 +0000

Merge branch 'patch' of and_who/libreboot into master

Diffstat:
libs/common | 19++++---------------
libs/git | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
libs/project | 2+-
3 files changed, 60 insertions(+), 24 deletions(-)

diff --git 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 @@ -169,7 +169,25 @@ git_commit() { ) } -git_patch() { +git_am() { + local repository_path=$1 + local branch=$2 + local patch=$3 + + ( + export GIT_COMMITTER_NAME=$GIT_NAME + export GIT_COMMITTER_EMAIL=$GIT_EMAIL + + cd "$repository_path" + git checkout "$branch" >/dev/null 2>&1 + + if git_apply_check "$repository_path" "$branch" "$patch"; then + git am "$patch" || git am --abort + fi + ) +} + +git_apply() { local repository_path=$1 local branch=$2 local patch=$3 @@ -179,12 +197,45 @@ git_patch() { export GIT_COMMITTER_EMAIL=$GIT_EMAIL cd "$repository_path" - git checkout "$branch" 2> /dev/null > /dev/null + git checkout "$branch" >/dev/null 2>&1 - git am "$patch" || git am --abort + if git_apply_check "$repository_path" "$branch" "$patch"; then + git apply --index "$patch" + fi ) } +git_apply_check() { + local repository_path=$1 + local branch=$2 + local patch=$3 + + ( + cd "$repository_path" + git checkout "$branch" >/dev/null 2>&1 + + git apply --check "$patch" + ) +} + +git_patch() { + local repository_path=$1 + local branch=$2 + local patch=$3 + + case $patch in + *.patch) + git_am "$repository_path" "$branch" "$patch" + ;; + *.diff) + git_apply "$repository_path" "$branch" "$patch" && + git_commit "$repository_path" "Applied ${patch##*/}" + ;; + *) + ;; + esac +} + git_revision() { local repository_path=$1 @@ -246,11 +297,7 @@ git_project_patch_recursive() { fi for patch in "$patches_path"/[!.]*.@(patch|diff); do - if [[ ${patch##*.} == patch ]]; then - git_patch "$repository_path" "$branch" "$patch" - else - diff_patch_file "$repository_path" "$patch" - fi + git_patch "$repository_path" "$branch" "$patch" done } diff --git 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 }