blob: 41c574663a14840aa726c46c19b071fa6555f0ef [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" */
18 unsigned char sha1[20];
19 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
Pierre Habouzit1dffb8f2007-09-25 10:22:44 +020029void cache_tree_write(struct strbuf *, struct cache_tree *root);
Junio C Hamanobad68ec2006-04-24 21:18:58 -070030struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
Junio C Hamano74986462006-04-23 16:52:20 -070031
Junio C Hamanobad68ec2006-04-24 21:18:58 -070032int cache_tree_fully_valid(struct cache_tree *);
Nguyễn Thái Ngọc Duyd0cfc3e2014-06-13 19:19:32 +070033int cache_tree_update(struct index_state *, int);
Thomas Rast996277c2011-12-06 18:43:37 +010034
35int update_main_cache_tree(int);
Junio C Hamano74986462006-04-23 16:52:20 -070036
Junio C Hamanod11b8d32009-05-20 11:04:35 -070037/* bitmasks to write_cache_as_tree flags */
38#define WRITE_TREE_MISSING_OK 1
39#define WRITE_TREE_IGNORE_CACHE_TREE 2
Nguyễn Thái Ngọc Duye859c692012-01-16 09:36:46 +070040#define WRITE_TREE_DRY_RUN 4
41#define WRITE_TREE_SILENT 8
David Turneraecf5672014-07-05 21:06:56 -070042#define WRITE_TREE_REPAIR 16
Junio C Hamanod11b8d32009-05-20 11:04:35 -070043
44/* error return codes */
Junio C Hamano45525bd2008-01-10 22:49:35 -080045#define WRITE_TREE_UNREADABLE_INDEX (-1)
46#define WRITE_TREE_UNMERGED_INDEX (-2)
47#define WRITE_TREE_PREFIX_ERROR (-3)
48
Paul Tand23a5112015-08-04 21:51:40 +080049int 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 -070050int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix);
Nguyễn Thái Ngọc Duye6c286e2014-06-13 19:19:33 +070051void prime_cache_tree(struct index_state *, struct tree *);
Junio C Hamanob9d37a52009-04-20 03:58:18 -070052
Junio C Hamanob65982b2009-05-20 15:57:22 -070053extern int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info);
54
Junio C Hamano74986462006-04-23 16:52:20 -070055#endif