From: "Glen Choo via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Jonathan Tan <jonathantanmy@google.com>,
Emily Shaffer <nasamuffin@google.com>, Jeff King <peff@peff.net>,
Derrick Stolee <derrickstolee@github.com>,
Glen Choo <chooglen@google.com>
Subject: [PATCH 0/6] [RFC] config.c: use struct for config reading state
Date: Wed, 01 Mar 2023 00:38:11 +0000 [thread overview]
Message-ID: <pull.1463.git.git.1677631097.gitgitgadget@gmail.com> (raw)
This RFC is preparation for config.[ch] to be libified as as part of the
libification effort that Emily described in [1]. One of the first goals is
to read config from a file, but the trouble with how config.c is written
today is that all reading operations rely on global state, so before turning
that into a library, we'd want to make that state non-global.
This series gets us about halfway there; it does enough plumbing for a
workable-but-kinda-ugly library interface, but with a little bit more work,
I think we can get rid of global state in-tree as well. That requires a fair
amount of work though, so I'd like to get thoughts on that before starting
work.
= Description
This series extracts the global config reading state into "struct
config_reader" and plumbs it through the config reading machinery. It's very
similar to how we've plumbed "struct repository" and other 'context objects'
in the past, except:
* The global state (named "the_reader") for the git process lives in a
config.c static variable, and not on "the_repository". See 3/6 for the
rationale.
* I've stopped short of adding "struct config_reader" to config.h public
functions, since that would affect non-config.c callers.
If we stop right here, it's quite easy to extend it to a future config-lib.h
without having to adjust the config.h interface:
* Move the core config reading functionality from config.c to config-lib.c.
* Have config-lib.h accept "struct config_reader" as an arg.
* Have config.h call config-lib.h while passing "the_reader".
and I have some WIP patches that do just that [3], but I think they can be
significantly improved if we go a bit further...
= Leftover bits and RFC
With a bit more work on the config machinery, we could make it so that
config reading stops being global even without adjusting non-config.c
callers. The idea is pretty simple: have the config machinery initialize an
internal "struct config_reader" every time we read config and expose that
state to the config callbacks (instead of, in this series, asking the caller
to initialize "struct config_reader" themselves). I believe that only config
callbacks are accessing this state, e.g. because they use the low-level
information (like builtin/config.c printing the filename and scope of the
value) or for error reporting (like git_parse_int() reporting the filename
and line number of the value it failed to parse), and only config callbacks
should be accessing this state anyway.
The catch (aka the reason I stopped halfway through) is that I couldn't find
a way to expose "struct config_reader" state without some fairly big
changes, complexity-wise or LoC-wise, e.g.
* We could add "struct config_reader" to "config_fn_t", i.e.
-typedef int (*config_fn_t)(const char *var, const char *val, void
*data); +typedef int (*config_fn_t)(const struct config_reader *reader,
const char *var, const char *val, void *data);
which isn't complex at all, except that there are ~100 config_fn_t
implementations [3] and a good number of them may never reference
"reader". If the churn is tolerable, I think this a good way forward.
* We could create a new kind of "config_fn_t" that accepts "struct
config_reader", e.g.
typedef int (*config_fn_t)(const char *var, const char *val, void *data);
+typedef int (*config_state_fn_t)(const struct config_reader *reader,
const char *var, const char *val, void *data);
and only adjust the callers that would actually reference "reader". This
is less churn, but I couldn't find a great way to do this kind of
'switching between config callback types' elegantly.
* We could smuggle "struct config_reader" to callback functions in a way
that interested callers could see it, but uninterested callers could
ignore. One trick that Jonathan Tan came up with (though not necessarily
endorsed) would be to allocate a struct for the config value + "struct
config_reader", then, interested callers could use "offset_of" to recover
the "struct config_reader". It's a little hacky, but it's low-churn.
= Questions
* Is this worth merging without the extra work? There are some cleanups in
this series that could make it valuable, but there are also some hacks
(see 4/6) that aren't so great.
* Is the extra work even worth it?
* Do any of the ideas seem more promising than the others? Are there other
ideas I'm missing?
[1]
https://lore.kernel.org/git/CAJoAoZ=Cig_kLocxKGax31sU7Xe4==BGzC__Bg2_pr7krNq6MA@mail.gmail.com
[2]
https://github.com/chooglen/git/compare/config/structify-reading...chooglen:git:config/read-without-globals
[3] This is a rough estimate based on "git grep"-ing callers of the config.h
functions. I vaguely recall callbacks being called "old-style", with the
suggestion that we should replace them with the "new-style" constant time
git_config_get_*() family of functions. That would decrease the number of
config callbacks significantly.
Glen Choo (6):
config.c: plumb config_source through static fns
config.c: don't assign to "cf" directly
config.c: create config_reader and the_reader
config.c: plumb the_reader through callbacks
config.c: remove current_config_kvi
config.c: remove current_parsing_scope
config.c | 489 ++++++++++++++++++++++++++++++++-----------------------
1 file changed, 287 insertions(+), 202 deletions(-)
base-commit: dadc8e6dacb629f46aee39bde90b6f09b73722eb
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1463%2Fchooglen%2Fconfig%2Fstructify-reading-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1463/chooglen/config/structify-reading-v1
Pull-Request: https://github.com/git/git/pull/1463
--
gitgitgadget
next reply other threads:[~2023-03-01 0:38 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-01 0:38 Glen Choo via GitGitGadget [this message]
2023-03-01 0:38 ` [PATCH 1/6] config.c: plumb config_source through static fns Glen Choo via GitGitGadget
2023-03-03 18:02 ` Junio C Hamano
2023-03-01 0:38 ` [PATCH 2/6] config.c: don't assign to "cf" directly Glen Choo via GitGitGadget
2023-03-01 0:38 ` [PATCH 3/6] config.c: create config_reader and the_reader Glen Choo via GitGitGadget
2023-03-03 18:05 ` Junio C Hamano
2023-03-01 0:38 ` [PATCH 4/6] config.c: plumb the_reader through callbacks Glen Choo via GitGitGadget
2023-03-08 9:54 ` Ævar Arnfjörð Bjarmason
2023-03-08 18:00 ` Glen Choo
2023-03-08 18:07 ` Junio C Hamano
2023-03-01 0:38 ` [PATCH 5/6] config.c: remove current_config_kvi Glen Choo via GitGitGadget
2023-03-06 20:12 ` Calvin Wan
2023-03-01 0:38 ` [PATCH 6/6] config.c: remove current_parsing_scope Glen Choo via GitGitGadget
2023-03-06 19:57 ` [PATCH 0/6] [RFC] config.c: use struct for config reading state Jonathan Tan
2023-03-06 21:45 ` Glen Choo
2023-03-06 22:38 ` Jonathan Tan
2023-03-08 10:32 ` Ævar Arnfjörð Bjarmason
2023-03-08 23:09 ` Glen Choo
2023-03-07 11:57 ` Ævar Arnfjörð Bjarmason
2023-03-07 18:22 ` Glen Choo
2023-03-07 18:36 ` Ævar Arnfjörð Bjarmason
2023-03-07 19:36 ` Junio C Hamano
2023-03-07 22:53 ` Glen Choo
2023-03-08 9:17 ` Ævar Arnfjörð Bjarmason
2023-03-08 23:18 ` Glen Choo
2023-03-16 0:11 ` [PATCH v2 0/8] " Glen Choo via GitGitGadget
2023-03-16 0:11 ` [PATCH v2 1/8] config.c: plumb config_source through static fns Glen Choo via GitGitGadget
2023-03-16 21:16 ` Jonathan Tan
2023-03-16 0:11 ` [PATCH v2 2/8] config.c: don't assign to "cf_global" directly Glen Choo via GitGitGadget
2023-03-16 21:18 ` Jonathan Tan
2023-03-16 21:31 ` Junio C Hamano
2023-03-16 22:56 ` Glen Choo
2023-03-16 0:11 ` [PATCH v2 3/8] config.c: create config_reader and the_reader Glen Choo via GitGitGadget
2023-03-16 21:22 ` Jonathan Tan
2023-03-16 0:11 ` [PATCH v2 4/8] config.c: plumb the_reader through callbacks Glen Choo via GitGitGadget
2023-03-16 0:11 ` [PATCH v2 5/8] config.c: remove current_config_kvi Glen Choo via GitGitGadget
2023-03-16 0:11 ` [PATCH v2 6/8] config.c: remove current_parsing_scope Glen Choo via GitGitGadget
2023-03-16 0:11 ` [PATCH v2 7/8] config: report cached filenames in die_bad_number() Glen Choo via GitGitGadget
2023-03-16 22:22 ` Jonathan Tan
2023-03-16 23:05 ` Glen Choo
2023-03-16 0:11 ` [PATCH v2 8/8] config.c: rename "struct config_source cf" Glen Choo via GitGitGadget
2023-03-16 0:15 ` [PATCH v2 0/8] config.c: use struct for config reading state Glen Choo
2023-03-16 22:29 ` Jonathan Tan
2023-03-17 5:01 ` [RFC PATCH 0/5] bypass config.c global state with configset Ævar Arnfjörð Bjarmason
2023-03-17 5:01 ` [RFC PATCH 1/5] config.h: move up "struct key_value_info" Ævar Arnfjörð Bjarmason
2023-03-17 5:01 ` [RFC PATCH 2/5] config.c: use "enum config_origin_type", not "int" Ævar Arnfjörð Bjarmason
2023-03-17 5:01 ` [RFC PATCH 3/5] config API: add a config_origin_type_name() helper Ævar Arnfjörð Bjarmason
2023-03-17 5:01 ` [RFC PATCH 4/5] config.c: refactor configset_iter() Ævar Arnfjörð Bjarmason
2023-03-17 5:01 ` [RFC PATCH 5/5] config API: add and use a repo_config_kvi() Ævar Arnfjörð Bjarmason
2023-03-17 17:17 ` Junio C Hamano
2023-03-17 20:59 ` Jonathan Tan
2023-03-17 16:21 ` [RFC PATCH 0/5] bypass config.c global state with configset Junio C Hamano
2023-03-17 16:28 ` Glen Choo
2023-03-17 19:20 ` Glen Choo
2023-03-17 23:32 ` Glen Choo
2023-03-29 11:53 ` Ævar Arnfjörð Bjarmason
2023-03-28 17:51 ` [PATCH v3 0/8] config.c: use struct for config reading state Glen Choo via GitGitGadget
2023-03-28 17:51 ` [PATCH v3 1/8] config.c: plumb config_source through static fns Glen Choo via GitGitGadget
2023-03-28 17:51 ` [PATCH v3 2/8] config.c: don't assign to "cf_global" directly Glen Choo via GitGitGadget
2023-03-28 17:51 ` [PATCH v3 3/8] config.c: create config_reader and the_reader Glen Choo via GitGitGadget
2023-03-29 10:41 ` Ævar Arnfjörð Bjarmason
2023-03-29 18:57 ` Junio C Hamano
2023-03-29 20:02 ` Glen Choo
2023-03-30 17:51 ` Glen Choo
2023-03-28 17:51 ` [PATCH v3 4/8] config.c: plumb the_reader through callbacks Glen Choo via GitGitGadget
2023-03-28 17:51 ` [PATCH v3 5/8] config.c: remove current_config_kvi Glen Choo via GitGitGadget
2023-03-28 17:51 ` [PATCH v3 6/8] config.c: remove current_parsing_scope Glen Choo via GitGitGadget
2023-03-28 17:51 ` [PATCH v3 7/8] config: report cached filenames in die_bad_number() Glen Choo via GitGitGadget
2023-03-28 17:51 ` [PATCH v3 8/8] config.c: rename "struct config_source cf" Glen Choo via GitGitGadget
2023-03-28 18:00 ` [PATCH v3 0/8] config.c: use struct for config reading state Glen Choo
2023-03-28 20:14 ` Junio C Hamano
2023-03-28 21:24 ` Glen Choo
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.1463.git.git.1677631097.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=chooglen@google.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=jonathantanmy@google.com \
--cc=nasamuffin@google.com \
--cc=peff@peff.net \
/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.