Skip to content

Commit 929e85a

Browse files
committed
Merge branch 'ss/wt-status-committable'
Code clean-up in the internal machinery used by "git status" and "git commit --dry-run". * ss/wt-status-committable: roll wt_status_state into wt_status and populate in the collect phase wt-status.c: set the committable flag in the collect phase t7501: add test of "commit --dry-run --short" wt-status: rename commitable to committable wt-status.c: move has_unmerged earlier in the file
2 parents 11877b9 + 73ba5d7 commit 929e85a

File tree

4 files changed

+123
-119
lines changed

4 files changed

+123
-119
lines changed

builtin/commit.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
508508

509509
wt_status_collect(s);
510510
wt_status_print(s);
511+
wt_status_collect_free_buffers(s);
511512

512-
return s->commitable;
513+
return s->committable;
513514
}
514515

515516
static int is_a_merge(const struct commit *current_head)
@@ -655,7 +656,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
655656
{
656657
struct stat statbuf;
657658
struct strbuf committer_ident = STRBUF_INIT;
658-
int commitable;
659+
int committable;
659660
struct strbuf sb = STRBUF_INIT;
660661
const char *hook_arg1 = NULL;
661662
const char *hook_arg2 = NULL;
@@ -872,7 +873,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
872873

873874
saved_color_setting = s->use_color;
874875
s->use_color = 0;
875-
commitable = run_status(s->fp, index_file, prefix, 1, s);
876+
committable = run_status(s->fp, index_file, prefix, 1, s);
876877
s->use_color = saved_color_setting;
877878
string_list_clear(&s->change, 1);
878879
} else {
@@ -891,7 +892,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
891892
for (i = 0; i < active_nr; i++)
892893
if (ce_intent_to_add(active_cache[i]))
893894
ita_nr++;
894-
commitable = active_nr - ita_nr > 0;
895+
committable = active_nr - ita_nr > 0;
895896
} else {
896897
/*
897898
* Unless the user did explicitly request a submodule
@@ -907,7 +908,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
907908
if (ignore_submodule_arg &&
908909
!strcmp(ignore_submodule_arg, "all"))
909910
flags.ignore_submodules = 1;
910-
commitable = index_differs_from(parent, &flags, 1);
911+
committable = index_differs_from(parent, &flags, 1);
911912
}
912913
}
913914
strbuf_release(&committer_ident);
@@ -919,7 +920,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
919920
* explicit --allow-empty. In the cherry-pick case, it may be
920921
* empty due to conflict resolution, which the user should okay.
921922
*/
922-
if (!commitable && whence != FROM_MERGE && !allow_empty &&
923+
if (!committable && whence != FROM_MERGE && !allow_empty &&
923924
!(amend && is_a_merge(current_head))) {
924925
s->display_comment_prefix = old_display_comment_prefix;
925926
run_status(stdout, index_file, prefix, 0, s);
@@ -1189,14 +1190,14 @@ static int parse_and_validate_options(int argc, const char *argv[],
11891190
static int dry_run_commit(int argc, const char **argv, const char *prefix,
11901191
const struct commit *current_head, struct wt_status *s)
11911192
{
1192-
int commitable;
1193+
int committable;
11931194
const char *index_file;
11941195

11951196
index_file = prepare_index(argc, argv, prefix, current_head, 1);
1196-
commitable = run_status(stdout, index_file, prefix, 0, s);
1197+
committable = run_status(stdout, index_file, prefix, 0, s);
11971198
rollback_index_files();
11981199

1199-
return commitable ? 0 : 1;
1200+
return committable ? 0 : 1;
12001201
}
12011202

12021203
define_list_config_array_extra(color_status_slots, {"added"});
@@ -1391,6 +1392,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13911392
s.prefix = prefix;
13921393

13931394
wt_status_print(&s);
1395+
wt_status_collect_free_buffers(&s);
1396+
13941397
return 0;
13951398
}
13961399

t/t7501-commit.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ test_expect_success '--dry-run with stuff to commit returns ok' '
9999
git commit -m next -a --dry-run
100100
'
101101

102-
test_expect_failure '--short with stuff to commit returns ok' '
102+
test_expect_success '--short with stuff to commit returns ok' '
103103
echo bongo bongo bongo >>file &&
104104
git commit -m next -a --short
105105
'
106106

107-
test_expect_failure '--porcelain with stuff to commit returns ok' '
107+
test_expect_success '--porcelain with stuff to commit returns ok' '
108108
echo bongo bongo bongo >>file &&
109109
git commit -m next -a --porcelain
110110
'
@@ -698,4 +698,10 @@ test_expect_success '--dry-run with conflicts fixed from a merge' '
698698
git commit -m "conflicts fixed from merge."
699699
'
700700

701+
test_expect_success '--dry-run --short' '
702+
>test-file &&
703+
git add test-file &&
704+
git commit --dry-run --short
705+
'
706+
701707
test_done

0 commit comments

Comments
 (0)