diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-06-24 12:02:39 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-06-24 12:02:39 -0700 |
commit | 64719b115d61582fa501690ee6caff4c478b4b1a (patch) | |
tree | 56e1208d62bdb762b9282d5a109f26d312f12b1c /split-index.c | |
parent | de950c577317f499df44c383ecbb7967f4905db9 (diff) | |
download | git-64719b115d61582fa501690ee6caff4c478b4b1a.tar.gz |
Revert "split-index: add and use unshare_split_index()"nd/split-index-unshare
This reverts commit f9d7abec2ad2f9eb3d8873169cc28c34273df082;
see public-inbox.org/git/CAP8UFD0bOfzY-_hBDKddOcJdPUpP2KEVaX_SrCgvAMYAHtseiQ@mail.gmail.com
Diffstat (limited to 'split-index.c')
-rw-r--r-- | split-index.c | 57 |
1 files changed, 13 insertions, 44 deletions
diff --git a/split-index.c b/split-index.c index 49bd197f71..f519e60f87 100644 --- a/split-index.c +++ b/split-index.c @@ -73,17 +73,10 @@ void move_cache_to_base_index(struct index_state *istate) int i; /* - * If "si" is shared with another index_state (e.g. by - * unpack-trees code), we will need to duplicate split_index - * struct. It's not happening now though, luckily. + * do not delete old si->base, its index entries may be shared + * with istate->cache[]. Accept a bit of leaking here because + * this code is only used by short-lived update-index. */ - assert(si->refcount <= 1); - - unshare_split_index(istate, 0); - if (si->base) { - discard_index(si->base); - free(si->base); - } si->base = xcalloc(1, sizeof(*si->base)); si->base->version = istate->version; /* zero timestamp disables racy test in ce_write_index() */ @@ -282,41 +275,11 @@ void finish_writing_split_index(struct index_state *istate) istate->cache_nr = si->saved_cache_nr; } -void unshare_split_index(struct index_state *istate, int discard) -{ - struct split_index *si = istate->split_index; - int i; - - if (!si || !si->base) - return; - - for (i = 0; i < istate->cache_nr; i++) { - struct cache_entry *ce = istate->cache[i]; - struct cache_entry *new = NULL; - - if (!ce->index || - ce->index > si->base->cache_nr || - ce != si->base->cache[ce->index - 1]) - continue; - - if (!discard) { - int len = ce_namelen(ce); - new = xcalloc(1, cache_entry_size(len)); - copy_cache_entry(new, ce); - memcpy(new->name, ce->name, len); - new->index = 0; - } - istate->cache[i] = new; - } -} - - void discard_split_index(struct index_state *istate) { struct split_index *si = istate->split_index; if (!si) return; - unshare_split_index(istate, 0); istate->split_index = NULL; si->refcount--; if (si->refcount) @@ -365,8 +328,14 @@ void add_split_index(struct index_state *istate) void remove_split_index(struct index_state *istate) { - if (!istate->split_index) - return; - discard_split_index(istate); - istate->cache_changed |= SOMETHING_CHANGED; + if (istate->split_index) { + /* + * can't discard_split_index(&the_index); because that + * will destroy split_index->base->cache[], which may + * be shared with the_index.cache[]. So yeah we're + * leaking a bit here. + */ + istate->split_index = NULL; + istate->cache_changed |= SOMETHING_CHANGED; + } } |