]> git.proxmox.com Git - libgit2.git/blame - src/git/odb.h
Fixup documentation to reflect the "git_obj" rename
[libgit2.git] / src / git / odb.h
CommitLineData
c15648cb
SP
1#ifndef INCLUDE_git_odb_h__
2#define INCLUDE_git_odb_h__
3
257bd746
AE
4#include "common.h"
5#include "oid.h"
ec250c6e 6#include <stdlib.h>
c15648cb
SP
7
8/**
d1ea30c3 9 * @file git/odb.h
c15648cb 10 * @brief Git object database routines
8edc2805 11 * @defgroup git_odb Git object database routines
c15648cb
SP
12 * @ingroup Git
13 * @{
14 */
15GIT_BEGIN_DECL
16
17/** An open object database handle. */
6533aadc 18typedef struct git_odb git_odb;
c15648cb
SP
19
20/**
21 * Open an object database for read/write access.
22 * @param out location to store the database pointer, if opened.
23 * Set to NULL if the open failed.
24 * @param objects_dir path of the database's "objects" directory.
25 * @return GIT_SUCCESS if the database opened; otherwise an error
26 * code describing why the open was not possible.
27 */
6533aadc 28GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
c15648cb
SP
29
30/**
31 * Close an open object database.
32 * @param db database pointer to close. If NULL no action is taken.
c15648cb 33 */
1699efc4 34GIT_EXTERN(void) git_odb_close(git_odb *db);
c15648cb
SP
35
36/** Basic type (loose or packed) of any Git object. */
37typedef enum {
bce499af
SP
38 GIT_OBJ_BAD = -1, /**< Object is invalid. */
39 GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */
40 GIT_OBJ_COMMIT = 1, /**< A commit object. */
41 GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */
42 GIT_OBJ_BLOB = 3, /**< A file revision object. */
43 GIT_OBJ_TAG = 4, /**< An annotated tag object. */
44 GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */
45 GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
46 GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */
6533aadc 47} git_otype;
c15648cb 48
43288a07 49/** An object read from the database. */
c15648cb 50typedef struct {
8722a77e
SP
51 void *data; /**< Raw, decompressed object data. */
52 size_t len; /**< Total number of bytes in data. */
6533aadc 53 git_otype type; /**< Type of this object. */
dff79e27 54} git_obj;
c15648cb
SP
55
56/**
43288a07 57 * Read an object from the database.
b51eb250
SP
58 *
59 * If GIT_ENOTFOUND then out->data is set to NULL.
60 *
c15648cb
SP
61 * @param out object descriptor to populate upon reading.
62 * @param db database to search for the object in.
63 * @param id identity of the object to read.
b51eb250
SP
64 * @return
65 * - GIT_SUCCESS if the object was read;
66 * - GIT_ENOTFOUND if the object is not in the database.
c15648cb 67 */
dff79e27 68GIT_EXTERN(int) git_odb_read(git_obj *out, git_odb *db, const git_oid *id);
c15648cb
SP
69
70/**
43288a07 71 * Read an object from the database using only pack files.
b51eb250
SP
72 *
73 * If GIT_ENOTFOUND then out->data is set to NULL.
74 *
c15648cb
SP
75 * @param out object descriptor to populate upon reading.
76 * @param db database to search for the object in.
77 * @param id identity of the object to read.
b51eb250
SP
78 * @return
79 * - GIT_SUCCESS if the object was read.
80 * - GIT_ENOTFOUND if the object is not in the database.
c15648cb 81 */
dff79e27 82GIT_EXTERN(int) git_odb__read_packed(git_obj *out, git_odb *db, const git_oid *id);
c15648cb
SP
83
84/**
43288a07 85 * Read an object from the database using only loose object files.
b51eb250
SP
86 *
87 * If GIT_ENOTFOUND then out->data is set to NULL.
88 *
c15648cb
SP
89 * @param out object descriptor to populate upon reading.
90 * @param db database to search for the object in.
91 * @param id identity of the object to read.
b51eb250
SP
92 * @return
93 * - GIT_SUCCESS if the object was read.
94 * - GIT_ENOTFOUND if the object is not in the database.
c15648cb 95 */
dff79e27 96GIT_EXTERN(int) git_odb__read_loose(git_obj *out, git_odb *db, const git_oid *id);
c15648cb 97
111d5ccf 98/**
43288a07 99 * Release all memory used by the obj structure.
111d5ccf
SP
100 *
101 * As a result of this call, obj->data will be set to NULL.
102 *
103 * If obj->data is already NULL, nothing happens.
104 *
105 * @param obj object descriptor to free.
106 */
dff79e27 107GIT_INLINE(void) git_obj_close(git_obj *obj)
1699efc4
SP
108{
109 free(obj->data);
110 obj->data = NULL;
111}
111d5ccf 112
c15648cb
SP
113/** @} */
114GIT_END_DECL
115#endif