From: Junio C Hamano Date: Thu, 11 Sep 2014 17:33:32 +0000 (-0700) Subject: Merge branch 'dt/cache-tree-repair' X-Git-Tag: v2.2.0-rc0~138 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3fd13cbcd58f078476cabab926931a3d5bdedfe2 Merge branch 'dt/cache-tree-repair' Add a few more places in "commit" and "checkout" that make sure that the cache-tree is fully populated in the index. * dt/cache-tree-repair: cache-tree: do not try to use an invalidated subtree info to build a tree cache-tree: Write updated cache-tree after commit cache-tree: subdirectory tests test-dump-cache-tree: invalid trees are not errors cache-tree: create/update cache-tree on checkout --- 3fd13cbcd58f078476cabab926931a3d5bdedfe2 diff --cc builtin/checkout.c index f71e74531d,054214fe43..8afdf2b5c4 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -552,7 -553,16 +552,13 @@@ static int merge_working_tree(const str } } + if (!active_cache_tree) + active_cache_tree = cache_tree(); + + if (!cache_tree_fully_valid(active_cache_tree)) - cache_tree_update(active_cache_tree, - (const struct cache_entry * const *)active_cache, - active_nr, WRITE_TREE_SILENT | WRITE_TREE_REPAIR); ++ cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR); + - if (write_cache(newfd, active_cache, active_nr) || - commit_locked_index(lock_file)) + if (write_locked_index(&the_index, lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); if (!opts->force && !opts->quiet) diff --cc builtin/commit.c index 5911447486,77570c48ba..41f481bd03 --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -353,6 -342,17 +353,13 @@@ static char *prepare_index(int argc, co discard_cache(); read_cache_from(index_lock.filename); + if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) { - fd = open(index_lock.filename, O_WRONLY); - if (fd >= 0) - if (write_cache(fd, active_cache, active_nr) < 0) - die(_("unable to write index file")); - else - close_lock_file(&index_lock); - else ++ if (reopen_lock_file(&index_lock) < 0) + die(_("unable to write index file")); ++ if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK)) ++ die(_("unable to update temporary index")); + } else + warning(_("Failed to update main cache tree")); commit_style = COMMIT_NORMAL; return index_lock.filename; @@@ -391,12 -392,16 +398,16 @@@ * We still need to refresh the index here. */ if (!only && !pathspec.nr) { - fd = hold_locked_index(&index_lock, 1); + hold_locked_index(&index_lock, 1); refresh_cache_or_die(refresh_flags); - if (active_cache_changed) { + if (active_cache_changed + || !cache_tree_fully_valid(active_cache_tree)) { update_main_cache_tree(WRITE_TREE_SILENT); + active_cache_changed = 1; + } + if (active_cache_changed) { - if (write_cache(fd, active_cache, active_nr) || - commit_locked_index(&index_lock)) + if (write_locked_index(&the_index, &index_lock, + COMMIT_LOCK)) die(_("unable to write new_index file")); } else { rollback_lock_file(&index_lock); @@@ -441,16 -447,18 +452,17 @@@ if (read_cache() < 0) die(_("cannot read the index")); - fd = hold_locked_index(&index_lock, 1); + hold_locked_index(&index_lock, 1); add_remove_files(&partial); refresh_cache(REFRESH_QUIET); + update_main_cache_tree(WRITE_TREE_SILENT); - if (write_cache(fd, active_cache, active_nr) || - close_lock_file(&index_lock)) + if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK)) die(_("unable to write new_index file")); - fd = hold_lock_file_for_update(&false_lock, - git_path("next-index-%"PRIuMAX, - (uintmax_t) getpid()), - LOCK_DIE_ON_ERROR); + hold_lock_file_for_update(&false_lock, + git_path("next-index-%"PRIuMAX, + (uintmax_t) getpid()), + LOCK_DIE_ON_ERROR); create_base_index(current_head); add_remove_files(&partial);