@@ -200,8 +200,18 @@ class RepositoriesManager(val client: LocalModelClient) {
200
200
}
201
201
202
202
suspend fun removeBranches (repository : RepositoryId , branchNames : Set <String >) {
203
+ return store.runTransactionSuspendable {
204
+ removeBranchesBlocking(repository, branchNames)
205
+ }
206
+ }
207
+
208
+ /* *
209
+ * Same as [removeBranches] but blocking.
210
+ * Caller is expected to execute it outside the request thread.
211
+ */
212
+ fun removeBranchesBlocking (repository : RepositoryId , branchNames : Set <String >) {
203
213
if (branchNames.isEmpty()) return
204
- store.runTransactionSuspendable {
214
+ store.runTransaction {
205
215
val key = branchListKey(repository)
206
216
val existingBranches = store[key]?.lines()?.toSet() ? : emptySet()
207
217
val remainingBranches = existingBranches - branchNames
@@ -213,9 +223,18 @@ class RepositoriesManager(val client: LocalModelClient) {
213
223
}
214
224
215
225
suspend fun mergeChanges (branch : BranchReference , newVersionHash : String ): String {
216
- var result: String? = null
217
- store.runTransactionSuspendable {
218
- val headHash = getVersionHashInsideTransaction(branch)
226
+ return store.runTransactionSuspendable {
227
+ mergeChangesBlocking(branch, newVersionHash)
228
+ }
229
+ }
230
+
231
+ /* *
232
+ * Same as [mergeChanges] but blocking.
233
+ * Caller is expected to execute it outside the request thread.
234
+ */
235
+ fun mergeChangesBlocking (branch : BranchReference , newVersionHash : String ): String {
236
+ return store.runTransaction {
237
+ val headHash = getVersionHashBlocking(branch)
219
238
val mergedHash = if (headHash == null ) {
220
239
newVersionHash
221
240
} else {
@@ -232,9 +251,8 @@ class RepositoriesManager(val client: LocalModelClient) {
232
251
putVersionHash(branch, mergedHash)
233
252
ensureRepositoriesAreInList(setOf (branch.repositoryId))
234
253
ensureBranchesAreInList(branch.repositoryId, setOf (branch.branchName))
235
- result = mergedHash
254
+ mergedHash
236
255
}
237
- return result!!
238
256
}
239
257
240
258
suspend fun getVersion (branch : BranchReference ): CLVersion ? {
@@ -243,12 +261,24 @@ class RepositoriesManager(val client: LocalModelClient) {
243
261
244
262
suspend fun getVersionHash (branch : BranchReference ): String? {
245
263
return store.runTransactionSuspendable {
246
- getVersionHashInsideTransaction (branch)
264
+ getVersionHashBlocking (branch)
247
265
}
248
266
}
249
267
250
- private fun getVersionHashInsideTransaction (branch : BranchReference ): String? {
251
- return store[branchKey(branch)] ? : store[legacyBranchKey(branch)]?.also { store.put(branchKey(branch), it, true ) }
268
+ /* *
269
+ * Same as [getVersionHash] but blocking.
270
+ * Caller is expected to execute it outside the request thread.
271
+ */
272
+ private fun getVersionHashBlocking (branch : BranchReference ): String? {
273
+ return store.runTransaction {
274
+ store[branchKey(branch)] ? : store[legacyBranchKey(branch)]?.also {
275
+ store.put(
276
+ branchKey(branch),
277
+ it,
278
+ true ,
279
+ )
280
+ }
281
+ }
252
282
}
253
283
254
284
private fun putVersionHash (branch : BranchReference , hash : String? ) {
@@ -368,6 +398,7 @@ class ObjectDataMap(private val byHashObjects: Map<String, String>) : ObjectData
368
398
init {
369
399
HashUtil .checkObjectHashes(byHashObjects)
370
400
}
401
+
371
402
override suspend fun asMap (): Map <String , String > = byHashObjects
372
403
override fun asFlow (): Flow <Pair <String , String >> = byHashObjects.entries.asFlow().map { it.toPair() }
373
404
}
0 commit comments