Skip to content

Commit 976b97e

Browse files
committed
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43c8a30 commit 976b97e

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

add-interactive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static int get_modified_files(struct repository *r,
569569
copy_pathspec(&rev.prune_data, ps);
570570

571571
if (s.mode == FROM_INDEX)
572-
run_diff_index(&rev, 1);
572+
run_diff_index(&rev, DIFF_INDEX_CACHED);
573573
else {
574574
rev.diffopt.flags.ignore_dirty_submodules = 1;
575575
run_diff_files(&rev, 0);

builtin/am.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ static void write_index_patch(const struct am_state *state)
14301430
rev_info.diffopt.close_file = 1;
14311431
add_pending_object(&rev_info, &tree->object, "");
14321432
diff_setup_done(&rev_info.diffopt);
1433-
run_diff_index(&rev_info, 1);
1433+
run_diff_index(&rev_info, DIFF_INDEX_CACHED);
14341434
release_revisions(&rev_info);
14351435
}
14361436

@@ -1593,7 +1593,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15931593
rev_info.diffopt.filter |= diff_filter_bit('M');
15941594
add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
15951595
diff_setup_done(&rev_info.diffopt);
1596-
run_diff_index(&rev_info, 1);
1596+
run_diff_index(&rev_info, DIFF_INDEX_CACHED);
15971597
release_revisions(&rev_info);
15981598
}
15991599

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ static int check_changes_tracked_files(const struct pathspec *ps)
11111111
add_head_to_pending(&rev);
11121112
diff_setup_done(&rev.diffopt);
11131113

1114-
result = run_diff_index(&rev, 1);
1114+
result = run_diff_index(&rev, DIFF_INDEX_CACHED);
11151115
if (diff_result_code(&rev.diffopt, result)) {
11161116
ret = 1;
11171117
goto done;

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ static int compute_summary_module_list(struct object_id *head_oid,
11411141
}
11421142

11431143
if (diff_cmd == DIFF_INDEX)
1144-
run_diff_index(&rev, info->cached);
1144+
run_diff_index(&rev, info->cached ? DIFF_INDEX_CACHED : 0);
11451145
else
11461146
run_diff_files(&rev, 0);
11471147
prepare_submodule_summary(info, &list);

diff-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ int index_differs_from(struct repository *r,
682682
rev.diffopt.flags.ignore_submodules = flags->ignore_submodules;
683683
}
684684
rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
685-
run_diff_index(&rev, 1);
685+
run_diff_index(&rev, DIFF_INDEX_CACHED);
686686
has_changes = rev.diffopt.flags.has_changes;
687687
release_revisions(&rev);
688688
return (has_changes != 0);

wt-status.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
675675
rev.diffopt.flags.recursive = 1;
676676

677677
copy_pathspec(&rev.prune_data, &s->pathspec);
678-
run_diff_index(&rev, 1);
678+
run_diff_index(&rev, DIFF_INDEX_CACHED);
679679
release_revisions(&rev);
680680
}
681681

@@ -1156,7 +1156,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
11561156
rev.diffopt.a_prefix = "c/";
11571157
rev.diffopt.b_prefix = "i/";
11581158
} /* else use prefix as per user config */
1159-
run_diff_index(&rev, 1);
1159+
run_diff_index(&rev, DIFF_INDEX_CACHED);
11601160
if (s->verbose > 1 &&
11611161
wt_status_check_worktree_changes(s, &dirty_submodules)) {
11621162
status_printf_ln(s, c,
@@ -2614,7 +2614,7 @@ int has_uncommitted_changes(struct repository *r,
26142614
}
26152615

26162616
diff_setup_done(&rev_info.diffopt);
2617-
result = run_diff_index(&rev_info, 1);
2617+
result = run_diff_index(&rev_info, DIFF_INDEX_CACHED);
26182618
result = diff_result_code(&rev_info.diffopt, result);
26192619
release_revisions(&rev_info);
26202620
return result;

0 commit comments

Comments
 (0)