From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH v2 0/2] checkout/fetch/pull/pack-objects: allow -h outside a repository again
Date: Tue, 08 Feb 2022 11:21:52 +0000 [thread overview]
Message-ID: <pull.1139.v2.git.1644319314.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1139.git.1644277797.gitgitgadget@gmail.com>
As reported in https://github.com/git-for-windows/git/issues/3688, calling
git fetch -h outside a repository now results in a very ugly
BUG: repo-settings.c:23: Cannot add settings for uninitialized repository
The reason is that the prepare_repo_settings() calls (that we introduced to
support sparse index) assume that there is a gitdir, but the hack to allow
parse_options() to handle -h even outside a repository invalidates that
assumption.
One strategy I considered was to move the prepare_repo_settings() calls
after parse_options(). This would work because when parse_options() handles
-h, it exits without returning.
However, this strategy failed in my tests because e.g. cmd_unpack_objects()
does need the pack_use_sparse to be populated correctly before even parsing
the options so that it can be overridden via --sparse/--no-sparse.
Hence the current strategy where the code that prepares the repo settings
and then accesses them is guarded behind the condition that we must have a
gitdir to do so.
Note: There are other instances where prepare_repo_settings() is called
before parse_options(), e.g. in cmd_status(), in seen there are even more
instances (e.g. cmd_checkout_index()). All of those instances that are not
touched by this here patch do have special code to handle -h early, though,
before calling prepare_repo_settings() let alone parse_options().
Johannes Schindelin (2):
checkout/fetch/pull/pack-objects: allow `-h` outside a repository
t0012: verify that built-ins handle `-h` even without gitdir
builtin/checkout.c | 7 ++++---
builtin/fetch.c | 6 ++++--
builtin/pack-objects.c | 8 +++++---
builtin/pull.c | 6 ++++--
t/t0012-help.sh | 7 ++++++-
5 files changed, 23 insertions(+), 11 deletions(-)
base-commit: 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1139%2Fdscho%2Fprepare_repo_settings-after-parse_options-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1139/dscho/prepare_repo_settings-after-parse_options-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1139
Range-diff vs v1:
1: 25d1a2963f2 ! 1: 6e9cdd10a70 checkout/fetch/pull/pack-objects: allow `-h` outside a repository
@@ builtin/fetch.c: int cmd_fetch(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix,
builtin_fetch_options, builtin_fetch_usage, 0);
-+
- if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
- int *sfjc = submodule_fetch_jobs_config == -1
- ? &submodule_fetch_jobs_config : NULL;
## builtin/pack-objects.c ##
@@ builtin/pack-objects.c: int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2: 49977ff9f4e = 2: 93df4a73dab t0012: verify that built-ins handle `-h` even without gitdir
--
gitgitgadget
next prev parent reply other threads:[~2022-02-08 11:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-07 23:49 [PATCH 0/2] checkout/fetch/pull/pack-objects: allow -h outside a repository again Johannes Schindelin via GitGitGadget
2022-02-07 23:49 ` [PATCH 1/2] checkout/fetch/pull/pack-objects: allow `-h` outside a repository Johannes Schindelin via GitGitGadget
2022-02-08 6:50 ` Junio C Hamano
2022-02-08 10:29 ` Johannes Schindelin
2022-02-07 23:49 ` [PATCH 2/2] t0012: verify that built-ins handle `-h` even without gitdir Johannes Schindelin via GitGitGadget
2022-02-08 11:21 ` Johannes Schindelin via GitGitGadget [this message]
2022-02-08 11:21 ` [PATCH v2 1/2] checkout/fetch/pull/pack-objects: allow `-h` outside a repository Johannes Schindelin via GitGitGadget
2022-02-08 11:21 ` [PATCH v2 2/2] t0012: verify that built-ins handle `-h` even without gitdir Johannes Schindelin via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1139.v2.git.1644319314.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.