Skip to content

Commit

Permalink
unpack-trees: factor out dup_entry
Browse files Browse the repository at this point in the history
While we're add it, mark the struct cache_entry pointer of add_entry
const because we only read from it and this allows callers to pass in
const pointers.

Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Jun 2, 2013
1 parent 21a6b9f commit a33bd4d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,20 @@ static void do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
}

static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
unsigned int set, unsigned int clear)
static struct cache_entry *dup_entry(const struct cache_entry *ce)
{
unsigned int size = ce_size(ce);
struct cache_entry *new = xmalloc(size);

memcpy(new, ce, size);
do_add_entry(o, new, set, clear);
return new;
}

static void add_entry(struct unpack_trees_options *o,
const struct cache_entry *ce,
unsigned int set, unsigned int clear)
{
do_add_entry(o, dup_entry(ce), set, clear);
}

/*
Expand Down

0 comments on commit a33bd4d

Please sign in to comment.