File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1167,6 +1167,54 @@ internal extension Repository
11671167
11681168
11691169
1170+ /// Calls the given closure with a ``Repository`` instance and a pointer
1171+ /// to an opened reference database.
1172+ /// - Parameter body: The closure to call.
1173+ /// - Returns: The return value of the given closure.
1174+ /// - Throws: An error if an operation fails.
1175+ static func withRefDB< T> (
1176+ _ body: ( Repository , OpaquePointer ) throws -> T
1177+ ) throws -> T
1178+ {
1179+ return try Repository . withRepository
1180+ {
1181+ repository in
1182+
1183+ var refDBPointer : OpaquePointer ? = nil
1184+
1185+ defer
1186+ {
1187+ gitRefDBFree ( refDB: refDBPointer)
1188+ }
1189+
1190+
1191+
1192+ let refDBOpenResult : GitErrorCode = gitRefDBOpen (
1193+ out: & refDBPointer,
1194+ repo: repository. pointer
1195+ )
1196+
1197+ XCTAssertOK ( refDBOpenResult)
1198+
1199+ guard let refDBPointer: OpaquePointer = refDBPointer
1200+ else
1201+ {
1202+ throw NSError . makeError (
1203+ " The reference database pointer was nil. "
1204+ )
1205+ }
1206+
1207+
1208+
1209+ return try body (
1210+ repository,
1211+ refDBPointer
1212+ )
1213+ }
1214+ }
1215+
1216+
1217+
11701218 /// Calls the given closure with a ``Repository`` instance and a pointer
11711219 /// to a tree.
11721220 /// - Parameter body: The closure to call.
Original file line number Diff line number Diff line change @@ -15,6 +15,21 @@ import XCTest
1515
1616final class RefDBTests : XCTestCaseStopOnFail
1717{
18+ func testGitRefDBCompress( ) throws
19+ {
20+ try Repository . withRefDB
21+ {
22+ _, refDBPointer in
23+
24+ let refDBCompressResult : GitErrorCode
25+ = gitRefDBCompress ( out: refDBPointer)
26+
27+ XCTAssertOK ( refDBCompressResult)
28+ }
29+ }
30+
31+
32+
1833 func testGitRefDBFree( ) throws
1934 {
2035 gitRefDBFree ( refDB: nil )
@@ -49,41 +64,11 @@ final class RefDBTests: XCTestCaseStopOnFail
4964
5065
5166
52- func testGitRefDBOpenAndCompress ( ) throws
67+ func testGitRefDBOpen ( ) throws
5368 {
54- try Repository . withRepository
69+ try Repository . withRefDB
5570 {
56- repository in
57-
58- var refDBPointer : OpaquePointer ? = nil
59-
60- defer
61- {
62- gitRefDBFree ( refDB: refDBPointer)
63- }
64-
65-
66-
67- let refDBOpenResult : GitErrorCode = gitRefDBOpen (
68- out: & refDBPointer,
69- repo: repository. pointer
70- )
71-
72- XCTAssertOK ( refDBOpenResult)
73-
74- guard let refDBPointer: OpaquePointer = refDBPointer
75- else
76- {
77- XCTFail ( " The reference database pointer was nil. " )
78- return
79- }
80-
81-
82-
83- let refDBCompressResult : GitErrorCode
84- = gitRefDBCompress ( out: refDBPointer)
85-
86- XCTAssertOK ( refDBCompressResult)
71+ _, _ in
8772 }
8873 }
8974}
You can’t perform that action at this time.
0 commit comments