Skip to content

Commit 6f5cafe

Browse files
Merge pull request #83 from swift-developer-tools/feature/remote-advanced
Add Remote (Advanced) bindings
2 parents 522bee5 + 873deb0 commit 6f5cafe

4 files changed

Lines changed: 177 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 flags indicating a remote's capabilities.
15+
///
16+
/// ## C Equivalent
17+
///
18+
/// [`git_remote_capability_t`](https://libgit2.org/docs/reference/main/sys/remote/git_remote_capability_t.html)
19+
public struct GitRemoteCapabilityT: COptionSet
20+
{
21+
/// The raw value to use.
22+
public let rawValue: UInt32
23+
24+
25+
26+
/// Initializes a ``GitRemoteCapabilityT`` instance from the given raw
27+
/// value.
28+
/// - Parameter rawValue: The raw value to use.
29+
public init(
30+
rawValue: UInt32
31+
)
32+
{
33+
self.rawValue = rawValue
34+
}
35+
36+
37+
38+
/// Initializes a ``GitRemoteCapabilityT`` instance from the given
39+
/// `git_remote_capability_t` instance.
40+
/// - Parameter remoteCapability: The `git_remote_capability_t` instance
41+
/// to use.
42+
internal init(
43+
cValue remoteCapability: git_remote_capability_t
44+
)
45+
{
46+
self.rawValue = remoteCapability.rawValue
47+
}
48+
49+
50+
51+
/// The remote supports fetching an advertised object by its ID.
52+
public static let gitRemoteCapabilityTipOID = GitRemoteCapabilityT(rawValue: GIT_REMOTE_CAPABILITY_TIP_OID.rawValue)
53+
54+
/// The remote supports fetching an individual reachable object.
55+
public static let gitRemoteCapabilityReachableOID = GitRemoteCapabilityT(rawValue: GIT_REMOTE_CAPABILITY_REACHABLE_OID.rawValue)
56+
57+
/// The remote supports push options.
58+
public static let gitRemoteCapabilityPushOptions = GitRemoteCapabilityT(rawValue: GIT_REMOTE_CAPABILITY_PUSH_OPTIONS.rawValue)
59+
60+
61+
62+
/// Converts the ``GitRemoteCapabilityT`` instance into a
63+
/// `git_remote_capability_t` instance.
64+
/// - Returns: The `git_remote_capability_t` instance.
65+
internal func cValue() -> git_remote_capability_t
66+
{
67+
return git_remote_capability_t(rawValue)
68+
}
69+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
// TODO: Replace `git_transport_remote_connect_options()` in documentation.
15+
/// Frees the memory allocated for the given `git_remote_connect_options`
16+
/// instance.
17+
/// - Parameter opts: The remote connect options to free.
18+
///
19+
/// ## Discussion
20+
///
21+
/// This function does not free the `git_remote_connect_options` instance
22+
/// itself. It disposes the libgit2-initialized fields of the given options.
23+
///
24+
/// - Important: This function must be called only with a
25+
/// `git_remote_connect_options` instance that was returned by
26+
/// `git_transport_remote_connect_options()`.
27+
///
28+
/// ## C Equivalent
29+
///
30+
/// [`git_remote_connect_options_dispose()`](https://libgit2.org/docs/reference/main/sys/remote/git_remote_connect_options_dispose.html)
31+
public func gitRemoteConnectOptionsDispose(
32+
opts: UnsafeMutablePointer<git_remote_connect_options>?
33+
)
34+
{
35+
guard let opts: UnsafeMutablePointer<git_remote_connect_options> = opts
36+
else
37+
{
38+
return
39+
}
40+
41+
git_remote_connect_options_dispose(opts)
42+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Remote (Advanced)
2+
3+
Low-level remote custom transports.
4+
5+
## Topics
6+
7+
### Enums
8+
9+
- ``GitRemoteCapabilityT``
10+
11+
### Functions
12+
13+
- ``gitRemoteConnectOptionsDispose(opts:)``
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
import XCTest
12+
@testable import SwiftLibgit2
13+
14+
15+
16+
final class RemoteAdvancedTests: XCTestCaseStopOnFail
17+
{
18+
func testGitRemoteCapabilityT() throws
19+
{
20+
XCTAssertEqual(GitRemoteCapabilityT.gitRemoteCapabilityTipOID.rawValue, GIT_REMOTE_CAPABILITY_TIP_OID.rawValue)
21+
XCTAssertEqual(GitRemoteCapabilityT.gitRemoteCapabilityReachableOID.rawValue, GIT_REMOTE_CAPABILITY_REACHABLE_OID.rawValue)
22+
XCTAssertEqual(GitRemoteCapabilityT.gitRemoteCapabilityPushOptions.rawValue, GIT_REMOTE_CAPABILITY_PUSH_OPTIONS.rawValue)
23+
24+
XCTAssertEqual(GitRemoteCapabilityT(rawValue: 123).cValue().rawValue, 123)
25+
26+
XCTAssertEqual(GitRemoteCapabilityT.gitRemoteCapabilityTipOID.cValue(), GIT_REMOTE_CAPABILITY_TIP_OID)
27+
XCTAssertEqual(GitRemoteCapabilityT.gitRemoteCapabilityReachableOID.cValue(), GIT_REMOTE_CAPABILITY_REACHABLE_OID)
28+
XCTAssertEqual(GitRemoteCapabilityT.gitRemoteCapabilityPushOptions.cValue(), GIT_REMOTE_CAPABILITY_PUSH_OPTIONS)
29+
30+
XCTAssertEqual(GitRemoteCapabilityT(cValue: GIT_REMOTE_CAPABILITY_TIP_OID), .gitRemoteCapabilityTipOID)
31+
XCTAssertEqual(GitRemoteCapabilityT(cValue: GIT_REMOTE_CAPABILITY_REACHABLE_OID), .gitRemoteCapabilityReachableOID)
32+
XCTAssertEqual(GitRemoteCapabilityT(cValue: GIT_REMOTE_CAPABILITY_PUSH_OPTIONS), .gitRemoteCapabilityPushOptions)
33+
34+
35+
36+
let flags: GitRemoteCapabilityT =
37+
[
38+
.gitRemoteCapabilityTipOID,
39+
.gitRemoteCapabilityReachableOID
40+
]
41+
42+
XCTAssertTrue(flags.contains(.gitRemoteCapabilityTipOID))
43+
XCTAssertTrue(flags.contains(.gitRemoteCapabilityReachableOID))
44+
XCTAssertFalse(flags.contains(.gitRemoteCapabilityPushOptions))
45+
}
46+
47+
48+
49+
func testGitRemoteConnectOptionsDispose() throws
50+
{
51+
gitRemoteConnectOptionsDispose(opts: nil)
52+
}
53+
}

0 commit comments

Comments
 (0)