git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/4] read-cache: add remove_file_from_index_with_flags()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 29, 2026, 17:25 UTC
Message-ID
<20260729172524.4022621-4-gitster@pobox.com>
In-Reply-To
<20260729172524.4022621-1-gitster@pobox.com>

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 |  3 +++
 read-cache.c    | 19 +++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 71b87615eb..8eb266cfd1 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -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
diff --git a/read-cache.c b/read-cache.c
index 58c378414a..ad77c0d5e2 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -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;
 		}
 	}
-- 
2.55.0-609-g9a17695db7
Previous: Junio C HamanoNext: Junio C Hamano
Message 17 of 30 in “git add --resolved”
  1. 0/4 git add --resolvedJunio C Hamano, Jul 28, 2026
  2. 1/4 merge-ll: consolidate conflict marker scanning logicJunio C Hamano, Jul 28, 2026
  3. 2/4 read-cache: add remove_file_from_index_with_flags()Junio C Hamano, Jul 28, 2026
  4. 3/4 add: introduce '--resolved' optionJunio C Hamano, Jul 28, 2026
  5. Michael MontalboJul 29, 2026
  6. Junio C HamanoJul 29, 2026
  7. Junio C HamanoJul 29, 2026
  8. Junio C HamanoAug 2, 2026
  9. Junio C HamanoJul 29, 2026
  10. Michael MontalboAug 2, 2026
  11. Junio C HamanoAug 2, 2026
  12. Michael MontalboAug 3, 2026
  13. 4/4 read-cache: reindentJunio C Hamano, Jul 28, 2026
  14. 0/4 git add --resolvedJunio C Hamano, Jul 29, 2026
  15. 1/4 read-cache: reindentJunio C Hamano, Jul 29, 2026
  16. 2/4 merge-ll: consolidate conflict marker scanning logicJunio C Hamano, Jul 29, 2026
  17. 3/4 read-cache: add remove_file_from_index_with_flags()Junio C Hamano, Jul 29, 2026
  18. 4/4 add: introduce '--resolved' optionJunio C Hamano, Jul 29, 2026
  19. Junio C HamanoJul 29, 2026
  20. Michael MontalboJul 29, 2026
  21. Junio C HamanoJul 30, 2026
  22. Michael MontalboAug 2, 2026
  23. 0/4 git add --resolvedJunio C Hamano, Jul 31, 2026
  24. 1/4 read-cache: reindentJunio C Hamano, Jul 31, 2026
  25. 2/4 merge-ll: consolidate conflict marker scanning logicJunio C Hamano, Jul 31, 2026
  26. 3/4 read-cache: add remove_file_from_index_with_flags()Junio C Hamano, Jul 31, 2026
  27. 4/4 add: introduce '--resolved' optionJunio C Hamano, Jul 31, 2026
  28. Jeff KingAug 1, 2026
  29. Junio C HamanoAug 1, 2026
  30. Junio C HamanoAug 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.