]> git.ipfire.org Git - thirdparty/git.git/commitdiff
read-cache: add remove_file_from_index_with_flags()
authorJunio C Hamano <gitster@pobox.com>
Wed, 29 Jul 2026 17:25:23 +0000 (10:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 29 Jul 2026 17:26:47 +0000 (10:26 -0700)
add_file_to_index() takes flags such as ADD_CACHE_PRETEND and
ADD_CACHE_VERBOSE and internally handles both reporting (e.g.,
"add 'path'") and suppressing index updates during dry runs.

In contrast, remove_file_from_index() takes only istate and path
without flags.  Callers that perform file removals (such as
update_callback() in read-cache.c) are forced to manually inspect
ADD_CACHE_PRETEND and ADD_CACHE_VERBOSE flags for removed
files.

Introduce remove_file_from_index_with_flags() to encapsulate
pretend mode and verbose reporting for index removals.  Update
update_callback() to use the new helper.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache-ll.h
read-cache.c

index 71b87615ebc6d3965ae5d7a89cb4c47d5717d672..8eb266cfd13308fb37c7e1156a45e4ec7fe55208 100644 (file)
@@ -391,11 +391,14 @@ int remove_index_entry_at(struct index_state *, int pos);
 
 void remove_marked_cache_entries(struct index_state *istate, int invalidate);
 int remove_file_from_index(struct index_state *, const char *path);
+int remove_file_from_index_with_flags(struct index_state *, const char *, int);
+
 #define ADD_CACHE_VERBOSE 1
 #define ADD_CACHE_PRETEND 2
 #define ADD_CACHE_IGNORE_ERRORS        4
 #define ADD_CACHE_IGNORE_REMOVAL 8
 #define ADD_CACHE_INTENT 16
+
 /*
  * These two are used to add the contents of the file at path
  * to the index, marking the working tree up-to-date by storing
index 58c378414a661809c1c6ec3b29015b2b518bc7be..ad77c0d5e259282e40a6a0f6d97c43d7c71fb3ec 100644 (file)
@@ -638,6 +638,20 @@ int remove_file_from_index(struct index_state *istate, const char *path)
        return 0;
 }
 
+int remove_file_from_index_with_flags(struct index_state *istate,
+                                     const char *path,
+                                     int flags)
+{
+       int verbose = flags & (ADD_CACHE_VERBOSE | ADD_CACHE_PRETEND);
+       int pretend = flags & ADD_CACHE_PRETEND;
+
+       if (verbose)
+               printf(_("remove '%s'\n"), path);
+       if (pretend)
+               return 0;
+       return remove_file_from_index(istate, path);
+}
+
 static int compare_name(struct cache_entry *ce, const char *path, int namelen)
 {
        return namelen != ce_namelen(ce) || memcmp(path, ce->name, namelen);
@@ -4004,10 +4018,7 @@ static void update_callback(struct diff_queue_struct *q,
                case DIFF_STATUS_DELETED:
                        if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
                                break;
-                       if (!(data->flags & ADD_CACHE_PRETEND))
-                               remove_file_from_index(data->index, path);
-                       if (data->flags & (ADD_CACHE_PRETEND|ADD_CACHE_VERBOSE))
-                               printf(_("remove '%s'\n"), path);
+                       remove_file_from_index_with_flags(data->index, path, data->flags);
                        break;
                }
        }