Also use the functions in cmd_update_index() in
builtin/update-index.c.

Signed-off-by: Christian Couder <[email protected]>
---
 builtin/update-index.c | 17 ++++-------------
 split-index.c          | 18 ++++++++++++++++++
 split-index.h          |  2 ++
 3 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/builtin/update-index.c b/builtin/update-index.c
index 6cdfd5f..f06fe80 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -1108,19 +1108,10 @@ int cmd_update_index(int argc, const char **argv, const 
char *prefix)
                strbuf_release(&buf);
        }
 
-       if (split_index > 0) {
-               init_split_index(&the_index);
-               the_index.cache_changed |= SPLIT_INDEX_ORDERED;
-       } else if (!split_index && the_index.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.
-                */
-               the_index.split_index = NULL;
-               the_index.cache_changed |= SOMETHING_CHANGED;
-       }
+       if (split_index > 0)
+               add_split_index(&the_index);
+       else if (!split_index && the_index.split_index)
+               remove_split_index(&the_index);
 
        switch (untracked_cache) {
        case UC_UNSPECIFIED:
diff --git a/split-index.c b/split-index.c
index 3c75d4b..9466b69 100644
--- a/split-index.c
+++ b/split-index.c
@@ -319,3 +319,21 @@ void replace_index_entry_in_base(struct index_state 
*istate,
                istate->split_index->base->cache[new->index - 1] = new;
        }
 }
+
+void add_split_index(struct index_state *istate)
+{
+       init_split_index(istate);
+       istate->cache_changed |= SPLIT_INDEX_ORDERED;
+}
+
+void remove_split_index(struct index_state *istate)
+{
+       /*
+        * 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;
+}
diff --git a/split-index.h b/split-index.h
index c1324f5..df91c1b 100644
--- a/split-index.h
+++ b/split-index.h
@@ -31,5 +31,7 @@ void merge_base_index(struct index_state *istate);
 void prepare_to_write_split_index(struct index_state *istate);
 void finish_writing_split_index(struct index_state *istate);
 void discard_split_index(struct index_state *istate);
+void add_split_index(struct index_state *istate);
+void remove_split_index(struct index_state *istate);
 
 #endif
-- 
2.9.0.250.g7087ccc.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to