From bc1158c1ebf19dd300cd7a6665ebb8fb13551b9f Mon Sep 17 00:00:00 2001 From: Dan Guest Date: Wed, 5 Jun 2024 11:01:18 +0200 Subject: [PATCH 1/4] wip --- git-fatlas.sh | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/git-fatlas.sh b/git-fatlas.sh index 619773d..2dabc2b 100644 --- a/git-fatlas.sh +++ b/git-fatlas.sh @@ -69,14 +69,24 @@ 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} + echo setting sparse + git sparse-checkout set + + echo checking out ${RELEASE} + git checkout ${RELEASE} + + echo caching package list + git-fatlas-remake-package-list + + # echo fetching and setting upstream + # git fetch --set-upstream atlas ${RELEASE} + # if [[ ${RELEASE} != main ]]; then + # git branch ${RELEASE} atlas/${RELEASE} + # fi + # echo resetting + # git reset --soft atlas/${RELEASE} + # echo symlinking + # git symbolic-ref HEAD refs/heads/${RELEASE} ) @@ -138,16 +148,7 @@ function git-fatlas-remake-package-list() { # function git-fatlas-add() ( set -eu - 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 + git sparse-checkout set ${1} ) # ____________________________________________________________________ From 0d804919d98d633dcab0e653e34687d0dcaf6f4f Mon Sep 17 00:00:00 2001 From: Dan Guest Date: Wed, 5 Jun 2024 14:34:50 +0200 Subject: [PATCH 2/4] mostly working changes --- git-fatlas.sh | 80 +++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/git-fatlas.sh b/git-fatlas.sh index 2dabc2b..e163450 100644 --- a/git-fatlas.sh +++ b/git-fatlas.sh @@ -70,23 +70,13 @@ EOF # branch. Note that this leaves git in a rather ugly position # since there are no packages checked out. echo setting sparse - git sparse-checkout set + git sparse-checkout init --cone echo checking out ${RELEASE} git checkout ${RELEASE} echo caching package list - git-fatlas-remake-package-list - - # echo fetching and setting upstream - # git fetch --set-upstream atlas ${RELEASE} - # if [[ ${RELEASE} != main ]]; then - # git branch ${RELEASE} atlas/${RELEASE} - # fi - # echo resetting - # git reset --soft atlas/${RELEASE} - # echo symlinking - # git symbolic-ref HEAD refs/heads/${RELEASE} + git-fatlas-remake-package-list > /dev/null ) @@ -146,10 +136,26 @@ function git-fatlas-remake-package-list() { # the working tree. There are also tab complete functions defined # below. # -function git-fatlas-add() ( - set -eu - git sparse-checkout set ${1} -) +function git-fatlas-add() { + + local LOG=${TABTEST-/dev/null} + + echo "--- trying to add a package ---" >> $LOG + local pkg_list=$(git-fatlas-get-package-list) + 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 @@ -182,20 +188,10 @@ EOF # 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 @@ -215,27 +211,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 From 5707f4113833ef000c0eb15929724f0ff9e4cd1c Mon Sep 17 00:00:00 2001 From: Dan Guest Date: Wed, 5 Jun 2024 14:57:36 +0200 Subject: [PATCH 3/4] rewrite package adder --- git-fatlas.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/git-fatlas.sh b/git-fatlas.sh index e163450..889dda6 100644 --- a/git-fatlas.sh +++ b/git-fatlas.sh @@ -143,8 +143,8 @@ function git-fatlas-add() { echo "--- trying to add a package ---" >> $LOG local pkg_list=$(git-fatlas-get-package-list) echo "matching against $pkg_list" >> $LOG - echo "looking for $1" >> $LOG - local reply=( $(fgrep ${1} $pkg_list | egrep "[/^]$1$") ) + echo "looking for: $1" >> $LOG + local reply=( $(fgrep ${1} $pkg_list | egrep "(/|^)$1$") ) echo "matches ${reply[*]}" >> $LOG if (( ${#reply[*]} > 1 )); then @@ -163,9 +163,8 @@ function git-fatlas-add() { # 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 @@ -177,10 +176,11 @@ 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 From f037715e84fe5587e57ba763201dd16e0a976764 Mon Sep 17 00:00:00 2001 From: Dan Guest Date: Wed, 5 Jun 2024 15:11:56 +0200 Subject: [PATCH 4/4] verbosity --- git-fatlas.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/git-fatlas.sh b/git-fatlas.sh index 889dda6..61b349e 100644 --- a/git-fatlas.sh +++ b/git-fatlas.sh @@ -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() ( @@ -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 < $VLOG git checkout ${RELEASE} - echo caching package list - git-fatlas-remake-package-list > /dev/null + echo caching package list > $VLOG + git-fatlas-remake-package-list > $VLOG )