Move old index entry removal from "unpack_trees()" into the individual functions
This makes no changes to current code, but it allows the individual merge functions to decide what to do about the old entry. They might decide to update it in place, rather than force them to always delete and re-add it. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Aug 10, 2007 at 12:15 UTC
b48d5a050afa30402c8281c223df9d7e58b4493c
2 files changed
+29
-11
unpack-trees.c
+23
-6
@@ -58,10 +58,17 @@ static int entcmp(const char *name1, int dir1, const char *name2, int dir2)
58
return ret;
59
}
60
61
+static inline void remove_entry(int remove)
62
+{
63
+ if (remove >= 0)
64
+ remove_cache_entry_at(remove);
65
+}
66
+
67
static int unpack_trees_rec(struct tree_entry_list **posns, int len,
68
const char *base, struct unpack_trees_options *o,
69
struct tree_entry_list *df_conflict_list)
70
{
71
+ int remove;
72
int baselen = strlen(base);
73
int src_size = len + 1;
74
int i_stk = i_stk;
@@ -145,10 +152,11 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
152
153
subposns = xcalloc(len, sizeof(struct tree_list_entry *));
154
155
+ remove = -1;
156
if (cache_name && !strcmp(cache_name, first)) {
157
any_files = 1;
158
src[0] = active_cache[o->pos];
151
- remove_cache_entry_at(o->pos);
159
+ remove = o->pos;
160
}
161
162
for (i = 0; i < len; i++) {
@@ -214,13 +222,14 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
222
printf("\n");
223
}
224
#endif
217
- ret = o->fn(src, o);
225
+ ret = o->fn(src, o, remove);
226
227
#if DBRT_DEBUG > 1
228
printf("Added %d entries\n", ret);
229
#endif
230
o->pos += ret;
231
} else {
232
+ remove_entry(remove);
233
for (i = 0; i < src_size; i++) {
234
if (src[i]) {
235
add_cache_entry(src[i], ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
@@ -641,7 +650,8 @@ static void show_stage_entry(FILE *o,
650
#endif
651
652
int threeway_merge(struct cache_entry **stages,
644
- struct unpack_trees_options *o)
653
+ struct unpack_trees_options *o,
654
+ int remove)
655
{
656
struct cache_entry *index;
657
struct cache_entry *head;
@@ -657,6 +667,7 @@ int threeway_merge(struct cache_entry **stages,
667
int no_anc_exists = 1;
668
int i;
669
670
+ remove_entry(remove);
671
for (i = 1; i < o->head_idx; i++) {
672
if (!stages[i] || stages[i] == o->df_conflict_entry)
673
any_anc_missing = 1;
@@ -809,12 +820,14 @@ int threeway_merge(struct cache_entry **stages,
820
*
821
*/
822
int twoway_merge(struct cache_entry **src,
812
- struct unpack_trees_options *o)
823
+ struct unpack_trees_options *o,
824
+ int remove)
825
{
826
struct cache_entry *current = src[0];
827
struct cache_entry *oldtree = src[1];
828
struct cache_entry *newtree = src[2];
829
830
+ remove_entry(remove);
831
if (o->merge_size != 2)
832
return error("Cannot do a twoway merge of %d trees",
833
o->merge_size);
@@ -868,11 +881,13 @@ int twoway_merge(struct cache_entry **src,
881
* stage0 does not have anything there.
882
*/
883
int bind_merge(struct cache_entry **src,
871
- struct unpack_trees_options *o)
884
+ struct unpack_trees_options *o,
885
+ int remove)
886
{
887
struct cache_entry *old = src[0];
888
struct cache_entry *a = src[1];
889
890
+ remove_entry(remove);
891
if (o->merge_size != 1)
892
return error("Cannot do a bind merge of %d trees\n",
893
o->merge_size);
@@ -891,11 +906,13 @@ int bind_merge(struct cache_entry **src,
906
* - take the stat information from stage0, take the data from stage1
907
*/
908
int oneway_merge(struct cache_entry **src,
894
- struct unpack_trees_options *o)
909
+ struct unpack_trees_options *o,
910
+ int remove)
911
{
912
struct cache_entry *old = src[0];
913
struct cache_entry *a = src[1];
914
915
+ remove_entry(remove);
916
if (o->merge_size != 1)
917
return error("Cannot do a oneway merge of %d trees",
918
o->merge_size);
unpack-trees.h
+6
-5
@@ -4,7 +4,8 @@
4
struct unpack_trees_options;
5
6
typedef int (*merge_fn_t)(struct cache_entry **src,
7
- struct unpack_trees_options *options);
7
+ struct unpack_trees_options *options,
8
+ int remove);
9
10
struct unpack_trees_options {
11
int reset;
@@ -29,9 +30,9 @@ struct unpack_trees_options {
30
extern int unpack_trees(unsigned n, struct tree_desc *t,
31
struct unpack_trees_options *options);
32
32
-int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o);
33
-int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o);
34
-int bind_merge(struct cache_entry **src, struct unpack_trees_options *o);
35
-int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o);
33
+int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o, int);
34
+int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o, int);
35
+int bind_merge(struct cache_entry **src, struct unpack_trees_options *o, int);
36
+int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o, int);
37
38
#endif