Browse Source

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>
maint
Thomas Gummerer 6 years ago committed by Junio C Hamano
parent
commit
b702dd12d5
  1. 5
      cache.h
  2. 15
      entry.c
  3. 19
      unpack-trees.c

5
cache.h

@ -1542,6 +1542,11 @@ struct checkout { @@ -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;

15
entry.c

@ -508,3 +508,18 @@ int checkout_entry(struct cache_entry *ce, @@ -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));
}

19
unpack-trees.c

@ -300,25 +300,6 @@ static void load_gitmodules_file(struct index_state *index, @@ -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;

Loading…
Cancel
Save