This allows cache-tree to produce trees directly in a pack, for instance. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- cache-tree.c | 18 +++++++++++++++--- cache-tree.h | 3 +++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cache-tree.c b/cache-tree.c index c60cf91..7fd7203 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -237,6 +237,7 @@ static int update_one(struct cache_tree *it, int entries, const char *base, int baselen, + write_tree_fn write_tree, int missing_ok, int dryrun) { @@ -284,6 +285,7 @@ static int update_one(struct cache_tree *it, cache + i, entries - i, path, baselen + sublen + 1, + write_tree, missing_ok, dryrun); if (subcnt < 0) @@ -349,7 +351,7 @@ static int update_one(struct cache_tree *it, if (dryrun) hash_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1); - else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1)) { + else if (write_tree(buffer.buf, buffer.len, tree_type, it->sha1)) { strbuf_release(&buffer); return -1; } @@ -364,9 +366,10 @@ static int update_one(struct cache_tree *it, return i; } -int cache_tree_update(struct cache_tree *it, +int cache_tree_update_fn(struct cache_tree *it, struct cache_entry **cache, int entries, + write_tree_fn write_tree, int missing_ok, int dryrun) { @@ -374,12 +377,21 @@ int cache_tree_update(struct cache_tree *it, i = verify_cache(cache, entries); if (i) return i; - i = update_one(it, cache, entries, "", 0, missing_ok, dryrun); + i = update_one(it, cache, entries, "", 0, write_tree, missing_ok, dryrun); if (i < 0) return i; return 0; } +int cache_tree_update(struct cache_tree *it, + struct cache_entry **cache, + int entries, + int missing_ok, + int dryrun) +{ + return cache_tree_update_fn(it, cache, entries, write_sha1_file, missing_ok, dryrun); +} + static void write_one(struct strbuf *buffer, struct cache_tree *it, const char *path, int pathlen) { diff --git a/cache-tree.h b/cache-tree.h index 3df641f..b32ae41 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -20,6 +20,8 @@ struct cache_tree { struct cache_tree_sub **down; }; +typedef int (*write_tree_fn)(const void *, unsigned long, const char *, unsigned char *); + struct cache_tree *cache_tree(void); void cache_tree_free(struct cache_tree **); void cache_tree_invalidate_path(struct cache_tree *, const char *); @@ -29,6 +31,7 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root); struct cache_tree *cache_tree_read(const char *buffer, unsigned long size); int cache_tree_fully_valid(struct cache_tree *); +int cache_tree_update_fn(struct cache_tree *, struct cache_entry **, int, write_tree_fn, int, int); int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int); /* bitmasks to write_cache_as_tree flags */ -- 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