Skip to content

Commit a958d40

Browse files
szedergitster
authored andcommitted
completion: don't guard git executions with __gitdir()
Three completion functions, namely __git_index_files(), __git_heads() and __git_tags(), first run __gitdir() and check that the path it outputs exists, i.e. that there is a git repository, and run a git command only if there is one. After the previous changes in this series there are no further uses of __gitdir()'s output in these functions besides those checks. And those checks are unnecessary, because we can just execute those git commands outside of a repository and let them error out. We don't perform such a check in other places either. Remove this check and the __gitdir() call from these functions, sparing the fork()+exec() overhead of the command substitution and the potential 'git rev-parse' execution. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e15098a commit a958d40

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

contrib/completion/git-completion.bash

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -312,35 +312,25 @@ __git_ls_files_helper ()
312312
# slash.
313313
__git_index_files ()
314314
{
315-
local dir="$(__gitdir)" root="${2-.}" file
316-
317-
if [ -d "$dir" ]; then
318-
__git_ls_files_helper "$root" "$1" |
319-
while read -r file; do
320-
case "$file" in
321-
?*/*) echo "${file%%/*}" ;;
322-
*) echo "$file" ;;
323-
esac
324-
done | sort | uniq
325-
fi
315+
local root="${2-.}" file
316+
317+
__git_ls_files_helper "$root" "$1" |
318+
while read -r file; do
319+
case "$file" in
320+
?*/*) echo "${file%%/*}" ;;
321+
*) echo "$file" ;;
322+
esac
323+
done | sort | uniq
326324
}
327325

328326
__git_heads ()
329327
{
330-
local dir="$(__gitdir)"
331-
if [ -d "$dir" ]; then
332-
__git for-each-ref --format='%(refname:short)' refs/heads
333-
return
334-
fi
328+
__git for-each-ref --format='%(refname:short)' refs/heads
335329
}
336330

337331
__git_tags ()
338332
{
339-
local dir="$(__gitdir)"
340-
if [ -d "$dir" ]; then
341-
__git for-each-ref --format='%(refname:short)' refs/tags
342-
return
343-
fi
333+
__git for-each-ref --format='%(refname:short)' refs/tags
344334
}
345335

346336
# Lists refs from the local (by default) or from a remote repository.

0 commit comments

Comments
 (0)