diff options
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 32 |
1 files changed, 21 insertions, 11 deletions
@@ -22,7 +22,8 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b ce = xcalloc(1, size); ce->ce_mode = create_ce_mode(mode); - ce->ce_flags = create_ce_flags(baselen + len, stage); + ce->ce_flags = create_ce_flags(stage); + ce->ce_namelen = baselen + len; memcpy(ce->name, base, baselen); memcpy(ce->name + baselen, pathname, len+1); hashcpy(ce->sha1, sha1); @@ -46,13 +47,14 @@ static int read_one_entry_quick(const unsigned char *sha1, const char *base, int } static int read_tree_1(struct tree *tree, struct strbuf *base, - int stage, struct pathspec *pathspec, + int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context) { struct tree_desc desc; struct name_entry entry; unsigned char sha1[20]; - int len, retval = 0, oldlen = base->len; + int len, oldlen = base->len; + enum interesting retval = entry_not_interesting; if (parse_tree(tree)) return -1; @@ -60,11 +62,11 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { - if (retval != 2) { + if (retval != all_entries_interesting) { retval = tree_entry_interesting(&entry, base, 0, pathspec); - if (retval < 0) + if (retval == all_entries_not_interesting) break; - if (retval == 0) + if (retval == entry_not_interesting) continue; } @@ -99,7 +101,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, else continue; - len = tree_entry_len(entry.path, entry.sha1); + len = tree_entry_len(&entry); strbuf_add(base, entry.path, len); strbuf_addch(base, '/'); retval = read_tree_1(lookup_tree(sha1), @@ -114,7 +116,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, int read_tree_recursive(struct tree *tree, const char *base, int baselen, - int stage, struct pathspec *pathspec, + int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context) { struct strbuf sb = STRBUF_INIT; @@ -132,8 +134,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_) ce1 = *((const struct cache_entry **)a_); ce2 = *((const struct cache_entry **)b_); - return cache_name_compare(ce1->name, ce1->ce_flags, - ce2->name, ce2->ce_flags); + return cache_name_stage_compare(ce1->name, ce1->ce_namelen, ce_stage(ce1), + ce2->name, ce2->ce_namelen, ce_stage(ce2)); } int read_tree(struct tree *tree, int stage, struct pathspec *match) @@ -157,7 +159,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match) * sort at the end. */ for (i = 0; !fn && i < active_nr; i++) { - struct cache_entry *ce = active_cache[i]; + const struct cache_entry *ce = active_cache[i]; if (ce_stage(ce) == stage) fn = read_one_entry; } @@ -223,6 +225,14 @@ int parse_tree(struct tree *item) return parse_tree_buffer(item, buffer, size); } +void free_tree_buffer(struct tree *tree) +{ + free(tree->buffer); + tree->buffer = NULL; + tree->size = 0; + tree->object.parsed = 0; +} + struct tree *parse_tree_indirect(const unsigned char *sha1) { struct object *obj = parse_object(sha1); |