]> git.proxmox.com Git - libgit2.git/blame - src/git_odb.h
Hide GIT_{BEGIN,END}_DECL from doxygen as its not part of our API
[libgit2.git] / src / git_odb.h
CommitLineData
c15648cb
SP
1/*
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
6 * conditions are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
15 *
16 * - Neither the name of the Git Development Community nor the
17 * names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef INCLUDE_git_odb_h__
37#define INCLUDE_git_odb_h__
38
39#include "git_common.h"
40#include "git_oid.h"
41#include <unistd.h>
42
43/**
44 * @file git_odb.h
45 * @brief Git object database routines
46 * @defgroup git_odb Git object database routines
47 * @ingroup Git
48 * @{
49 */
50GIT_BEGIN_DECL
51
52/** An open object database handle. */
53typedef struct git_odb {
54 /** Path to the "objects" directory. */
55 const char *path;
56
57 /** Alternate databases to search. */
58 struct git_odb **alternates;
59
60 /** Number of alternates available. */
61 unsigned n_alternates;
62} git_odb;
63
64/**
65 * Open an object database for read/write access.
66 * @param out location to store the database pointer, if opened.
67 * Set to NULL if the open failed.
68 * @param objects_dir path of the database's "objects" directory.
69 * @return GIT_SUCCESS if the database opened; otherwise an error
70 * code describing why the open was not possible.
71 */
72GIT_EXTERN(git_result) git_odb_open(git_odb **out, const char *objects_dir);
73
74/**
75 * Close an open object database.
76 * @param db database pointer to close. If NULL no action is taken.
77 * The pointer is set to NULL when the close is completed.
78 */
79GIT_EXTERN(void) git_odb_close(git_odb** db);
80
81/** Basic type (loose or packed) of any Git object. */
82typedef enum {
83 OBJ_BAD = -1, /**< Object is invalid. */
84 OBJ__EXT1 = 0, /**< Reserved for future use. */
85 OBJ_COMMIT = 1, /**< A commit object. */
86 OBJ_TREE = 2, /**< A tree (directory listing) object. */
87 OBJ_BLOB = 3, /**< A file revision object. */
88 OBJ_TAG = 4, /**< An annotated tag object. */
89 OBJ__EXT2 = 5, /**< Reserved for future use. */
90 OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
91 OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */
92} git_otype;
93
94/** A small object read from the database. */
95typedef struct {
96 void *data; /**< Raw, decompressed object data. */
97 size_t len; /**< Total number of bytes in data. */
98 git_otype type; /**< Type of this object. */
99} git_sobj;
100
101/**
102 * Read a small object from the database.
103 * @param out object descriptor to populate upon reading.
104 * @param db database to search for the object in.
105 * @param id identity of the object to read.
106 * @return GIT_SUCCESS if the object was read;
107 * GIT_ENOTFOUND if the object is not in the database.
108 */
46d8b885 109GIT_EXTERN(git_result) git_odb_read(git_sobj *out, git_odb *db, const git_oid *id);
c15648cb
SP
110
111/**
112 * Read a small object from the database using only pack files.
113 * @param out object descriptor to populate upon reading.
114 * @param db database to search for the object in.
115 * @param id identity of the object to read.
116 * @return GIT_SUCCESS if the object was read;
117 * GIT_ENOTFOUND if the object is not in the database.
118 */
46d8b885 119GIT_EXTERN(git_result) git_odb__read_packed(git_sobj *out, git_odb *db, const git_oid *id);
c15648cb
SP
120
121/**
122 * Read a small object from the database using only loose object files.
123 * @param out object descriptor to populate upon reading.
124 * @param db database to search for the object in.
125 * @param id identity of the object to read.
126 * @return GIT_SUCCESS if the object was read;
127 * GIT_ENOTFOUND if the object is not in the database.
128 */
46d8b885 129GIT_EXTERN(git_result) git_odb__read_loose(git_sobj *out, git_odb *db, const git_oid *id);
c15648cb
SP
130
131/** @} */
132GIT_END_DECL
133#endif