Fix rev
parent: tbd commit: 088af7f
1 | use ; |
2 | |
3 | use ; |
4 | use |
5 | , |
6 | , |
7 | , | ObjectBackend
8 | , |
9 | |
10 | Commit, DefaultBranch, Description, LatestCommit, Repository, |
11 | RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffRequest, RepositoryFile, |
12 | RepositoryFileFromIdRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, |
13 | RepositorySummary, RepositoryView, Visibility, |
14 | , |
15 | , |
16 | , |
17 | , |
18 | ; |
19 | |
20 | use DatabaseBackend; |
21 | |
22 | |
23 | |
24 | O: GiteratedObject, |
25 | D: GiteratedOperation<O>, |
26 | S: Send + Sync + Clone, |
27 | > |
28 | |
29 | ; |
30 | ; |
31 | |
32 | async |
33 | &self, |
34 | object: &O, |
35 | operation: D, |
36 | state: S, |
37 | ; |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | F: FnMut( |
44 | &O, |
45 | D, |
46 | S, |
47 | ) -> |
48 | , |
49 | > + Send |
50 | + Sync |
51 | + Clone, |
52 | O: GiteratedObject + Send + Sync, |
53 | D: + 'static, |
54 | : Send, | Failure
55 | S: Send + Sync + Clone + 'static, |
56 | |
57 | |
58 | operation_name |
59 | |
60 | |
61 | |
62 | object_name |
63 | |
64 | |
65 | async |
66 | &self, |
67 | object: &O, |
68 | operation: D, |
69 | state: S, |
70 | |
71 | self.clone .await |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | dyn Fn( |
78 | AnyObject, |
79 | AnyOperation, |
80 | S, |
81 | ) |
82 | |
83 | + Send |
84 | + Sync, |
85 | >, |
86 | ); |
87 | |
88 | |
89 | |
90 | O: GiteratedObject + Send + Sync, |
91 | D: + 'static, |
92 | F: + Send + Sync + 'static + Clone, |
93 | > |
94 | handler: F, |
95 | |
96 | let handler = new; |
97 | Self |
98 | let handler = handler.clone; |
99 | async move |
100 | let handler = handler.clone; |
101 | let object: O = from_object_str .unwrap; |
102 | let operation: D = from_value .unwrap; |
103 | |
104 | let result = handler.handle .await; |
105 | result |
106 | .map |
107 | .map_err |
108 | => | Operation
109 | Operation |
110 | |
111 | => Internal, | Internal
112 | => Unhandled, | Unhandled
113 | |
114 | |
115 | .boxed |
116 | |
117 | |
118 | |
119 | async |
120 | &mut self, |
121 | object: AnyObject, |
122 | operation: AnyOperation, |
123 | state: S, |
124 | |
125 | self.0 .await |
126 | |
127 | |
128 | |
129 | |
130 | object: &User, |
131 | _operation: UserRepositoriesRequest, |
132 | state: DatabaseBackend, |
133 | |
134 | let object = object.clone; |
135 | |
136 | async move |
137 | let mut user_backend = state.user_backend.lock .await; |
138 | let repositories = user_backend |
139 | .repositories_for_user |
140 | .await |
141 | .map_err?; |
142 | |
143 | Ok |
144 | |
145 | .boxed |
146 | |
147 | |
148 | |
149 | object: &User, |
150 | operation: , |
151 | state: DatabaseBackend, |
152 | |
153 | let object = object.clone; |
154 | |
155 | async move |
156 | let mut user_backend = state.user_backend.lock .await; |
157 | let value = user_backend |
158 | .get_value |
159 | .await |
160 | .map_err?; |
161 | |
162 | Ok |
163 | |
164 | .boxed |
165 | |
166 | |
167 | |
168 | object: &User, |
169 | operation: , |
170 | state: DatabaseBackend, |
171 | |
172 | let object = object.clone; |
173 | |
174 | async move |
175 | let mut user_backend = state.user_backend.lock .await; |
176 | let value = user_backend |
177 | .get_setting |
178 | .await |
179 | .map_err?; |
180 | |
181 | Ok |
182 | |
183 | .boxed |
184 | |
185 | |
186 | |
187 | object: &User, |
188 | operation: , |
189 | state: DatabaseBackend, |
190 | |
191 | let object = object.clone; |
192 | |
193 | async move |
194 | let mut user_backend = state.user_backend.lock .await; |
195 | let value = user_backend |
196 | .write_setting |
197 | .await |
198 | .map_err?; |
199 | |
200 | Ok |
201 | |
202 | .boxed |
203 | |
204 | |
205 | |
206 | object: &Repository, |
207 | operation: RepositoryInfoRequest, |
208 | state: DatabaseBackend, |
209 | |
210 | let object = object.clone; |
211 | |
212 | async move |
213 | let mut object = state |
214 | . |
215 | .await |
216 | .unwrap; |
217 | |
218 | let mut repository_backend = state.repository_backend.lock .await; |
219 | let tree = repository_backend |
220 | .repository_file_inspect |
221 | None, |
222 | object.object, |
223 | &RepositoryFileInspectRequest |
224 | extra_metadata: operation.extra_metadata, |
225 | path: operation.path, |
226 | rev: operation.rev.clone, |
227 | , |
228 | |
229 | .await |
230 | .map_err?; |
231 | drop; |
232 | |
233 | let info = RepositoryView |
234 | name: object.object .name.clone, |
235 | owner: object.object .owner.clone, |
236 | description: object. .await.ok, |
237 | visibility: object |
238 | . |
239 | .await |
240 | .map_err?, |
241 | default_branch: object |
242 | . |
243 | .await |
244 | .map_err?, |
245 | // TODO: Can't be a simple get function, this needs to be returned alongside the tree as this differs depending on the rev and path. |
246 | latest_commit: object. .await.ok, |
247 | tree_rev: operation.rev, |
248 | tree, |
249 | ; |
250 | |
251 | Ok |
252 | |
253 | .boxed |
254 | |
255 | |
256 | |
257 | object: &Repository, |
258 | operation: RepositoryFileFromIdRequest, |
259 | state: DatabaseBackend, |
260 | |
261 | let object = object.clone; |
262 | |
263 | async move |
264 | let object = state |
265 | . |
266 | .await |
267 | .unwrap; |
268 | |
269 | let mut repository_backend = state.repository_backend.lock .await; |
270 | let file = repository_backend |
271 | .repository_file_from_id |
272 | None, |
273 | object.object, |
274 | &RepositoryFileFromIdRequest, |
275 | |
276 | .await |
277 | .map_err?; |
278 | drop; |
279 | |
280 | Ok |
281 | |
282 | .boxed |
283 | |
284 | |
285 | |
286 | object: &Repository, |
287 | operation: RepositoryDiffRequest, |
288 | state: DatabaseBackend, |
289 | |
290 | let object = object.clone; |
291 | |
292 | async move |
293 | let object = state |
294 | . |
295 | .await |
296 | .unwrap; |
297 | |
298 | let mut repository_backend = state.repository_backend.lock .await; |
299 | let file = repository_backend |
300 | .repository_diff |
301 | .await |
302 | .map_err?; |
303 | drop; |
304 | |
305 | Ok |
306 | |
307 | .boxed |
308 | |
309 | |
310 | |
311 | object: &Repository, |
312 | operation: RepositoryCommitBeforeRequest, |
313 | state: DatabaseBackend, |
314 | |
315 | let object = object.clone; |
316 | |
317 | async move |
318 | let object = state |
319 | . |
320 | .await |
321 | .unwrap; |
322 | |
323 | let mut repository_backend = state.repository_backend.lock .await; |
324 | let file = repository_backend |
325 | .repository_commit_before |
326 | .await |
327 | .map_err?; |
328 | drop; |
329 | |
330 | Ok |
331 | |
332 | .boxed |
333 | |
334 | |
335 | |
336 | object: &Repository, |
337 | operation: , |
338 | state: DatabaseBackend, |
339 | |
340 | let object = object.clone; |
341 | |
342 | async move |
343 | let mut repository_backend = state.repository_backend.lock .await; |
344 | let value = repository_backend |
345 | .get_value |
346 | .await |
347 | .map_err |
348 | Internal |
349 | ?; |
350 | |
351 | Ok |
352 | |
353 | .boxed |
354 | |
355 | |
356 | |
357 | object: &Repository, |
358 | operation: , |
359 | state: DatabaseBackend, |
360 | |
361 | let object = object.clone; |
362 | |
363 | async move |
364 | let mut repository_backend = state.repository_backend.lock .await; |
365 | let value = repository_backend |
366 | .get_setting |
367 | .await |
368 | .map_err?; |
369 | |
370 | Ok |
371 | |
372 | .boxed |
373 | |
374 | |
375 | |
376 | object: &Repository, |
377 | operation: , |
378 | state: DatabaseBackend, |
379 | |
380 | let object = object.clone; |
381 | |
382 | async move |
383 | let mut repository_backend = state.repository_backend.lock .await; |
384 | let value = repository_backend |
385 | .write_setting |
386 | .await |
387 | .map_err?; |
388 | |
389 | Ok |
390 | |
391 | .boxed |
392 | |
393 | |
394 | |
395 | operations: , |
396 | |
397 | |
398 | |
399 | |
400 | Self |
401 | operations: new, |
402 | |
403 | |
404 | |
405 | |
406 | |
407 | |
408 | O: GiteratedObject + Send + Sync, |
409 | D: + 'static, |
410 | H: + Send + Sync + 'static + Clone, |
411 | > |
412 | &mut self, |
413 | handler: H, |
414 | |
415 | let operation_name = handler.operation_name .to_string; |
416 | |
417 | let wrapped = new; |
418 | |
419 | self.operations.insert; |
420 | |
421 | self |
422 | |
423 | |
424 | pub async |
425 | &mut self, |
426 | object: &O, |
427 | operation_name: &str, |
428 | operation: AnyOperation, |
429 | state: S, |
430 | |
431 | if let Some = self.operations.get_mut |
432 | handler |
433 | .handle |
434 | .await |
435 | else |
436 | Err |
437 | "unknown operation: {}" |
438 | operation_name |
439 | ) |
440 | |
441 | |
442 | |
443 |