Git fork

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>

authored by

Ayush Chandekar and committed by
Junio C Hamano
9a49aef8 f9aa0eed

+10 -8
+2 -1
builtin/fmt-merge-msg.c
··· 19 19 const char *message = NULL; 20 20 char *into_name = NULL; 21 21 int shortlog_len = -1; 22 + int merge_log_config = -1; 22 23 struct option options[] = { 23 24 { 24 25 .type = OPTION_INTEGER, ··· 53 54 int ret; 54 55 struct fmt_merge_msg_opts opts; 55 56 56 - git_config(fmt_merge_msg_config, NULL); 57 + git_config(fmt_merge_msg_config, &merge_log_config); 57 58 argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage, 58 59 0); 59 60 if (argc > 0)
+2 -1
builtin/merge.c
··· 1316 1316 struct commit_list *remoteheads = NULL, *p; 1317 1317 void *branch_to_free; 1318 1318 int orig_argc = argc; 1319 + int merge_log_config = -1; 1319 1320 1320 1321 show_usage_with_options_if_asked(argc, argv, 1321 1322 builtin_merge_usage, builtin_merge_options); ··· 1334 1335 skip_prefix(branch, "refs/heads/", &branch); 1335 1336 1336 1337 init_diff_ui_defaults(); 1337 - git_config(git_merge_config, NULL); 1338 + git_config(git_merge_config, &merge_log_config); 1338 1339 1339 1340 if (!branch || is_null_oid(&head_oid)) 1340 1341 head_commit = NULL;
-1
environment.c
··· 67 67 int core_apply_sparse_checkout; 68 68 int core_sparse_checkout_cone; 69 69 int sparse_expect_files_outside_of_patterns; 70 - int merge_log_config = -1; 71 70 int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ 72 71 unsigned long pack_size_limit_cfg; 73 72 int max_allowed_tree_depth =
+6 -4
fmt-merge-msg.c
··· 26 26 int fmt_merge_msg_config(const char *key, const char *value, 27 27 const struct config_context *ctx, void *cb) 28 28 { 29 + int *merge_log_config = cb; 30 + 29 31 if (!strcmp(key, "merge.log") || !strcmp(key, "merge.summary")) { 30 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) 33 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; 36 38 } else if (!strcmp(key, "merge.branchdesc")) { 37 39 use_branch_desc = git_config_bool(key, value); 38 40 } else if (!strcmp(key, "merge.suppressdest")) {
-1
fmt-merge-msg.h
··· 12 12 const char *into_name; 13 13 }; 14 14 15 - extern int merge_log_config; 16 15 int fmt_merge_msg_config(const char *key, const char *value, 17 16 const struct config_context *ctx, void *cb); 18 17 int fmt_merge_msg(struct strbuf *in, struct strbuf *out,