Simple branch staleness implementation
parent: tbd commit: efc3f02
1 | use |
2 | , | UserAuthenticationToken
3 | , |
4 | |
5 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
6 | , |
7 | , | ObjectBackend
8 | |
9 | Commit, DefaultBranch, Description, LatestCommit, Repository, RepositoryBranch, |
10 | RepositoryBranchesRequest, RepositoryCommitBeforeRequest, RepositoryCommitFromIdRequest, |
11 | RepositoryDiff, RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, |
12 | RepositoryFileFromIdRequest, RepositoryFileFromPathRequest, RepositoryFileInspectRequest, |
13 | RepositoryInfoRequest, RepositoryLastCommitOfFileRequest, RepositoryStatistics, |
14 | RepositoryStatisticsRequest, RepositorySummary, RepositoryView, Visibility, |
15 | , |
16 | , |
17 | ; |
18 | use ; |
19 | |
20 | use DatabaseBackend; |
21 | |
22 | pub async |
23 | object: User, |
24 | _operation: UserRepositoriesRequest, |
25 | state: DatabaseBackend, |
26 | OperationState | : ,
27 | requester: , |
28 | |
29 | let object = object.clone; |
30 | |
31 | let mut user_backend = state.user_backend.lock .await; |
32 | let repositories_response = user_backend |
33 | .repositories_for_user |
34 | .await |
35 | .as_internal_error?; |
36 | drop; |
37 | let mut repositories_backend = state.repository_backend.lock .await; |
38 | |
39 | let mut repositories = vec!; |
40 | |
41 | for repository in repositories_response |
42 | if repositories_backend |
43 | .exists |
44 | .await |
45 | .as_internal_error? |
46 | |
47 | repositories.push; |
48 | |
49 | |
50 | |
51 | Ok |
52 | |
53 | |
54 | pub async |
55 | object: Repository, |
56 | operation: RepositoryInfoRequest, |
57 | state: DatabaseBackend, |
58 | OperationState | : ,
59 | backend: GiteratedStack, |
60 | requester: , |
61 | |
62 | info!; |
63 | let mut object = backend |
64 | . |
65 | .await |
66 | .unwrap; |
67 | let mut repository_backend = state.repository_backend.lock .await; |
68 | let tree = repository_backend |
69 | .repository_file_inspect |
70 | &requester, |
71 | object.object, |
72 | &RepositoryFileInspectRequest |
73 | extra_metadata: operation.extra_metadata, |
74 | path: operation.path.clone, |
75 | rev: operation.rev.clone, |
76 | , |
77 | |
78 | .await |
79 | .as_internal_error?; |
80 | |
81 | let statistics = repository_backend |
82 | .repository_get_statistics |
83 | &requester, |
84 | object.object, |
85 | &RepositoryStatisticsRequest |
86 | rev: operation.rev.clone, |
87 | , |
88 | |
89 | .await |
90 | .as_internal_error?; |
91 | drop; |
92 | |
93 | let info = RepositoryView |
94 | name: object.object .name.clone, |
95 | owner: object.object .owner.clone, |
96 | description: object. .await.ok, |
97 | visibility: object |
98 | . |
99 | .await |
100 | .as_internal_error?, |
101 | default_branch: object |
102 | . |
103 | .await |
104 | .as_internal_error?, |
105 | // 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. |
106 | latest_commit: object. .await.ok, |
107 | stats: statistics, |
108 | tree_rev: operation.rev.clone, |
109 | tree, |
110 | ; |
111 | |
112 | Ok |
113 | |
114 | |
115 | pub async |
116 | object: Repository, |
117 | operation: RepositoryStatisticsRequest, |
118 | state: DatabaseBackend, |
119 | OperationState | : ,
120 | backend: GiteratedStack, |
121 | requester: , |
122 | |
123 | let object = backend |
124 | . |
125 | .await |
126 | .unwrap; |
127 | |
128 | let mut repository_backend = state.repository_backend.lock .await; |
129 | let statistics = repository_backend |
130 | .repository_get_statistics |
131 | &requester, |
132 | object.object, |
133 | &RepositoryStatisticsRequest |
134 | rev: operation.rev.clone, |
135 | , |
136 | |
137 | .await |
138 | .as_internal_error?; |
139 | drop; |
140 | |
141 | Ok |
142 | |
143 | |
144 | pub async |
145 | object: Repository, |
146 | operation: RepositoryBranchesRequest, |
147 | state: DatabaseBackend, |
148 | OperationState | : ,
149 | backend: GiteratedStack, |
150 | requester: , |
151 | |
152 | let mut object = backend |
153 | . |
154 | .await |
155 | .unwrap; |
156 | |
157 | let mut repository_backend = state.repository_backend.lock .await; |
158 | let branches = repository_backend |
159 | .repository_get_branches |
160 | &requester, |
161 | &mut object, |
162 | OperationState, |
163 | &operation, |
164 | |
165 | .await |
166 | .as_internal_error?; |
167 | drop; |
168 | |
169 | Ok |
170 | |
171 | |
172 | pub async |
173 | object: Repository, |
174 | operation: RepositoryFileFromIdRequest, |
175 | state: DatabaseBackend, |
176 | OperationState | : ,
177 | backend: GiteratedStack, |
178 | requester: , |
179 | |
180 | let object = backend |
181 | . |
182 | .await |
183 | .unwrap; |
184 | |
185 | let mut repository_backend = state.repository_backend.lock .await; |
186 | let file = repository_backend |
187 | .repository_file_from_id |
188 | &requester, |
189 | object.object, |
190 | &RepositoryFileFromIdRequest, |
191 | |
192 | .await |
193 | .as_internal_error?; |
194 | drop; |
195 | |
196 | Ok |
197 | |
198 | |
199 | pub async |
200 | object: Repository, |
201 | operation: RepositoryFileFromPathRequest, |
202 | state: DatabaseBackend, |
203 | OperationState | : ,
204 | backend: GiteratedStack, |
205 | requester: , |
206 | |
207 | let object = backend |
208 | . |
209 | .await |
210 | .unwrap; |
211 | |
212 | let mut repository_backend = state.repository_backend.lock .await; |
213 | let file = repository_backend |
214 | .repository_file_from_path |
215 | &requester, |
216 | object.object, |
217 | &RepositoryFileFromPathRequest |
218 | rev: operation.rev.clone, |
219 | path: operation.path.clone, |
220 | , |
221 | |
222 | .await |
223 | .as_internal_error?; |
224 | drop; |
225 | |
226 | Ok |
227 | |
228 | |
229 | pub async |
230 | object: Repository, |
231 | operation: RepositoryLastCommitOfFileRequest, |
232 | state: DatabaseBackend, |
233 | OperationState | : ,
234 | backend: GiteratedStack, |
235 | requester: , |
236 | |
237 | let object = backend |
238 | . |
239 | .await |
240 | .unwrap; |
241 | |
242 | let mut repository_backend = state.repository_backend.lock .await; |
243 | let commit = repository_backend |
244 | .repository_last_commit_of_file |
245 | &requester, |
246 | object.object, |
247 | &RepositoryLastCommitOfFileRequest |
248 | start_commit: operation.start_commit.clone, |
249 | path: operation.path.clone, |
250 | , |
251 | |
252 | .await |
253 | .as_internal_error?; |
254 | drop; |
255 | |
256 | Ok |
257 | |
258 | |
259 | pub async |
260 | object: Repository, |
261 | operation: RepositoryCommitFromIdRequest, |
262 | state: DatabaseBackend, |
263 | OperationState | : ,
264 | backend: GiteratedStack, |
265 | requester: , |
266 | |
267 | let object = backend |
268 | . |
269 | .await |
270 | .unwrap; |
271 | |
272 | let mut repository_backend = state.repository_backend.lock .await; |
273 | let commit = repository_backend |
274 | .repository_commit_from_id |
275 | &requester, |
276 | object.object, |
277 | &RepositoryCommitFromIdRequest, |
278 | |
279 | .await |
280 | .as_internal_error?; |
281 | drop; |
282 | |
283 | Ok |
284 | |
285 | |
286 | pub async |
287 | object: Repository, |
288 | operation: RepositoryDiffRequest, |
289 | state: DatabaseBackend, |
290 | OperationState | : ,
291 | backend: GiteratedStack, |
292 | requester: , |
293 | |
294 | let object = backend |
295 | . |
296 | .await |
297 | .unwrap; |
298 | |
299 | let mut repository_backend = state.repository_backend.lock .await; |
300 | let diff = repository_backend |
301 | .repository_diff |
302 | .await |
303 | .as_internal_error?; |
304 | drop; |
305 | |
306 | Ok |
307 | |
308 | |
309 | pub async |
310 | object: Repository, |
311 | operation: RepositoryDiffPatchRequest, |
312 | state: DatabaseBackend, |
313 | OperationState | : ,
314 | backend: GiteratedStack, |
315 | requester: , |
316 | |
317 | let object = backend |
318 | . |
319 | .await |
320 | .unwrap; |
321 | |
322 | let mut repository_backend = state.repository_backend.lock .await; |
323 | let patch = repository_backend |
324 | .repository_diff_patch |
325 | .await |
326 | .as_internal_error?; |
327 | drop; |
328 | |
329 | Ok |
330 | |
331 | |
332 | pub async |
333 | object: Repository, |
334 | operation: RepositoryCommitBeforeRequest, |
335 | state: DatabaseBackend, |
336 | OperationState | : ,
337 | backend: GiteratedStack, |
338 | requester: , |
339 | |
340 | let object = backend |
341 | . |
342 | .await |
343 | .unwrap; |
344 | |
345 | let mut repository_backend = state.repository_backend.lock .await; |
346 | let file = repository_backend |
347 | .repository_commit_before |
348 | .await |
349 | .as_internal_error?; |
350 | drop; |
351 | |
352 | Ok |
353 | |
354 | |
355 | pub async |
356 | object: Instance, |
357 | operation: AuthenticationTokenRequest, |
358 | state: DatabaseBackend, |
359 | OperationState | : ,
360 | // Authorizes the request for SAME-INSTANCE |
361 | // _authorized_instance: AuthorizedInstance, |
362 | |
363 | let mut backend = state.user_backend.lock .await; |
364 | |
365 | backend |
366 | .login |
367 | .await |
368 | .as_internal_error |
369 | |
370 | |
371 | pub async |
372 | _object: Instance, |
373 | operation: RegisterAccountRequest, |
374 | state: DatabaseBackend, |
375 | OperationState// Authorizes the request for SAME-INSTANCE | : ,
376 | // _authorized_instance: AuthorizedInstance, |
377 | |
378 | let mut backend = state.user_backend.lock .await; |
379 | |
380 | backend |
381 | .register |
382 | .await |
383 | .as_internal_error |
384 | |
385 | |
386 | pub async |
387 | _object: Instance, |
388 | operation: RepositoryCreateRequest, |
389 | state: DatabaseBackend, |
390 | OperationState | : ,
391 | requester: AuthenticatedUser, |
392 | // Authorizes the request for SAME-INSTANCE |
393 | // _authorized_instance: AuthorizedInstance, |
394 | |
395 | let mut backend = state.repository_backend.lock .await; |
396 | |
397 | backend |
398 | .create_repository |
399 | .await |
400 | .as_internal_error |
401 | |
402 | |
403 | pub async |
404 | _repository: Repository, |
405 | _state: DatabaseBackend, |
406 | OperationState | : ,
407 | |
408 | Ok |
409 | |
410 |