general improvements
[gitweb.git] / cache-tree.c
index 9d454d24bca62dcdb8c941a64d09b7a53556323a..0e5724fad752e9157dbcf1caba0438b42386ee3d 100644 (file)
@@ -5,9 +5,10 @@
 #include "cache-tree.h"
 #include "object-store.h"
 #include "replace-object.h"
+#include "promisor-remote.h"
 
-#ifndef DEBUG
-#define DEBUG 0
+#ifndef DEBUG_CACHE_TREE
+#define DEBUG_CACHE_TREE 0
 #endif
 
 struct cache_tree *cache_tree(void)
@@ -111,7 +112,7 @@ static int do_invalidate_path(struct cache_tree *it, const char *path)
        int namelen;
        struct cache_tree_sub *down;
 
-#if DEBUG
+#if DEBUG_CACHE_TREE
        fprintf(stderr, "cache-tree invalidate <%s>\n", path);
 #endif
 
@@ -225,7 +226,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
        int i;
        if (!it)
                return 0;
-       if (it->entry_count < 0 || !has_sha1_file(it->oid.hash))
+       if (it->entry_count < 0 || !has_object_file(&it->oid))
                return 0;
        for (i = 0; i < it->subtree_nr; i++) {
                if (!cache_tree_fully_valid(it->down[i]->cache_tree))
@@ -253,7 +254,7 @@ static int update_one(struct cache_tree *it,
 
        *skip_count = 0;
 
-       if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
+       if (0 <= it->entry_count && has_object_file(&it->oid))
                return it->entry_count;
 
        /*
@@ -357,7 +358,7 @@ static int update_one(struct cache_tree *it,
                }
 
                ce_missing_ok = mode == S_IFGITLINK || missing_ok ||
-                       (repository_format_partial_clone &&
+                       (has_promisor_remote() &&
                         ce_skip_worktree(ce));
                if (is_null_oid(oid) ||
                    (!ce_missing_ok && !has_object_file(oid))) {
@@ -398,7 +399,7 @@ static int update_one(struct cache_tree *it,
                strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
                strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz);
 
-#if DEBUG
+#if DEBUG_CACHE_TREE
                fprintf(stderr, "cache-tree update-one %o %.*s\n",
                        mode, entlen, path + baselen);
 #endif
@@ -421,7 +422,7 @@ static int update_one(struct cache_tree *it,
 
        strbuf_release(&buffer);
        it->entry_count = to_invalidate ? -1 : i - *skip_count;
-#if DEBUG
+#if DEBUG_CACHE_TREE
        fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n",
                it->entry_count, it->subtree_nr,
                oid_to_hex(&it->oid));
@@ -448,7 +449,7 @@ int cache_tree_update(struct index_state *istate, int flags)
 }
 
 static void write_one(struct strbuf *buffer, struct cache_tree *it,
-                      const char *path, int pathlen)
+                     const char *path, int pathlen)
 {
        int i;
 
@@ -462,7 +463,7 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it,
        strbuf_add(buffer, path, pathlen);
        strbuf_addf(buffer, "%c%d %d\n", 0, it->entry_count, it->subtree_nr);
 
-#if DEBUG
+#if DEBUG_CACHE_TREE
        if (0 <= it->entry_count)
                fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n",
                        pathlen, path, it->entry_count, it->subtree_nr,
@@ -536,7 +537,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
                size -= rawsz;
        }
 
-#if DEBUG
+#if DEBUG_CACHE_TREE
        if (0 <= it->entry_count)
                fprintf(stderr, "cache-tree <%s> (%d ent, %d subtree) %s\n",
                        *buffer, it->entry_count, subtree_nr,
@@ -659,7 +660,9 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state,
        return ret;
 }
 
-static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
+static void prime_cache_tree_rec(struct repository *r,
+                                struct cache_tree *it,
+                                struct tree *tree)
 {
        struct tree_desc desc;
        struct name_entry entry;
@@ -673,24 +676,25 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
                        cnt++;
                else {
                        struct cache_tree_sub *sub;
-                       struct tree *subtree = lookup_tree(the_repository,
-                                                          entry.oid);
+                       struct tree *subtree = lookup_tree(r, &entry.oid);
                        if (!subtree->object.parsed)
                                parse_tree(subtree);
                        sub = cache_tree_sub(it, entry.path);
                        sub->cache_tree = cache_tree();
-                       prime_cache_tree_rec(sub->cache_tree, subtree);
+                       prime_cache_tree_rec(r, sub->cache_tree, subtree);
                        cnt += sub->cache_tree->entry_count;
                }
        }
        it->entry_count = cnt;
 }
 
-void prime_cache_tree(struct index_state *istate, struct tree *tree)
+void prime_cache_tree(struct repository *r,
+                     struct index_state *istate,
+                     struct tree *tree)
 {
        cache_tree_free(&istate->cache_tree);
        istate->cache_tree = cache_tree();
-       prime_cache_tree_rec(istate->cache_tree, tree);
+       prime_cache_tree_rec(r, istate->cache_tree, tree);
        istate->cache_changed |= CACHE_TREE_CHANGED;
 }
 
@@ -710,7 +714,7 @@ static struct cache_tree *find_cache_tree_from_traversal(struct cache_tree *root
        if (!info->prev)
                return root;
        our_parent = find_cache_tree_from_traversal(root, info->prev);
-       return cache_tree_find(our_parent, info->name.path);
+       return cache_tree_find(our_parent, info->name);
 }
 
 int cache_tree_matches_traversal(struct cache_tree *root,
@@ -721,12 +725,13 @@ int cache_tree_matches_traversal(struct cache_tree *root,
 
        it = find_cache_tree_from_traversal(root, info);
        it = cache_tree_find(it, ent->path);
-       if (it && it->entry_count > 0 && oideq(ent->oid, &it->oid))
+       if (it && it->entry_count > 0 && oideq(&ent->oid, &it->oid))
                return it->entry_count;
        return 0;
 }
 
-static void verify_one(struct index_state *istate,
+static void verify_one(struct repository *r,
+                      struct index_state *istate,
                       struct cache_tree *it,
                       struct strbuf *path)
 {
@@ -736,13 +741,13 @@ static void verify_one(struct index_state *istate,
 
        for (i = 0; i < it->subtree_nr; i++) {
                strbuf_addf(path, "%s/", it->down[i]->name);
-               verify_one(istate, it->down[i]->cache_tree, path);
+               verify_one(r, istate, it->down[i]->cache_tree, path);
                strbuf_setlen(path, len);
        }
 
        if (it->entry_count < 0 ||
            /* no verification on tests (t7003) that replace trees */
-           lookup_replace_object(the_repository, &it->oid) != &it->oid)
+           lookup_replace_object(r, &it->oid) != &it->oid)
                return;
 
        if (path->len) {
@@ -793,12 +798,12 @@ static void verify_one(struct index_state *istate,
        strbuf_release(&tree_buf);
 }
 
-void cache_tree_verify(struct index_state *istate)
+void cache_tree_verify(struct repository *r, struct index_state *istate)
 {
        struct strbuf path = STRBUF_INIT;
 
        if (!istate->cache_tree)
                return;
-       verify_one(istate, istate->cache_tree, &path);
+       verify_one(r, istate, istate->cache_tree, &path);
        strbuf_release(&path);
 }