diff: spell DIFF_INDEX_CACHED out when calling run_diff_index()

Many callers of run_diff_index() passed literal "1" for the option flag word, which should better be spelled out as DIFF_INDEX_CACHED for readablity. Everybody else passes "0" that can stay as-is. The other bit in the option flag word is DIFF_INDEX_MERGE_BASE, but curiously there is only one caller that can pass it, which is "git diff-index --merge-base" itself---no internal callers uses the feature. A bit tricky call to the function is in builtin/submodule--helper.c where the .cached member in a private struct is set/reset as a plain Boolean flag, which happens to be "1" and happens to match the value of DIFF_INDEX_CACHED. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 21, 2023 at 16:14 UTC 976b97e3fd95d5daa38ed453349f5a92157a1db2
6 files changed +9 -9
add-interactive.c
+1 -1
@@ -569,7 +569,7 @@ static int get_modified_files(struct repository *r,
569 copy_pathspec(&rev.prune_data, ps);
570
571 if (s.mode == FROM_INDEX)
572 - run_diff_index(&rev, 1);
572 + run_diff_index(&rev, DIFF_INDEX_CACHED);
573 else {
574 rev.diffopt.flags.ignore_dirty_submodules = 1;
575 run_diff_files(&rev, 0);
builtin/am.c
+2 -2
@@ -1430,7 +1430,7 @@ static void write_index_patch(const struct am_state *state)
1430 rev_info.diffopt.close_file = 1;
1431 add_pending_object(&rev_info, &tree->object, "");
1432 diff_setup_done(&rev_info.diffopt);
1433 - run_diff_index(&rev_info, 1);
1433 + run_diff_index(&rev_info, DIFF_INDEX_CACHED);
1434 release_revisions(&rev_info);
1435 }
1436
@@ -1593,7 +1593,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
1593 rev_info.diffopt.filter |= diff_filter_bit('M');
1594 add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
1595 diff_setup_done(&rev_info.diffopt);
1596 - run_diff_index(&rev_info, 1);
1596 + run_diff_index(&rev_info, DIFF_INDEX_CACHED);
1597 release_revisions(&rev_info);
1598 }
1599
builtin/stash.c
+1 -1
@@ -1111,7 +1111,7 @@ static int check_changes_tracked_files(const struct pathspec *ps)
1111 add_head_to_pending(&rev);
1112 diff_setup_done(&rev.diffopt);
1113
1114 - result = run_diff_index(&rev, 1);
1114 + result = run_diff_index(&rev, DIFF_INDEX_CACHED);
1115 if (diff_result_code(&rev.diffopt, result)) {
1116 ret = 1;
1117 goto done;
builtin/submodule--helper.c
+1 -1
@@ -1141,7 +1141,7 @@ static int compute_summary_module_list(struct object_id *head_oid,
1141 }
1142
1143 if (diff_cmd == DIFF_INDEX)
1144 - run_diff_index(&rev, info->cached);
1144 + run_diff_index(&rev, info->cached ? DIFF_INDEX_CACHED : 0);
1145 else
1146 run_diff_files(&rev, 0);
1147 prepare_submodule_summary(info, &list);
diff-lib.c
+1 -1
@@ -682,7 +682,7 @@ int index_differs_from(struct repository *r,
682 rev.diffopt.flags.ignore_submodules = flags->ignore_submodules;
683 }
684 rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
685 - run_diff_index(&rev, 1);
685 + run_diff_index(&rev, DIFF_INDEX_CACHED);
686 has_changes = rev.diffopt.flags.has_changes;
687 release_revisions(&rev);
688 return (has_changes != 0);
wt-status.c
+3 -3
@@ -675,7 +675,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
675 rev.diffopt.flags.recursive = 1;
676
677 copy_pathspec(&rev.prune_data, &s->pathspec);
678 - run_diff_index(&rev, 1);
678 + run_diff_index(&rev, DIFF_INDEX_CACHED);
679 release_revisions(&rev);
680 }
681
@@ -1156,7 +1156,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
1156 rev.diffopt.a_prefix = "c/";
1157 rev.diffopt.b_prefix = "i/";
1158 } /* else use prefix as per user config */
1159 - run_diff_index(&rev, 1);
1159 + run_diff_index(&rev, DIFF_INDEX_CACHED);
1160 if (s->verbose > 1 &&
1161 wt_status_check_worktree_changes(s, &dirty_submodules)) {
1162 status_printf_ln(s, c,
@@ -2614,7 +2614,7 @@ int has_uncommitted_changes(struct repository *r,
2614 }
2615
2616 diff_setup_done(&rev_info.diffopt);
2617 - result = run_diff_index(&rev_info, 1);
2617 + result = run_diff_index(&rev_info, DIFF_INDEX_CACHED);
2618 result = diff_result_code(&rev_info.diffopt, result);
2619 release_revisions(&rev_info);
2620 return result;