Skip to content

Commit c1c5139

Browse files
Merge pull request #86 from swift-developer-tools/feature/transport-advanced
Add Transport (Advanced) bindings
2 parents f0e13e0 + 0ae6161 commit c1c5139

38 files changed

Lines changed: 2080 additions & 371 deletions

Sources/SwiftLibgit2/ODB/ODB-Callbacks.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import CLibgit2
1313

1414
/// The callback invoked for each object.
1515
/// - Parameters:
16-
/// - blobID: The ID of an object in the object database.
16+
/// - id: The ID of the object in the object database.
1717
/// - payload: The payload provided by the caller.
1818
/// - Returns: `0` on success, or an error code.
1919
///
2020
/// ## C Equivalent
2121
///
22-
/// [`git_note_foreach_cb()`](https://libgit2.org/docs/reference/main/notes/git_note_foreach_cb.html)
22+
/// [`git_odb_foreach_cb()`](https://libgit2.org/docs/reference/main/odb/git_odb_foreach_cb.html)
2323
public typealias GitODBForEachCB = @convention(c)
2424
(
2525
UnsafePointer<git_oid>?,

Sources/SwiftLibgit2/Remote-Advanced/Remote-Advanced-Functions.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import CLibgit2
1111

1212

1313

14-
// TODO: Replace `git_transport_remote_connect_options()` in documentation.
1514
/// Frees the memory allocated for the given `git_remote_connect_options`
1615
/// instance.
1716
/// - Parameter opts: The remote connect options to free.
@@ -23,7 +22,7 @@ import CLibgit2
2322
///
2423
/// - Important: This function must be called only with a
2524
/// `git_remote_connect_options` instance that was returned by
26-
/// `git_transport_remote_connect_options()`.
25+
/// ``gitTransportRemoteConnectOptions(out:transport:)``.
2726
///
2827
/// ## C Equivalent
2928
///

Sources/SwiftLibgit2/Remote/Remote-Structs.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public struct GitRemoteCreateOptions: CStructMutable, WithCConvertible
2626
/// The default value is ``gitRemoteCreateOptionsVersion``.
2727
public var version : UInt32
2828

29-
/// The repository that should own the remote. The underlying type must
30-
/// be `git_repository`.
29+
/// The repository to own the remote. The underlying type must be
30+
/// `git_repository`.
3131
///
3232
/// ## Discussion
3333
///

Sources/SwiftLibgit2/Stream-Advanced/Stream-Advanced-Enums.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public enum GitStreamT: UInt32, CEnum
2626

2727

2828

29-
/// Initializes a ``GitStreamT`` instance from the given `git_stream_t`
29+
/// Initializes a ``GitStreamT`` instance from the given `git_stream_t`
3030
/// instance.
3131
/// - Parameter stream: The `git_stream_t` instance to use.
3232
internal init?(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Transport (Advanced)
2+
3+
Custom transports.
4+
5+
## Topics
6+
7+
### Structs
8+
9+
- ``GitFetchNegotiation``
10+
- ``GitTransport``
11+
- ``GitSmartSubtransportStream``
12+
- ``GitSmartSubtransport``
13+
- ``GitSmartSubtransportDefinition``
14+
15+
### Macros
16+
17+
- ``gitTransportVersion``
18+
19+
### Enums
20+
21+
- ``GitSmartServiceT``
22+
23+
### Callbacks
24+
25+
- ``GitSmartSubtransportCB``
26+
27+
### Functions
28+
29+
- ``gitTransportInit(transport:version:)``
30+
- ``gitTransportNew(out:owner:url:)``
31+
- ``gitTransportSSHWithPaths(out:owner:payload:)``
32+
- ``gitTransportRegister(prefix:cb:param:)``
33+
- ``gitTransportUnregister(prefix:)``
34+
- ``gitTransportLocal(out:owner:payload:)``
35+
- ``gitTransportSmart(out:owner:payload:)``
36+
- ``gitTransportSmartCertificateCheck(transport:cert:valid:hostName:)``
37+
- ``gitTransportSmartCredentials(out:transport:user:methods:)``
38+
- ``gitTransportRemoteConnectOptions(out:transport:)``
39+
- ``gitSmartSubtransportHTTP(out:owner:param:)``
40+
- ``gitSmartSubtransportGit(out:owner:param:)``
41+
- ``gitSmartSubtransportSSH(out:owner:param:)``
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 subtransport for the given smart
15+
/// transport.
16+
/// - Parameters:
17+
/// - out: The pointer in which to store the smart subtransport.
18+
/// - owner: The transport owner to use.
19+
/// - param: The input parameter to use.
20+
/// - Returns: `0` on success, or an error code.
21+
///
22+
/// ## C Equivalent
23+
///
24+
/// [`git_smart_subtransport_cb()`](https://libgit2.org/docs/reference/main/sys/transport/git_smart_subtransport_cb.html)
25+
public typealias GitSmartSubtransportCB = @convention(c)
26+
(
27+
UnsafeMutablePointer<UnsafeMutablePointer<git_smart_subtransport>?>?,
28+
UnsafeMutablePointer<git_transport>?,
29+
UnsafeMutableRawPointer?
30+
) -> Int32
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 actions that a smart transport can ask a subtransport to perform.
15+
///
16+
/// ## C Equivalent
17+
///
18+
/// [`git_smart_service_t`](https://libgit2.org/docs/reference/main/sys/transport/git_smart_service_t.html)
19+
public enum GitSmartServiceT: UInt32, CEnum
20+
{
21+
/// List the references available for fetching or cloning.
22+
///
23+
/// ## Discussion
24+
///
25+
/// This is equivalent to `git-upload-pack --advertise-refs` or
26+
/// `git-upload-pack --http-backend-info-refs`.
27+
case gitServiceUploadPackLS = 1
28+
29+
/// Fetch objects from the remote repository.
30+
///
31+
/// ## Discussion
32+
///
33+
/// This is equivalent to `git-upload-pack`.
34+
case gitServiceUploadPack = 2
35+
36+
/// List the references available for pushing.
37+
///
38+
/// ## Discussion
39+
///
40+
/// This is equivalent to `git-receive-pack --http-backend-info-refs`.
41+
case gitServiceReceivePackLS = 3
42+
43+
/// Push objects to the remote repository.
44+
///
45+
/// ## Discussion
46+
///
47+
/// This is equivalent to `git-receive-pack`.
48+
case gitServiceReceivePack = 4
49+
50+
51+
52+
/// Initializes a ``GitSmartServiceT`` instance from the given
53+
/// `git_smart_service_t` instance.
54+
/// - Parameter smartService: The `git_smart_service_t` instance to use.
55+
internal init?(
56+
cValue smartService: git_smart_service_t
57+
)
58+
{
59+
switch smartService
60+
{
61+
case GIT_SERVICE_UPLOADPACK_LS : self = .gitServiceUploadPackLS
62+
case GIT_SERVICE_UPLOADPACK : self = .gitServiceUploadPack
63+
case GIT_SERVICE_RECEIVEPACK_LS : self = .gitServiceReceivePackLS
64+
case GIT_SERVICE_RECEIVEPACK : self = .gitServiceReceivePack
65+
default : return nil
66+
}
67+
}
68+
69+
70+
71+
/// Converts the ``GitSmartServiceT`` instance into a `git_smart_service_t`
72+
/// instance.
73+
/// - Returns: The `git_smart_service_t` instance.
74+
internal func cValue() -> git_smart_service_t
75+
{
76+
switch self
77+
{
78+
case .gitServiceUploadPackLS : return GIT_SERVICE_UPLOADPACK_LS
79+
case .gitServiceUploadPack : return GIT_SERVICE_UPLOADPACK
80+
case .gitServiceReceivePackLS : return GIT_SERVICE_RECEIVEPACK_LS
81+
case .gitServiceReceivePack : return GIT_SERVICE_RECEIVEPACK
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)