Skip to content

Commit 869f44a

Browse files
committed
Merge branch 'ac/deglobal-fmt-merge-log-config' into jch
* ac/deglobal-fmt-merge-log-config: builtin/fmt-merge-msg: stop depending on 'the_repository' environment: remove the global variable 'merge_log_config'
2 parents dbbf963 + 22d421f commit 869f44a

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

builtin/fmt-merge-msg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#include "builtin.h"
32
#include "config.h"
43
#include "fmt-merge-msg.h"
@@ -13,12 +12,13 @@ static const char * const fmt_merge_msg_usage[] = {
1312
int cmd_fmt_merge_msg(int argc,
1413
const char **argv,
1514
const char *prefix,
16-
struct repository *repo UNUSED)
15+
struct repository *repo)
1716
{
1817
char *inpath = NULL;
1918
const char *message = NULL;
2019
char *into_name = NULL;
2120
int shortlog_len = -1;
21+
int merge_log_config = -1;
2222
struct option options[] = {
2323
{
2424
.type = OPTION_INTEGER,
@@ -53,7 +53,7 @@ int cmd_fmt_merge_msg(int argc,
5353
int ret;
5454
struct fmt_merge_msg_opts opts;
5555

56-
repo_config(the_repository, fmt_merge_msg_config, NULL);
56+
repo_config(repo, fmt_merge_msg_config, &merge_log_config);
5757
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
5858
0);
5959
if (argc > 0)

builtin/merge.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ int cmd_merge(int argc,
13741374
struct commit_list *remoteheads = NULL, *p;
13751375
void *branch_to_free;
13761376
int orig_argc = argc;
1377+
int merge_log_config = -1;
13771378

13781379
show_usage_with_options_if_asked(argc, argv,
13791380
builtin_merge_usage, builtin_merge_options);
@@ -1395,7 +1396,7 @@ int cmd_merge(int argc,
13951396
skip_prefix(branch, "refs/heads/", &branch);
13961397

13971398
init_diff_ui_defaults();
1398-
repo_config(the_repository, git_merge_config, NULL);
1399+
repo_config(the_repository, git_merge_config, &merge_log_config);
13991400

14001401
if (!branch || is_null_oid(&head_oid))
14011402
head_commit = NULL;

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ int grafts_keep_true_parents;
7878
int core_apply_sparse_checkout;
7979
int core_sparse_checkout_cone;
8080
int sparse_expect_files_outside_of_patterns;
81-
int merge_log_config = -1;
8281
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
8382
unsigned long pack_size_limit_cfg;
8483
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,

t/t1517-outside-repo.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,11 @@ do
135135
'
136136
done
137137

138+
test_expect_success 'fmt-merge-msg does not crash with -h' '
139+
test_expect_code 129 git fmt-merge-msg -h >usage &&
140+
test_grep "[Uu]sage: git fmt-merge-msg " usage &&
141+
test_expect_code 129 nongit git fmt-merge-msg -h >usage &&
142+
test_grep "[Uu]sage: git fmt-merge-msg " usage
143+
'
144+
138145
test_done

0 commit comments

Comments
 (0)