Skip to content

Commit b702dd1

Browse files
tgummerergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0cc584 commit b702dd1

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

cache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,11 @@ struct checkout {
15421542
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
15431543
extern void enable_delayed_checkout(struct checkout *state);
15441544
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);
15451550

15461551
struct cache_def {
15471552
struct strbuf path;

entry.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,18 @@ int checkout_entry(struct cache_entry *ce,
508508
create_directories(path.buf, path.len, state);
509509
return write_entry(ce, path.buf, state, 0);
510510
}
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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,6 @@ static void load_gitmodules_file(struct index_state *index,
300300
}
301301
}
302302

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-
322303
static struct progress *get_progress(struct unpack_trees_options *o)
323304
{
324305
unsigned cnt = 0, total = 0;

0 commit comments

Comments
 (0)