git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 08/19] completion: use $__git_dir instead of $(__gitdir)

From
SZEDER Gábor <szeder@ira.uka.de>
Date
May 9, 2012, 21:36 UTC
Message-ID
<20120509213636.GC7824@goldbirke>
In-Reply-To
<7vmx5hqdjx.fsf@alter.siamese.dyndns.org>
On Wed, May 09, 2012 at 01:56:02PM -0700, Junio C Hamano wrote:
Show 27 quoted lines
> SZEDER Gábor <szeder@ira.uka.de> writes:
> 
> >> > @@ -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
> >> 
> >> Now this worries me.  The way I read 07/19 was that the local __git_dir=""
> >> declarations in __git_ps1 and __git were what protected this whole
> >> machinery to protect us against surprises from user doing "cd" between
> >> interactive commands, but you have the same __gitdir call to set up the
> >> global $__git_dir variable there, without the initialization to "".
> >> 
> >> Having to have a call to __gitdir seems to indicate to me that you cannot
> >> assume that the other initialization sites may not have been called before
> >> we get to this point.  Then why is 'local __git_dir=""' unneeded here?
> >
> > Your comments to the previous patch apply here.
> 
> Not really.  __git_ps1 and __gitk seems to do __gitdir very early to make
> sure anybody that use $__git_dir can rely on it

No, __git_ps1() and __gitk() do __gitdir() early, because they need the path to the repository very early.

Show 5 quoted lines
> but having to sprinkle
> "set up $__git_dir variable" everywhere means anybody who wants to update
> need to know if it is already called, which defeats the point of "we can
> use $__git_dir instead of calling $(__gitdir)" from maintainability's
> point of view.
Well, the point is better explained in the body of the commit message:
  just call __gitdir() directly and then use $__git_dir instead of
  doing 'dir="$(__gitdir)"' command substitution

Unfortunately, I just couldn't manage to squeeze all this into a one-line short description. So it really is about performance, and not maintainability.

Previous: Junio C HamanoNext: SZEDER Gábor
Message 25 of 50 in “Bash prompt speedup”
  1. 00/19 Bash prompt speedupSZEDER Gábor, May 9, 2012
  2. 01/19 tests: move code to run tests under bash into a helper librarySZEDER Gábor, May 9, 2012
  3. 02/19 tests: add tests for the bash prompt functions in the completion scriptSZEDER Gábor, May 9, 2012
  4. Johannes SixtMay 9, 2012
  5. Junio C HamanoMay 9, 2012
  6. Johannes SixtMay 10, 2012
  7. Junio C HamanoMay 9, 2012
  8. SZEDER GáborMay 9, 2012
  9. 03/19 completion: use __gitdir() in _git_log()SZEDER Gábor, May 9, 2012
  10. Junio C HamanoMay 9, 2012
  11. SZEDER GáborMay 9, 2012
  12. 04/19 completion: respect $GIT_DIRSZEDER Gábor, May 9, 2012
  13. Johannes SixtMay 9, 2012
  14. Junio C HamanoMay 9, 2012
  15. 05/19 bash prompt: don't show the prompt when .git/HEAD is unreadableSZEDER Gábor, May 9, 2012
  16. Junio C HamanoMay 9, 2012
  17. SZEDER GáborMay 9, 2012
  18. 06/19 bash prompt: return early from __git_ps1() when not in a git repositorySZEDER Gábor, May 9, 2012
  19. 07/19 completion: make __gitdir() store repository path in $__git_dirSZEDER Gábor, May 9, 2012
  20. Junio C HamanoMay 9, 2012
  21. 08/19 completion: use $__git_dir instead of $(__gitdir)SZEDER Gábor, May 9, 2012
  22. Junio C HamanoMay 9, 2012
  23. SZEDER GáborMay 9, 2012
  24. Junio C HamanoMay 9, 2012
  25. SZEDER GáborMay 9, 2012
  26. 09/19 completion: platform-specific helper function to get physical pathSZEDER Gábor, May 9, 2012
  27. Johannes SixtMay 9, 2012
  28. 10/19 completion: use bash builtins to search for repositorySZEDER Gábor, May 9, 2012
  29. Junio C HamanoMay 9, 2012
  30. SZEDER GáborMay 9, 2012
  31. Junio C HamanoMay 9, 2012
  32. 11/19 bash prompt: use bash builtins to find out current branchSZEDER Gábor, May 9, 2012
  33. Junio C HamanoMay 9, 2012
  34. SZEDER GáborMay 9, 2012
  35. Junio C HamanoMay 9, 2012
  36. SZEDER GáborMay 9, 2012
  37. Junio C HamanoMay 9, 2012
  38. 12/19 bash prompt: use bash builtins to check whether inside git dirSZEDER Gábor, May 9, 2012
  39. Johannes SixtMay 9, 2012
  40. Junio C HamanoMay 9, 2012
  41. 13/19 bash prompt: check whether inside the worktree only when necessarySZEDER Gábor, May 9, 2012
  42. 14/19 bash prompt: use bash builtins to find out current branch during rebaseSZEDER Gábor, May 9, 2012
  43. 15/19 bash prompt: use bash builtins to get detached HEAD abbrev. object nameSZEDER Gábor, May 9, 2012
  44. 16/19 bash prompt: display stash and upstream state even inside the repositorySZEDER Gábor, May 9, 2012
  45. 17/19 bash prompt: use bash builtins to check stash stateSZEDER Gábor, May 9, 2012
  46. 18/19 bash prompt: avoid command substitution when checking for untracked filesSZEDER Gábor, May 9, 2012
  47. Junio C HamanoMay 9, 2012
  48. 19/19 bash prompt: alternative git prompt without command substitutionSZEDER Gábor, May 9, 2012
  49. Andrew SayersMay 9, 2012
  50. SZEDER GáborMay 9, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.