[PATCH v2 1/9] read-cache: split out function to drop unmerged entries to stage 0
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jun 3, 2026, 16:14 UTC
- Message-ID
- <20260603-b4-pks-history-drop-v2-1-742cb5b5176d@pks.im>
- In-Reply-To
- <20260603-b4-pks-history-drop-v2-0-742cb5b5176d@pks.im>
In `repo_read_index_unmerged()` we read the index and then drop any unmerged entries to stage 0. In a subsequent commit we'll want to perform this operation on arbitrary indexes, not only the one of the given repository.
Prepare for this by splitting out the functionality into a new function that can act on an arbitrary index.
While at it, fix a signedness mismatch when iterating through the index cache entries.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- read-cache-ll.h | 1 + read-cache.c | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/read-cache-ll.h b/read-cache-ll.h index 2c8b4b21b1..71b87615eb 100644 --- a/read-cache-ll.h +++ b/read-cache-ll.h @@ -309,6 +309,7 @@ int write_locked_index(struct index_state *, struct lock_file *lock, unsigned fl void discard_index(struct index_state *); void move_index_extensions(struct index_state *dst, struct index_state *src); int unmerged_index(const struct index_state *); +int index_state_unmerged_to_stage0(struct index_state *istate); /** * Returns 1 if istate differs from tree, 0 otherwise. If tree is NULL, diff --git a/read-cache.c b/read-cache.c index 21829102ae..799a5bc719 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3403,13 +3403,15 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock, */ int repo_read_index_unmerged(struct repository *repo) { - struct index_state *istate; - int i; + repo_read_index(repo); + return index_state_unmerged_to_stage0(repo->index); +} + +int index_state_unmerged_to_stage0(struct index_state *istate) +{ int unmerged = 0; - repo_read_index(repo); - istate = repo->index; - for (i = 0; i < istate->cache_nr; i++) { + for (unsigned int i = 0; i < istate->cache_nr; i++) { struct cache_entry *ce = istate->cache[i]; struct cache_entry *new_ce; int len;
-- 2.54.0.1064.gd145956f57.dirty