]> git.ipfire.org Git - thirdparty/git.git/commitdiff
read-cache: split out function to drop unmerged entries to stage 0
authorPatrick Steinhardt <ps@pks.im>
Wed, 3 Jun 2026 16:14:00 +0000 (18:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 4 Jun 2026 00:04:24 +0000 (09:04 +0900)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache-ll.h
read-cache.c

index 2c8b4b21b1c7e97f9c122390da9fd353c97be819..71b87615ebc6d3965ae5d7a89cb4c47d5717d672 100644 (file)
@@ -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,
index 21829102ae275e124eb7b94550bc7ccf16993bac..799a5bc7199fe0c05f93674d3ba4b9f14f0cec0b 100644 (file)
@@ -3403,13 +3403,15 @@ out:
  */
 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;