]> git.proxmox.com Git - libgit2.git/blob - src/odb.h
Create public filter object and use it
[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 /* DO NOT EXPORT */
24 typedef struct {
25 void *data; /**< Raw, decompressed object data. */
26 size_t len; /**< Total number of bytes in data. */
27 git_otype type; /**< Type of this object. */
28 } git_rawobj;
29
30 /* EXPORT */
31 struct git_odb_object {
32 git_cached_obj cached;
33 void *buffer;
34 };
35
36 /* EXPORT */
37 struct git_odb {
38 git_refcount rc;
39 git_vector backends;
40 git_cache own_cache;
41 };
42
43 /*
44 * Hash a git_rawobj internally.
45 * The `git_rawobj` is supposed to be previously initialized
46 */
47 int git_odb__hashobj(git_oid *id, git_rawobj *obj);
48
49 /*
50 * Format the object header such as it would appear in the on-disk object
51 */
52 int git_odb__format_object_header(char *hdr, size_t n, size_t obj_len, git_otype obj_type);
53 /*
54 * Hash an open file descriptor.
55 * This is a performance call when the contents of a fd need to be hashed,
56 * but the fd is already open and we have the size of the contents.
57 *
58 * Saves us some `stat` calls.
59 *
60 * The fd is never closed, not even on error. It must be opened and closed
61 * by the caller
62 */
63 int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type);
64
65 /*
66 * Hash an open file descriptor applying an array of filters
67 * Acts just like git_odb__hashfd with the addition of filters...
68 */
69 int git_odb__hashfd_filtered(
70 git_oid *out, git_file fd, size_t len, git_otype type, git_filter_list *fl);
71
72 /*
73 * Hash a `path`, assuming it could be a POSIX symlink: if the path is a
74 * symlink, then the raw contents of the symlink will be hashed. Otherwise,
75 * this will fallback to `git_odb__hashfd`.
76 *
77 * The hash type for this call is always `GIT_OBJ_BLOB` because symlinks may
78 * only point to blobs.
79 */
80 int git_odb__hashlink(git_oid *out, const char *path);
81
82 /*
83 * Generate a GIT_ENOTFOUND error for the ODB.
84 */
85 int git_odb__error_notfound(const char *message, const git_oid *oid);
86
87 /*
88 * Generate a GIT_EAMBIGUOUS error for the ODB.
89 */
90 int git_odb__error_ambiguous(const char *message);
91
92 /*
93 * Attempt to read object header or just return whole object if it could
94 * not be read.
95 */
96 int git_odb__read_header_or_object(
97 git_odb_object **out, size_t *len_p, git_otype *type_p,
98 git_odb *db, const git_oid *id);
99
100 /* fully free the object; internal method, DO NOT EXPORT */
101 void git_odb_object__free(void *object);
102
103 #endif