]> git.proxmox.com Git - libgit2.git/blame - include/git2/odb_backend.h
New upstream version 0.28.1+dfsg.1
[libgit2.git] / include / git2 / odb_backend.h
CommitLineData
f5918330 1/*
359fc2d2 2 * Copyright (C) the libgit2 contributors. All rights reserved.
f5918330 3 *
bb742ede
VM
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.
f5918330 6 */
d12299fe
VM
7#ifndef INCLUDE_git_odb_backend_h__
8#define INCLUDE_git_odb_backend_h__
9
f313843c
JJ
10#include "common.h"
11#include "types.h"
d12299fe 12
f5918330
VM
13/**
14 * @file git2/backend.h
15 * @brief Git custom backend functions
83cc70d9 16 * @defgroup git_odb Git object database routines
f5918330
VM
17 * @ingroup Git
18 * @{
19 */
d12299fe
VM
20GIT_BEGIN_DECL
21
9a9de29d 22/*
83cc70d9 23 * Constructors for in-box ODB backends.
c3fb7d04 24 */
9a9de29d
CMN
25
26/**
27 * Create a backend for the packfiles.
28 *
29 * @param out location to store the odb backend pointer
30 * @param objects_dir the Git repository's objects directory
31 *
32 * @return 0 or an error code
33 */
83cc70d9 34GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
9a9de29d
CMN
35
36/**
37 * Create a backend for loose objects
38 *
39 * @param out location to store the odb backend pointer
40 * @param objects_dir the Git repository's objects directory
41 * @param compression_level zlib compression level to use
fc27fe21 42 * @param do_fsync whether to do an fsync() after writing
dd64c71c
ET
43 * @param dir_mode permissions to use creating a directory or 0 for defaults
44 * @param file_mode permissions to use creating a file or 0 for defaults
9a9de29d
CMN
45 *
46 * @return 0 or an error code
47 */
dd64c71c
ET
48GIT_EXTERN(int) git_odb_backend_loose(
49 git_odb_backend **out,
50 const char *objects_dir,
51 int compression_level,
52 int do_fsync,
f966acd1
ET
53 unsigned int dir_mode,
54 unsigned int file_mode);
9a9de29d
CMN
55
56/**
57 * Create a backend out of a single packfile
58 *
59 * This can be useful for inspecting the contents of a single
60 * packfile.
61 *
62 * @param out location to store the odb backend pointer
63 * @param index_file path to the packfile's .idx file
64 *
65 * @return 0 or an error code
66 */
83cc70d9 67GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
bde336ea 68
2e2e9785 69/** Streaming mode */
0f1f9833 70typedef enum {
2e2e9785
VM
71 GIT_STREAM_RDONLY = (1 << 1),
72 GIT_STREAM_WRONLY = (1 << 2),
73 GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
0f1f9833 74} git_odb_stream_t;
2e2e9785 75
7a3764be
CMN
76/**
77 * A stream to read/write from a backend.
78 *
79 * This represents a stream of data being written to or read from a
80 * backend. When writing, the frontend functions take care of
81 * calculating the object's id and all `finalize_write` needs to do is
82 * store the object with the id it is passed.
83 */
72a3fe42 84struct git_odb_stream {
83cc70d9 85 git_odb_backend *backend;
0ed67c1c 86 unsigned int mode;
67c177ef 87 void *hash_ctx;
72a3fe42 88
77b339f7
CMN
89 git_off_t declared_size;
90 git_off_t received_bytes;
031f3f80 91
7a3764be 92 /**
4dfe3820 93 * Write at most `len` bytes into `buffer` and advance the stream.
7a3764be 94 */
ac3d33df 95 int GIT_CALLBACK(read)(git_odb_stream *stream, char *buffer, size_t len);
7a3764be
CMN
96
97 /**
98 * Write `len` bytes from `buffer` into the stream.
99 */
ac3d33df 100 int GIT_CALLBACK(write)(git_odb_stream *stream, const char *buffer, size_t len);
7a3764be
CMN
101
102 /**
103 * Store the contents of the stream as an object with the id
104 * specified in `oid`.
4047950f 105 *
4dfe3820
RB
106 * This method might not be invoked if:
107 * - an error occurs earlier with the `write` callback,
108 * - the object referred to by `oid` already exists in any backend, or
109 * - the final number of received bytes differs from the size declared
110 * with `git_odb_open_wstream()`
7a3764be 111 */
ac3d33df 112 int GIT_CALLBACK(finalize_write)(git_odb_stream *stream, const git_oid *oid);
7a3764be
CMN
113
114 /**
115 * Free the stream's memory.
4dfe3820
RB
116 *
117 * This method might be called without a call to `finalize_write` if
118 * an error occurs or if the object is already present in the ODB.
7a3764be 119 */
ac3d33df 120 void GIT_CALLBACK(free)(git_odb_stream *stream);
72a3fe42
VM
121};
122
09cc0b92
ET
123/** A stream to write a pack file to the ODB */
124struct git_odb_writepack {
83cc70d9 125 git_odb_backend *backend;
09cc0b92 126
ac3d33df
JK
127 int GIT_CALLBACK(append)(git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
128 int GIT_CALLBACK(commit)(git_odb_writepack *writepack, git_transfer_progress *stats);
129 void GIT_CALLBACK(free)(git_odb_writepack *writepack);
09cc0b92
ET
130};
131
d12299fe
VM
132GIT_END_DECL
133
134#endif