]> git.proxmox.com Git - libgit2.git/blob - src/tree.h
Merge pull request #1350 from arrbee/fix-1292
[libgit2.git] / src / tree.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_tree_h__
8 #define INCLUDE_tree_h__
9
10 #include "git2/tree.h"
11 #include "repository.h"
12 #include "odb.h"
13 #include "vector.h"
14
15 struct git_tree_entry {
16 uint16_t removed;
17 uint16_t attr;
18 git_oid oid;
19 size_t filename_len;
20 char filename[1];
21 };
22
23 struct git_tree {
24 git_object object;
25 git_vector entries;
26 };
27
28 struct git_treebuilder {
29 git_vector entries;
30 size_t entrycount; /* vector may contain "removed" entries */
31 };
32
33 GIT_INLINE(int) git_tree__dup(git_tree **dest, git_tree *source)
34 {
35 return git_object__dup((git_object **)dest, (git_object *)source);
36 }
37
38 GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
39 {
40 return (S_ISDIR(e->attr) && !S_ISGITLINK(e->attr));
41 }
42
43 extern int git_tree_entry_icmp(const git_tree_entry *e1, const git_tree_entry *e2);
44
45 void git_tree__free(git_tree *tree);
46 int git_tree__parse(git_tree *tree, git_odb_object *obj);
47
48 /**
49 * Lookup the first position in the tree with a given prefix.
50 *
51 * @param tree a previously loaded tree.
52 * @param prefix the beginning of a path to find in the tree.
53 * @return index of the first item at or after the given prefix.
54 */
55 int git_tree__prefix_position(git_tree *tree, const char *prefix);
56
57
58 /**
59 * Write a tree to the given repository
60 */
61 int git_tree__write_index(
62 git_oid *oid, git_index *index, git_repository *repo);
63
64 /**
65 * Obsolete mode kept for compatibility reasons
66 */
67 #define GIT_FILEMODE_BLOB_GROUP_WRITABLE 0100664
68
69 #endif