From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>
Subject: [PATCH] diff: spell DIFF_INDEX_CACHED out when calling run_diff_index()
Date: Mon, 21 Aug 2023 09:21:50 -0700 [thread overview]
Message-ID: <xmqqfs4cqsbl.fsf@gitster.g> (raw)
In-Reply-To: xmqqlee4s82d.fsf@gitster.g
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>
---
add-interactive.c | 2 +-
builtin/am.c | 4 ++--
builtin/stash.c | 2 +-
builtin/submodule--helper.c | 2 +-
diff-lib.c | 2 +-
wt-status.c | 6 +++---
6 files changed, 9 insertions(+), 9 deletions(-)
diff --git c/add-interactive.c w/add-interactive.c
index add9a1ad43..7fd00c5e25 100644
--- c/add-interactive.c
+++ w/add-interactive.c
@@ -569,7 +569,7 @@ static int get_modified_files(struct repository *r,
copy_pathspec(&rev.prune_data, ps);
if (s.mode == FROM_INDEX)
- run_diff_index(&rev, 1);
+ run_diff_index(&rev, DIFF_INDEX_CACHED);
else {
rev.diffopt.flags.ignore_dirty_submodules = 1;
run_diff_files(&rev, 0);
diff --git c/builtin/am.c w/builtin/am.c
index 8bde034fae..202040b62e 100644
--- c/builtin/am.c
+++ w/builtin/am.c
@@ -1430,7 +1430,7 @@ static void write_index_patch(const struct am_state *state)
rev_info.diffopt.close_file = 1;
add_pending_object(&rev_info, &tree->object, "");
diff_setup_done(&rev_info.diffopt);
- run_diff_index(&rev_info, 1);
+ run_diff_index(&rev_info, DIFF_INDEX_CACHED);
release_revisions(&rev_info);
}
@@ -1593,7 +1593,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
rev_info.diffopt.filter |= diff_filter_bit('M');
add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
diff_setup_done(&rev_info.diffopt);
- run_diff_index(&rev_info, 1);
+ run_diff_index(&rev_info, DIFF_INDEX_CACHED);
release_revisions(&rev_info);
}
diff --git c/builtin/stash.c w/builtin/stash.c
index fe64cde9ce..fe5052f12f 100644
--- c/builtin/stash.c
+++ w/builtin/stash.c
@@ -1111,7 +1111,7 @@ static int check_changes_tracked_files(const struct pathspec *ps)
add_head_to_pending(&rev);
diff_setup_done(&rev.diffopt);
- result = run_diff_index(&rev, 1);
+ result = run_diff_index(&rev, DIFF_INDEX_CACHED);
if (diff_result_code(&rev.diffopt, result)) {
ret = 1;
goto done;
diff --git c/builtin/submodule--helper.c w/builtin/submodule--helper.c
index f6871efd95..125ea80d21 100644
--- c/builtin/submodule--helper.c
+++ w/builtin/submodule--helper.c
@@ -1141,7 +1141,7 @@ static int compute_summary_module_list(struct object_id *head_oid,
}
if (diff_cmd == DIFF_INDEX)
- run_diff_index(&rev, info->cached);
+ run_diff_index(&rev, info->cached ? DIFF_INDEX_CACHED : 0);
else
run_diff_files(&rev, 0);
prepare_submodule_summary(info, &list);
diff --git c/diff-lib.c w/diff-lib.c
index 6b0c6a7180..cfa3489111 100644
--- c/diff-lib.c
+++ w/diff-lib.c
@@ -682,7 +682,7 @@ int index_differs_from(struct repository *r,
rev.diffopt.flags.ignore_submodules = flags->ignore_submodules;
}
rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
- run_diff_index(&rev, 1);
+ run_diff_index(&rev, DIFF_INDEX_CACHED);
has_changes = rev.diffopt.flags.has_changes;
release_revisions(&rev);
return (has_changes != 0);
diff --git c/wt-status.c w/wt-status.c
index 5b1378965c..bf8687b357 100644
--- c/wt-status.c
+++ w/wt-status.c
@@ -675,7 +675,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
rev.diffopt.flags.recursive = 1;
copy_pathspec(&rev.prune_data, &s->pathspec);
- run_diff_index(&rev, 1);
+ run_diff_index(&rev, DIFF_INDEX_CACHED);
release_revisions(&rev);
}
@@ -1156,7 +1156,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
rev.diffopt.a_prefix = "c/";
rev.diffopt.b_prefix = "i/";
} /* else use prefix as per user config */
- run_diff_index(&rev, 1);
+ run_diff_index(&rev, DIFF_INDEX_CACHED);
if (s->verbose > 1 &&
wt_status_check_worktree_changes(s, &dirty_submodules)) {
status_printf_ln(s, c,
@@ -2614,7 +2614,7 @@ int has_uncommitted_changes(struct repository *r,
}
diff_setup_done(&rev_info.diffopt);
- result = run_diff_index(&rev_info, 1);
+ result = run_diff_index(&rev_info, DIFF_INDEX_CACHED);
result = diff_result_code(&rev_info.diffopt, result);
release_revisions(&rev_info);
return result;
next prev parent reply other threads:[~2023-08-21 16:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-20 19:52 "git diff --no-pager --exit-code" errors out but returns zero exit code Romain Chossart
2023-08-21 0:35 ` [PATCH] diff: handle negative status in diff_result_code() Jeff King
2023-08-21 15:56 ` Junio C Hamano
2023-08-21 16:21 ` Junio C Hamano [this message]
2023-08-21 18:36 ` [PATCH] diff: spell DIFF_INDEX_CACHED out when calling run_diff_index() Jeff King
2023-08-21 22:08 ` Junio C Hamano
2023-08-21 18:09 ` [PATCH] diff: handle negative status in diff_result_code() Jeff King
2023-08-21 18:39 ` Junio C Hamano
2023-08-21 20:13 ` [PATCH v2 0/7] cleaning up diff_result_code() Jeff King
2023-08-21 20:14 ` [PATCH v2 1/7] diff: spell DIFF_INDEX_CACHED out when calling run_diff_index() Jeff King
2023-08-21 20:15 ` [PATCH v2 2/7] diff-files: avoid negative exit value Jeff King
2023-08-21 20:16 ` [PATCH v2 3/7] diff: show usage for unknown builtin_diff_files() options Jeff King
2023-08-21 20:17 ` [PATCH v2 4/7] diff: die when failing to read index in git-diff builtin Jeff King
2023-08-22 23:27 ` Junio C Hamano
2023-08-21 20:18 ` [PATCH v2 5/7] diff: drop useless return from run_diff_{files,index} functions Jeff King
2023-08-21 20:19 ` [PATCH v2 6/7] diff: drop useless return values in git-diff helpers Jeff King
2023-08-21 20:20 ` [PATCH v2 7/7] diff: drop useless "status" parameter from diff_result_code() Jeff King
2023-08-22 23:38 ` Junio C Hamano
2023-08-23 19:00 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqfs4cqsbl.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.