Skip to content

Commit 33ecf7e

Browse files
iabervongitster
authored andcommitted
Discard "deleted" cache entries after using them to update the working tree
Way back in read-tree.c, we used a mode 0 cache entry to indicate that an entry had been deleted, so that the update code would remove the working tree file, and we would just skip it when writing out the index file afterward. These days, unpack_trees is a library function, and it is still leaving these entries in the active cache. Furthermore, unpack_trees doesn't correctly ignore those entries, and who knows what other code wouldn't expect them to be there, but just isn't yet called after a call to unpack_trees. To avoid having other code trip over these entries, have check_updates() remove them after it removes the working tree files. While we're at it, simplify the loop in check_updates(), and avoid passing global variables as parameters to check_updates(): there is only one call site anyway. Signed-off-by: Daniel Barkalow <[email protected]>
1 parent b05c6df commit 33ecf7e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

unpack-trees.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,16 @@ static void unlink_entry(char *name, char *last_symlink)
288288
}
289289

290290
static struct checkout state;
291-
static void check_updates(struct cache_entry **src, int nr,
292-
struct unpack_trees_options *o)
291+
static void check_updates(struct unpack_trees_options *o)
293292
{
294293
unsigned cnt = 0, total = 0;
295294
struct progress *progress = NULL;
296295
char last_symlink[PATH_MAX];
296+
int i;
297297

298298
if (o->update && o->verbose_update) {
299-
for (total = cnt = 0; cnt < nr; cnt++) {
300-
struct cache_entry *ce = src[cnt];
299+
for (total = cnt = 0; cnt < active_nr; cnt++) {
300+
struct cache_entry *ce = active_cache[cnt];
301301
if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
302302
total++;
303303
}
@@ -308,14 +308,16 @@ static void check_updates(struct cache_entry **src, int nr,
308308
}
309309

310310
*last_symlink = '\0';
311-
while (nr--) {
312-
struct cache_entry *ce = *src++;
311+
for (i = 0; i < active_nr; i++) {
312+
struct cache_entry *ce = active_cache[i];
313313

314314
if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
315315
display_progress(progress, ++cnt);
316316
if (ce->ce_flags & CE_REMOVE) {
317317
if (o->update)
318318
unlink_entry(ce->name, last_symlink);
319+
remove_cache_entry_at(i);
320+
i--;
319321
continue;
320322
}
321323
if (ce->ce_flags & CE_UPDATE) {
@@ -374,7 +376,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
374376
error("Merge requires file-level merging");
375377
}
376378

377-
check_updates(active_cache, active_nr, o);
379+
check_updates(o);
378380
return 0;
379381
}
380382

0 commit comments

Comments
 (0)