From 4a493108d1aefe3151096c3b22234d0c8cf893d9 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Mon, 18 Mar 2019 22:17:45 -0400 Subject: libs/git: Avoid some redundancies in git_patch() The subshell, changing directory, and checking out was unecessary considering all of these are done within the functions called by git_patch() git_am() was added in order to mirror the same wrapper style as used by git_apply() and git_commit() --- libs/git | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/libs/git b/libs/git index 104239c1..f5d764ef 100755 --- a/libs/git +++ b/libs/git @@ -169,7 +169,7 @@ git_commit() { ) } -git_apply() { +git_am() { local repository_path=$1 local branch=$2 local patch=$3 @@ -182,50 +182,60 @@ git_apply() { git checkout "$branch" >/dev/null 2>&1 if git_apply_check "$repository_path" "$branch" "$patch"; then - git apply --index "$patch" + git am "$patch" || git am --abort fi ) } -git_apply_check() { +git_apply() { 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 - git apply --check "$patch" + if git_apply_check "$repository_path" "$branch" "$patch"; then + git apply --index "$patch" + fi ) } -git_patch() { +git_apply_check() { 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 - case $patch in - *.patch) - git am "$patch" || git am --abort - ;; - *.diff) - git_apply "$repository_path" "$branch" "$patch" && - git_commit "$repository_path" "Applied ${patch##*/}" - ;; - *) - ;; - esac + 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 -- cgit v1.2.3-70-g09d2