Skip to content

Commit 749ef94

Browse files
Merge pull request #81 from swift-developer-tools/feature/refdb-backend-advanced
Add RefDB Backend (Advanced) bindings
2 parents 73056c5 + 7cc69a1 commit 749ef94

12 files changed

Lines changed: 802 additions & 11 deletions

File tree

Sources/SwiftLibgit2/Commit/Commit-Structs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public struct GitCommitCreateOptions: CStructMutable, WithCConvertible, Sendable
146146
/// [`git_commitarray`](https://libgit2.org/docs/reference/main/commit/git_commitarray.html)
147147
public struct GitCommitArray: CStruct
148148
{
149-
/// The commits.
149+
/// The commits. The underlying types must be `git_commit`.
150150
public let commits : [OpaquePointer]
151151

152152
/// The length of ``commits``.

Sources/SwiftLibgit2/ODB-Backend-Advanced/ODB-Backend-Advanced-Structs.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct GitODBBackend: CStruct
2626
/// The struct version.
2727
public let version : UInt32
2828

29-
/// The object database.
29+
/// The object database. The underlying type must be `git_odb`.
3030
public let odb : OpaquePointer?
3131

3232
/// Reads the specified object from the given object database backend.
@@ -81,7 +81,7 @@ public struct GitODBBackend: CStruct
8181

8282

8383

84-
/// Initializes a ``GitAllocator`` instance from the given `git_odb_backend`
84+
/// Initializes a ``GitODBBackend`` instance from the given `git_odb_backend`
8585
/// instance.
8686
/// - Parameter backend: The `git_odb_backend` instance to use.
8787
internal init(
@@ -238,7 +238,7 @@ public struct GitODBBackend: CStruct
238238
/// - backend: The object database backend to search.
239239
/// - id: The ID of the object for which to search.
240240
/// - Returns: Whether the specified object can be found in the given
241-
/// object database backend.
241+
/// object database backend, or an error code.
242242
public typealias Exists = @convention(c)
243243
(
244244
UnsafeMutablePointer<git_odb_backend>?,
@@ -258,7 +258,7 @@ public struct GitODBBackend: CStruct
258258
/// than or equal to ``gitOIDMinPrefixLen``, and long enough to identify
259259
/// a unique object matching the prefix.
260260
/// - Returns: Whether the specified object can be found in the given
261-
/// object database backend.
261+
/// object database backend, or an error code.
262262
public typealias ExistsPrefix = @convention(c)
263263
(
264264
UnsafeMutablePointer<git_oid>?,

Sources/SwiftLibgit2/ODB/ODB-Functions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ public func gitODBGetBackend(
11951195
/// ## Discussion
11961196
///
11971197
/// - Important: If the operation succeeds, ownership of the given commit graph
1198-
/// will be transferred to libgit2. The caller must not free it.
1198+
/// will be transferred to libgit2. The caller must not free the commit graph.
11991199
///
12001200
/// ## C Equivalent
12011201
///
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-libgit2 open source project.
4+
//
5+
// Copyright (c) Margins Technologies LLC.
6+
// Licensed under the Apache License, Version 2.0.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
import CLibgit2
11+
12+
13+
14+
/// Initializes the given `git_refdb_backend` instance.
15+
/// - Parameters:
16+
/// - opts: The `git_refdb_backend` instance to initialize.
17+
/// - version: The version to use. Pass ``gitRefDBBackendVersion``.
18+
/// - Returns: A ``GitErrorCode`` instance.
19+
///
20+
/// ## C Equivalent
21+
///
22+
/// [`git_refdb_init_backend()`](https://libgit2.org/docs/reference/main/sys/refdb_backend/git_refdb_init_backend.html)
23+
public func gitRefDBInitBackend(
24+
opts : UnsafeMutablePointer<git_refdb_backend>,
25+
version : UInt32
26+
) -> GitErrorCode
27+
{
28+
return withCConversion
29+
{
30+
return git_refdb_init_backend(
31+
opts,
32+
version
33+
)
34+
}
35+
}
36+
37+
38+
39+
/// Creates a default reference database backend, based on the file system.
40+
/// - Parameters:
41+
/// - backendOut: The pointer in which to store the reference database
42+
/// backend.
43+
/// - repo: The repository to use. The underlying type must be
44+
/// `git_repository`.
45+
/// - Returns: A ``GitErrorCode`` instance.
46+
///
47+
/// ## Discussion
48+
///
49+
/// This function is normally called automatically when a repository is
50+
/// created or opened. It may be called manually to explicitly create a file
51+
/// system-based reference database backend for a repository.
52+
///
53+
/// ## C Equivalent
54+
///
55+
/// [`git_refdb_backend_fs()`](https://libgit2.org/docs/reference/main/sys/refdb_backend/git_refdb_backend_fs.html)
56+
public func gitRefDBBackendFS(
57+
backendOut : UnsafeMutablePointer<UnsafeMutablePointer<git_refdb_backend>?>,
58+
repo : OpaquePointer
59+
) -> GitErrorCode
60+
{
61+
return withCConversion
62+
{
63+
return git_refdb_backend_fs(
64+
backendOut,
65+
repo
66+
)
67+
}
68+
}
69+
70+
71+
72+
/// Sets the given reference database backend as the custom backend of the
73+
/// given reference database.
74+
/// - Parameters:
75+
/// - refDB: The reference database to update. The underlying type must be
76+
/// `git_refdb`.
77+
/// - backend: The reference database backend to use.
78+
/// - Returns: A ``GitErrorCode`` instance.
79+
///
80+
/// ## Discussion
81+
///
82+
/// - Important: If the operation succeeds, ownership of the given reference
83+
/// database backend will be transferred to the given reference database. The
84+
/// caller must not free the reference database backend.
85+
///
86+
/// ## C Equivalent
87+
///
88+
/// [`git_refdb_set_backend()`](https://libgit2.org/docs/reference/main/sys/refdb_backend/git_refdb_set_backend.html)
89+
public func gitRefDBSetBackend(
90+
refDB : OpaquePointer,
91+
backend : UnsafeMutablePointer<git_refdb_backend>
92+
) -> GitErrorCode
93+
{
94+
return withCConversion
95+
{
96+
return git_refdb_set_backend(
97+
refDB,
98+
backend
99+
)
100+
}
101+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-libgit2 open source project.
4+
//
5+
// Copyright (c) Margins Technologies LLC.
6+
// Licensed under the Apache License, Version 2.0.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
/// The current version for ``GitRefDBBackend``.
11+
///
12+
/// ## C Equivalent
13+
///
14+
/// [`GIT_REFDB_BACKEND_VERSION`](https://libgit2.org/docs/reference/main/sys/refdb_backend/GIT_REFDB_BACKEND_VERSION.html)
15+
public let gitRefDBBackendVersion: UInt32 = 1

0 commit comments

Comments
 (0)