]> git.proxmox.com Git - libgit2.git/blame - src/tree.c
Add support for tree objects in revision pools
[libgit2.git] / src / tree.c
CommitLineData
225fe215
VM
1/*
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
5 *
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
14 *
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25
26#include "common.h"
27#include "commit.h"
28#include "revwalk.h"
29#include "tree.h"
30
31void git_tree__free(git_tree *tree)
32{
33 free(tree);
34}
35
36const git_oid *git_tree_id(git_tree *tree)
37{
38 return &tree->object.id;
39}
40
41git_tree *git_tree_lookup(git_revpool *pool, const git_oid *id)
42{
43 git_tree *tree = NULL;
44
45 if (pool == NULL)
46 return NULL;
47
48 tree = (git_tree *)git_revpool_table_lookup(pool->objects, id);
49 if (tree != NULL)
50 return tree;
51
52 tree = git__malloc(sizeof(git_tree));
53
54 if (tree == NULL)
55 return NULL;
56
57 memset(tree, 0x0, sizeof(git_tree));
58
59 /* Initialize parent object */
60 git_oid_cpy(&tree->object.id, id);
61 tree->object.pool = pool;
62 tree->object.type = GIT_OBJ_TREE;
63
64 git_revpool_table_insert(pool->objects, (git_revpool_object *)tree);
65
66 return tree;
67}