[PATCH v2 1/3] dir: hash ignore files before appending newline
- From
Tamir Duberstein <tamird@gmail.com>
- Date
- Sep 23, 2026, 22:26 UTC
- Message-ID
- <20260923-ls-files-untracked-cache-v2-1-d7ee33476eb8@gmail.com>
- In-Reply-To
- <20260923-ls-files-untracked-cache-v2-0-d7ee33476eb8@gmail.com>
add_patterns() appends a newline for the pattern parser before computing an ignore file's object ID. Hashing the buffer therefore includes a byte that is absent from the file. When the file has an up-to-date index entry and needs no content conversion, the function instead uses that entry's object ID.
Switching between these paths changes the cached object ID even when the file has not changed, invalidating the untracked cache below it. Compute the hash before appending the newline so both paths agree. Update the expected object IDs of the untracked ignore files accordingly.
Assisted-by: LLM Signed-off-by: Tamir Duberstein <tamird@gmail.com> --- dir.c | 6 +++++- t/t7063-status-untracked-cache.sh | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/dir.c b/dir.c index d896e7be4b..5484eb1562 100644 --- a/dir.c +++ b/dir.c @@ -1195,7 +1195,6 @@ static int add_patterns(const char *fname, const char *base, int baselen, close(fd); return -1; } - buf[size++] = '\n'; close(fd); if (oid_stat) { int pos; @@ -1215,6 +1214,11 @@ static int add_patterns(const char *fname, const char *base, int baselen, fill_stat_data(&oid_stat->stat, &st); oid_stat->valid = 1; } + /* + * The extra newline is only for parsing. Like do_read_blob(), + * keep it out of the file's object ID. + */ + buf[size++] = '\n'; } if (size > PATTERN_MAX_FILE_SIZE) { diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh index 8929ef481f..10d4850077 100755 --- a/t/t7063-status-untracked-cache.sh +++ b/t/t7063-status-untracked-cache.sh @@ -98,11 +98,11 @@ test_expect_success 'setup' ' : >.git/info/exclude && git update-index --untracked-cache && test_oid_cache <<-EOF - root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e - root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974 + root sha1:8510665149157c2bc901848c3e0b746954e9cbd9 + root sha256:09ef24b38105f396a61ad78d73ba6a18ee3cbd89ce4524b4e13b6c1af191e2d8 - exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0 - exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c + exclude sha1:2bdf67abb163a4ffb2d7f3f0880c9fe5068ce782 + exclude sha256:b83643f4390b339c1b3ff2f5132c99bd4a77687dd321d3f386c25953aa6f1ce4 done sha1:1946f0437f90c5005533cbe1736a6451ca301714 done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
-- 2.56.0.rc0.807.ga0c0929ce1.frankengit