[PATCH v6 1/6] repo: introduce repo_info context plumbing
- From
- Eslam reda ragheb via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Mar 2, 2026, 05:15 UTC
- Message-ID
- <bddea1a22e56b7b2988f795e5e0556c6707a126c.1772428548.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2208.v6.git.git.1772428548.gitgitgadget@gmail.com>
From: Eslam reda ragheb <eslam.reda.div@gmail.com>
Introduce a repo_info context and thread it through get_value_fn, field lookup, and value-printing helpers.
This prepares repo info for fields that need invocation-specific context in addition to the repository handle.
Signed-off-by: Eslam reda ragheb <eslam.reda.div@gmail.com> --- builtin/repo.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/builtin/repo.c b/builtin/repo.c index 6a62a6020a..e687d833b4 100644 --- a/builtin/repo.c +++ b/builtin/repo.c @@ -23,7 +23,12 @@ static const char *const repo_usage[] = { NULL }; -typedef int get_value_fn(struct repository *repo, struct strbuf *buf); +struct repo_info { + struct repository *repo; + const char *prefix; +}; + +typedef int get_value_fn(struct repo_info *info, struct strbuf *buf); enum output_format { FORMAT_TABLE, @@ -36,27 +41,30 @@ struct field { get_value_fn *get_value; }; -static int get_layout_bare(struct repository *repo UNUSED, struct strbuf *buf) +static int get_layout_bare(struct repo_info *info UNUSED, struct strbuf *buf) { strbuf_addstr(buf, is_bare_repository() ? "true" : "false"); return 0; } -static int get_layout_shallow(struct repository *repo, struct strbuf *buf) +static int get_layout_shallow(struct repo_info *info, struct strbuf *buf) { + struct repository *repo = info->repo; strbuf_addstr(buf, is_repository_shallow(repo) ? "true" : "false"); return 0; } -static int get_object_format(struct repository *repo, struct strbuf *buf) +static int get_object_format(struct repo_info *info, struct strbuf *buf) { + struct repository *repo = info->repo; strbuf_addstr(buf, repo->hash_algo->name); return 0; } -static int get_references_format(struct repository *repo, struct strbuf *buf) +static int get_references_format(struct repo_info *info, struct strbuf *buf) { + struct repository *repo = info->repo; strbuf_addstr(buf, ref_storage_format_to_name(repo->ref_storage_format)); return 0; @@ -106,7 +114,7 @@ static void print_field(enum output_format format, const char *key, } static int print_fields(int argc, const char **argv, - struct repository *repo, + struct repo_info *info, enum output_format format) { int ret = 0; @@ -124,7 +132,7 @@ static int print_fields(int argc, const char **argv, } strbuf_reset(&valbuf); - get_value(repo, &valbuf); + get_value(info, &valbuf); print_field(format, key, valbuf.buf); } @@ -132,7 +140,7 @@ static int print_fields(int argc, const char **argv, return ret; } -static int print_all_fields(struct repository *repo, +static int print_all_fields(struct repo_info *info, enum output_format format) { struct strbuf valbuf = STRBUF_INIT; @@ -141,7 +149,7 @@ static int print_all_fields(struct repository *repo, const struct field *field = &repo_info_fields[i]; strbuf_reset(&valbuf); - field->get_value(repo, &valbuf); + field->get_value(info, &valbuf); print_field(format, field->key, valbuf.buf); } @@ -195,6 +203,10 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix, struct repository *repo) { enum output_format format = FORMAT_NEWLINE_TERMINATED; + struct repo_info info = { + .repo = repo, + .prefix = prefix, + }; int all_keys = 0; int show_keys = 0; struct option options[] = { @@ -225,9 +237,9 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix, die(_("--all and <key> cannot be used together")); if (all_keys) - return print_all_fields(repo, format); + return print_all_fields(&info, format); else - return print_fields(argc, argv, repo, format); + return print_fields(argc, argv, &info, format); } struct ref_stats {
-- gitgitgadget