Skip to content

Commit 83cc70d

Browse files
committed
Move odb_backend implementors stuff into git2/sys
This moves some of the odb_backend stuff that is related to the internals of an odb_backend implementation into include/git2/sys. Some of the stuff related to streaming I left in include/git2 because it seemed like it would be reasonably needed by a normal user who wanted to stream objects into and out of the ODB. Also, I added APIs for traversing the list of backends so that some of the tests would not need to access ODB internals.
1 parent 83041c7 commit 83cc70d

File tree

15 files changed

+225
-182
lines changed

15 files changed

+225
-182
lines changed

include/git2/indexer.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,11 @@
88
#define _INCLUDE_git_indexer_h__
99

1010
#include "common.h"
11+
#include "types.h"
1112
#include "oid.h"
1213

1314
GIT_BEGIN_DECL
1415

15-
/**
16-
* This is passed as the first argument to the callback to allow the
17-
* user to see the progress.
18-
*/
19-
typedef struct git_transfer_progress {
20-
unsigned int total_objects;
21-
unsigned int indexed_objects;
22-
unsigned int received_objects;
23-
size_t received_bytes;
24-
} git_transfer_progress;
25-
26-
27-
/**
28-
* Type for progress callbacks during indexing. Return a value less than zero
29-
* to cancel the transfer.
30-
*
31-
* @param stats Structure containing information about the state of the transfer
32-
* @param payload Payload provided by caller
33-
*/
34-
typedef int (*git_transfer_progress_callback)(const git_transfer_progress *stats, void *payload);
35-
3616
typedef struct git_indexer_stream git_indexer_stream;
3717

3818
/**

include/git2/odb.h

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include "common.h"
1111
#include "types.h"
1212
#include "oid.h"
13-
#include "odb_backend.h"
14-
#include "indexer.h"
1513

1614
/**
1715
* @file git2/odb.h
@@ -22,6 +20,11 @@
2220
*/
2321
GIT_BEGIN_DECL
2422

23+
/**
24+
* Function type for callbacks from git_odb_foreach.
25+
*/
26+
typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
27+
2528
/**
2629
* Create a new object database with no backends.
2730
*
@@ -52,42 +55,6 @@ GIT_EXTERN(int) git_odb_new(git_odb **out);
5255
*/
5356
GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
5457

55-
/**
56-
* Add a custom backend to an existing Object DB
57-
*
58-
* The backends are checked in relative ordering, based on the
59-
* value of the `priority` parameter.
60-
*
61-
* Read <odb_backends.h> for more information.
62-
*
63-
* @param odb database to add the backend to
64-
* @param backend pointer to a git_odb_backend instance
65-
* @param priority Value for ordering the backends queue
66-
* @return 0 on success; error code otherwise
67-
*/
68-
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
69-
70-
/**
71-
* Add a custom backend to an existing Object DB; this
72-
* backend will work as an alternate.
73-
*
74-
* Alternate backends are always checked for objects *after*
75-
* all the main backends have been exhausted.
76-
*
77-
* The backends are checked in relative ordering, based on the
78-
* value of the `priority` parameter.
79-
*
80-
* Writing is disabled on alternate backends.
81-
*
82-
* Read <odb_backends.h> for more information.
83-
*
84-
* @param odb database to add the backend to
85-
* @param backend pointer to a git_odb_backend instance
86-
* @param priority Value for ordering the backends queue
87-
* @return 0 on success; error code otherwise
88-
*/
89-
GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
90-
9158
/**
9259
* Add an on-disk alternate to an existing Object DB.
9360
*
@@ -406,6 +373,60 @@ GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
406373
*/
407374
GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
408375

376+
/**
377+
* Add a custom backend to an existing Object DB
378+
*
379+
* The backends are checked in relative ordering, based on the
380+
* value of the `priority` parameter.
381+
*
382+
* Read <odb_backends.h> for more information.
383+
*
384+
* @param odb database to add the backend to
385+
* @param backend pointer to a git_odb_backend instance
386+
* @param priority Value for ordering the backends queue
387+
* @return 0 on success; error code otherwise
388+
*/
389+
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
390+
391+
/**
392+
* Add a custom backend to an existing Object DB; this
393+
* backend will work as an alternate.
394+
*
395+
* Alternate backends are always checked for objects *after*
396+
* all the main backends have been exhausted.
397+
*
398+
* The backends are checked in relative ordering, based on the
399+
* value of the `priority` parameter.
400+
*
401+
* Writing is disabled on alternate backends.
402+
*
403+
* Read <odb_backends.h> for more information.
404+
*
405+
* @param odb database to add the backend to
406+
* @param backend pointer to a git_odb_backend instance
407+
* @param priority Value for ordering the backends queue
408+
* @return 0 on success; error code otherwise
409+
*/
410+
GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
411+
412+
/**
413+
* Get the number of ODB backend objects
414+
*
415+
* @param odb object database
416+
* @return number of backends in the ODB
417+
*/
418+
GIT_EXTERN(size_t) git_odb_num_backends(git_odb *odb);
419+
420+
/**
421+
* Lookup an ODB backend object by index
422+
*
423+
* @param out output pointer to ODB backend at pos
424+
* @param odb object database
425+
* @param pos index into object database backend list
426+
* @return 0 on success; GIT_ENOTFOUND if pos is invalid; other errors < 0
427+
*/
428+
GIT_EXTERN(int) git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos);
429+
409430
/** @} */
410431
GIT_END_DECL
411432
#endif

include/git2/odb_backend.h

Lines changed: 16 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -7,106 +7,24 @@
77
#ifndef INCLUDE_git_odb_backend_h__
88
#define INCLUDE_git_odb_backend_h__
99

10-
#include "common.h"
11-
#include "types.h"
12-
#include "oid.h"
13-
#include "indexer.h"
10+
#include "git2/common.h"
11+
#include "git2/types.h"
1412

1513
/**
1614
* @file git2/backend.h
1715
* @brief Git custom backend functions
18-
* @defgroup git_backend Git custom backend API
16+
* @defgroup git_odb Git object database routines
1917
* @ingroup Git
2018
* @{
2119
*/
2220
GIT_BEGIN_DECL
2321

24-
struct git_odb_stream;
25-
struct git_odb_writepack;
26-
27-
/**
28-
* Function type for callbacks from git_odb_foreach.
29-
*/
30-
typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
31-
3222
/**
33-
* An instance for a custom backend
23+
* Constructors for in-box ODB backends.
3424
*/
35-
struct git_odb_backend {
36-
unsigned int version;
37-
git_odb *odb;
38-
39-
/* read and read_prefix each return to libgit2 a buffer which
40-
* will be freed later. The buffer should be allocated using
41-
* the function git_odb_backend_malloc to ensure that it can
42-
* be safely freed later. */
43-
int (* read)(
44-
void **, size_t *, git_otype *,
45-
struct git_odb_backend *,
46-
const git_oid *);
47-
48-
/* To find a unique object given a prefix
49-
* of its oid.
50-
* The oid given must be so that the
51-
* remaining (GIT_OID_HEXSZ - len)*4 bits
52-
* are 0s.
53-
*/
54-
int (* read_prefix)(
55-
git_oid *,
56-
void **, size_t *, git_otype *,
57-
struct git_odb_backend *,
58-
const git_oid *,
59-
size_t);
60-
61-
int (* read_header)(
62-
size_t *, git_otype *,
63-
struct git_odb_backend *,
64-
const git_oid *);
65-
66-
/* The writer may assume that the object
67-
* has already been hashed and is passed
68-
* in the first parameter.
69-
*/
70-
int (* write)(
71-
git_oid *,
72-
struct git_odb_backend *,
73-
const void *,
74-
size_t,
75-
git_otype);
76-
77-
int (* writestream)(
78-
struct git_odb_stream **,
79-
struct git_odb_backend *,
80-
size_t,
81-
git_otype);
82-
83-
int (* readstream)(
84-
struct git_odb_stream **,
85-
struct git_odb_backend *,
86-
const git_oid *);
87-
88-
int (* exists)(
89-
struct git_odb_backend *,
90-
const git_oid *);
91-
92-
int (* refresh)(struct git_odb_backend *);
93-
94-
int (* foreach)(
95-
struct git_odb_backend *,
96-
git_odb_foreach_cb cb,
97-
void *payload);
98-
99-
int (* writepack)(
100-
struct git_odb_writepack **,
101-
struct git_odb_backend *,
102-
git_transfer_progress_callback progress_cb,
103-
void *progress_payload);
104-
105-
void (* free)(struct git_odb_backend *);
106-
};
107-
108-
#define GIT_ODB_BACKEND_VERSION 1
109-
#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
25+
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
26+
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
27+
GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
11028

11129
/** Streaming mode */
11230
enum {
@@ -117,33 +35,24 @@ enum {
11735

11836
/** A stream to read/write from a backend */
11937
struct git_odb_stream {
120-
struct git_odb_backend *backend;
38+
git_odb_backend *backend;
12139
unsigned int mode;
12240

123-
int (*read)(struct git_odb_stream *stream, char *buffer, size_t len);
124-
int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len);
125-
int (*finalize_write)(git_oid *oid_p, struct git_odb_stream *stream);
126-
void (*free)(struct git_odb_stream *stream);
41+
int (*read)(git_odb_stream *stream, char *buffer, size_t len);
42+
int (*write)(git_odb_stream *stream, const char *buffer, size_t len);
43+
int (*finalize_write)(git_oid *oid_p, git_odb_stream *stream);
44+
void (*free)(git_odb_stream *stream);
12745
};
12846

12947
/** A stream to write a pack file to the ODB */
13048
struct git_odb_writepack {
131-
struct git_odb_backend *backend;
49+
git_odb_backend *backend;
13250

133-
int (*add)(struct git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
134-
int (*commit)(struct git_odb_writepack *writepack, git_transfer_progress *stats);
135-
void (*free)(struct git_odb_writepack *writepack);
51+
int (*add)(git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
52+
int (*commit)(git_odb_writepack *writepack, git_transfer_progress *stats);
53+
void (*free)(git_odb_writepack *writepack);
13654
};
13755

138-
GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
139-
140-
/**
141-
* Constructors for in-box ODB backends.
142-
*/
143-
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
144-
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
145-
GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
146-
14756
GIT_END_DECL
14857

14958
#endif

include/git2/sys/config.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* This file is part of libgit2, distributed under the GNU GPL v2 with
55
* a Linking Exception. For full terms see the included COPYING file.
66
*/
7-
#ifndef INCLUDE_git_sys_config_h__
8-
#define INCLUDE_git_sys_config_h__
7+
#ifndef INCLUDE_sys_git_config_backend_h__
8+
#define INCLUDE_sys_git_config_backend_h__
99

1010
#include "git2/common.h"
1111
#include "git2/types.h"
@@ -14,6 +14,7 @@
1414
/**
1515
* @file git2/sys/config.h
1616
* @brief Git config backend routines
17+
* @defgroup git_backend Git custom backend APIs
1718
* @ingroup Git
1819
* @{
1920
*/

0 commit comments

Comments
 (0)