Skip to content

Commit 9a49aef

Browse files
ayu-chgitster
authored andcommitted
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 <[email protected]> Mentored-by: Ghanshyam Thakkar <[email protected]> Signed-off-by: Ayush Chandekar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f9aa0ee commit 9a49aef

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

builtin/fmt-merge-msg.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int cmd_fmt_merge_msg(int argc,
1919
const char *message = NULL;
2020
char *into_name = NULL;
2121
int shortlog_len = -1;
22+
int merge_log_config = -1;
2223
struct option options[] = {
2324
{
2425
.type = OPTION_INTEGER,
@@ -53,7 +54,7 @@ int cmd_fmt_merge_msg(int argc,
5354
int ret;
5455
struct fmt_merge_msg_opts opts;
5556

56-
git_config(fmt_merge_msg_config, NULL);
57+
git_config(fmt_merge_msg_config, &merge_log_config);
5758
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
5859
0);
5960
if (argc > 0)

builtin/merge.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,7 @@ int cmd_merge(int argc,
13161316
struct commit_list *remoteheads = NULL, *p;
13171317
void *branch_to_free;
13181318
int orig_argc = argc;
1319+
int merge_log_config = -1;
13191320

13201321
show_usage_with_options_if_asked(argc, argv,
13211322
builtin_merge_usage, builtin_merge_options);
@@ -1334,7 +1335,7 @@ int cmd_merge(int argc,
13341335
skip_prefix(branch, "refs/heads/", &branch);
13351336

13361337
init_diff_ui_defaults();
1337-
git_config(git_merge_config, NULL);
1338+
git_config(git_merge_config, &merge_log_config);
13381339

13391340
if (!branch || is_null_oid(&head_oid))
13401341
head_commit = NULL;

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ int grafts_keep_true_parents;
6767
int core_apply_sparse_checkout;
6868
int core_sparse_checkout_cone;
6969
int sparse_expect_files_outside_of_patterns;
70-
int merge_log_config = -1;
7170
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7271
unsigned long pack_size_limit_cfg;
7372
int max_allowed_tree_depth =

fmt-merge-msg.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ static struct string_list suppress_dest_patterns = STRING_LIST_INIT_DUP;
2626
int fmt_merge_msg_config(const char *key, const char *value,
2727
const struct config_context *ctx, void *cb)
2828
{
29+
int *merge_log_config = cb;
30+
2931
if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) {
3032
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)
3335
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;
3638
} else if (!strcmp(key, "merge.branchdesc")) {
3739
use_branch_desc = git_config_bool(key, value);
3840
} else if (!strcmp(key, "merge.suppressdest")) {

fmt-merge-msg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ struct fmt_merge_msg_opts {
1212
const char *into_name;
1313
};
1414

15-
extern int merge_log_config;
1615
int fmt_merge_msg_config(const char *key, const char *value,
1716
const struct config_context *ctx, void *cb);
1817
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,

0 commit comments

Comments
 (0)