Update draft release notes to 1.7.9
[gitweb.git] / cache-tree.c
index d91743775dfbe98d99d8ab25a270af320c8b984e..8de39590d57e14d08ee4d04b74965191aa905b29 100644 (file)
@@ -22,8 +22,10 @@ void cache_tree_free(struct cache_tree **it_p)
        if (!it)
                return;
        for (i = 0; i < it->subtree_nr; i++)
-               if (it->down[i])
+               if (it->down[i]) {
                        cache_tree_free(&it->down[i]->cache_tree);
+                       free(it->down[i]);
+               }
        free(it->down);
        free(it);
        *it_p = NULL;
@@ -148,7 +150,7 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
 }
 
 static int verify_cache(struct cache_entry **cache,
-                       int entries)
+                       int entries, int silent)
 {
        int i, funny;
 
@@ -157,6 +159,8 @@ static int verify_cache(struct cache_entry **cache,
        for (i = 0; i < entries; i++) {
                struct cache_entry *ce = cache[i];
                if (ce_stage(ce) || (ce->ce_flags & CE_INTENT_TO_ADD)) {
+                       if (silent)
+                               return -1;
                        if (10 < ++funny) {
                                fprintf(stderr, "...\n");
                                break;
@@ -328,9 +332,11 @@ static int update_one(struct cache_tree *it,
                        mode = ce->ce_mode;
                        entlen = pathlen - baselen;
                }
-               if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1))
+               if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) {
+                       strbuf_release(&buffer);
                        return error("invalid object %06o %s for '%.*s'",
                                mode, sha1_to_hex(sha1), entlen+baselen, path);
+               }
 
                if (ce->ce_flags & CE_REMOVE)
                        continue; /* entry being removed */
@@ -366,10 +372,11 @@ int cache_tree_update(struct cache_tree *it,
                      struct cache_entry **cache,
                      int entries,
                      int missing_ok,
-                     int dryrun)
+                     int dryrun,
+                     int silent)
 {
        int i;
-       i = verify_cache(cache, entries);
+       i = verify_cache(cache, entries, silent);
        if (i)
                return i;
        i = update_one(it, cache, entries, "", 0, missing_ok, dryrun);
@@ -569,7 +576,7 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
 
                if (cache_tree_update(active_cache_tree,
                                      active_cache, active_nr,
-                                     missing_ok, 0) < 0)
+                                     missing_ok, 0, 0) < 0)
                        return WRITE_TREE_UNMERGED_INDEX;
                if (0 <= newfd) {
                        if (!write_cache(newfd, active_cache, active_nr) &&
@@ -664,3 +671,11 @@ int cache_tree_matches_traversal(struct cache_tree *root,
                return it->entry_count;
        return 0;
 }
+
+int update_main_cache_tree (int silent)
+{
+       if (!the_index.cache_tree)
+               the_index.cache_tree = cache_tree();
+       return cache_tree_update(the_index.cache_tree,
+                                the_index.cache, the_index.cache_nr, 0, 0, silent);
+}