Skip to content

Commit f0e13e0

Browse files
Merge pull request #85 from swift-developer-tools/feature/stream-advanced
Add Stream (Advanced) bindings
2 parents 2cf04d3 + b71c32b commit f0e13e0

11 files changed

Lines changed: 635 additions & 22 deletions

File tree

Sources/SwiftLibgit2/Config-Advanced/Config-Advanced-Structs.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public struct GitConfigIterator: CStruct
7878
/// Gets the next backend entry.
7979
public let next : GitConfigIterator.Next?
8080

81-
/// Frees the memory allocated for the iterator.
81+
/// Frees the memory allocated for the given `git_config_iterator` instance.
8282
public let free : GitConfigIterator.Free?
8383

8484

@@ -144,37 +144,37 @@ public struct GitConfigBackend: CStruct
144144
/// The repository configuration.
145145
public let cfg : OpaquePointer?
146146

147-
/// Opens the backend at the given level.
147+
/// Opens the given backend at the given level.
148148
public let open : GitConfigBackend.Open?
149149

150-
/// Gets the specified configuration entry from the backend.
150+
/// Gets the specified configuration entry from the given backend.
151151
public let get : GitConfigBackend.Get?
152152

153-
/// Sets a configuration entry in the backend.
153+
/// Sets a configuration entry in the given backend.
154154
public let set : GitConfigBackend.Set?
155155

156-
/// Sets a multivar entry in the backend.
156+
/// Sets a multivar entry in the given backend.
157157
public let setMultivar : GitConfigBackend.SetMultivar?
158158

159-
/// Deletes the specified configuration entry from the backend.
159+
/// Deletes the specified configuration entry from the given backend.
160160
public let del : GitConfigBackend.Del?
161161

162-
/// Deletes the specified multivar entry from the backend.
162+
/// Deletes the specified multivar entry from the given backend.
163163
public let delMultivar : GitConfigBackend.DelMultivar?
164164

165-
/// Creates an iterator for the backend.
165+
/// Creates an iterator for the given backend.
166166
public let iterator : GitConfigBackend.Iterator?
167167

168-
/// Creates a read-only snapshot of the backend.
168+
/// Creates a read-only snapshot of the given backend.
169169
public let snapshot : GitConfigBackend.Snapshot?
170170

171-
/// Locks the backend.
171+
/// Locks the given backend.
172172
public let lock : GitConfigBackend.Lock?
173173

174-
/// Unlocks the backend.
174+
/// Unlocks the given backend.
175175
public let unlock : GitConfigBackend.Unlock?
176176

177-
/// Frees the memory allocated for the backend.
177+
/// Frees the memory allocated for the given backend.
178178
public let free : GitConfigBackend.Free?
179179

180180

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ public struct GitODBStream: CStruct
171171
public let receivedBytes : GitObjectSizeT
172172

173173
/// Writes at most the specified number of bytes into the given buffer,
174-
/// and advances the stream.
174+
/// and advances the given stream.
175175
public let read : GitODBStream.Read?
176176

177177
/// Writes the specified number of bytes into the given buffer.
178178
public let write : GitODBStream.Write?
179179

180-
/// Stores the contents of the stream as an object with the given ID.
180+
/// Stores the contents of the given stream as an object with the given ID.
181181
///
182182
/// ## Discussion
183183
///
@@ -290,10 +290,10 @@ public struct GitODBWritePack: CStruct
290290
/// The object database backend.
291291
public let backend : UnsafeMutablePointer<git_odb_backend>
292292

293-
/// Appends data to the packfile.
293+
/// Appends the given data to the given packfile.
294294
public let append : GitODBWritePack.Append?
295295

296-
/// Commits the packfile to the object database.
296+
/// Commits the given packfile to the given object database.
297297
public let commit : GitODBWritePack.Commit?
298298

299299
/// Frees the memory allocated for the given `git_odb_writepack` instance.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import CLibgit2
2323
/// [`git_reference_iterator`](https://libgit2.org/docs/reference/main/sys/refdb_backend/git_reference_iterator.html)
2424
public struct GitReferenceIterator: CStruct
2525
{
26-
2726
/// The reference database. The underlying type must be `git_refdb`.
2827
public let db : OpaquePointer?
2928

@@ -106,7 +105,7 @@ public struct GitReferenceIterator: CStruct
106105
/// ## C Equivalent
107106
///
108107
/// [`git_refdb_backend`](https://libgit2.org/docs/reference/main/sys/refdb_backend/git_refdb_backend.html)
109-
public struct GitRefDBBackend: CStruct
108+
public struct GitRefDBBackend: CStruct, Sendable
110109
{
111110

112111
/// The struct version.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
/// The callback invoked to create a new connection to the given host and port.
15+
/// - Parameters:
16+
/// - out: The pointer in which to store the stream.
17+
/// - host: The name of the host to which to connect the stream.
18+
/// - port: The port to which to connect the stream.
19+
/// - Returns: `0` on success, or an error code.
20+
///
21+
/// ## Discussion
22+
///
23+
/// - Warning: This is deprecated in libgit2 and will be removed in the next
24+
/// major release. Use ``GitStreamRegistration/Initialize`` instead.
25+
///
26+
/// ## C Equivalent
27+
///
28+
/// [`git_stream_cb()`](https://libgit2.org/docs/reference/main/sys/stream/git_stream_cb.html)
29+
public typealias GitStreamCB = @convention(c)
30+
(
31+
UnsafeMutablePointer<UnsafeMutablePointer<git_stream>?>?,
32+
UnsafePointer<CChar>?,
33+
UnsafePointer<CChar>?
34+
) -> Int32
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
/// The type of stream.
15+
///
16+
/// ## C Equivalent
17+
///
18+
/// [`git_stream_t`](https://libgit2.org/docs/reference/main/sys/stream/git_stream_t.html)
19+
public enum GitStreamT: UInt32, CEnum
20+
{
21+
/// A standard non-TLS socket.
22+
case gitStreamStandard = 1
23+
24+
/// A TLS-encrypted socket.
25+
case gitStreamTLS = 2
26+
27+
28+
29+
/// Initializes a ``GitStreamT`` instance from the given `git_stream_t`
30+
/// instance.
31+
/// - Parameter stream: The `git_stream_t` instance to use.
32+
internal init?(
33+
cValue stream: git_stream_t
34+
)
35+
{
36+
switch stream
37+
{
38+
case GIT_STREAM_STANDARD : self = .gitStreamStandard
39+
case GIT_STREAM_TLS : self = .gitStreamTLS
40+
default : return nil
41+
}
42+
}
43+
44+
45+
46+
/// Converts the ``GitStreamT`` instance into a `git_stream_t` instance.
47+
/// - Returns: The `git_stream_t` instance.
48+
internal func cValue() -> git_stream_t
49+
{
50+
switch self
51+
{
52+
case .gitStreamStandard : return GIT_STREAM_STANDARD
53+
case .gitStreamTLS : return GIT_STREAM_TLS
54+
}
55+
}
56+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
/// Registers the specified stream constructor.
15+
/// - Parameters:
16+
/// - type: The type of stream to register.
17+
/// - registration: The stream registration information to use. Pass `nil`
18+
/// to unregister the stream and use the system defaults.
19+
/// - Returns: A ``GitErrorCode`` instance.
20+
///
21+
/// ## Discussion
22+
///
23+
/// If the specified stream constructor has already been registered, it will
24+
/// be overwritten.
25+
///
26+
/// ## C Equivalent
27+
///
28+
/// [`git_stream_register()`](https://libgit2.org/docs/reference/main/sys/stream/git_stream_register.html)
29+
public func gitStreamRegister(
30+
type : GitStreamT,
31+
registration : UnsafeMutablePointer<git_stream_registration>?
32+
) -> GitErrorCode
33+
{
34+
return withCConversion
35+
{
36+
return git_stream_register(
37+
type.cValue(),
38+
registration
39+
)
40+
}
41+
}
42+
43+
44+
45+
/// Registers a TLS stream constructor.
46+
/// - Parameter ctor: The ``GitStreamCB`` callback to invoke to create a new
47+
/// connection. Pass `nil` to unregister the stream and use the system defaults.
48+
/// - Returns: A ``GitErrorCode`` instance.
49+
///
50+
/// ## Discussion
51+
///
52+
/// - Note: This function does not support HTTP CONNECT proxies.
53+
///
54+
/// - Warning: This is deprecated in libgit2 and will be removed in the next
55+
/// major release. Use ``GitStreamRegistration/Initialize`` instead.
56+
///
57+
/// ## C Equivalent
58+
///
59+
/// [`git_stream_register_tls()`](https://libgit2.org/docs/reference/main/sys/stream/git_stream_register_tls.html)
60+
public func gitStreamRegisterTLS(
61+
ctor: GitStreamCB?
62+
) -> GitErrorCode
63+
{
64+
return withCConversion
65+
{
66+
return git_stream_register_tls(ctor)
67+
}
68+
}
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 ``GitStream``.
11+
///
12+
/// ## C Equivalent
13+
///
14+
/// [`GIT_STREAM_VERSION`](https://libgit2.org/docs/reference/main/sys/stream/GIT_STREAM_VERSION.html)
15+
public let gitStreamVersion: Int32 = 1

0 commit comments

Comments
 (0)