From: "SZEDER Gábor" <szeder@ira.uka.de>
To: git@vger.kernel.org
Cc: "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH 08/19] completion: use $__git_dir instead of $(__gitdir)
Date: Wed, 9 May 2012 02:44:39 +0200 [thread overview]
Message-ID: <1336524290-30023-9-git-send-email-szeder@ira.uka.de> (raw)
In-Reply-To: <1336524290-30023-1-git-send-email-szeder@ira.uka.de>
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@ira.uka.de>
---
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
next prev parent reply other threads:[~2012-05-09 0:46 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-09 0:44 [PATCH 00/19] Bash prompt speedup SZEDER Gábor
2012-05-09 0:44 ` [PATCH 01/19] tests: move code to run tests under bash into a helper library SZEDER Gábor
2012-05-09 0:44 ` [PATCH 02/19] tests: add tests for the bash prompt functions in the completion script SZEDER Gábor
2012-05-09 8:07 ` Johannes Sixt
2012-05-09 18:08 ` Junio C Hamano
2012-05-10 6:09 ` Johannes Sixt
2012-05-09 18:36 ` Junio C Hamano
2012-05-09 20:33 ` SZEDER Gábor
2012-05-09 0:44 ` [PATCH 03/19] completion: use __gitdir() in _git_log() SZEDER Gábor
2012-05-09 18:41 ` Junio C Hamano
2012-05-09 19:01 ` SZEDER Gábor
2012-05-09 0:44 ` [PATCH 04/19] completion: respect $GIT_DIR SZEDER Gábor
2012-05-09 8:09 ` Johannes Sixt
2012-05-09 18:54 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 05/19] bash prompt: don't show the prompt when .git/HEAD is unreadable SZEDER Gábor
2012-05-09 19:32 ` Junio C Hamano
2012-05-09 19:45 ` SZEDER Gábor
2012-05-09 0:44 ` [PATCH 06/19] bash prompt: return early from __git_ps1() when not in a git repository SZEDER Gábor
2012-05-09 0:44 ` [PATCH 07/19] completion: make __gitdir() store repository path in $__git_dir SZEDER Gábor
2012-05-09 19:36 ` Junio C Hamano
2012-05-09 0:44 ` SZEDER Gábor [this message]
2012-05-09 19:43 ` [PATCH 08/19] completion: use $__git_dir instead of $(__gitdir) Junio C Hamano
2012-05-09 20:22 ` SZEDER Gábor
2012-05-09 20:56 ` Junio C Hamano
2012-05-09 21:36 ` SZEDER Gábor
2012-05-09 0:44 ` [RFC PATCH 09/19] completion: platform-specific helper function to get physical path SZEDER Gábor
2012-05-09 7:37 ` Johannes Sixt
2012-05-09 0:44 ` [PATCH 10/19] completion: use bash builtins to search for repository SZEDER Gábor
2012-05-09 19:52 ` Junio C Hamano
2012-05-09 22:34 ` SZEDER Gábor
2012-05-09 22:59 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 11/19] bash prompt: use bash builtins to find out current branch SZEDER Gábor
2012-05-09 20:02 ` Junio C Hamano
2012-05-09 21:11 ` SZEDER Gábor
2012-05-09 21:25 ` Junio C Hamano
2012-05-09 21:45 ` SZEDER Gábor
2012-05-09 21:50 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 12/19] bash prompt: use bash builtins to check whether inside git dir SZEDER Gábor
2012-05-09 8:07 ` Johannes Sixt
2012-05-09 20:06 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 13/19] bash prompt: check whether inside the worktree only when necessary SZEDER Gábor
2012-05-09 0:44 ` [PATCH 14/19] bash prompt: use bash builtins to find out current branch during rebase SZEDER Gábor
2012-05-09 0:44 ` [PATCH 15/19] bash prompt: use bash builtins to get detached HEAD abbrev. object name SZEDER Gábor
2012-05-09 0:44 ` [PATCH 16/19] bash prompt: display stash and upstream state even inside the repository SZEDER Gábor
2012-05-09 0:44 ` [PATCH 17/19] bash prompt: use bash builtins to check stash state SZEDER Gábor
2012-05-09 0:44 ` [RFC PATCH 18/19] bash prompt: avoid command substitution when checking for untracked files SZEDER Gábor
2012-05-09 20:32 ` Junio C Hamano
2012-05-09 0:44 ` [PATCH 19/19] bash prompt: alternative git prompt without command substitution SZEDER Gábor
2012-05-09 19:38 ` Andrew Sayers
2012-05-09 22:08 ` SZEDER Gábor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1336524290-30023-9-git-send-email-szeder@ira.uka.de \
--to=szeder@ira.uka.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).