Merge branch 'nd/split-index-unshare'
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 May 2017 03:34:43 +0000 (12:34 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 May 2017 03:34:43 +0000 (12:34 +0900)
Plug some leaks and updates internal API used to implement the
split index feature to make it easier to avoid such a leak in the
future.

* nd/split-index-unshare:
p3400: add perf tests for rebasing many changes
split-index: add and use unshare_split_index()

1  2 
read-cache.c
diff --combined read-cache.c
index 3339de812460c903db085dc2be39e4c8b491478f,8da84ae2d19c93220c6fb7e2956508396ab65c7a..22ab8b5b61636cbc3bf8bcaf5a2ef964bf69c4c3
@@@ -1877,15 -1877,9 +1877,9 @@@ int discard_index(struct index_state *i
  {
        int i;
  
-       for (i = 0; i < istate->cache_nr; i++) {
-               if (istate->cache[i]->index &&
-                   istate->split_index &&
-                   istate->split_index->base &&
-                   istate->cache[i]->index <= istate->split_index->base->cache_nr &&
-                   istate->cache[i] == istate->split_index->base->cache[istate->cache[i]->index - 1])
-                       continue;
+       unshare_split_index(istate, 1);
+       for (i = 0; i < istate->cache_nr; i++)
                free(istate->cache[i]);
-       }
        resolve_undo_clear_index(istate);
        istate->cache_nr = 0;
        istate->cache_changed = 0;
@@@ -2197,7 -2191,6 +2191,7 @@@ static int do_write_index(struct index_
        int entries = istate->cache_nr;
        struct stat st;
        struct strbuf previous_name_buf = STRBUF_INIT, *previous_name;
 +      int drop_cache_tree = 0;
  
        for (i = removed = extended = 0; i < entries; i++) {
                if (cache[i]->ce_flags & CE_REMOVE)
                                warning(msg, ce->name);
                        else
                                return error(msg, ce->name);
 +
 +                      drop_cache_tree = 1;
                }
                if (ce_write_entry(&c, newfd, ce, previous_name) < 0)
                        return -1;
                if (err)
                        return -1;
        }
 -      if (!strip_extensions && istate->cache_tree) {
 +      if (!strip_extensions && !drop_cache_tree && istate->cache_tree) {
                struct strbuf sb = STRBUF_INIT;
  
                cache_tree_write(&sb, istate->cache_tree);