entry: factor out unlink_entry function
authorThomas Gummerer <t.gummerer@gmail.com>
Thu, 20 Dec 2018 13:48:14 +0000 (13:48 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Jan 2019 23:28:05 +0000 (15:28 -0800)
Factor out the 'unlink_entry()' function from unpack-trees.c to
entry.c. It will be used in other places as well in subsequent
steps.

As it's no longer a static function, also move the documentation to
the header file to make it more discoverable.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
entry.c
unpack-trees.c
diff --git a/cache.h b/cache.h
index ca36b44ee0b5851f837616c322a201ac420a90d2..c1c953e810abcc506d05cd26c21d389418dd17c6 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1542,6 +1542,11 @@ struct checkout {
 extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
 extern void enable_delayed_checkout(struct checkout *state);
 extern int finish_delayed_checkout(struct checkout *state);
+/*
+ * Unlink the last component and schedule the leading directories for
+ * removal, such that empty directories get removed.
+ */
+extern void unlink_entry(const struct cache_entry *ce);
 
 struct cache_def {
        struct strbuf path;
diff --git a/entry.c b/entry.c
index 0a3c451f5f0f08deabe20b4ca1858825f2b29f3f..b9eef57117169487157e9e14e6b96b7defee113e 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -508,3 +508,18 @@ int checkout_entry(struct cache_entry *ce,
        create_directories(path.buf, path.len, state);
        return write_entry(ce, path.buf, state, 0);
 }
+
+void unlink_entry(const struct cache_entry *ce)
+{
+       const struct submodule *sub = submodule_from_ce(ce);
+       if (sub) {
+               /* state.force is set at the caller. */
+               submodule_move_head(ce->name, "HEAD", NULL,
+                                   SUBMODULE_MOVE_HEAD_FORCE);
+       }
+       if (!check_leading_path(ce->name, ce_namelen(ce)))
+               return;
+       if (remove_or_warn(ce->ce_mode, ce->name))
+               return;
+       schedule_dir_for_removal(ce->name, ce_namelen(ce));
+}
index 7570df481bf69824e4b163a6c7a15985b72d1326..e8d1a6ac504ec04be62dbb26998c1cf79a6901da 100644 (file)
@@ -300,25 +300,6 @@ static void load_gitmodules_file(struct index_state *index,
        }
 }
 
-/*
- * Unlink the last component and schedule the leading directories for
- * removal, such that empty directories get removed.
- */
-static void unlink_entry(const struct cache_entry *ce)
-{
-       const struct submodule *sub = submodule_from_ce(ce);
-       if (sub) {
-               /* state.force is set at the caller. */
-               submodule_move_head(ce->name, "HEAD", NULL,
-                                   SUBMODULE_MOVE_HEAD_FORCE);
-       }
-       if (!check_leading_path(ce->name, ce_namelen(ce)))
-               return;
-       if (remove_or_warn(ce->ce_mode, ce->name))
-               return;
-       schedule_dir_for_removal(ce->name, ce_namelen(ce));
-}
-
 static struct progress *get_progress(struct unpack_trees_options *o)
 {
        unsigned cnt = 0, total = 0;