blob: 8efeccebfc9f0bf8c9cfda1aa4ac531108b52650 [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
Derrick Stoleec80dd392021-01-23 19:58:13 +000030int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen);
31
Pierre Habouzit1dffb8f2007-09-25 10:22:44 +020032void cache_tree_write(struct strbuf *, struct cache_tree *root);
Junio C Hamanobad68ec2006-04-24 21:18:58 -070033struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
Junio C Hamano74986462006-04-23 16:52:20 -070034
Junio C Hamanobad68ec2006-04-24 21:18:58 -070035int cache_tree_fully_valid(struct cache_tree *);
Nguyễn Thái Ngọc Duyd0cfc3e2014-06-13 19:19:32 +070036int cache_tree_update(struct index_state *, int);
Nguyễn Thái Ngọc Duyc207e9e2018-11-10 06:49:02 +010037void cache_tree_verify(struct repository *, struct index_state *);
Thomas Rast996277c2011-12-06 18:43:37 +010038
Elijah Newren724dd762019-08-17 11:41:32 -070039/* bitmasks to write_index_as_tree flags */
Junio C Hamanod11b8d32009-05-20 11:04:35 -070040#define WRITE_TREE_MISSING_OK 1
41#define WRITE_TREE_IGNORE_CACHE_TREE 2
Nguyễn Thái Ngọc Duye859c692012-01-16 09:36:46 +070042#define WRITE_TREE_DRY_RUN 4
43#define WRITE_TREE_SILENT 8
David Turneraecf5672014-07-05 21:06:56 -070044#define WRITE_TREE_REPAIR 16
Junio C Hamanod11b8d32009-05-20 11:04:35 -070045
46/* error return codes */
Junio C Hamano45525bd2008-01-10 22:49:35 -080047#define WRITE_TREE_UNREADABLE_INDEX (-1)
48#define WRITE_TREE_UNMERGED_INDEX (-2)
49#define WRITE_TREE_PREFIX_ERROR (-3)
50
Elijah Newren724dd762019-08-17 11:41:32 -070051struct tree* write_in_core_index_as_tree(struct repository *repo);
brian m. carlsonfc5cb992018-03-12 02:27:23 +000052int write_index_as_tree(struct object_id *oid, struct index_state *index_state, const char *index_path, int flags, const char *prefix);
Nguyễn Thái Ngọc Duyc207e9e2018-11-10 06:49:02 +010053void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
Junio C Hamanob9d37a52009-04-20 03:58:18 -070054
Nguyễn Thái Ngọc Duy9ab34f92018-06-30 11:20:23 +020055int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
Junio C Hamanob65982b2009-05-20 15:57:22 -070056
Nguyễn Thái Ngọc Duyf8adbec2019-01-24 15:29:12 +070057#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS
Nguyễn Thái Ngọc Duy07096c92018-08-13 18:14:19 +020058static inline int write_cache_as_tree(struct object_id *oid, int flags, const char *prefix)
59{
60 return write_index_as_tree(oid, &the_index, get_index_file(), flags, prefix);
61}
62
63static inline int update_main_cache_tree(int flags)
64{
65 if (!the_index.cache_tree)
66 the_index.cache_tree = cache_tree();
67 return cache_tree_update(&the_index, flags);
68}
69#endif
70
Junio C Hamano74986462006-04-23 16:52:20 -070071#endif