split-index: add {add,remove}_split_index() functions
Also use the functions in cmd_update_index() in builtin/update-index.c. These functions will be used in a following commit to tweak our use of the split-index feature depending on the setting of a configuration variable. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Feb 27, 2017 at 19:00 UTC
cef4fc7ebe869e910d0fd5643cd60328ed76356a
3 files changed
+30
-12
builtin/update-index.c
+6
-12
@@ -1099,18 +1099,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1099
}
1100
1101
if (split_index > 0) {
1102
- init_split_index(&the_index);
1103
- the_index.cache_changed |= SPLIT_INDEX_ORDERED;
1104
- } else if (!split_index && the_index.split_index) {
1105
- /*
1106
- * can't discard_split_index(&the_index); because that
1107
- * will destroy split_index->base->cache[], which may
1108
- * be shared with the_index.cache[]. So yeah we're
1109
- * leaking a bit here.
1110
- */
1111
- the_index.split_index = NULL;
1112
- the_index.cache_changed |= SOMETHING_CHANGED;
1113
- }
1102
+ if (the_index.split_index)
1103
+ the_index.cache_changed |= SPLIT_INDEX_ORDERED;
1104
+ else
1105
+ add_split_index(&the_index);
1106
+ } else if (!split_index)
1107
+ remove_split_index(&the_index);
1108
1109
switch (untracked_cache) {
1110
case UC_UNSPECIFIED:
split-index.c
+22
@@ -317,3 +317,25 @@ void replace_index_entry_in_base(struct index_state *istate,
317
istate->split_index->base->cache[new->index - 1] = new;
318
}
319
}
320
+
321
+void add_split_index(struct index_state *istate)
322
+{
323
+ if (!istate->split_index) {
324
+ init_split_index(istate);
325
+ istate->cache_changed |= SPLIT_INDEX_ORDERED;
326
+ }
327
+}
328
+
329
+void remove_split_index(struct index_state *istate)
330
+{
331
+ if (istate->split_index) {
332
+ /*
333
+ * can't discard_split_index(&the_index); because that
334
+ * will destroy split_index->base->cache[], which may
335
+ * be shared with the_index.cache[]. So yeah we're
336
+ * leaking a bit here.
337
+ */
338
+ istate->split_index = NULL;
339
+ istate->cache_changed |= SOMETHING_CHANGED;
340
+ }
341
+}
split-index.h
+2
@@ -31,5 +31,7 @@ void merge_base_index(struct index_state *istate);
31
void prepare_to_write_split_index(struct index_state *istate);
32
void finish_writing_split_index(struct index_state *istate);
33
void discard_split_index(struct index_state *istate);
34
+void add_split_index(struct index_state *istate);
35
+void remove_split_index(struct index_state *istate);
36
37
#endif