]> rtime.felk.cvut.cz Git - git.git/commitdiff
Merge branch 'dt/cache-tree-repair'
authorJunio C Hamano <gitster@pobox.com>
Thu, 11 Sep 2014 17:33:32 +0000 (10:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Sep 2014 17:33:32 +0000 (10:33 -0700)
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

1  2 
builtin/checkout.c
builtin/commit.c
cache-tree.c
cache-tree.h
test-dump-cache-tree.c

index f71e74531d2a7d195ff2987f6dca3c69c636aa7c,054214fe43c8f8e3b815d4afb747408f2524c378..8afdf2b5c4bfbd53e7315afe9d8ae3d88f93dd57
@@@ -552,7 -553,16 +552,13 @@@ static int merge_working_tree(const str
                }
        }
  
 -              cache_tree_update(active_cache_tree,
 -                                (const struct cache_entry * const *)active_cache,
 -                                active_nr, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
+       if (!active_cache_tree)
+               active_cache_tree = cache_tree();
+       if (!cache_tree_fully_valid(active_cache_tree))
 -      if (write_cache(newfd, active_cache, active_nr) ||
 -          commit_locked_index(lock_file))
++              cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR);
 +      if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
  
        if (!opts->force && !opts->quiet)
index 5911447486f5b2325dff4747872a25dd4325c1e2,77570c48ba02adf7aa78654c644b13478246a4e0..41f481bd030ba96f8883e64517eda95931344545
@@@ -353,6 -342,17 +353,13 @@@ static char *prepare_index(int argc, co
  
                discard_cache();
                read_cache_from(index_lock.filename);
 -                      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 (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
++                      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;
         * 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);
 -                      if (write_cache(fd, active_cache, active_nr) ||
 -                          commit_locked_index(&index_lock))
+                       active_cache_changed = 1;
+               }
+               if (active_cache_changed) {
 +                      if (write_locked_index(&the_index, &index_lock,
 +                                             COMMIT_LOCK))
                                die(_("unable to write new_index file"));
                } else {
                        rollback_lock_file(&index_lock);
        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);
 -      if (write_cache(fd, active_cache, active_nr) ||
 -          close_lock_file(&index_lock))
+       update_main_cache_tree(WRITE_TREE_SILENT);
 +      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);
diff --cc cache-tree.c
Simple merge
diff --cc cache-tree.h
Simple merge
Simple merge