git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/19] Bash prompt speedup
@ 2012-05-09  0:44 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
                   ` (18 more replies)
  0 siblings, 19 replies; 50+ messages in thread
From: SZEDER Gábor @ 2012-05-09  0:44 UTC (permalink / raw)
  To: git; +Cc: SZEDER Gábor

Hi,

It was pointed out about a year ago that displaying the git-specific bash
prompt on Windows/MinGW takes quite long, long enough to be noticeable.
And indeed, while in a subdirectory of a repository and stash indicator
enabled and my laptop running from battery I get this:

  $ time prompt=$(__git_ps1)

  real    0m0.412s
  user    0m0.048s
  sys     0m0.210s

This is mainly caused by the numerous fork()s and exec()s to create
subshells and run git commands, which are rather expensive on Windows.

This patch series eliminates many command substitutions and git commands
from __git_ps1() by reorganizing code or replacing them with bash
builtins.  This speeds up the prompt immensely: now I get the same prompt
as above in about 10ms(!).  Timing results are shown in the log message of
patch 19.

Unfortunately, to achive this users have to change their configuration, in
particular change their $PS1 and $PROMPT_COMMAND (see patch 19) and should
enable the discovery of git repositories across filesystem boundaries (see
patch 10).

There are two RFC patches in there (9 and 18), please have a look.


Here's an outline of the series:

First, a couple of tests for the bash prompt, to lessen the chance that I
break something ;)  These are basically the same patches that I sent out a
while ago in [1], the only noteworthy change is that I renamed the helper
library to lib-bash.sh (from lib-completion.sh), because all it does is to
run tests under bash and there is nothing completion-specific in there.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/195587/focus=195711

  [PATCH 01/19] tests: move code to run tests under bash into a helper library
  [PATCH 02/19] tests: add tests for the bash prompt functions in the completion script

The next four patches contain a couple of fixes and cleanups:

  [PATCH 03/19] completion: use __gitdir() in _git_log()
  [PATCH 04/19] completion: respect $GIT_DIR
  [PATCH 05/19] bash prompt: don't show the prompt when .git/HEAD is unreadable
  [PATCH 06/19] bash prompt: return early from __git_ps1() when not in a git repository

These four make __gitdir() faster, so they'll benefit not only the
bash prompt but completing refs, aliases, config variables, etc., too.

  [PATCH 07/19] completion: make __gitdir() store repository path in $__git_dir
  [PATCH 08/19] completion: use $__git_dir instead of $(__gitdir)
  [RFC PATCH 09/19] completion: platform-specific helper function to get physical path
  [PATCH 10/19] completion: use bash builtins to search for repository

These three make the main codepath in __git_ps1() faster by eliminating a
couple of command substitutions and git commands.

  [PATCH 11/19] bash prompt: use bash builtins to find out current branch
  [PATCH 12/19] bash prompt: use bash builtins to check whether inside git dir
  [PATCH 13/19] bash prompt: check whether inside the worktree only when necessary

Eliminate some more command substitutions and git commands that are not
necessarily run for every prompt:

  [PATCH 14/19] bash prompt: use bash builtins to find out current branch during rebase
  [PATCH 15/19] bash prompt: use bash builtins to get detached HEAD abbrev. object name
  [PATCH 16/19] bash prompt: display stash and upstream state even inside the repository
  [PATCH 17/19] bash prompt: use bash builtins to check stash state
  [RFC PATCH 18/19] bash prompt: avoid command substitution when checking for untracked files

And finally get rid of the command substitution used to include the git
prompt in $PS1:

  [PATCH 19/19] bash prompt: alternative git prompt without command substitution

Enjoy.


Best,
Gábor


SZEDER Gábor (19):
  tests: move code to run tests under bash into a helper library
  tests: add tests for the bash prompt functions in the completion
    script
  completion: use __gitdir() in _git_log()
  completion: respect $GIT_DIR
  bash prompt: don't show the prompt when .git/HEAD is unreadable
  bash prompt: return early from __git_ps1() when not in a git
    repository
  completion: make __gitdir() store repository path in $__git_dir
  completion: use $__git_dir instead of $(__gitdir)
  completion: platform-specific helper function to get physical path
  completion: use bash builtins to search for repository
  bash prompt: use bash builtins to find out current branch
  bash prompt: use bash builtins to check whether inside git dir
  bash prompt: check whether inside the worktree only when necessary
  bash prompt: use bash builtins to find out current branch during
    rebase
  bash prompt: use bash builtins to get detached HEAD abbrev. object
    name
  bash prompt: display stash and upstream state even inside the
    repository
  bash prompt: use bash builtins to check stash state
  bash prompt: avoid command substitution when checking for untracked
    files
  bash prompt: alternative git prompt without command substitution

 contrib/completion/git-completion.bash | 315 ++++++++++-------
 t/lib-bash.sh                          |  18 +
 t/t9902-completion.sh                  |  14 +-
 t/t9903-bash-prompt.sh                 | 593 +++++++++++++++++++++++++++++++++
 4 files changed, 815 insertions(+), 125 deletions(-)
 create mode 100644 t/lib-bash.sh
 create mode 100755 t/t9903-bash-prompt.sh

-- 
1.7.10.1.541.gb1be298

^ permalink raw reply	[flat|nested] 50+ messages in thread

end of thread, other threads:[~2012-05-10  6:09 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 08/19] completion: use $__git_dir instead of $(__gitdir) SZEDER Gábor
2012-05-09 19:43   ` 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

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).