@matheusbsbs / matheus-bagliano / commits / 33ecf7eb61
Fork 0

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 <barkalow@iabervon.org>

Daniel Barkalow committed Feb 7, 2008 at 11:39 UTC 33ecf7eb6143143711ccaf828134beb2dacbe5c9
1 file changed +9 -7
unpack-trees.c
+9 -7
@@ -288,16 +288,16 @@ static void unlink_entry(char *name, char *last_symlink)
288 }
289
290 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)
292 {
293 unsigned cnt = 0, total = 0;
294 struct progress *progress = NULL;
295 char last_symlink[PATH_MAX];
296 + int i;
297
298 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];
301 if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
302 total++;
303 }
@@ -308,14 +308,16 @@ static void check_updates(struct cache_entry **src, int nr,
308 }
309
310 *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];
313
314 if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
315 display_progress(progress, ++cnt);
316 if (ce->ce_flags & CE_REMOVE) {
317 if (o->update)
318 unlink_entry(ce->name, last_symlink);
319 + remove_cache_entry_at(i);
320 + i--;
321 continue;
322 }
323 if (ce->ce_flags & CE_UPDATE) {
@@ -374,7 +376,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
376 error("Merge requires file-level merging");
377 }
378
377 - check_updates(active_cache, active_nr, o);
379 + check_updates(o);
380 return 0;
381 }
382