The previous commit changed __gitdir() to store the repository path in the $__git_dir variable. Now we change all call sites to just call __gitdir() directly and then use $__git_dir instead of doing 'dir="$(__gitdir)"' command substitution, thereby sparing the overhead of fork()ing a subshell. Signed-off-by: SZEDER Gábor <szeder@xxxxxxxxxx> --- contrib/completion/git-completion.bash | 106 ++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 48 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 85b933f2..5c8d4aea 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -219,33 +219,33 @@ __git_ps1_show_upstream () __git_ps1 () { local __git_dir="" - local g="$(__gitdir)" - if [ -z "$g" ]; then + __gitdir >/dev/null + if [ -z "$__git_dir" ]; then return fi local r="" local b="" - if [ -f "$g/rebase-merge/interactive" ]; then + if [ -f "$__git_dir/rebase-merge/interactive" ]; then r="|REBASE-i" - b="$(cat "$g/rebase-merge/head-name")" - elif [ -d "$g/rebase-merge" ]; then + b="$(cat "$__git_dir/rebase-merge/head-name")" + elif [ -d "$__git_dir/rebase-merge" ]; then r="|REBASE-m" - b="$(cat "$g/rebase-merge/head-name")" + b="$(cat "$__git_dir/rebase-merge/head-name")" else - if [ -d "$g/rebase-apply" ]; then - if [ -f "$g/rebase-apply/rebasing" ]; then + if [ -d "$__git_dir/rebase-apply" ]; then + if [ -f "$__git_dir/rebase-apply/rebasing" ]; then r="|REBASE" - elif [ -f "$g/rebase-apply/applying" ]; then + elif [ -f "$__git_dir/rebase-apply/applying" ]; then r="|AM" else r="|AM/REBASE" fi - elif [ -f "$g/MERGE_HEAD" ]; then + elif [ -f "$__git_dir/MERGE_HEAD" ]; then r="|MERGING" - elif [ -f "$g/CHERRY_PICK_HEAD" ]; then + elif [ -f "$__git_dir/CHERRY_PICK_HEAD" ]; then r="|CHERRY-PICKING" - elif [ -f "$g/BISECT_LOG" ]; then + elif [ -f "$__git_dir/BISECT_LOG" ]; then r="|BISECTING" fi @@ -263,7 +263,7 @@ __git_ps1 () git describe --tags --exact-match HEAD ;; esac 2>/dev/null)" || - b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." || + b="$(cut -c1-7 "$__git_dir/HEAD" 2>/dev/null)..." || return b="($b)" } @@ -522,9 +522,9 @@ __gitcomp_nl () __git_heads () { - local dir="$(__gitdir)" - if [ -d "$dir" ]; then - git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ + __gitdir "${1-}" >/dev/null + if [ -d "$__git_dir" ]; then + git --git-dir="$__git_dir" for-each-ref --format='%(refname:short)' \ refs/heads return fi @@ -532,9 +532,9 @@ __git_heads () __git_tags () { - local dir="$(__gitdir)" - if [ -d "$dir" ]; then - git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ + __gitdir "${1-}" >/dev/null + if [ -d "$__git_dir" ]; then + git --git-dir="$__git_dir" for-each-ref --format='%(refname:short)' \ refs/tags return fi @@ -545,9 +545,10 @@ __git_tags () # by checkout for tracking branches __git_refs () { - local i hash dir="$(__gitdir "${1-}")" track="${2-}" + local i hash track="${2-}" local format refs - if [ -d "$dir" ]; then + __gitdir "${1-}" >/dev/null + if [ -d "$__git_dir" ]; then case "$cur" in refs|refs/*) format="refname" @@ -556,20 +557,20 @@ __git_refs () ;; *) for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do - if [ -e "$dir/$i" ]; then echo $i; fi + if [ -e "$__git_dir/$i" ]; then echo $i; fi done format="refname:short" refs="refs/tags refs/heads refs/remotes" ;; esac - git --git-dir="$dir" for-each-ref --format="%($format)" \ + git --git-dir="$__git_dir" for-each-ref --format="%($format)" \ $refs if [ -n "$track" ]; then # employ the heuristic used by git checkout # Try to find a remote branch that matches the completion word # but only output if the branch name is unique local ref entry - git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \ + git --git-dir="$__git_dir" for-each-ref --shell --format="ref=%(refname:short)" \ "refs/remotes/" | \ while read -r entry; do eval "$entry" @@ -583,7 +584,7 @@ __git_refs () fi case "$cur" in refs|refs/*) - git ls-remote "$dir" "$cur*" 2>/dev/null | \ + git ls-remote "$__git_dir" "$cur*" 2>/dev/null | \ while read -r hash i; do case "$i" in *^{}) ;; @@ -592,7 +593,7 @@ __git_refs () done ;; *) - git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \ + git ls-remote "$__git_dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \ while read -r hash i; do case "$i" in *^{}) ;; @@ -625,9 +626,10 @@ __git_refs_remotes () __git_remotes () { - local i IFS=$'\n' d="$(__gitdir)" - test -d "$d/remotes" && ls -1 "$d/remotes" - for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do + local i IFS=$'\n' + __gitdir >/dev/null + test -d "$__git_dir/remotes" && ls -1 "$__git_dir/remotes" + for i in $(git --git-dir="$__git_dir" config --get-regexp 'remote\..*\.url' 2>/dev/null); do i="${i#remote.}" echo "${i/.url*/}" done @@ -685,8 +687,9 @@ __git_complete_revlist_file () esac local IFS=$'\n' + __gitdir >/dev/null COMPREPLY=($(compgen -P "$pfx" \ - -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \ + -W "$(git --git-dir="$__git_dir" ls-tree "$ls" \ | sed '/^100... blob /{ s,^.* ,, s,$, , @@ -936,7 +939,8 @@ __git_compute_porcelain_commands () __git_pretty_aliases () { local i IFS=$'\n' - for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do + __gitdir >/dev/null + for i in $(git --git-dir="$__git_dir" config --get-regexp "pretty\..*" 2>/dev/null); do case "$i" in pretty.*) i="${i#pretty.}" @@ -949,7 +953,8 @@ __git_pretty_aliases () __git_aliases () { local i IFS=$'\n' - for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do + __gitdir >/dev/null + for i in $(git --git-dir="$__git_dir" config --get-regexp "alias\..*" 2>/dev/null); do case "$i" in alias.*) i="${i#alias.}" @@ -962,7 +967,8 @@ __git_aliases () # __git_aliased_command requires 1 argument __git_aliased_command () { - local word cmdline=$(git --git-dir="$(__gitdir)" \ + __gitdir >/dev/null + local word cmdline=$(git --git-dir="$__git_dir" \ config --get "alias.$1") for word in $cmdline; do case "$word" in @@ -1013,8 +1019,8 @@ __git_whitespacelist="nowarn warn error error-all fix" _git_am () { - local dir="$(__gitdir)" - if [ -d "$dir"/rebase-apply ]; then + __gitdir >/dev/null + if [ -d "$__git_dir"/rebase-apply ]; then __gitcomp "--skip --continue --resolved --abort" return fi @@ -1099,7 +1105,8 @@ _git_bisect () local subcommands="start bad good skip reset visualize replay log run" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then - if [ -f "$(__gitdir)"/BISECT_START ]; then + __gitdir >/dev/null + if [ -f "$__git_dir"/BISECT_START ]; then __gitcomp "$subcommands" else __gitcomp "replay start" @@ -1559,9 +1566,9 @@ _git_log () { __git_has_doubledash && return - local g="$(__gitdir)" + __gitdir >/dev/null local merge="" - if [ -f "$g/MERGE_HEAD" ]; then + if [ -f "$__git_dir/MERGE_HEAD" ]; then merge="--merge" fi case "$cur" in @@ -1745,8 +1752,8 @@ _git_push () _git_rebase () { - local dir="$(__gitdir)" - if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then + __gitdir >/dev/null + if [ -d "$__git_dir"/rebase-apply ] || [ -d "$__git_dir"/rebase-merge ]; then __gitcomp "--continue --skip --abort" return fi @@ -1845,7 +1852,8 @@ __git_config_get_set_variables () c=$((--c)) done - git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null | + __gitdir >/dev/null + git --git-dir="$__git_dir" config $config_file --list 2>/dev/null | while read -r line do case "$line" in @@ -1880,7 +1888,8 @@ _git_config () remote.*.push) local remote="${prev#remote.}" remote="${remote%.push}" - __gitcomp_nl "$(git --git-dir="$(__gitdir)" \ + __gitdir >/dev/null + __gitcomp_nl "$(git --git-dir="$__git_dir" \ for-each-ref --format='%(refname):%(refname)' \ refs/heads)" return @@ -2304,7 +2313,8 @@ _git_remote () ;; update) local i c='' IFS=$'\n' - for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do + __gitdir >/dev/null + for i in $(git --git-dir="$__git_dir" config --get-regexp "remotes\..*" 2>/dev/null); do i="${i#remotes.}" c="$c ${i/ */}" done @@ -2441,7 +2451,8 @@ _git_stash () COMPREPLY=() ;; show,*|apply,*|drop,*|pop,*|branch,*) - __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ + __gitdir >/dev/null + __gitcomp_nl "$(git --git-dir="$__git_dir" stash list \ | sed -n -e 's/:.*//p')" ;; *) @@ -2693,10 +2704,9 @@ _gitk () __git_has_doubledash && return - local __git_dir="" - local g="$(__gitdir)" - local merge="" - if [ -f "$g/MERGE_HEAD" ]; then + local __git_dir="" merge="" + __gitdir >/dev/null + if [ -f "$__git_dir/MERGE_HEAD" ]; then merge="--merge" fi case "$cur" in -- 1.7.10.1.541.gb1be298 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html