diff options
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 56 |
1 files changed, 31 insertions, 25 deletions
@@ -1,3 +1,4 @@ +#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "cache-tree.h" #include "tree.h" @@ -8,7 +9,11 @@ const char *tree_type = "tree"; -static int read_one_entry_opt(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, int opt) +static int read_one_entry_opt(struct index_state *istate, + const unsigned char *sha1, + const char *base, int baselen, + const char *pathname, + unsigned mode, int stage, int opt) { int len; unsigned int size; @@ -26,15 +31,16 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b ce->ce_namelen = baselen + len; memcpy(ce->name, base, baselen); memcpy(ce->name + baselen, pathname, len+1); - hashcpy(ce->sha1, sha1); - return add_cache_entry(ce, opt); + hashcpy(ce->oid.hash, sha1); + return add_index_entry(istate, ce, opt); } static int read_one_entry(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { - return read_one_entry_opt(sha1, base->buf, base->len, pathname, + struct index_state *istate = context; + return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname, mode, stage, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); } @@ -47,7 +53,8 @@ static int read_one_entry_quick(const unsigned char *sha1, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { - return read_one_entry_opt(sha1, base->buf, base->len, pathname, + struct index_state *istate = context; + return read_one_entry_opt(istate, sha1, base->buf, base->len, pathname, mode, stage, ADD_CACHE_JUST_APPEND); } @@ -58,7 +65,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, { struct tree_desc desc; struct name_entry entry; - unsigned char sha1[20]; + struct object_id oid; int len, oldlen = base->len; enum interesting retval = entry_not_interesting; @@ -87,11 +94,11 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, } if (S_ISDIR(entry.mode)) - hashcpy(sha1, entry.oid->hash); + oidcpy(&oid, entry.oid); else if (S_ISGITLINK(entry.mode)) { struct commit *commit; - commit = lookup_commit(entry.oid->hash); + commit = lookup_commit(entry.oid); if (!commit) die("Commit %s in submodule path %s%s not found", oid_to_hex(entry.oid), @@ -102,7 +109,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, oid_to_hex(entry.oid), base->buf, entry.path); - hashcpy(sha1, commit->tree->object.oid.hash); + oidcpy(&oid, &commit->tree->object.oid); } else continue; @@ -110,7 +117,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(sha1), + retval = read_tree_1(lookup_tree(&oid), base, stage, pathspec, fn, context); strbuf_setlen(base, oldlen); @@ -144,7 +151,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) +int read_tree(struct tree *tree, int stage, struct pathspec *match, + struct index_state *istate) { read_tree_fn_t fn = NULL; int i, err; @@ -164,32 +172,31 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match) * do it the original slow way, otherwise, append and then * sort at the end. */ - for (i = 0; !fn && i < active_nr; i++) { - const struct cache_entry *ce = active_cache[i]; + for (i = 0; !fn && i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; if (ce_stage(ce) == stage) fn = read_one_entry; } if (!fn) fn = read_one_entry_quick; - err = read_tree_recursive(tree, "", 0, stage, match, fn, NULL); + err = read_tree_recursive(tree, "", 0, stage, match, fn, istate); if (fn == read_one_entry || err) return err; /* * Sort the cache entry -- we need to nuke the cache tree, though. */ - cache_tree_free(&active_cache_tree); - qsort(active_cache, active_nr, sizeof(active_cache[0]), - cmp_cache_name_compare); + cache_tree_free(&istate->cache_tree); + QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); return 0; } -struct tree *lookup_tree(const unsigned char *sha1) +struct tree *lookup_tree(const struct object_id *oid) { - struct object *obj = lookup_object(sha1); + struct object *obj = lookup_object(oid->hash); if (!obj) - return create_object(sha1, alloc_tree_node()); + return create_object(oid->hash, alloc_tree_node()); return object_as_type(obj, OBJ_TREE, 0); } @@ -227,15 +234,14 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing) void free_tree_buffer(struct tree *tree) { - free(tree->buffer); - tree->buffer = NULL; + FREE_AND_NULL(tree->buffer); tree->size = 0; tree->object.parsed = 0; } -struct tree *parse_tree_indirect(const unsigned char *sha1) +struct tree *parse_tree_indirect(const struct object_id *oid) { - struct object *obj = parse_object(sha1); + struct object *obj = parse_object(oid); do { if (!obj) return NULL; @@ -248,6 +254,6 @@ struct tree *parse_tree_indirect(const unsigned char *sha1) else return NULL; if (!obj->parsed) - parse_object(obj->oid.hash); + parse_object(&obj->oid); } while (1); } |