These function traverse the given tree and set/clear object.flags Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- tree.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ tree.h | 3 +++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/tree.c b/tree.c index 5ab90af..434bf56 100644 --- a/tree.c +++ b/tree.c @@ -284,3 +284,47 @@ struct tree *parse_tree_indirect(const unsigned char *sha1) parse_object(obj->sha1); } while (1); } + +void set_tree_marks(struct tree *tree, unsigned mark) +{ + struct name_entry entry; + struct tree_desc desc; + enum object_type type; + unsigned long size; + void *buffer; + + tree->object.flags |= mark; + + buffer = read_sha1_file(tree->object.sha1, &type, &size); + if (!buffer || type != OBJ_TREE) + die("%s is not a tree", sha1_to_hex(tree->object.sha1)); + + init_tree_desc(&desc, buffer, size); + while (tree_entry(&desc, &entry)) { + if (S_ISDIR(entry.mode)) + set_tree_marks(lookup_tree(entry.sha1), mark); + } + free(buffer); +} + +void clear_tree_marks(struct tree *tree, unsigned mark) +{ + struct name_entry entry; + struct tree_desc desc; + enum object_type type; + unsigned long size; + void *buffer; + + tree->object.flags &= ~mark; + + buffer = read_sha1_file(tree->object.sha1, &type, &size); + if (!buffer || type != OBJ_TREE) + die("%s is not a tree", sha1_to_hex(tree->object.sha1)); + + init_tree_desc(&desc, buffer, size); + while (tree_entry(&desc, &entry)) { + if (S_ISDIR(entry.mode)) + clear_tree_marks(lookup_tree(entry.sha1), mark); + } + free(buffer); +} diff --git a/tree.h b/tree.h index 2ff01a4..4376a3a 100644 --- a/tree.h +++ b/tree.h @@ -30,4 +30,7 @@ extern int read_tree_recursive(struct tree *tree, extern int read_tree(struct tree *tree, int stage, const char **paths); +extern void set_tree_marks(struct tree *tree, unsigned mark); +extern void clear_tree_marks(struct tree *tree, unsigned mark); + #endif /* TREE_H */ -- 1.7.1.rc1.69.g24c2f7 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html