Skip to content

Commit 5c25dfa

Browse files
moygitster
authored andcommitted
commit: factor status configuration is a helper function
cmd_commit and cmd_status use very similar code to initialize the wt_status structure. Factor this code into a function to ensure future changes will keep both versions consistent. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e230c56 commit 5c25dfa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

builtin/commit.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ static void determine_whence(struct wt_status *s)
163163
s->whence = whence;
164164
}
165165

166+
static void status_init_config(struct wt_status *s, config_fn_t fn)
167+
{
168+
wt_status_prepare(s);
169+
gitmodules_config();
170+
git_config(fn, s);
171+
determine_whence(s);
172+
}
173+
166174
static void rollback_index_files(void)
167175
{
168176
switch (commit_style) {
@@ -1246,10 +1254,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
12461254
if (argc == 2 && !strcmp(argv[1], "-h"))
12471255
usage_with_options(builtin_status_usage, builtin_status_options);
12481256

1249-
wt_status_prepare(&s);
1250-
gitmodules_config();
1251-
git_config(git_status_config, &s);
1252-
determine_whence(&s);
1257+
status_init_config(&s, git_status_config);
12531258
argc = parse_options(argc, argv, prefix,
12541259
builtin_status_options,
12551260
builtin_status_usage, 0);
@@ -1492,11 +1497,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14921497
if (argc == 2 && !strcmp(argv[1], "-h"))
14931498
usage_with_options(builtin_commit_usage, builtin_commit_options);
14941499

1495-
wt_status_prepare(&s);
1496-
gitmodules_config();
1497-
git_config(git_commit_config, &s);
1500+
status_init_config(&s, git_commit_config);
14981501
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
1499-
determine_whence(&s);
15001502
s.colopts = 0;
15011503

15021504
if (get_sha1("HEAD", sha1))

0 commit comments

Comments
 (0)