-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bash/zsh completion: reimplement and decrease runtime by factor 1863
Fixes: #795 ("tab completion is really slow") When run on a Git repository with a large amount of files, like the linux repository, __tig_complete_file() can take a very long time to complete. This is unfortunate because when accidentally pressing Tab in such a repo, bash gets stuck until the completion function has finished, and does not even allow the user to cancel the operation with Ctrl-C. In contrast, the current git completion does not have these problems, and since tig's command line parameters are mostly parameters to git-log or git-diff, we can use git's native completion for those cases instead. This also has the advantage that we do not need to care about updating the tig completion when new parameters are added to git-log or git-diff. I have tested this only in bash, not in zsh. For comparison, here is an exemplary runtime measurement of the old and the new completion in bash, showing an improvement of factor 1863. Admittedly, this was on a fairly loaded system (a build server), but still then the new completion runs in unnoticable time. I'm also getting similar results on an idle system in the same repo with runtime improvements of about factor 1000. linux (master) $ echo $BASH_VERSION 5.0.3(1)-release linux (master) $ git describe v5.4-rc3-38-gbc88f85c6c09 linux (master) $ uptime 16:45:52 up 36 days, 3:33, 224 users, load average: 24.17, 38.87, 31.21 # The new completion: linux (master) $ . ../tig/contrib/tig-completion.bash linux (master) $ time COMP_WORDS=("tig log") COMP_CWORD=2 __git_wrap_tig real 0m0.127s user 0m0.085s sys 0m0.024s # The old completion: linux (master) $ . /usr/share/bash-completion/completions/tig linux (master) $ time COMP_WORDS=("tig log") COMP_CWORD=2 _tig real 2m1.145s user 1m40.379s sys 0m1.347s With this change, almost nothing of the old completion remains, so change the copyright header accordingly. I'm also now adding a GPL-2.0-or-later dedication, which is the same license as most other code in this repository; and which, I presume, was also the author's intent since the first incarnation of this file. While at it, fix some typos in old comments, and update installation instructions. Signed-off-by: Roland Hieber <[email protected]>
- Loading branch information
Showing
1 changed file
with
69 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using
__git_complete
is a good idea... but there are cases when it is not defined becausegit
completions are loaded dynamically bybash_completion
. See #1011 (comment)