SZEDER Gábor [off-list ref] writes:
Also declare $__git_dir as local in __git_ps1() and _gitk() to prevent
the variable from leaking into the environment when they call
__gitdir() (that would break completion and bash prompt when the user
moves to a different git repository).
Good; this was actually the only major thing I worried about when I saw
the tail part of the series. So $__git_dir is global across the call
chain of a single invocation to show __git_ps1, but it always is reset
once __git_ps1 is called again, so that it will always know where the
then-current git repository is, right?
Looks quite a sane and valid optimization to me.