From dbfed91bd4c8500d21f30c51d20530ff6742d7f4 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Sat, 23 Mar 2019 14:52:34 -0400 Subject: libs/git: Simplify logic for operating on branches Previous patches made certain tests unnecessary due to the setting of $BRANCH_PREFIX in $branch. By adding the branch prefix right before it's actually needed we can retain the usefulness of those conditional tests. --- libs/git | 198 ++++++++++++++++++++++++--------------------------------------- 1 file changed, 76 insertions(+), 122 deletions(-) (limited to 'libs') diff --git a/libs/git b/libs/git index f5d764ef..f00b2874 100755 --- a/libs/git +++ b/libs/git @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Copyright (C) 2016 Paul Kocialkowski +# Copyright (C) 2019 Andrew Robbins # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -371,32 +372,27 @@ git_project_prepare_patch() { local project_path=$(project_path "$project") local configs_path="$project_path/$CONFIGS" - local prepare_branch - local prepare_path - local branch=$BRANCH_PREFIX$project + local branch=$project local argument local path - for argument in "" "$@" + for argument in "$@" do - if [[ -n "$argument" ]] + if [[ -z "$path" ]] then - if [[ -z "$path" ]] - then - path="$argument" - else - path="$path/$argument" - fi - - branch="$branch-$argument" + path="$argument" + else + path="$path/$argument" fi - prepare_branch=$branch - prepare_path=$path + branch="$branch-$argument" done - if [[ -n "$prepare_branch" ]] + if [[ -n $branch ]] then + local prepare_branch=$BRANCH_PREFIX$branch + local prepare_path=$path + git_project_patch_recursive "$project" "$repository" "$prepare_branch" "$prepare_path" fi } @@ -410,17 +406,16 @@ git_project_prepare_revision() { local repository_path=$(git_project_repository_path "$repository") local project_path=$(project_path "$project") local configs_path="$project_path/$CONFIGS" - local prepare_branch + local branch=$project local prepare_revision - local branch=$BRANCH_PREFIX$project local argument local path for argument in "" "$@" do - if [[ -n "$argument" ]] + if [[ -n $argument ]] then - if [[ -z "$path" ]] + if [[ -z $path ]] then path="$argument" else @@ -435,12 +430,12 @@ git_project_prepare_revision() { if [[ -f $revision_path ]]; then prepare_revision=$(< "$revision_path") fi - - prepare_branch=$branch done - if [[ -n "$prepare_branch" ]] + if [[ -n $branch ]] then + local prepare_branch=$BRANCH_PREFIX$branch + git_branch_create "$repository_path" "$prepare_branch" "$prepare_revision" fi } @@ -454,30 +449,18 @@ git_project_prepare_check() { local repository_path=$(git_project_repository_path "$repository") local project_path=$(project_path "$project") local configs_path="$project_path/$CONFIGS" - local prepare_branch - local branch=$BRANCH_PREFIX$project + local branch=$project local argument - local path - for argument in "" "$@" + for argument in "$@" do - if [[ -n "$argument" ]] - then - if [[ -z "$path" ]] - then - path="$argument" - else - path="$path/$argument" - fi - - branch="$branch-$argument" - fi - - prepare_branch=$branch + branch="$branch-$argument" done - if [[ -n "$prepare_branch" ]] + if [[ -n $branch ]] then + local prepare_branch=$BRANCH_PREFIX$branch + git_branch_check "$repository_path" "$prepare_branch" fi } @@ -489,38 +472,27 @@ git_project_prepare_clean() { shift local repository_path=$(git_project_repository_path "$repository") - local prepare_branch - local branch=$BRANCH_PREFIX$project + local branch=$project local argument - for argument in "" "$@" + for argument in "$@" do - if [[ -n "$argument" ]] - then - branch="$branch-$argument" - fi - - if ! git_branch_check "$repository_path" "$branch" - then - continue - fi - - prepare_branch=$branch + branch="$branch-$argument" done - if [[ -n "$prepare_branch" ]] + if [[ -n $branch ]] then - # Let's not worry about missing branches. - ( - set +e + local prepare_branch=$BRANCH_PREFIX$branch + if git_branch_check "$repository_path" "$prepare_branch" + then git_branch_delete "$repository_path" "$prepare_branch" if [[ $? -ne 0 ]] then return 0 fi - ) + fi fi } @@ -531,29 +503,23 @@ git_project_checkout() { shift local repository_path=$(git_project_repository_path "$repository") - local checkout_branch - local branch=$BRANCH_PREFIX$project + local branch=$project local argument - for argument in "" "$@" + for argument in "$@" do - if [[ -n "$argument" ]] - then - branch="$branch-$argument" - fi - - if ! git_branch_check "$repository_path" "$branch" - then - continue - fi - - checkout_branch=$branch + branch="$branch-$argument" done - if [[ -n "$checkout_branch" ]] + if [[ -n $branch ]] then - git_branch_checkout "$repository_path" "$checkout_branch" - git_submodule_update "$repository_path" + local checkout_branch=$BRANCH_PREFIX$branch + + if git_branch_check "$repository_path" "$checkout_branch" + then + git_branch_checkout "$repository_path" "$checkout_branch" + git_submodule_update "$repository_path" + fi fi } @@ -591,37 +557,31 @@ git_project_release() { local arguments=$@ local repository_path=$(git_project_repository_path "$repository") - local release_branch - local branch=$BRANCH_PREFIX$project + local branch=$project local argument - for argument in "" "$@" + for argument in "$@" do - if [[ -n "$argument" ]] - then - branch="$branch-$argument" - fi - - if ! git_branch_check "$repository_path" "$branch" - then - continue - fi - - release_branch=$branch + branch="$branch-$argument" done - if [[ -n "$release_branch" ]] + if [[ -n $branch ]] then - local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" - local sources_path="$root/$SOURCES/$repository" + local release_branch=$BRANCH_PREFIX$branch + + if git_branch_check "$repository_path" "$release_branch" + then + local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" + local sources_path="$root/$SOURCES/$repository" - printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument}) from "$repository" git" + printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument}) from "$repository" git" - git_branch_checkout "$repository_path" "$release_branch" - git_submodule_update "$repository_path" - git_clean "$repository_path" - archive_create "$archive_path" "$sources_path" "$release_branch" - file_verification_create "$archive_path" + git_branch_checkout "$repository_path" "$release_branch" + git_submodule_update "$repository_path" + git_clean "$repository_path" + archive_create "$archive_path" "$sources_path" "$release_branch" + file_verification_create "$archive_path" + fi fi } @@ -632,36 +592,30 @@ git_project_release_check() { shift local repository_path=$(git_project_repository_path "$repository") - local release_branch - local branch=$BRANCH_PREFIX$project + local branch=$project local argument - for argument in "" "$@" + for argument in "$@" do - if [[ -n "$argument" ]] - then - branch="$branch-$argument" - fi - - if ! git_branch_check "$repository_path" "$branch" - then - continue - fi - - release_branch=$branch + branch="$branch-$argument" done - if [[ -n "$release_branch" ]] + if [[ -n $branch ]] then - local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" + local release_branch=$BRANCH_PREFIX$branch - file_exists_check "$archive_path" - - if [[ $? -ne 0 ]] + if git_branch_check "$repository_path" "$release_branch" then - return 1 - else - return 0 + local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" + + file_exists_check "$archive_path" + + if [[ $? -ne 0 ]] + then + return 1 + else + return 0 + fi fi fi } -- cgit v1.2.3-70-g09d2 From 6700afb57b7af0b39a6fc9aa8a1b0c02730577c8 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Sat, 23 Mar 2019 15:19:08 -0400 Subject: libs/git: Avoid checking exit codes indirectly --- libs/git | 40 +++++----------------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) (limited to 'libs') diff --git a/libs/git b/libs/git index f00b2874..8c893e74 100755 --- a/libs/git +++ b/libs/git @@ -97,17 +97,9 @@ git_branch_check() { local branch=$2 ( - cd "$repository_path" 2> /dev/null > /dev/null - if [[ $? -ne 0 ]] - then - return 1 - fi + cd "$repository_path" >/dev/null 2>&1 || return 1 - git rev-parse --verify "$branch" 2> /dev/null > /dev/null - if [[ $? -ne 0 ]] - then - return 1 - fi + git rev-parse --verify "$branch" >/dev/null 2>&1 ) } @@ -124,17 +116,9 @@ git_fetch_check() { local repository_path=$1 ( - cd "$repository_path" 2> /dev/null > /dev/null - if [[ $? -ne 0 ]] - then - return 1 - fi + cd "$repository_path" >/dev/null 2>&1 || return 1 - local output=$(git fetch --dry-run origin 2>&1) - if [[ -n "$output" ]] - then - return 1 - fi + git fetch --dry-run origin >/dev/null 2>&1 ) } @@ -318,9 +302,7 @@ git_project_clone() { for url in $urls do - git_clone "$repository_path" "$url" - - if [[ $? -eq 0 ]] + if git_clone "$repository_path" "$url" then return 0 fi @@ -487,11 +469,6 @@ git_project_prepare_clean() { if git_branch_check "$repository_path" "$prepare_branch" then git_branch_delete "$repository_path" "$prepare_branch" - - if [[ $? -ne 0 ]] - then - return 0 - fi fi fi } @@ -609,13 +586,6 @@ git_project_release_check() { local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" file_exists_check "$archive_path" - - if [[ $? -ne 0 ]] - then - return 1 - else - return 0 - fi fi fi } -- cgit v1.2.3-70-g09d2 From fbdb6292b5d3932065a7ce1b5ab8578e310d7235 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Sat, 23 Mar 2019 15:37:09 -0400 Subject: libs/git: Remove some unused variable definitions --- libs/git | 8 -------- 1 file changed, 8 deletions(-) (limited to 'libs') diff --git a/libs/git b/libs/git index 8c893e74..2a88bf84 100755 --- a/libs/git +++ b/libs/git @@ -178,9 +178,6 @@ git_apply() { 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 @@ -352,8 +349,6 @@ git_project_prepare_patch() { local repository=$1 shift - local project_path=$(project_path "$project") - local configs_path="$project_path/$CONFIGS" local branch=$project local argument local path @@ -429,8 +424,6 @@ git_project_prepare_check() { shift local repository_path=$(git_project_repository_path "$repository") - local project_path=$(project_path "$project") - local configs_path="$project_path/$CONFIGS" local branch=$project local argument @@ -531,7 +524,6 @@ git_project_release() { shift local repository=$1 shift - local arguments=$@ local repository_path=$(git_project_repository_path "$repository") local branch=$project -- cgit v1.2.3-70-g09d2 From e996aefdea2e3e7e11c1d886c356e24e527d05f4 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Sat, 23 Mar 2019 15:46:31 -0400 Subject: libs/git: Remove unnecessary env invocation LC_ALL is already set to "C.UTF-8" and exported if libfaketime path is given in libreboot.conf --- libs/git | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libs') diff --git a/libs/git b/libs/git index 2a88bf84..fa4434f7 100755 --- a/libs/git +++ b/libs/git @@ -241,8 +241,8 @@ git_files() { ( cd "$repository_path" - # Reproducible sorting. - git ls-files -z | env LC_ALL='C.UTF-8' sort -z + + git ls-files -z | sort -z ) } -- cgit v1.2.3-70-g09d2