Removing the multiple calls to determine VCS type
This removed the subshell from _determine_vcs_base_and_type so it can set environment variables. Because this always runs at the beginning of the scripts, there's no need to do checking if REPOBASE is unset or if VCS_TYPE is not yet determined, thus I simplified one function and eliminated which_vcs. Conflicts: bin/blackbox_deregister_file I found this easier to just cherry pick since there was a merge and the merge was reverted.
This commit is contained in:
@@ -23,45 +23,36 @@ source "${0%/*}"/_stack_lib.sh
|
|||||||
: "${EDITOR:=vi}" ;
|
: "${EDITOR:=vi}" ;
|
||||||
|
|
||||||
|
|
||||||
# Outputs a string that is the base directory of this VCS repo.
|
# Set REPOBASE to the top of the repository
|
||||||
# By side-effect, sets the variable VCS_TYPE to either 'git', 'hg',
|
# Set VCS_TYPE to 'git', 'hg', 'svn' or 'unknown'
|
||||||
# 'svn' or 'unknown'.
|
if git rev-parse --show-toplevel >/dev/null 2>&1 ; then
|
||||||
function _determine_vcs_base_and_type() {
|
VCS_TYPE=git
|
||||||
if git rev-parse --show-toplevel 2>/dev/null ; then
|
REPOBASE=$(git rev-parse --show-toplevel)
|
||||||
VCS_TYPE=git
|
elif [ -d ".svn" ] ; then
|
||||||
elif [ -d ".svn" ] ; then
|
# Find topmost dir with .svn sub-dir
|
||||||
#find topmost dir with .svn sub-dir
|
parent=""
|
||||||
parent=""
|
grandparent="."
|
||||||
grandparent="."
|
while [ -d "$grandparent/.svn" ]; do
|
||||||
mydir="$(pwd)"
|
parent=$grandparent
|
||||||
while [ -d "$grandparent/.svn" ]; do
|
grandparent="$parent/.."
|
||||||
parent=$grandparent
|
done
|
||||||
grandparent="$parent/.."
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ! -z "$parent" ]; then
|
REPOBASE=$(cd "$parent" ; pwd)
|
||||||
cd "$parent"
|
VCS_TYPE=svn
|
||||||
pwd
|
elif hg root >/dev/null 2>&1 ; then
|
||||||
else
|
# NOTE: hg has to be tested last because it always "succeeds".
|
||||||
exit 1
|
VCS_TYPE=hg
|
||||||
fi
|
REPOBASE=$(hg root 2>/dev/null)
|
||||||
cd "$mydir"
|
else
|
||||||
VCS_TYPE=svn
|
# We aren't in a repo at all. Assume the cwd is the root
|
||||||
elif hg root 2>/dev/null ; then
|
# of the tree.
|
||||||
# NOTE: hg has to be tested last because it always "succeeds".
|
VCS_TYPE=unknown
|
||||||
VCS_TYPE=hg
|
REPOBASE="$(pwd)"
|
||||||
else
|
fi
|
||||||
# We aren't in a repo at all. Assume the cwd is the root
|
export VCS_TYPE
|
||||||
# of the tree.
|
# FIXME: Verify this function by checking for .hg or .git
|
||||||
echo .
|
# after determining what we believe to be the answer.
|
||||||
VCS_TYPE=unknown
|
|
||||||
fi
|
|
||||||
export VCS_TYPE
|
|
||||||
# FIXME: Verify this function by checking for .hg or .git
|
|
||||||
# after determining what we believe to be the answer.
|
|
||||||
}
|
|
||||||
|
|
||||||
REPOBASE=$(_determine_vcs_base_and_type)
|
|
||||||
KEYRINGDIR="$REPOBASE/$BLACKBOXDATA"
|
KEYRINGDIR="$REPOBASE/$BLACKBOXDATA"
|
||||||
BB_ADMINS_FILE="blackbox-admins.txt"
|
BB_ADMINS_FILE="blackbox-admins.txt"
|
||||||
BB_ADMINS="${KEYRINGDIR}/${BB_ADMINS_FILE}"
|
BB_ADMINS="${KEYRINGDIR}/${BB_ADMINS_FILE}"
|
||||||
@@ -97,7 +88,6 @@ function fail_if_not_exists() {
|
|||||||
|
|
||||||
# Exit we we aren't in a VCS repo.
|
# Exit we we aren't in a VCS repo.
|
||||||
function fail_if_not_in_repo() {
|
function fail_if_not_in_repo() {
|
||||||
_determine_vcs_base_and_type
|
|
||||||
if [[ $VCS_TYPE = "unknown" ]]; then
|
if [[ $VCS_TYPE = "unknown" ]]; then
|
||||||
echo "ERROR: This must be run in a VCS repo: git, hg, or svn." >&2
|
echo "ERROR: This must be run in a VCS repo: git, hg, or svn." >&2
|
||||||
echo Exiting... >&2
|
echo Exiting... >&2
|
||||||
@@ -285,10 +275,6 @@ function enumerate_subdirs() {
|
|||||||
|
|
||||||
# chdir to the base of the repo.
|
# chdir to the base of the repo.
|
||||||
function change_to_vcs_root() {
|
function change_to_vcs_root() {
|
||||||
if [[ $REPOBASE = '' ]]; then
|
|
||||||
echo 'ERROR: _determine_vcs_base_and_type failed to set REPOBASE.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
cd "$REPOBASE"
|
cd "$REPOBASE"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,18 +337,9 @@ function md5sum_file() {
|
|||||||
# Abstract the difference between git and hg:
|
# Abstract the difference between git and hg:
|
||||||
#
|
#
|
||||||
|
|
||||||
# Are we in git, hg, or unknown repo?
|
|
||||||
function which_vcs() {
|
|
||||||
if [[ $VCS_TYPE = '' ]]; then
|
|
||||||
_determine_vcs_base_and_type >/dev/null
|
|
||||||
fi
|
|
||||||
echo "$VCS_TYPE"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Is this file in the current repo?
|
# Is this file in the current repo?
|
||||||
function is_in_vcs() {
|
function is_in_vcs() {
|
||||||
is_in_$(which_vcs) "$@"
|
is_in_$VCS_TYPE "$@"
|
||||||
}
|
}
|
||||||
# Mercurial
|
# Mercurial
|
||||||
function is_in_hg() {
|
function is_in_hg() {
|
||||||
@@ -416,7 +393,7 @@ function is_in_unknown() {
|
|||||||
|
|
||||||
# Add a file to the repo (but don't commit it).
|
# Add a file to the repo (but don't commit it).
|
||||||
function vcs_add() {
|
function vcs_add() {
|
||||||
vcs_add_$(which_vcs) "$@"
|
vcs_add_$VCS_TYPE "$@"
|
||||||
}
|
}
|
||||||
# Mercurial
|
# Mercurial
|
||||||
function vcs_add_hg() {
|
function vcs_add_hg() {
|
||||||
@@ -442,7 +419,7 @@ function vcs_add_unknown() {
|
|||||||
|
|
||||||
# Commit a file to the repo
|
# Commit a file to the repo
|
||||||
function vcs_commit() {
|
function vcs_commit() {
|
||||||
vcs_commit_$(which_vcs) "$@"
|
vcs_commit_$VCS_TYPE "$@"
|
||||||
}
|
}
|
||||||
# Mercurial
|
# Mercurial
|
||||||
function vcs_commit_hg() {
|
function vcs_commit_hg() {
|
||||||
@@ -469,7 +446,7 @@ function vcs_commit_unknown() {
|
|||||||
# Remove file from repo, even if it was deleted locally already.
|
# Remove file from repo, even if it was deleted locally already.
|
||||||
# If it doesn't exist yet in the repo, it should be a no-op.
|
# If it doesn't exist yet in the repo, it should be a no-op.
|
||||||
function vcs_remove() {
|
function vcs_remove() {
|
||||||
vcs_remove_$(which_vcs) "$@"
|
vcs_remove_$VCS_TYPE "$@"
|
||||||
}
|
}
|
||||||
# Mercurial
|
# Mercurial
|
||||||
function vcs_remove_hg() {
|
function vcs_remove_hg() {
|
||||||
@@ -497,7 +474,7 @@ function vcs_remove_unknown() {
|
|||||||
function vcs_ignore() {
|
function vcs_ignore() {
|
||||||
local file
|
local file
|
||||||
for file in "$@"; do
|
for file in "$@"; do
|
||||||
vcs_ignore_$(which_vcs) "$file"
|
vcs_ignore_$VCS_TYPE "$file"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
# Mercurial
|
# Mercurial
|
||||||
@@ -538,7 +515,7 @@ function vcs_ignore_generic_file() {
|
|||||||
function vcs_notice() {
|
function vcs_notice() {
|
||||||
local file
|
local file
|
||||||
for file in "$@"; do
|
for file in "$@"; do
|
||||||
vcs_notice_$(which_vcs) "$file"
|
vcs_notice_$VCS_TYPE "$file"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
# Mercurial
|
# Mercurial
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
source "${0%/*}/_blackbox_common.sh"
|
source "${0%/*}/_blackbox_common.sh"
|
||||||
_determine_vcs_base_and_type
|
|
||||||
|
|
||||||
unencrypted_file=$(get_unencrypted_filename "$1")
|
unencrypted_file=$(get_unencrypted_filename "$1")
|
||||||
encrypted_file=$(get_encrypted_filename "$1")
|
encrypted_file=$(get_encrypted_filename "$1")
|
||||||
@@ -31,4 +30,4 @@ vcs_remove "$BB_FILES"
|
|||||||
vcs_commit "Removing from blackbox: ${unencrypted_file}"
|
vcs_commit "Removing from blackbox: ${unencrypted_file}"
|
||||||
echo "========== UPDATING VCS: DONE"
|
echo "========== UPDATING VCS: DONE"
|
||||||
echo "Local repo updated. Please push when ready."
|
echo "Local repo updated. Please push when ready."
|
||||||
echo " $(which_vcs) push"
|
echo " $VCS_TYPE push"
|
||||||
|
|||||||
@@ -46,4 +46,4 @@ vcs_add "$BB_FILES" "$encrypted_file"
|
|||||||
vcs_commit "registered in blackbox: ${unencrypted_file}" "$BB_FILES" "$encrypted_file"
|
vcs_commit "registered in blackbox: ${unencrypted_file}" "$BB_FILES" "$encrypted_file"
|
||||||
echo "========== UPDATING VCS: DONE"
|
echo "========== UPDATING VCS: DONE"
|
||||||
echo "Local repo updated. Please push when ready."
|
echo "Local repo updated. Please push when ready."
|
||||||
echo " $(which_vcs) push"
|
echo " $VCS_TYPE push"
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ while IFS= read <&99 -r unencrypted_file; do
|
|||||||
done 99<"$BB_FILES"
|
done 99<"$BB_FILES"
|
||||||
vcs_commit 'Re-encrypted keys'
|
vcs_commit 'Re-encrypted keys'
|
||||||
|
|
||||||
VCSCMD=$(which_vcs)
|
|
||||||
echo '========== DONE.'
|
echo '========== DONE.'
|
||||||
echo 'Likely next step:'
|
echo 'Likely next step:'
|
||||||
echo " ${VCSCMD} push"
|
echo " $VCS_TYPE push"
|
||||||
|
|||||||
Reference in New Issue
Block a user