These patches are an attempt to make Git's startup sequence a bit less
surprising.
The idea here is to discover the .git/ directory gently (i.e. without
changing the current working directory, or global variables), and to use
it to read the .git/config file early, before we actually called
setup_git_directory() (if we ever do that).
This also allows us to fix the early config e.g. to determine the pager
or to resolve aliases in a non-surprising manner.
The first iteration of this patch series still tried to be clever and to
avoid having to disentangle the side effects from the
setup_git_directory_gently_1() function simply by duplicating the logic.
However, Peff suggested in a very short sentence that this would not fly
well.
Little did I know that I would spend the better part of an entire week
on trying to address that innocuous comment! There are simply *so many*
side effects in that code. Who would have thought that a function
called check_repository_format() would set global variables?
But after all that work, I am actually quite a bit satisfied with the
way things turned out.
My dirty little secret is that I actually need this for something else
entirely. I need to patch an internal version of Git to gather
statistics, and to that end I need to read the config before and after
running every Git command. Hence the need for a gentle, and correct
early config.
Notes:
- I do not handle dashed invocations of `init` and `clone` correctly.
That is, even if `git-init` and `git-clone` clearly do not want to
read the local config, they do. It does not matter all that much
because they do not use a pager, but still. It is a wart.
- The read_early_config() function is still called multiple times,
re-reading all the config files and re-discovering the .git/ directory
multiple times, which is quite wasteful. I was tempted to take care of
that but I must not run the danger to spread myself even thinner these
days. If a patch adding that caching were to fly my way, I'd gladly
integrate it, of course... ;-)
Changes since v1:
- the discover_git_directory() function is no longer completely separate
from setup_git_directory(), but a callee of the latter.
- t7006 succeeds now (I removed the incorrect test case in favor of one
that verifies that setup_git_directory() was not run via the tell-tale
that the current working directory has not changed when the pager
runs).
Johannes Schindelin (9):
t7006: replace dubious test
setup_git_directory(): use is_dir_sep() helper
setup_git_directory(): avoid changing global state during discovery
Export the discover_git_directory() function
Make read_early_config() reusable
read_early_config(): special-case builtins that create a repository
read_early_config(): avoid .git/config hack when unneeded
read_early_config(): really discover .git/
Test read_early_config()
cache.h | 4 +-
config.c | 36 +++++++++
git.c | 3 +
pager.c | 31 -------
setup.c | 211 +++++++++++++++++++++++++++++++-----------------
t/helper/test-config.c | 15 ++++
t/t1309-early-config.sh | 50 ++++++++++++
t/t7006-pager.sh | 18 ++++-
8 files changed, 257 insertions(+), 111 deletions(-)
create mode 100755 t/t1309-early-config.sh
base-commit: 3bc53220cb2dcf709f7a027a3f526befd021d858
Submitted-As: https://public-inbox.org/git/cover.1488506615.git.johannes.schindelin@gmx.de
In-Reply-To: https://public-inbox.org/git/cover.1481211338.git.johannes.schindelin@gmx.de
Assets
2
-
2017-03-03T02:03:35Z
-
2017-03-03T02:03:35Z
-