blob: faae88be63c2ce012c700af3a88e02e165982a4e [file] [log] [blame]
Junio C Hamano74986462006-04-23 16:52:20 -07001#ifndef CACHE_TREE_H
2#define CACHE_TREE_H
3
Junio C Hamanob9d37a52009-04-20 03:58:18 -07004#include "tree.h"
Junio C Hamanob65982b2009-05-20 15:57:22 -07005#include "tree-walk.h"
Junio C Hamanob9d37a52009-04-20 03:58:18 -07006
Junio C Hamano74986462006-04-23 16:52:20 -07007struct cache_tree;
8struct cache_tree_sub {
9 struct cache_tree *cache_tree;
Nguyễn Thái Ngọc Duy3cf773e2012-12-16 11:15:27 +070010 int count; /* internally used by update_one() */
Junio C Hamano74986462006-04-23 16:52:20 -070011 int namelen;
12 int used;
13 char name[FLEX_ARRAY];
14};
15
16struct cache_tree {
17 int entry_count; /* negative means "invalid" */
brian m. carlsone0a92802017-05-01 02:28:56 +000018 struct object_id oid;
Junio C Hamano74986462006-04-23 16:52:20 -070019 int subtree_nr;
20 int subtree_alloc;
21 struct cache_tree_sub **down;
22};
23
24struct cache_tree *cache_tree(void);
Junio C Hamanobad68ec2006-04-24 21:18:58 -070025void cache_tree_free(struct cache_tree **);
Nguyễn Thái Ngọc Duya5400ef2014-06-13 19:19:31 +070026void cache_tree_invalidate_path(struct index_state *, const char *);
Junio C Hamano7927a552006-04-27 01:33:07 -070027struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
Junio C Hamano74986462006-04-23 16:52:20 -070028
Derrick Stoleec80dd392021-01-23 19:58:13 +000029int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen);
30
Pierre Habouzit1dffb8f2007-09-25 10:22:44 +020031void cache_tree_write(struct strbuf *, struct cache_tree *root);
Junio C Hamanobad68ec2006-04-24 21:18:58 -070032struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
Junio C Hamano74986462006-04-23 16:52:20 -070033
Junio C Hamanobad68ec2006-04-24 21:18:58 -070034int cache_tree_fully_valid(struct cache_tree *);
Nguyễn Thái Ngọc Duyd0cfc3e2014-06-13 19:19:32 +070035int cache_tree_update(struct index_state *, int);
Nguyễn Thái Ngọc Duyc207e9e2018-11-10 06:49:02 +010036void cache_tree_verify(struct repository *, struct index_state *);
Thomas Rast996277c2011-12-06 18:43:37 +010037
Elijah Newren724dd762019-08-17 11:41:32 -070038/* bitmasks to write_index_as_tree flags */
Junio C Hamanod11b8d32009-05-20 11:04:35 -070039#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
Elijah Newren724dd762019-08-17 11:41:32 -070050struct tree* write_in_core_index_as_tree(struct repository *repo);
brian m. carlsonfc5cb992018-03-12 02:27:23 +000051int 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 +010052void prime_cache_tree(struct repository *, struct index_state *, struct tree *);
Junio C Hamanob9d37a52009-04-20 03:58:18 -070053
Nguyễn Thái Ngọc Duy9ab34f92018-06-30 11:20:23 +020054int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
Junio C Hamano74986462006-04-23 16:52:20 -070055#endif