]> git.ipfire.org Git - thirdparty/git.git/blobdiff - tree.c
Merge branch 'jt/interpret-branch-name-fallback'
[thirdparty/git.git] / tree.c
diff --git a/tree.c b/tree.c
index 244eb5e665e931a6b735366d74b5ed2bcbce4c9b..e76517f6b180e4703a032706f6d388d491df22a5 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -1,11 +1,13 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "cache-tree.h"
 #include "tree.h"
+#include "object-store.h"
 #include "blob.h"
 #include "commit.h"
 #include "tag.h"
+#include "alloc.h"
 #include "tree-walk.h"
+#include "repository.h"
 
 const char *tree_type = "tree";
 
@@ -16,15 +18,13 @@ static int read_one_entry_opt(struct index_state *istate,
                              unsigned mode, int stage, int opt)
 {
        int len;
-       unsigned int size;
        struct cache_entry *ce;
 
        if (S_ISDIR(mode))
                return READ_TREE_RECURSIVE;
 
        len = strlen(pathname);
-       size = cache_entry_size(baselen + len);
-       ce = xcalloc(1, size);
+       ce = make_empty_cache_entry(istate, baselen + len);
 
        ce->ce_mode = create_ce_mode(mode);
        ce->ce_flags = create_ce_flags(stage);
@@ -59,7 +59,8 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base
                                  ADD_CACHE_JUST_APPEND);
 }
 
-static int read_tree_1(struct tree *tree, struct strbuf *base,
+static int read_tree_1(struct repository *r,
+                      struct tree *tree, struct strbuf *base,
                       int stage, const struct pathspec *pathspec,
                       read_tree_fn_t fn, void *context)
 {
@@ -76,14 +77,15 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 
        while (tree_entry(&desc, &entry)) {
                if (retval != all_entries_interesting) {
-                       retval = tree_entry_interesting(&entry, base, 0, pathspec);
+                       retval = tree_entry_interesting(r->index, &entry,
+                                                       base, 0, pathspec);
                        if (retval == all_entries_not_interesting)
                                break;
                        if (retval == entry_not_interesting)
                                continue;
                }
 
-               switch (fn(entry.oid, base,
+               switch (fn(&entry.oid, base,
                           entry.path, entry.mode, stage, context)) {
                case 0:
                        continue;
@@ -94,19 +96,19 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
                }
 
                if (S_ISDIR(entry.mode))
-                       oidcpy(&oid, entry.oid);
+                       oidcpy(&oid, &entry.oid);
                else if (S_ISGITLINK(entry.mode)) {
                        struct commit *commit;
 
-                       commit = lookup_commit(entry.oid);
+                       commit = lookup_commit(r, &entry.oid);
                        if (!commit)
                                die("Commit %s in submodule path %s%s not found",
-                                   oid_to_hex(entry.oid),
+                                   oid_to_hex(&entry.oid),
                                    base->buf, entry.path);
 
                        if (parse_commit(commit))
                                die("Invalid commit %s in submodule path %s%s",
-                                   oid_to_hex(entry.oid),
+                                   oid_to_hex(&entry.oid),
                                    base->buf, entry.path);
 
                        oidcpy(&oid, get_commit_tree_oid(commit));
@@ -117,7 +119,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
                len = tree_entry_len(&entry);
                strbuf_add(base, entry.path, len);
                strbuf_addch(base, '/');
-               retval = read_tree_1(lookup_tree(&oid),
+               retval = read_tree_1(r, lookup_tree(r, &oid),
                                     base, stage, pathspec,
                                     fn, context);
                strbuf_setlen(base, oldlen);
@@ -127,7 +129,8 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
        return 0;
 }
 
-int read_tree_recursive(struct tree *tree,
+int read_tree_recursive(struct repository *r,
+                       struct tree *tree,
                        const char *base, int baselen,
                        int stage, const struct pathspec *pathspec,
                        read_tree_fn_t fn, void *context)
@@ -136,7 +139,7 @@ int read_tree_recursive(struct tree *tree,
        int ret;
 
        strbuf_add(&sb, base, baselen);
-       ret = read_tree_1(tree, &sb, stage, pathspec, fn, context);
+       ret = read_tree_1(r, tree, &sb, stage, pathspec, fn, context);
        strbuf_release(&sb);
        return ret;
 }
@@ -151,8 +154,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
                                  ce2->name, ce2->ce_namelen, ce_stage(ce2));
 }
 
-int read_tree(struct tree *tree, int stage, struct pathspec *match,
-             struct index_state *istate)
+int read_tree(struct repository *r, struct tree *tree, int stage,
+             struct pathspec *match, struct index_state *istate)
 {
        read_tree_fn_t fn = NULL;
        int i, err;
@@ -180,7 +183,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
 
        if (!fn)
                fn = read_one_entry_quick;
-       err = read_tree_recursive(tree, "", 0, stage, match, fn, istate);
+       err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate);
        if (fn == read_one_entry || err)
                return err;
 
@@ -192,11 +195,11 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
        return 0;
 }
 
-struct tree *lookup_tree(const struct object_id *oid)
+struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
 {
-       struct object *obj = lookup_object(oid->hash);
+       struct object *obj = lookup_object(r, oid);
        if (!obj)
-               return create_object(oid->hash, alloc_tree_node());
+               return create_object(r, oid, alloc_tree_node(r));
        return object_as_type(obj, OBJ_TREE, 0);
 }
 
@@ -241,19 +244,7 @@ void free_tree_buffer(struct tree *tree)
 
 struct tree *parse_tree_indirect(const struct object_id *oid)
 {
-       struct object *obj = parse_object(oid);
-       do {
-               if (!obj)
-                       return NULL;
-               if (obj->type == OBJ_TREE)
-                       return (struct tree *) obj;
-               else if (obj->type == OBJ_COMMIT)
-                       obj = &(get_commit_tree(((struct commit *)obj))->object);
-               else if (obj->type == OBJ_TAG)
-                       obj = ((struct tag *) obj)->tagged;
-               else
-                       return NULL;
-               if (!obj->parsed)
-                       parse_object(&obj->oid);
-       } while (1);
+       struct repository *r = the_repository;
+       struct object *obj = parse_object(r, oid);
+       return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
 }