diff options
author | Andrew Robbins <contact@andrewrobbins.info> | 2019-03-23 14:52:34 -0400 |
---|---|---|
committer | Andrew Robbins <contact@andrewrobbins.info> | 2019-03-23 15:22:24 -0400 |
commit | dbfed91bd4c8500d21f30c51d20530ff6742d7f4 (patch) | |
tree | 5f60f600d71089ceff1e14e447f71063086a7a95 /libs | |
parent | c2a50176d9815484a61021e6852fdd7e1e9b1d98 (diff) | |
download | librebootfr-dbfed91bd4c8500d21f30c51d20530ff6742d7f4.tar.gz librebootfr-dbfed91bd4c8500d21f30c51d20530ff6742d7f4.zip |
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.
Diffstat (limited to 'libs')
-rwxr-xr-x | libs/git | 198 |
1 files changed, 76 insertions, 122 deletions
@@ -1,6 +1,7 @@ #!/usr/bin/env bash # Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr> +# Copyright (C) 2019 Andrew Robbins <contact@andrewrobbins.info> # # 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 } |