convert: drop arguments other than 'path' from would_convert_to_git()
[gitweb.git] / split-index.c
index b03a250e7cb9072aae525e646184239111f09c3f..21485e20665979458fb794ee4c3cc77c27032fa8 100644 (file)
@@ -74,6 +74,29 @@ static void mark_base_index_entries(struct index_state *base)
                base->cache[i]->index = i + 1;
 }
 
+void move_cache_to_base_index(struct index_state *istate)
+{
+       struct split_index *si = istate->split_index;
+       int i;
+
+       /*
+        * 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.
+        */
+       si->base = xcalloc(1, sizeof(*si->base));
+       si->base->version = istate->version;
+       /* zero timestamp disables racy test in ce_write_index() */
+       si->base->timestamp = istate->timestamp;
+       ALLOC_GROW(si->base->cache, istate->cache_nr, si->base->cache_alloc);
+       si->base->cache_nr = istate->cache_nr;
+       memcpy(si->base->cache, istate->cache,
+              sizeof(*istate->cache) * istate->cache_nr);
+       mark_base_index_entries(si->base);
+       for (i = 0; i < si->base->cache_nr; i++)
+               si->base->cache[i]->ce_flags &= ~CE_UPDATE_IN_BASE;
+}
+
 static void mark_entry_for_delete(size_t pos, void *data)
 {
        struct index_state *istate = data;
@@ -89,6 +112,7 @@ static void replace_entry(size_t pos, void *data)
        struct index_state *istate = data;
        struct split_index *si = istate->split_index;
        struct cache_entry *dst, *src;
+
        if (pos >= istate->cache_nr)
                die("position for replacement %d exceeds base index size %d",
                    (int)pos, istate->cache_nr);
@@ -100,10 +124,14 @@ static void replace_entry(size_t pos, void *data)
                die("entry %d is marked as both replaced and deleted",
                    (int)pos);
        src = si->saved_cache[si->nr_replacements];
+       if (ce_namelen(src))
+               die("corrupt link extension, entry %d should have "
+                   "zero length name", (int)pos);
        src->index = pos + 1;
        src->ce_flags |= CE_UPDATE_IN_BASE;
-       free(dst);
-       dst = src;
+       src->ce_namelen = dst->ce_namelen;
+       copy_cache_entry(dst, src);
+       free(src);
        si->nr_replacements++;
 }
 
@@ -131,8 +159,12 @@ void merge_base_index(struct index_state *istate)
                remove_marked_cache_entries(istate);
 
        for (i = si->nr_replacements; i < si->saved_cache_nr; i++) {
+               if (!ce_namelen(si->saved_cache[i]))
+                       die("corrupt link extension, entry %d should "
+                           "have non-zero length name", i);
                add_index_entry(istate, si->saved_cache[i],
                                ADD_CACHE_OK_TO_ADD |
+                               ADD_CACHE_KEEP_CACHE_TREE |
                                /*
                                 * we may have to replay what
                                 * merge-recursive.c:update_stages()
@@ -212,6 +244,7 @@ void prepare_to_write_split_index(struct index_state *istate)
                                ewah_set(si->delete_bitmap, i);
                        else if (ce->ce_flags & CE_UPDATE_IN_BASE) {
                                ewah_set(si->replace_bitmap, i);
+                               ce->ce_flags |= CE_STRIP_NAME;
                                ALLOC_GROW(entries, nr_entries+1, nr_alloc);
                                entries[nr_entries++] = ce;
                        }
@@ -221,6 +254,7 @@ void prepare_to_write_split_index(struct index_state *istate)
        for (i = 0; i < istate->cache_nr; i++) {
                ce = istate->cache[i];
                if ((!si->base || !ce->index) && !(ce->ce_flags & CE_REMOVE)) {
+                       assert(!(ce->ce_flags & CE_STRIP_NAME));
                        ALLOC_GROW(entries, nr_entries+1, nr_alloc);
                        entries[nr_entries++] = ce;
                }