environment: remove the global variable 'merge_log_config'

The global variable 'merge_log_config', set via the "merge.log" or "merge.summary" settings, is only used in 'cmd_fmt_merge_msg()' and 'cmd_merge()' to adjust the 'shortlog_len' variable. Remove 'merge_log_config' globally and localize it in 'cmd_fmt_merge_msg()' and 'cmd_merge()'. Set its value by passing it in 'fmt_merge_msg_config()' by passing its pointer to the function via the callback parameter. This change is part of an ongoing effort to eliminate global variables, improve modularity and help libify the codebase. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com> Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ayush Chandekar committed Aug 11, 2025 at 05:15 UTC 9a49aef8dcdf899e94cddab14eacc7118c611524
5 files changed +10 -8
builtin/fmt-merge-msg.c
+2 -1
@@ -19,6 +19,7 @@ int cmd_fmt_merge_msg(int argc,
19 const char *message = NULL;
20 char *into_name = NULL;
21 int shortlog_len = -1;
22 + int merge_log_config = -1;
23 struct option options[] = {
24 {
25 .type = OPTION_INTEGER,
@@ -53,7 +54,7 @@ int cmd_fmt_merge_msg(int argc,
54 int ret;
55 struct fmt_merge_msg_opts opts;
56
56 - git_config(fmt_merge_msg_config, NULL);
57 + git_config(fmt_merge_msg_config, &merge_log_config);
58 argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
59 0);
60 if (argc > 0)
builtin/merge.c
+2 -1
@@ -1316,6 +1316,7 @@ int cmd_merge(int argc,
1316 struct commit_list *remoteheads = NULL, *p;
1317 void *branch_to_free;
1318 int orig_argc = argc;
1319 + int merge_log_config = -1;
1320
1321 show_usage_with_options_if_asked(argc, argv,
1322 builtin_merge_usage, builtin_merge_options);
@@ -1334,7 +1335,7 @@ int cmd_merge(int argc,
1335 skip_prefix(branch, "refs/heads/", &branch);
1336
1337 init_diff_ui_defaults();
1337 - git_config(git_merge_config, NULL);
1338 + git_config(git_merge_config, &merge_log_config);
1339
1340 if (!branch || is_null_oid(&head_oid))
1341 head_commit = NULL;
environment.c
-1
@@ -67,7 +67,6 @@ int grafts_keep_true_parents;
67 int core_apply_sparse_checkout;
68 int core_sparse_checkout_cone;
69 int sparse_expect_files_outside_of_patterns;
70 -int merge_log_config = -1;
70 int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
71 unsigned long pack_size_limit_cfg;
72 int max_allowed_tree_depth =
fmt-merge-msg.c
+6 -4
@@ -26,13 +26,15 @@ static struct string_list suppress_dest_patterns = STRING_LIST_INIT_DUP;
26 int fmt_merge_msg_config(const char *key, const char *value,
27 const struct config_context *ctx, void *cb)
28 {
29 + int *merge_log_config = cb;
30 +
31 if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
32 int is_bool;
31 - merge_log_config = git_config_bool_or_int(key, value, ctx->kvi, &is_bool);
32 - if (!is_bool && merge_log_config < 0)
33 + *merge_log_config = git_config_bool_or_int(key, value, ctx->kvi, &is_bool);
34 + if (!is_bool && *merge_log_config < 0)
35 return error("%s: negative length %s", key, value);
34 - if (is_bool && merge_log_config)
35 - merge_log_config = DEFAULT_MERGE_LOG_LEN;
36 + if (is_bool && *merge_log_config)
37 + *merge_log_config = DEFAULT_MERGE_LOG_LEN;
38 } else if (!strcmp(key, "merge.branchdesc")) {
39 use_branch_desc = git_config_bool(key, value);
40 } else if (!strcmp(key, "merge.suppressdest")) {
fmt-merge-msg.h
-1
@@ -12,7 +12,6 @@ struct fmt_merge_msg_opts {
12 const char *into_name;
13 };
14
15 -extern int merge_log_config;
15 int fmt_merge_msg_config(const char *key, const char *value,
16 const struct config_context *ctx, void *cb);
17 int fmt_merge_msg(struct strbuf *in, struct strbuf *out,