1
0
mirror of https://github.com/git/git.git synced 2024-11-15 15:03:47 +01:00

Merge branch 'nk/diff-index-fsmonitor'

"git diff-index" codepath has been taught to trust fsmonitor status
to reduce number of lstat() calls.

* nk/diff-index-fsmonitor:
  fsmonitor: add perf test for git diff HEAD
  fsmonitor: add assertion that fsmonitor is valid to check_removed
  fsmonitor: skip lstat deletion check during git diff-index
This commit is contained in:
Junio C Hamano 2021-03-24 14:36:27 -07:00
commit 858119f6d7
4 changed files with 32 additions and 10 deletions

@ -28,9 +28,10 @@
* exists for ce that is a submodule -- it is a submodule that is not * exists for ce that is a submodule -- it is a submodule that is not
* checked out). Return negative for an error. * checked out). Return negative for an error.
*/ */
static int check_removed(const struct cache_entry *ce, struct stat *st) static int check_removed(const struct index_state *istate, const struct cache_entry *ce, struct stat *st)
{ {
if (lstat(ce->name, st) < 0) { assert(is_fsmonitor_refreshed(istate));
if (!(ce->ce_flags & CE_FSMONITOR_VALID) && lstat(ce->name, st) < 0) {
if (!is_missing_file_error(errno)) if (!is_missing_file_error(errno))
return -1; return -1;
return 1; return 1;
@ -136,7 +137,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
memset(&(dpath->parent[0]), 0, memset(&(dpath->parent[0]), 0,
sizeof(struct combine_diff_parent)*5); sizeof(struct combine_diff_parent)*5);
changed = check_removed(ce, &st); changed = check_removed(istate, ce, &st);
if (!changed) if (!changed)
wt_mode = ce_mode_from_stat(ce, st.st_mode); wt_mode = ce_mode_from_stat(ce, st.st_mode);
else { else {
@ -216,7 +217,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
} else { } else {
struct stat st; struct stat st;
changed = check_removed(ce, &st); changed = check_removed(istate, ce, &st);
if (changed) { if (changed) {
if (changed < 0) { if (changed < 0) {
perror(ce->name); perror(ce->name);
@ -278,7 +279,8 @@ static void diff_index_show_file(struct rev_info *revs,
oid, oid_valid, ce->name, dirty_submodule); oid, oid_valid, ce->name, dirty_submodule);
} }
static int get_stat_data(const struct cache_entry *ce, static int get_stat_data(const struct index_state *istate,
const struct cache_entry *ce,
const struct object_id **oidp, const struct object_id **oidp,
unsigned int *modep, unsigned int *modep,
int cached, int match_missing, int cached, int match_missing,
@ -290,7 +292,7 @@ static int get_stat_data(const struct cache_entry *ce,
if (!cached && !ce_uptodate(ce)) { if (!cached && !ce_uptodate(ce)) {
int changed; int changed;
struct stat st; struct stat st;
changed = check_removed(ce, &st); changed = check_removed(istate, ce, &st);
if (changed < 0) if (changed < 0)
return -1; return -1;
else if (changed) { else if (changed) {
@ -321,12 +323,13 @@ static void show_new_file(struct rev_info *revs,
const struct object_id *oid; const struct object_id *oid;
unsigned int mode; unsigned int mode;
unsigned dirty_submodule = 0; unsigned dirty_submodule = 0;
struct index_state *istate = revs->diffopt.repo->index;
/* /*
* New file in the index: it might actually be different in * New file in the index: it might actually be different in
* the working tree. * the working tree.
*/ */
if (get_stat_data(new_file, &oid, &mode, cached, match_missing, if (get_stat_data(istate, new_file, &oid, &mode, cached, match_missing,
&dirty_submodule, &revs->diffopt) < 0) &dirty_submodule, &revs->diffopt) < 0)
return; return;
@ -342,8 +345,9 @@ static int show_modified(struct rev_info *revs,
unsigned int mode, oldmode; unsigned int mode, oldmode;
const struct object_id *oid; const struct object_id *oid;
unsigned dirty_submodule = 0; unsigned dirty_submodule = 0;
struct index_state *istate = revs->diffopt.repo->index;
if (get_stat_data(new_entry, &oid, &mode, cached, match_missing, if (get_stat_data(istate, new_entry, &oid, &mode, cached, match_missing,
&dirty_submodule, &revs->diffopt) < 0) { &dirty_submodule, &revs->diffopt) < 0) {
if (report_missing) if (report_missing)
diff_index_show_file(revs, "-", old_entry, diff_index_show_file(revs, "-", old_entry,
@ -574,6 +578,7 @@ int run_diff_index(struct rev_info *revs, unsigned int option)
struct object_id oid; struct object_id oid;
const char *name; const char *name;
char merge_base_hex[GIT_MAX_HEXSZ + 1]; char merge_base_hex[GIT_MAX_HEXSZ + 1];
struct index_state *istate = revs->diffopt.repo->index;
if (revs->pending.nr != 1) if (revs->pending.nr != 1)
BUG("run_diff_index must be passed exactly one tree"); BUG("run_diff_index must be passed exactly one tree");
@ -581,6 +586,8 @@ int run_diff_index(struct rev_info *revs, unsigned int option)
trace_performance_enter(); trace_performance_enter();
ent = revs->pending.objects; ent = revs->pending.objects;
refresh_fsmonitor(istate);
if (merge_base) { if (merge_base) {
diff_get_merge_base(revs, &oid); diff_get_merge_base(revs, &oid);
name = oid_to_hex_r(merge_base_hex, &oid); name = oid_to_hex_r(merge_base_hex, &oid);

@ -49,6 +49,17 @@ void refresh_fsmonitor(struct index_state *istate);
*/ */
int fsmonitor_is_trivial_response(const struct strbuf *query_result); int fsmonitor_is_trivial_response(const struct strbuf *query_result);
/*
* Check if refresh_fsmonitor has been called at least once.
* refresh_fsmonitor is idempotent. Returns true if fsmonitor is
* not enabled (since the state will be "fresh" w/ CE_FSMONITOR_VALID unset)
* This version is useful for assertions
*/
static inline int is_fsmonitor_refreshed(const struct index_state *istate)
{
return !core_fsmonitor || istate->fsmonitor_has_run_once;
}
/* /*
* Set the given cache entries CE_FSMONITOR_VALID bit. This should be * Set the given cache entries CE_FSMONITOR_VALID bit. This should be
* called any time the cache entry has been updated to reflect the * called any time the cache entry has been updated to reflect the

@ -109,9 +109,9 @@ int cmd__chmtime(int argc, const char **argv)
uintmax_t mtime; uintmax_t mtime;
if (stat(argv[i], &sb) < 0) { if (stat(argv[i], &sb) < 0) {
fprintf(stderr, "Failed to stat %s: %s\n", fprintf(stderr, "Failed to stat %s: %s. Skipping\n",
argv[i], strerror(errno)); argv[i], strerror(errno));
return 1; continue;
} }
#ifdef GIT_WINDOWS_NATIVE #ifdef GIT_WINDOWS_NATIVE

@ -216,6 +216,10 @@ test_fsmonitor_suite() {
git diff git diff
' '
test_perf_w_drop_caches "diff HEAD ($DESC)" '
git diff HEAD
'
test_perf_w_drop_caches "diff -- 0_files ($DESC)" ' test_perf_w_drop_caches "diff -- 0_files ($DESC)" '
git diff -- 1_file git diff -- 1_file
' '