unpack-trees: factor out dup_entry

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>

René Scharfe committed Jun 2, 2013 at 17:46 UTC a33bd4d34def15d12372aeb8c59a7465416f9f66
1 file changed +9 -3
unpack-trees.c
+9 -3
@@ -116,14 +116,20 @@ static void do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
116 ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
117 }
118
119 -static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
120 - unsigned int set, unsigned int clear)
119 +static struct cache_entry *dup_entry(const struct cache_entry *ce)
120 {
121 unsigned int size = ce_size(ce);
122 struct cache_entry *new = xmalloc(size);
123
124 memcpy(new, ce, size);
126 - do_add_entry(o, new, set, clear);
125 + return new;
126 +}
127 +
128 +static void add_entry(struct unpack_trees_options *o,
129 + const struct cache_entry *ce,
130 + unsigned int set, unsigned int clear)
131 +{
132 + do_add_entry(o, dup_entry(ce), set, clear);
133 }
134
135 /*