blob: f7b9cab7ee87dd04cecbd25f34101a58fc002014 [file] [log] [blame]
Junio C Hamano74986462006-04-23 16:52:20 -07001#ifndef CACHE_TREE_H
2#define CACHE_TREE_H
3
brian m. carlsone0a92802017-05-01 02:28:56 +00004#include "cache.h"
Junio C Hamanob9d37a52009-04-20 03:58:18 -07005#include "tree.h"
Junio C Hamanob65982b2009-05-20 15:57:22 -07006#include "tree-walk.h"
Junio C Hamanob9d37a52009-04-20 03:58:18 -07007
Junio C Hamano74986462006-04-23 16:52:20 -07008struct cache_tree;
9struct cache_tree_sub {
10 struct cache_tree *cache_tree;
Nguyễn Thái Ngọc Duy3cf773e2012-12-16 11:15:27 +070011 int count; /* internally used by update_one() */
Junio C Hamano74986462006-04-23 16:52:20 -070012 int namelen;
13 int used;
14 char name[FLEX_ARRAY];
15};
16
17struct cache_tree {
18 int entry_count; /* negative means "invalid" */
brian m. carlsone0a92802017-05-01 02:28:56 +000019 struct object_id oid;
Junio C Hamano74986462006-04-23 16:52:20 -070020 int subtree_nr;
21 int subtree_alloc;
22 struct cache_tree_sub **down;
23};
24
25struct cache_tree *cache_tree(void);
Junio C Hamanobad68ec2006-04-24 21:18:58 -070026void cache_tree_free(struct cache_tree **);
Nguyễn Thái Ngọc Duya5400ef2014-06-13 19:19:31 +070027void cache_tree_invalidate_path(struct index_state *, const char *);
Junio C Hamano7927a552006-04-27 01:33:07 -070028struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
Junio C Hamano74986462006-04-23 16:52:20 -070029
Pierre Habouzit1dffb8f2007-09-25 10:22:44 +020030void cache_tree_write(struct strbuf *, struct cache_tree *root);
Junio C Hamanobad68ec2006-04-24 21:18:58 -070031struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
Junio C Hamano74986462006-04-23 16:52:20 -070032
Junio C Hamanobad68ec2006-04-24 21:18:58 -070033int cache_tree_fully_valid(struct cache_tree *);
Nguyễn Thái Ngọc Duyd0cfc3e2014-06-13 19:19:32 +070034int cache_tree_update(struct index_state *, int);
Thomas Rast996277c2011-12-06 18:43:37 +010035
36int update_main_cache_tree(int);
Junio C Hamano74986462006-04-23 16:52:20 -070037
Junio C Hamanod11b8d32009-05-20 11:04:35 -070038/* bitmasks to write_cache_as_tree flags */
39#define WRITE_TREE_MISSING_OK 1
40#define WRITE_TREE_IGNORE_CACHE_TREE 2
Nguyễn Thái Ngọc Duye859c692012-01-16 09:36:46 +070041#define WRITE_TREE_DRY_RUN 4
42#define WRITE_TREE_SILENT 8
David Turneraecf5672014-07-05 21:06:56 -070043#define WRITE_TREE_REPAIR 16
Junio C Hamanod11b8d32009-05-20 11:04:35 -070044
45/* error return codes */
Junio C Hamano45525bd2008-01-10 22:49:35 -080046#define WRITE_TREE_UNREADABLE_INDEX (-1)
47#define WRITE_TREE_UNMERGED_INDEX (-2)
48#define WRITE_TREE_PREFIX_ERROR (-3)
49
Paul Tand23a5112015-08-04 21:51:40 +080050int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
Junio C Hamanod11b8d32009-05-20 11:04:35 -070051int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix);
Nguyễn Thái Ngọc Duye6c286e2014-06-13 19:19:33 +070052void prime_cache_tree(struct index_state *, struct tree *);
Junio C Hamanob9d37a52009-04-20 03:58:18 -070053
Junio C Hamanob65982b2009-05-20 15:57:22 -070054extern int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
55
Junio C Hamano74986462006-04-23 16:52:20 -070056#endif