split-index: add and use unshare_split_index()
commitf9d7abec2ad2f9eb3d8873169cc28c34273df082
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 5 May 2017 14:57:12 +0000 (5 16:57 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 May 2017 01:50:20 +0000 (8 10:50 +0900)
tree8ac02895a20ac3928aa40fbc1d5e2c58ba47bb8e
parent4fa66c85f11bc5a541462ca5ae3246aa0ce02e74
split-index: add and use unshare_split_index()

When split-index is being used, we have two cache_entry arrays in
index_state->cache[] and index_state->split_index->base->cache[].

index_state->cache[] may share the same entries with base->cache[] so
we can quickly determine what entries are shared. This makes memory
management tricky, we can't free base->cache[] until we know
index_state->cache[] does not point to any of those entries.

unshare_split_index() is added for this purpose, to find shared
entries and either duplicate them in index_state->cache[], or discard
them. Either way it should be safe to free base->cache[] after
unshare_split_index().

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c
split-index.c
split-index.h