Skip to content

Commit d8ba74a

Browse files
Samuel Lijingitster
authored andcommitted
wt-status: teach wt_status_collect about merges in progress
To fix the breakages documented by t7501, the next patch in this series will teach wt_status_collect() to set the committable bit, instead of having wt_longstatus_print_updated() and show_merge_in_progress() set it (which is what currently happens). Unfortunately, wt_status_collect() needs to know whether or not there is a merge in progress to set the bit correctly, so teach its (two) callers to create, initialize, and pass in instances of wt_status_state, which records this metadata. Since wt_longstatus_print() and show_merge_in_progress() are in the same callpaths and currently create and init copies of wt_status_state, remove that logic and instead pass wt_status_state through. Make wt_status_get_state easier to use, add a helper method to clean up wt_status_state, const-ify as many struct pointers in method signatures as possible, and add a FIXME for a struct pointer which should be const but isn't (that this patch series will not address). Signed-off-by: Samuel Lijin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33e9f1c commit d8ba74a

File tree

4 files changed

+120
-116
lines changed

4 files changed

+120
-116
lines changed

builtin/commit.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
462462
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
463463
struct wt_status *s)
464464
{
465+
struct wt_status_state state;
465466
struct object_id oid;
466467

467468
if (s->relative_paths)
@@ -481,10 +482,12 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
481482
s->status_format = status_format;
482483
s->ignore_submodule_arg = ignore_submodule_arg;
483484

484-
wt_status_collect(s);
485-
wt_status_print(s);
485+
wt_status_get_state(s, &state);
486+
wt_status_collect(s, &state);
487+
wt_status_print(s, &state);
488+
wt_status_clear_state(&state);
486489

487-
return s->commitable;
490+
return s->committable;
488491
}
489492

490493
static int is_a_merge(const struct commit *current_head)
@@ -630,7 +633,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
630633
{
631634
struct stat statbuf;
632635
struct strbuf committer_ident = STRBUF_INIT;
633-
int commitable;
636+
int committable;
634637
struct strbuf sb = STRBUF_INIT;
635638
const char *hook_arg1 = NULL;
636639
const char *hook_arg2 = NULL;
@@ -847,7 +850,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
847850

848851
saved_color_setting = s->use_color;
849852
s->use_color = 0;
850-
commitable = run_status(s->fp, index_file, prefix, 1, s);
853+
committable = run_status(s->fp, index_file, prefix, 1, s);
851854
s->use_color = saved_color_setting;
852855
} else {
853856
struct object_id oid;
@@ -865,7 +868,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
865868
for (i = 0; i < active_nr; i++)
866869
if (ce_intent_to_add(active_cache[i]))
867870
ita_nr++;
868-
commitable = active_nr - ita_nr > 0;
871+
committable = active_nr - ita_nr > 0;
869872
} else {
870873
/*
871874
* Unless the user did explicitly request a submodule
@@ -881,7 +884,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
881884
if (ignore_submodule_arg &&
882885
!strcmp(ignore_submodule_arg, "all"))
883886
flags.ignore_submodules = 1;
884-
commitable = index_differs_from(parent, &flags, 1);
887+
committable = index_differs_from(parent, &flags, 1);
885888
}
886889
}
887890
strbuf_release(&committer_ident);
@@ -893,7 +896,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
893896
* explicit --allow-empty. In the cherry-pick case, it may be
894897
* empty due to conflict resolution, which the user should okay.
895898
*/
896-
if (!commitable && whence != FROM_MERGE && !allow_empty &&
899+
if (!committable && whence != FROM_MERGE && !allow_empty &&
897900
!(amend && is_a_merge(current_head))) {
898901
s->display_comment_prefix = old_display_comment_prefix;
899902
run_status(stdout, index_file, prefix, 0, s);
@@ -1163,14 +1166,14 @@ static int parse_and_validate_options(int argc, const char *argv[],
11631166
static int dry_run_commit(int argc, const char **argv, const char *prefix,
11641167
const struct commit *current_head, struct wt_status *s)
11651168
{
1166-
int commitable;
1169+
int committable;
11671170
const char *index_file;
11681171

11691172
index_file = prepare_index(argc, argv, prefix, current_head, 1);
1170-
commitable = run_status(stdout, index_file, prefix, 0, s);
1173+
committable = run_status(stdout, index_file, prefix, 0, s);
11711174
rollback_index_files();
11721175

1173-
return commitable ? 0 : 1;
1176+
return committable ? 0 : 1;
11741177
}
11751178

11761179
static int parse_status_slot(const char *slot)
@@ -1265,6 +1268,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
12651268
int cmd_status(int argc, const char **argv, const char *prefix)
12661269
{
12671270
static struct wt_status s;
1271+
struct wt_status_state state;
12681272
int fd;
12691273
struct object_id oid;
12701274
static struct option builtin_status_options[] = {
@@ -1337,15 +1341,17 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13371341
s.status_format = status_format;
13381342
s.verbose = verbose;
13391343

1340-
wt_status_collect(&s);
1344+
wt_status_get_state(&s, &state);
1345+
wt_status_collect(&s, &state);
13411346

13421347
if (0 <= fd)
13431348
update_index_if_able(&the_index, &index_lock);
13441349

13451350
if (s.relative_paths)
13461351
s.prefix = prefix;
13471352

1348-
wt_status_print(&s);
1353+
wt_status_print(&s, &state);
1354+
wt_status_clear_state(&state);
13491355
return 0;
13501356
}
13511357

ref-filter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,8 +1306,7 @@ char *get_head_description(void)
13061306
{
13071307
struct strbuf desc = STRBUF_INIT;
13081308
struct wt_status_state state;
1309-
memset(&state, 0, sizeof(state));
1310-
wt_status_get_state(&state, 1);
1309+
wt_status_get_state(NULL, &state);
13111310
if (state.rebase_in_progress ||
13121311
state.rebase_interactive_in_progress)
13131312
strbuf_addf(&desc, _("(no branch, rebasing %s)"),

0 commit comments

Comments
 (0)