entry: factor out unlink_entry function

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>

Thomas Gummerer committed Dec 20, 2018 at 13:48 UTC b702dd12d52816e192578c6206db5e6c332ba49b
3 files changed +20 -19
cache.h
+5
@@ -1542,6 +1542,11 @@ struct checkout {
1542 extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
1543 extern void enable_delayed_checkout(struct checkout *state);
1544 extern int finish_delayed_checkout(struct checkout *state);
1545 +/*
1546 + * Unlink the last component and schedule the leading directories for
1547 + * removal, such that empty directories get removed.
1548 + */
1549 +extern void unlink_entry(const struct cache_entry *ce);
1550
1551 struct cache_def {
1552 struct strbuf path;
entry.c
+15
@@ -508,3 +508,18 @@ int checkout_entry(struct cache_entry *ce,
508 create_directories(path.buf, path.len, state);
509 return write_entry(ce, path.buf, state, 0);
510 }
511 +
512 +void unlink_entry(const struct cache_entry *ce)
513 +{
514 + const struct submodule *sub = submodule_from_ce(ce);
515 + if (sub) {
516 + /* state.force is set at the caller. */
517 + submodule_move_head(ce->name, "HEAD", NULL,
518 + SUBMODULE_MOVE_HEAD_FORCE);
519 + }
520 + if (!check_leading_path(ce->name, ce_namelen(ce)))
521 + return;
522 + if (remove_or_warn(ce->ce_mode, ce->name))
523 + return;
524 + schedule_dir_for_removal(ce->name, ce_namelen(ce));
525 +}
unpack-trees.c
-19
@@ -300,25 +300,6 @@ static void load_gitmodules_file(struct index_state *index,
300 }
301 }
302
303 -/*
304 - * Unlink the last component and schedule the leading directories for
305 - * removal, such that empty directories get removed.
306 - */
307 -static void unlink_entry(const struct cache_entry *ce)
308 -{
309 - const struct submodule *sub = submodule_from_ce(ce);
310 - if (sub) {
311 - /* state.force is set at the caller. */
312 - submodule_move_head(ce->name, "HEAD", NULL,
313 - SUBMODULE_MOVE_HEAD_FORCE);
314 - }
315 - if (!check_leading_path(ce->name, ce_namelen(ce)))
316 - return;
317 - if (remove_or_warn(ce->ce_mode, ce->name))
318 - return;
319 - schedule_dir_for_removal(ce->name, ce_namelen(ce));
320 -}
321 -
303 static struct progress *get_progress(struct unpack_trees_options *o)
304 {
305 unsigned cnt = 0, total = 0;