]> git.proxmox.com Git - libgit2.git/blob - src/odb.h
odb: add option to turn off hash verification
[libgit2.git] / src / odb.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_odb_h__
8 #define INCLUDE_odb_h__
9
10 #include "git2/odb.h"
11 #include "git2/oid.h"
12 #include "git2/types.h"
13
14 #include "vector.h"
15 #include "cache.h"
16 #include "posix.h"
17 #include "filter.h"
18
19 #define GIT_OBJECTS_DIR "objects/"
20 #define GIT_OBJECT_DIR_MODE 0777
21 #define GIT_OBJECT_FILE_MODE 0444
22
23 extern bool git_odb__strict_hash_verification;
24
25 /* DO NOT EXPORT */
26 typedef struct {
27 void *data; /**< Raw, decompressed object data. */
28 size_t len; /**< Total number of bytes in data. */
29 git_otype type; /**< Type of this object. */
30 } git_rawobj;
31
32 /* EXPORT */
33 struct git_odb_object {
34 git_cached_obj cached;
35 void *buffer;
36 };
37
38 /* EXPORT */
39 struct git_odb {
40 git_refcount rc;
41 git_vector backends;
42 git_cache own_cache;
43 unsigned int do_fsync :1;
44 };
45
46 typedef enum {
47 GIT_ODB_CAP_FROM_OWNER = -1,
48 } git_odb_cap_t;
49
50 /*
51 * Set the capabilities for the object database.
52 */
53 int git_odb__set_caps(git_odb *odb, int caps);
54
55 /*
56 * Add the default loose and packed backends for a database.
57 */
58 int git_odb__add_default_backends(
59 git_odb *db, const char *objects_dir,
60 bool as_alternates, int alternate_depth);
61
62 /*
63 * Hash a git_rawobj internally.
64 * The `git_rawobj` is supposed to be previously initialized
65 */
66 int git_odb__hashobj(git_oid *id, git_rawobj *obj);
67
68 /*
69 * Format the object header such as it would appear in the on-disk object
70 */
71 int git_odb__format_object_header(char *hdr, size_t n, git_off_t obj_len, git_otype obj_type);
72 /*
73 * Hash an open file descriptor.
74 * This is a performance call when the contents of a fd need to be hashed,
75 * but the fd is already open and we have the size of the contents.
76 *
77 * Saves us some `stat` calls.
78 *
79 * The fd is never closed, not even on error. It must be opened and closed
80 * by the caller
81 */
82 int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type);
83
84 /*
85 * Hash an open file descriptor applying an array of filters
86 * Acts just like git_odb__hashfd with the addition of filters...
87 */
88 int git_odb__hashfd_filtered(
89 git_oid *out, git_file fd, size_t len, git_otype type, git_filter_list *fl);
90
91 /*
92 * Hash a `path`, assuming it could be a POSIX symlink: if the path is a
93 * symlink, then the raw contents of the symlink will be hashed. Otherwise,
94 * this will fallback to `git_odb__hashfd`.
95 *
96 * The hash type for this call is always `GIT_OBJ_BLOB` because symlinks may
97 * only point to blobs.
98 */
99 int git_odb__hashlink(git_oid *out, const char *path);
100
101 /**
102 * Generate a GIT_EMISMATCH error for the ODB.
103 */
104 int git_odb__error_mismatch(
105 const git_oid *expected, const git_oid *actual);
106
107 /*
108 * Generate a GIT_ENOTFOUND error for the ODB.
109 */
110 int git_odb__error_notfound(
111 const char *message, const git_oid *oid, size_t oid_len);
112
113 /*
114 * Generate a GIT_EAMBIGUOUS error for the ODB.
115 */
116 int git_odb__error_ambiguous(const char *message);
117
118 /*
119 * Attempt to read object header or just return whole object if it could
120 * not be read.
121 */
122 int git_odb__read_header_or_object(
123 git_odb_object **out, size_t *len_p, git_otype *type_p,
124 git_odb *db, const git_oid *id);
125
126 /* freshen an entry in the object database */
127 int git_odb__freshen(git_odb *db, const git_oid *id);
128
129 /* fully free the object; internal method, DO NOT EXPORT */
130 void git_odb_object__free(void *object);
131
132 #endif