diff mbox series

[RFC,2/4] entry: add threaded_unlink_entry function

Message ID 20231203133911.41594-3-hanyoung@protonmail.com (mailing list archive)
State New, archived
Headers show
Series add parallel unlink | expand

Commit Message

Han Young Dec. 3, 2023, 1:39 p.m. UTC
From: Han Young <hanyang.tony@bytedance.com>

Add threaded_unlink_entry function, the threaded function uses cache passed by arguments instead of the default cache. It also calls threaded variant of schedule_dir_for_removal to ensure dirs are removed in multithreaded unlink.
---
Another duplicated function. Because default removal cache and default lstat cache live in different source files,
threaded variant of check_leading_path and schedule_dir_for_removal must be called here
instead of choosing to pass explicit or default cache.

 entry.c | 16 ++++++++++++++++
 entry.h |  3 +++
 2 files changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/entry.c b/entry.c
index 076e97eb89..04440beb2b 100644
--- a/entry.c
+++ b/entry.c
@@ -567,6 +567,22 @@  int checkout_entry_ca(struct cache_entry *ce, struct conv_attrs *ca,
 	return write_entry(ce, path.buf, ca, state, 0, nr_checkouts);
 }
 
+void threaded_unlink_entry(const struct cache_entry *ce, const char *super_prefix,
+			   struct strbuf *removal, struct cache_def *cache)
+{
+	const struct submodule *sub = submodule_from_ce(ce);
+	if (sub) {
+		/* state.force is set at the caller. */
+		submodule_move_head(ce->name, super_prefix, "HEAD", NULL,
+				    SUBMODULE_MOVE_HEAD_FORCE);
+	}
+	if (threaded_check_leading_path(cache, ce->name, ce_namelen(ce), 1) >= 0)
+		return;
+	if (remove_or_warn(ce->ce_mode, ce->name))
+		return;
+	threaded_schedule_dir_for_removal(ce->name, ce_namelen(ce), removal);
+}
+
 void unlink_entry(const struct cache_entry *ce, const char *super_prefix)
 {
 	const struct submodule *sub = submodule_from_ce(ce);
diff --git a/entry.h b/entry.h
index ca3ed35bc0..413ca3822d 100644
--- a/entry.h
+++ b/entry.h
@@ -2,6 +2,7 @@ 
 #define ENTRY_H
 
 #include "convert.h"
+#include "symlinks.h"
 
 struct cache_entry;
 struct index_state;
@@ -56,6 +57,8 @@  int finish_delayed_checkout(struct checkout *state, int show_progress);
  * down from "read-tree" et al.
  */
 void unlink_entry(const struct cache_entry *ce, const char *super_prefix);
+void threaded_unlink_entry(const struct cache_entry *ce, const char *super_prefix,
+			   struct strbuf *removal, struct cache_def *cache);
 
 void *read_blob_entry(const struct cache_entry *ce, size_t *size);
 int fstat_checkout_output(int fd, const struct checkout *state, struct stat *st);