You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
My dirty little secret is that I need to discover the Git directory
early, without changing global state, for usage statistics gathering in
the GVFS Git project, so I actually do not care all that much about the
early config, although it is a welcome fallout (and a good reason for
accepting these patches and thereby releasing me of more maintenance
burden :-)).
Notable notes:
- In contrast to earlier versions, I no longer special-case init and
clone. Peff pointed out that this adds technical debt, and that we can
actually argue (for consistency's sake) that early config reads the
current repository config (if any) even for init and clone.
- The read_early_config() function does not cache Git directory
discovery nor read values. If needed, this can be implemented later,
in a separate patch series.
- The alias handling in git.c could possibly benefit from this work, but
again, this is a separate topic from the current patch series.
Changes since v2:
- replaced `test -e` by `test_path_is_file`
- fixed premature "cwd -> dir" in 2/9
- the setup_git_directory_gently_1() function is no longer renamed
because it is not exported directly, anyway
- fixed the way setup_discovered_git_dir() expected the offset parameter
to exclude the trailing slash (which is not true for root
directories); also verified that setup_bare_git_dir() does not require
a corresponding patch
- switched to using size_t instead of int to save the length of the
strbuf in discover_git_directory()
- ensured that discover_git_directory() turns a relative gitdir into an
absolute one even if there is already some text in the strbuf
- clarified under which circumstances we turn a relative gitdir into an
absolute one
- avoided absolute gitdir with trailing "/." to be returned
- the commit that fixes the "really dirty hack" now rewords that comment
to reflect that it is no longer a really dirty hack
- dropped the special-casing of init and clone
- the discover_git_directory() function now correctly checks the
repository version, warning (and returning NULL) in case of a problem
Johannes Schindelin (9):
t7006: replace dubious test
setup_git_directory(): use is_dir_sep() helper
Prepare setup_discovered_git_directory() the root directory
setup_git_directory_1(): avoid changing global state
Export the discover_git_directory() function
Make read_early_config() reusable
read_early_config(): avoid .git/config hack when unneeded
read_early_config(): really discover .git/
Test read_early_config()
cache.h | 3 +
config.c | 27 ++++++
pager.c | 31 -------
setup.c | 237 ++++++++++++++++++++++++++++++++----------------
t/helper/test-config.c | 15 +++
t/t1309-early-config.sh | 50 ++++++++++
t/t7006-pager.sh | 18 +++-
7 files changed, 269 insertions(+), 112 deletions(-)
create mode 100755 t/t1309-early-config.sh
base-commit: 3bc53220cb2dcf709f7a027a3f526befd021d858
Submitted-As: https://public-inbox.org/git/cover.1488562287.git.johannes.schindelin@gmx.de
In-Reply-To: https://public-inbox.org/git/cover.1481211338.git.johannes.schindelin@gmx.de
In-Reply-To: https://public-inbox.org/git/cover.1488506615.git.johannes.schindelin@gmx.de