From d5a485cd6a806ddd9cdf8c9415008570d98086c1 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 7 Jul 2020 23:05:46 -0700 Subject: [PATCH] shlib.sh: make v_get_proj_from_dir use gitdir.list if needed When translating a directory back into a relative project directory, make use of the `gitdir.list` file if the translation apparently involves symbolic links to a location outside of $reporoot. If that fails, go ahead and use the same _external fallback as before. In addition, if somehow the simple check ends up with a "worktrees" subdirectory, prune that part off. Signed-off-by: Kyle J. McKay --- shlib.sh | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/shlib.sh b/shlib.sh index 3399670..93a090d 100644 --- a/shlib.sh +++ b/shlib.sh @@ -685,16 +685,31 @@ v_get_proj_from_dir() { _projpart="${_abspd#$_absrr/}" ;; *) - # Must have been reached via a symbolic link, but - # we have no way to know the source, so use a - # generic "_external" leader combined with just the - # trailing directory name - _abspd="${_abspd%/}" - _abspd="${_abspd%/.git}" - _projpart="_external/${_abspd##*/}" + # Must have been reached via a symbolic link + # Attempt to translate using the gitdir.list file + # If not found use a generic "_external" leader + # combined with just the trailing directory name + _projpart= + if + [ -f "$cfg_projlist_cache_dir/gitdir.list" ] && + [ -s "$cfg_projlist_cache_dir/gitdir.list" ] + then + _projpart="$(LC_ALL=C awk -v fnd="$_abspd" \ + <"$cfg_projlist_cache_dir/gitdir.list" \ + 'NF>=2{p=$1; sub(/^[^ \t]+[ \t]+/,""); + if ($0 == fnd) {print p ".git"; exit;}}')" || : + fi + if [ -z "$_projpart" ]; then + _abspd="${_abspd%/}" + _abspd="${_abspd%/.git}" + _projpart="_external/${_abspd##*/}" + fi ;; esac esac + case "$_projpart" in *[!/]".git/worktrees/"?*) + _projpart="${_projpart%.git/worktrees/*}.git" + esac eval "$1="'"$_projpart"' } -- 2.11.4.GIT