Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 59 additions & 45 deletions git-fatlas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# the main athena repo and use release 21.2.
#
_git-fatlas-init_usage() {
echo "usage: $1 [-h] [-r release] [-u URL] [-s SHARED]"
echo "usage: $1 [-h] [-v] [-r release] [-u URL] [-s SHARED]"
}
function git-fatlas-init() (

Expand All @@ -22,10 +22,11 @@ function git-fatlas-init() (
local RELEASE=main
local URL=${GIT_FATLAS_UPSTREAM}
local SHARED=""
VLOG=/dev/null

# parse options
local opt
while getopts ":hr:u:s:" opt $@; do
while getopts ":hvr:u:s:" opt $@; do
case $opt in
h) _git-fatlas-init_usage $FUNCNAME;
cat <<EOF
Expand All @@ -40,6 +41,7 @@ default repo: $URL

EOF
return 1;;
v) VLOG=/dev/stdout ;;
r) RELEASE=${OPTARG} ;;
u) URL=${OPTARG} ;;
s) SHARED=${OPTARG} ;;
Expand Down Expand Up @@ -69,14 +71,13 @@ EOF
# set up the sparse checkout, then move to the desired
# branch. Note that this leaves git in a rather ugly position
# since there are no packages checked out.
git config core.sparsecheckout true
touch .git/info/sparse-checkout
if [[ ${RELEASE} != main ]]; then
git branch ${RELEASE} atlas/${RELEASE}
fi
git reset --soft ${RELEASE}
git symbolic-ref HEAD refs/heads/${RELEASE}
git fetch --set-upstream atlas ${RELEASE}
git sparse-checkout init --cone

echo checking out ${RELEASE} > $VLOG
git checkout ${RELEASE}

echo caching package list > $VLOG
git-fatlas-remake-package-list > $VLOG
)


Expand Down Expand Up @@ -136,29 +137,35 @@ function git-fatlas-remake-package-list() {
# the working tree. There are also tab complete functions defined
# below.
#
function git-fatlas-add() (
set -eu
function git-fatlas-add() {

local LOG=${TABTEST-/dev/null}

echo "--- trying to add a package ---" >> $LOG
local pkg_list=$(git-fatlas-get-package-list)
local SP=.git/info/sparse-checkout
local STUB
local FULLPATH
for STUB in ${@:1} ; do
egrep "(^|/)${STUB%/}(/|$)" $pkg_list | while read FULLPATH; do
echo ${FULLPATH%/}/ | tee -a $SP
done
done
git checkout HEAD
)
echo "matching against $pkg_list" >> $LOG
echo "looking for: $1" >> $LOG
local reply=( $(fgrep ${1} $pkg_list | egrep "(/|^)$1$") )
echo "matches ${reply[*]}" >> $LOG

if (( ${#reply[*]} > 1 )); then
echo "ERROR: too many replies" | tee -a $LOG 2>&1
return 1
elif (( ${#reply[*]} == 0 )); then
echo "ERROR: no matches" | tee -a $LOG 2>&1
return 1
fi
git sparse-checkout add ${reply[*]}
}

# ____________________________________________________________________
# Add a new package to the repo
#
# If you already have something in the working tree and want to check
# it in, you should call this function on it.
#
function git-fatlas-new() {
local SP=.git/info/sparse-checkout
local STUB
function git-fatlas-new() (
pkg_list=$(git-fatlas-get-package-list)
for STUB in ${@:1} ; do
if [[ ! -d ${STUB} ]]; then
echo "${STUB} is not a directory" 2>&1
Expand All @@ -170,31 +177,22 @@ contain this
EOF
return 1
fi
echo ${STUB%/}/ | tee -a $SP
echo ${STUB%/} >> $pkg_list
git-fatlas-add ${STUB%/}
git add ${STUB%/}/
done
}
)

# ____________________________________________________________________
# Remove package
#
# This one is a bit tricky in that we have to make sure we don't
# remove the last package. Git doesn't like that for some reason.
#
function git-fatlas-remove() {
local SP=.git/info/sparse-checkout
local TMP=$(cat $SP | sort -u | egrep -v $1)
if [[ ${TMP} == '' ]]; then
echo "ERROR: can't remove last package" 1>&2
return 1
fi
local FILE
rm $SP
for FILE in $TMP; do
echo $FILE >> $SP
done
git checkout HEAD
}
function git-fatlas-remove() (
local NEW=$(git sparse-checkout list | egrep -v $1 | tr '\n' ' ')
git sparse-checkout set $NEW
)

# ____________________________________________________________________
# Update copyright statements
Expand All @@ -214,27 +212,43 @@ function git-fatlas-copyright-update() {
# ____________________________________________________________________
# Tab complete function for the add utility
#
# if you set TABTEST and then read it with `tail -f` you will see some
# logging info
function _git-fatlas-add() {

local LOG=${TABTEST-/dev/null}

# build or get package list
echo "--- getting package list ---" >> $LOG
echo "looking for: $2" >> $LOG
local pkg_list=$(git-fatlas-get-package-list)
echo "got $pkg_list" >> $LOG

# first check for completion from the root up
echo "checking matches in package list" >> $LOG
COMPREPLY=( $(compgen -W "$(cat $pkg_list)" -- $2 ) )
if [[ ${#COMPREPLY[*]} != 0 ]]; then
echo "returning ${#COMPREPLY[*]} matches" >> $LOG
return 0
fi

# then check for a unique fgrep match
echo "checking with fgrep" >> $LOG
COMPREPLY=( $(fgrep ${2} $pkg_list ) )
if [[ ${#COMPREPLY[*]} == 1 ]]; then
echo "returning ${#COMPREPLY[*]} matches" >> $LOG
return 0
fi

# then check to see if any part of the package name matches note
# that we can't include the full path because that will trigger a
# completion to any stub that is shared among all matches.
echo "got ${#COMPREPLY[*]} replies, moving on" >> $LOG

# then check to see if any part of the package name matches
#
# note that we can't include the full path because that will
# trigger a completion to any stub that is shared among all
# matches.
echo "checking with fgrep, excluding some patterns" >> $LOG
COMPREPLY=( $(fgrep ${2} $pkg_list | egrep -o "[^/]*$2.*") )
echo "returning ${#COMPREPLY[*]} matches" >> $LOG
return 0
}
complete -F _git-fatlas-add git-fatlas-add