]> git.proxmox.com Git - libgit2.git/blob - include/git2/odb_backend.h
portability: Improve x86/amd64 compatibility
[libgit2.git] / include / git2 / odb_backend.h
1 /*
2 * Copyright (C) 2009-2012 the libgit2 contributors
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_git_odb_backend_h__
8 #define INCLUDE_git_odb_backend_h__
9
10 #include "common.h"
11 #include "types.h"
12 #include "oid.h"
13
14 /**
15 * @file git2/backend.h
16 * @brief Git custom backend functions
17 * @defgroup git_backend Git custom backend API
18 * @ingroup Git
19 * @{
20 */
21 GIT_BEGIN_DECL
22
23 struct git_odb_stream;
24
25 /** An instance for a custom backend */
26 struct git_odb_backend {
27 git_odb *odb;
28
29 int (* read)(
30 void **, size_t *, git_otype *,
31 struct git_odb_backend *,
32 const git_oid *);
33
34 /* To find a unique object given a prefix
35 * of its oid.
36 * The oid given must be so that the
37 * remaining (GIT_OID_HEXSZ - len)*4 bits
38 * are 0s.
39 */
40 int (* read_prefix)(
41 git_oid *,
42 void **, size_t *, git_otype *,
43 struct git_odb_backend *,
44 const git_oid *,
45 size_t);
46
47 int (* read_header)(
48 size_t *, git_otype *,
49 struct git_odb_backend *,
50 const git_oid *);
51
52 int (* write)(
53 git_oid *,
54 struct git_odb_backend *,
55 const void *,
56 size_t,
57 git_otype);
58
59 int (* writestream)(
60 struct git_odb_stream **,
61 struct git_odb_backend *,
62 size_t,
63 git_otype);
64
65 int (* readstream)(
66 struct git_odb_stream **,
67 struct git_odb_backend *,
68 const git_oid *);
69
70 int (* exists)(
71 struct git_odb_backend *,
72 const git_oid *);
73
74 int (*foreach)(
75 struct git_odb_backend *,
76 int (*cb)(git_oid *oid, void *data),
77 void *data
78 );
79
80 void (* free)(struct git_odb_backend *);
81 };
82
83 /** Streaming mode */
84 enum {
85 GIT_STREAM_RDONLY = (1 << 1),
86 GIT_STREAM_WRONLY = (1 << 2),
87 GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
88 };
89
90 /** A stream to read/write from a backend */
91 struct git_odb_stream {
92 struct git_odb_backend *backend;
93 int mode;
94
95 int (*read)(struct git_odb_stream *stream, char *buffer, size_t len);
96 int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len);
97 int (*finalize_write)(git_oid *oid_p, struct git_odb_stream *stream);
98 void (*free)(struct git_odb_stream *stream);
99 };
100
101 GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
102 GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir, int compression_level, int do_fsync);
103
104 GIT_END_DECL
105
106 #endif