Improve oid_from_reference tag id fetching and pass full Repository Object to every function
parent: tbd commit: 6d7e35e
Showing 3 changed files with 145 insertions and 75 deletions
giterated-daemon/src/backend/git.rs
@@ -352,21 +352,13 @@ impl GitBackend { | ||
352 | 352 | pub fn get_oid_from_reference( |
353 | 353 | git: &git2::Repository, |
354 | 354 | rev: Option<&str>, |
355 | default_branch: &DefaultBranch, | |
355 | 356 | ) -> Result<git2::Oid, GitBackendError> { |
356 | // TODO: Change to default branch instead of head | |
357 | // If the rev is None try and get the repository head | |
358 | let Some(rev) = rev else { | |
359 | if let Ok(head) = git.head() { | |
360 | // TODO: Fix for symbolic references | |
361 | // TODO: unsafe unwrap? | |
362 | return Ok(head.target().unwrap()); | |
363 | } else { | |
364 | // Nothing in database, render empty tree. | |
365 | return Err(GitBackendError::HeadNotFound); | |
366 | } | |
367 | }; | |
357 | // If the rev is None try and get the default branch instead | |
358 | let rev = rev.unwrap_or(default_branch.0.as_str()); | |
368 | 359 | |
369 | 360 | // TODO: This is far from ideal or speedy and would love for a better way to check this in the same order, but I can't find proper methods to do any of this. |
361 | trace!("Attempting to get ref with name {}", rev); | |
370 | 362 | |
371 | 363 | // Try getting it as a refname (refs/heads/name) |
372 | 364 | if let Ok(oid) = git.refname_to_id(rev) { |
@@ -377,15 +369,28 @@ impl GitBackend { | ||
377 | 369 | Ok(branch.get().target().unwrap()) |
378 | 370 | // As last resort, try revparsing (will catch short oid and tags) |
379 | 371 | } else if let Ok(object) = git.revparse_single(rev) { |
380 | Ok(object.id()) | |
372 | Ok(match object.kind() { | |
373 | Some(git2::ObjectType::Tag) => { | |
374 | if let Ok(commit) = object.peel_to_commit() { | |
375 | commit.id() | |
376 | } else { | |
377 | object.id() | |
378 | } | |
379 | } | |
380 | _ => object.id(), | |
381 | }) | |
381 | 382 | } else { |
382 | 383 | Err(GitBackendError::RefNotFound(rev.to_string())) |
383 | 384 | } |
384 | 385 | } |
385 | 386 | |
386 | 387 | /// Gets the last commit in a rev |
387 | pub fn get_last_commit_in_rev(git: &git2::Repository, rev: &str) -> anyhow::Result<Commit> { | |
388 | let oid = Self::get_oid_from_reference(git, Some(rev))?; | |
388 | pub fn get_last_commit_in_rev( | |
389 | git: &git2::Repository, | |
390 | rev: &str, | |
391 | default_branch: &DefaultBranch, | |
392 | ) -> anyhow::Result<Commit> { | |
393 | let oid = Self::get_oid_from_reference(git, Some(rev), default_branch)?; | |
389 | 394 | |
390 | 395 | // Walk through the repository commit graph starting at our rev |
391 | 396 | let mut revwalk = git.revwalk()?; |
@@ -515,19 +520,25 @@ impl RepositoryBackend for GitBackend { | ||
515 | 520 | async fn repository_file_inspect( |
516 | 521 | &mut self, |
517 | 522 | requester: &Option<AuthenticatedUser>, |
518 | repository: &Repository, | |
523 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
524 | OperationState(operation_state): OperationState<StackOperationState>, | |
519 | 525 | request: &RepositoryFileInspectRequest, |
520 | 526 | ) -> Result<Vec<RepositoryTreeEntry>, Error> { |
527 | let repository = repository_object.object(); | |
521 | 528 | let git = self |
522 | 529 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
523 | 530 | .await?; |
524 | 531 | |
532 | let default_branch = repository_object | |
533 | .get::<DefaultBranch>(&operation_state) | |
534 | .await?; | |
525 | 535 | // Try and find the tree_id/branch |
526 | let tree_id = match Self::get_oid_from_reference(&git, request.rev.as_deref()) { | |
527 | Ok(oid) => oid, | |
528 | Err(GitBackendError::HeadNotFound) => return Ok(vec![]), | |
529 | Err(err) => return Err(err.into()), | |
530 | }; | |
536 | let tree_id = | |
537 | match Self::get_oid_from_reference(&git, request.rev.as_deref(), &default_branch) { | |
538 | Ok(oid) => oid, | |
539 | Err(GitBackendError::HeadNotFound) => return Ok(vec![]), | |
540 | Err(err) => return Err(err.into()), | |
541 | }; | |
531 | 542 | |
532 | 543 | // Get the commit from the oid |
533 | 544 | let commit = match git.find_commit(tree_id) { |
@@ -620,9 +631,11 @@ impl RepositoryBackend for GitBackend { | ||
620 | 631 | async fn repository_file_from_id( |
621 | 632 | &mut self, |
622 | 633 | requester: &Option<AuthenticatedUser>, |
623 | repository: &Repository, | |
634 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
635 | OperationState(_operation_state): OperationState<StackOperationState>, | |
624 | 636 | request: &RepositoryFileFromIdRequest, |
625 | 637 | ) -> Result<RepositoryFile, Error> { |
638 | let repository = repository_object.object(); | |
626 | 639 | let git = self |
627 | 640 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
628 | 641 | .await?; |
@@ -652,14 +665,19 @@ impl RepositoryBackend for GitBackend { | ||
652 | 665 | async fn repository_file_from_path( |
653 | 666 | &mut self, |
654 | 667 | requester: &Option<AuthenticatedUser>, |
655 | repository: &Repository, | |
668 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
669 | OperationState(operation_state): OperationState<StackOperationState>, | |
656 | 670 | request: &RepositoryFileFromPathRequest, |
657 | 671 | ) -> Result<(RepositoryFile, String), Error> { |
672 | let repository = repository_object.object(); | |
658 | 673 | let git = self |
659 | 674 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
660 | 675 | .await?; |
661 | 676 | |
662 | let tree_id = Self::get_oid_from_reference(&git, request.rev.as_deref())?; | |
677 | let default_branch = repository_object | |
678 | .get::<DefaultBranch>(&operation_state) | |
679 | .await?; | |
680 | let tree_id = Self::get_oid_from_reference(&git, request.rev.as_deref(), &default_branch)?; | |
663 | 681 | |
664 | 682 | // unwrap might be dangerous? |
665 | 683 | // Get the commit from the oid |
@@ -700,9 +718,11 @@ impl RepositoryBackend for GitBackend { | ||
700 | 718 | async fn repository_commit_from_id( |
701 | 719 | &mut self, |
702 | 720 | requester: &Option<AuthenticatedUser>, |
703 | repository: &Repository, | |
721 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
722 | OperationState(_operation_state): OperationState<StackOperationState>, | |
704 | 723 | request: &RepositoryCommitFromIdRequest, |
705 | 724 | ) -> Result<Commit, Error> { |
725 | let repository = repository_object.object(); | |
706 | 726 | let git = self |
707 | 727 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
708 | 728 | .await?; |
@@ -722,9 +742,11 @@ impl RepositoryBackend for GitBackend { | ||
722 | 742 | async fn repository_last_commit_of_file( |
723 | 743 | &mut self, |
724 | 744 | requester: &Option<AuthenticatedUser>, |
725 | repository: &Repository, | |
745 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
746 | OperationState(_operation_state): OperationState<StackOperationState>, | |
726 | 747 | request: &RepositoryLastCommitOfFileRequest, |
727 | 748 | ) -> Result<Commit, Error> { |
749 | let repository = repository_object.object(); | |
728 | 750 | let git = self |
729 | 751 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
730 | 752 | .await?; |
@@ -748,17 +770,23 @@ impl RepositoryBackend for GitBackend { | ||
748 | 770 | async fn repository_get_statistics( |
749 | 771 | &mut self, |
750 | 772 | requester: &Option<AuthenticatedUser>, |
751 | repository: &Repository, | |
773 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
774 | OperationState(operation_state): OperationState<StackOperationState>, | |
752 | 775 | request: &RepositoryStatisticsRequest, |
753 | 776 | ) -> Result<RepositoryStatistics, Error> { |
777 | let repository = repository_object.object(); | |
754 | 778 | let git = self |
755 | 779 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
756 | 780 | .await?; |
757 | 781 | |
758 | let tree_id = match Self::get_oid_from_reference(&git, request.rev.as_deref()) { | |
759 | Ok(oid) => oid, | |
760 | Err(_) => return Ok(RepositoryStatistics::default()), | |
761 | }; | |
782 | let default_branch = repository_object | |
783 | .get::<DefaultBranch>(&operation_state) | |
784 | .await?; | |
785 | let tree_id = | |
786 | match Self::get_oid_from_reference(&git, request.rev.as_deref(), &default_branch) { | |
787 | Ok(oid) => oid, | |
788 | Err(_) => return Ok(RepositoryStatistics::default()), | |
789 | }; | |
762 | 790 | |
763 | 791 | // Count the amount of branches and tags |
764 | 792 | let mut branches = 0; |
@@ -797,17 +825,16 @@ impl RepositoryBackend for GitBackend { | ||
797 | 825 | OperationState(operation_state): OperationState<StackOperationState>, |
798 | 826 | request: &RepositoryBranchesRequest, |
799 | 827 | ) -> Result<(Vec<RepositoryBranch>, usize), Error> { |
800 | let repository: &Repository = repository_object.object(); | |
828 | let repository = repository_object.object(); | |
801 | 829 | let git = self |
802 | 830 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
803 | 831 | .await?; |
804 | 832 | |
805 | 833 | let default_branch_name = repository_object |
806 | 834 | .get::<DefaultBranch>(&operation_state) |
807 | .await? | |
808 | .0; | |
835 | .await?; | |
809 | 836 | let default_branch = git |
810 | .find_branch(&default_branch_name, BranchType::Local) | |
837 | .find_branch(&default_branch_name.0, BranchType::Local) | |
811 | 838 | .map_err(|_| GitBackendError::DefaultNotFound)?; |
812 | 839 | |
813 | 840 | // Get the stale(after X seconds) setting |
@@ -828,9 +855,12 @@ impl RepositoryBackend for GitBackend { | ||
828 | 855 | }; |
829 | 856 | |
830 | 857 | // TODO: Non UTF-8? |
831 | let Some(commit) = | |
832 | GitBackend::get_last_commit_in_rev(&git, branch.get().name().unwrap()).ok() | |
833 | else { | |
858 | let Some(commit) = GitBackend::get_last_commit_in_rev( | |
859 | &git, | |
860 | branch.get().name().unwrap(), | |
861 | &default_branch_name, | |
862 | ) | |
863 | .ok() else { | |
834 | 864 | return None; |
835 | 865 | }; |
836 | 866 | |
@@ -910,7 +940,7 @@ impl RepositoryBackend for GitBackend { | ||
910 | 940 | OperationState(operation_state): OperationState<StackOperationState>, |
911 | 941 | request: &RepositoryBranchRequest, |
912 | 942 | ) -> Result<RepositoryBranch, Error> { |
913 | let repository: &Repository = repository_object.object(); | |
943 | let repository = repository_object.object(); | |
914 | 944 | let git = self |
915 | 945 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
916 | 946 | .await?; |
@@ -919,10 +949,9 @@ impl RepositoryBackend for GitBackend { | ||
919 | 949 | // Get the default branch to compare against |
920 | 950 | let default_branch_name = repository_object |
921 | 951 | .get::<DefaultBranch>(&operation_state) |
922 | .await? | |
923 | .0; | |
952 | .await?; | |
924 | 953 | let default_branch = git |
925 | .find_branch(&default_branch_name, BranchType::Local) | |
954 | .find_branch(&default_branch_name.0, BranchType::Local) | |
926 | 955 | .map_err(|_| GitBackendError::DefaultNotFound)?; |
927 | 956 | |
928 | 957 | // Find the requested branch |
@@ -938,8 +967,12 @@ impl RepositoryBackend for GitBackend { | ||
938 | 967 | .0; |
939 | 968 | |
940 | 969 | // TODO: Non UTF-8? |
941 | let last_commit = | |
942 | GitBackend::get_last_commit_in_rev(&git, branch.get().name().unwrap()).ok(); | |
970 | let last_commit = GitBackend::get_last_commit_in_rev( | |
971 | &git, | |
972 | branch.get().name().unwrap(), | |
973 | &default_branch_name, | |
974 | ) | |
975 | .ok(); | |
943 | 976 | |
944 | 977 | let stale = if let Some(ref last_commit) = last_commit { |
945 | 978 | chrono::Utc::now() |
@@ -981,7 +1014,7 @@ impl RepositoryBackend for GitBackend { | ||
981 | 1014 | OperationState(_operation_state): OperationState<StackOperationState>, |
982 | 1015 | request: &RepositoryTagsRequest, |
983 | 1016 | ) -> Result<(Vec<RepositoryTag>, usize), Error> { |
984 | let repository: &Repository = repository_object.object(); | |
1017 | let repository = repository_object.object(); | |
985 | 1018 | let git = self |
986 | 1019 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
987 | 1020 | .await?; |
@@ -1100,9 +1133,11 @@ impl RepositoryBackend for GitBackend { | ||
1100 | 1133 | async fn repository_diff( |
1101 | 1134 | &mut self, |
1102 | 1135 | requester: &Option<AuthenticatedUser>, |
1103 | repository: &Repository, | |
1136 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
1137 | OperationState(_operation_state): OperationState<StackOperationState>, | |
1104 | 1138 | request: &RepositoryDiffRequest, |
1105 | 1139 | ) -> Result<RepositoryDiff, Error> { |
1140 | let repository = repository_object.object(); | |
1106 | 1141 | let git = self |
1107 | 1142 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
1108 | 1143 | .await?; |
@@ -1229,9 +1264,11 @@ impl RepositoryBackend for GitBackend { | ||
1229 | 1264 | async fn repository_diff_patch( |
1230 | 1265 | &mut self, |
1231 | 1266 | requester: &Option<AuthenticatedUser>, |
1232 | repository: &Repository, | |
1267 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
1268 | OperationState(_operation_state): OperationState<StackOperationState>, | |
1233 | 1269 | request: &RepositoryDiffPatchRequest, |
1234 | 1270 | ) -> Result<String, Error> { |
1271 | let repository = repository_object.object(); | |
1235 | 1272 | let git = self |
1236 | 1273 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
1237 | 1274 | .await?; |
@@ -1284,9 +1321,11 @@ impl RepositoryBackend for GitBackend { | ||
1284 | 1321 | async fn repository_commit_before( |
1285 | 1322 | &mut self, |
1286 | 1323 | requester: &Option<AuthenticatedUser>, |
1287 | repository: &Repository, | |
1324 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
1325 | OperationState(_operation_state): OperationState<StackOperationState>, | |
1288 | 1326 | request: &RepositoryCommitBeforeRequest, |
1289 | 1327 | ) -> Result<Commit, Error> { |
1328 | let repository = repository_object.object(); | |
1290 | 1329 | let git = self |
1291 | 1330 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
1292 | 1331 | .await?; |
giterated-daemon/src/backend/mod.rs
@@ -40,55 +40,64 @@ pub trait RepositoryBackend { | ||
40 | 40 | async fn repository_file_inspect( |
41 | 41 | &mut self, |
42 | 42 | requester: &Option<AuthenticatedUser>, |
43 | repository: &Repository, | |
43 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
44 | OperationState(operation_state): OperationState<StackOperationState>, | |
44 | 45 | request: &RepositoryFileInspectRequest, |
45 | 46 | ) -> Result<Vec<RepositoryTreeEntry>, Error>; |
46 | 47 | async fn repository_file_from_id( |
47 | 48 | &mut self, |
48 | 49 | requester: &Option<AuthenticatedUser>, |
49 | repository: &Repository, | |
50 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
51 | OperationState(operation_state): OperationState<StackOperationState>, | |
50 | 52 | request: &RepositoryFileFromIdRequest, |
51 | 53 | ) -> Result<RepositoryFile, Error>; |
52 | 54 | async fn repository_file_from_path( |
53 | 55 | &mut self, |
54 | 56 | requester: &Option<AuthenticatedUser>, |
55 | repository: &Repository, | |
57 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
58 | OperationState(operation_state): OperationState<StackOperationState>, | |
56 | 59 | request: &RepositoryFileFromPathRequest, |
57 | 60 | ) -> Result<(RepositoryFile, String), Error>; |
58 | 61 | async fn repository_commit_from_id( |
59 | 62 | &mut self, |
60 | 63 | requester: &Option<AuthenticatedUser>, |
61 | repository: &Repository, | |
64 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
65 | OperationState(operation_state): OperationState<StackOperationState>, | |
62 | 66 | request: &RepositoryCommitFromIdRequest, |
63 | 67 | ) -> Result<Commit, Error>; |
64 | 68 | async fn repository_last_commit_of_file( |
65 | 69 | &mut self, |
66 | 70 | requester: &Option<AuthenticatedUser>, |
67 | repository: &Repository, | |
71 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
72 | OperationState(operation_state): OperationState<StackOperationState>, | |
68 | 73 | request: &RepositoryLastCommitOfFileRequest, |
69 | 74 | ) -> Result<Commit, Error>; |
70 | 75 | async fn repository_diff( |
71 | 76 | &mut self, |
72 | 77 | requester: &Option<AuthenticatedUser>, |
73 | repository: &Repository, | |
78 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
79 | OperationState(operation_state): OperationState<StackOperationState>, | |
74 | 80 | request: &RepositoryDiffRequest, |
75 | 81 | ) -> Result<RepositoryDiff, Error>; |
76 | 82 | async fn repository_diff_patch( |
77 | 83 | &mut self, |
78 | 84 | requester: &Option<AuthenticatedUser>, |
79 | repository: &Repository, | |
85 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
86 | OperationState(operation_state): OperationState<StackOperationState>, | |
80 | 87 | request: &RepositoryDiffPatchRequest, |
81 | 88 | ) -> Result<String, Error>; |
82 | 89 | async fn repository_commit_before( |
83 | 90 | &mut self, |
84 | 91 | requester: &Option<AuthenticatedUser>, |
85 | repository: &Repository, | |
92 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
93 | OperationState(operation_state): OperationState<StackOperationState>, | |
86 | 94 | request: &RepositoryCommitBeforeRequest, |
87 | 95 | ) -> Result<Commit, Error>; |
88 | 96 | async fn repository_get_statistics( |
89 | 97 | &mut self, |
90 | 98 | requester: &Option<AuthenticatedUser>, |
91 | repository: &Repository, | |
99 | repository_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>, | |
100 | OperationState(operation_state): OperationState<StackOperationState>, | |
92 | 101 | request: &RepositoryStatisticsRequest, |
93 | 102 | ) -> Result<RepositoryStatistics, Error>; |
94 | 103 | async fn repository_get_branches( |
giterated-daemon/src/database_backend/handler.rs
@@ -69,7 +69,8 @@ pub async fn repository_info( | ||
69 | 69 | let tree = repository_backend |
70 | 70 | .repository_file_inspect( |
71 | 71 | &requester, |
72 | object.object(), | |
72 | &mut object, | |
73 | OperationState(operation_state.clone()), | |
73 | 74 | &RepositoryFileInspectRequest { |
74 | 75 | extra_metadata: operation.extra_metadata, |
75 | 76 | path: operation.path.clone(), |
@@ -82,7 +83,8 @@ pub async fn repository_info( | ||
82 | 83 | let statistics = repository_backend |
83 | 84 | .repository_get_statistics( |
84 | 85 | &requester, |
85 | object.object(), | |
86 | &mut object, | |
87 | OperationState(operation_state.clone()), | |
86 | 88 | &RepositoryStatisticsRequest { |
87 | 89 | rev: operation.rev.clone(), |
88 | 90 | }, |
@@ -121,7 +123,7 @@ pub async fn repository_get_statistics( | ||
121 | 123 | backend: GiteratedStack, |
122 | 124 | requester: Option<AuthenticatedUser>, |
123 | 125 | ) -> Result<RepositoryStatistics, OperationError<RepositoryError>> { |
124 | let object = backend | |
126 | let mut object = backend | |
125 | 127 | .get_object::<Repository>(&object.to_string(), &operation_state) |
126 | 128 | .await |
127 | 129 | .unwrap(); |
@@ -130,7 +132,8 @@ pub async fn repository_get_statistics( | ||
130 | 132 | let statistics = repository_backend |
131 | 133 | .repository_get_statistics( |
132 | 134 | &requester, |
133 | object.object(), | |
135 | &mut object, | |
136 | OperationState(operation_state), | |
134 | 137 | &RepositoryStatisticsRequest { |
135 | 138 | rev: operation.rev.clone(), |
136 | 139 | }, |
@@ -234,7 +237,7 @@ pub async fn repository_file_from_id( | ||
234 | 237 | backend: GiteratedStack, |
235 | 238 | requester: Option<AuthenticatedUser>, |
236 | 239 | ) -> Result<RepositoryFile, OperationError<RepositoryError>> { |
237 | let object = backend | |
240 | let mut object = backend | |
238 | 241 | .get_object::<Repository>(&object.to_string(), &operation_state) |
239 | 242 | .await |
240 | 243 | .unwrap(); |
@@ -243,7 +246,8 @@ pub async fn repository_file_from_id( | ||
243 | 246 | let file = repository_backend |
244 | 247 | .repository_file_from_id( |
245 | 248 | &requester, |
246 | object.object(), | |
249 | &mut object, | |
250 | OperationState(operation_state), | |
247 | 251 | &RepositoryFileFromIdRequest(operation.0.clone()), |
248 | 252 | ) |
249 | 253 | .await |
@@ -261,7 +265,7 @@ pub async fn repository_file_from_path( | ||
261 | 265 | backend: GiteratedStack, |
262 | 266 | requester: Option<AuthenticatedUser>, |
263 | 267 | ) -> Result<(RepositoryFile, String), OperationError<RepositoryError>> { |
264 | let object = backend | |
268 | let mut object = backend | |
265 | 269 | .get_object::<Repository>(&object.to_string(), &operation_state) |
266 | 270 | .await |
267 | 271 | .unwrap(); |
@@ -270,7 +274,8 @@ pub async fn repository_file_from_path( | ||
270 | 274 | let file = repository_backend |
271 | 275 | .repository_file_from_path( |
272 | 276 | &requester, |
273 | object.object(), | |
277 | &mut object, | |
278 | OperationState(operation_state), | |
274 | 279 | &RepositoryFileFromPathRequest { |
275 | 280 | rev: operation.rev.clone(), |
276 | 281 | path: operation.path.clone(), |
@@ -291,7 +296,7 @@ pub async fn repository_last_commit_of_file( | ||
291 | 296 | backend: GiteratedStack, |
292 | 297 | requester: Option<AuthenticatedUser>, |
293 | 298 | ) -> Result<Commit, OperationError<RepositoryError>> { |
294 | let object = backend | |
299 | let mut object = backend | |
295 | 300 | .get_object::<Repository>(&object.to_string(), &operation_state) |
296 | 301 | .await |
297 | 302 | .unwrap(); |
@@ -300,7 +305,8 @@ pub async fn repository_last_commit_of_file( | ||
300 | 305 | let commit = repository_backend |
301 | 306 | .repository_last_commit_of_file( |
302 | 307 | &requester, |
303 | object.object(), | |
308 | &mut object, | |
309 | OperationState(operation_state), | |
304 | 310 | &RepositoryLastCommitOfFileRequest { |
305 | 311 | start_commit: operation.start_commit.clone(), |
306 | 312 | path: operation.path.clone(), |
@@ -321,7 +327,7 @@ pub async fn repository_commit_by_id( | ||
321 | 327 | backend: GiteratedStack, |
322 | 328 | requester: Option<AuthenticatedUser>, |
323 | 329 | ) -> Result<Commit, OperationError<RepositoryError>> { |
324 | let object = backend | |
330 | let mut object = backend | |
325 | 331 | .get_object::<Repository>(&object.to_string(), &operation_state) |
326 | 332 | .await |
327 | 333 | .unwrap(); |
@@ -330,7 +336,8 @@ pub async fn repository_commit_by_id( | ||
330 | 336 | let commit = repository_backend |
331 | 337 | .repository_commit_from_id( |
332 | 338 | &requester, |
333 | object.object(), | |
339 | &mut object, | |
340 | OperationState(operation_state), | |
334 | 341 | &RepositoryCommitFromIdRequest(operation.0.clone()), |
335 | 342 | ) |
336 | 343 | .await |
@@ -348,14 +355,19 @@ pub async fn repository_diff( | ||
348 | 355 | backend: GiteratedStack, |
349 | 356 | requester: Option<AuthenticatedUser>, |
350 | 357 | ) -> Result<RepositoryDiff, OperationError<RepositoryError>> { |
351 | let object = backend | |
358 | let mut object = backend | |
352 | 359 | .get_object::<Repository>(&object.to_string(), &operation_state) |
353 | 360 | .await |
354 | 361 | .unwrap(); |
355 | 362 | |
356 | 363 | let mut repository_backend = state.repository_backend.lock().await; |
357 | 364 | let diff = repository_backend |
358 | .repository_diff(&requester, object.object(), &operation) | |
365 | .repository_diff( | |
366 | &requester, | |
367 | &mut object, | |
368 | OperationState(operation_state), | |
369 | &operation, | |
370 | ) | |
359 | 371 | .await |
360 | 372 | .as_internal_error()?; |
361 | 373 | drop(repository_backend); |
@@ -371,14 +383,19 @@ pub async fn repository_diff_patch( | ||
371 | 383 | backend: GiteratedStack, |
372 | 384 | requester: Option<AuthenticatedUser>, |
373 | 385 | ) -> Result<String, OperationError<RepositoryError>> { |
374 | let object = backend | |
386 | let mut object = backend | |
375 | 387 | .get_object::<Repository>(&object.to_string(), &operation_state) |
376 | 388 | .await |
377 | 389 | .unwrap(); |
378 | 390 | |
379 | 391 | let mut repository_backend = state.repository_backend.lock().await; |
380 | 392 | let patch = repository_backend |
381 | .repository_diff_patch(&requester, object.object(), &operation) | |
393 | .repository_diff_patch( | |
394 | &requester, | |
395 | &mut object, | |
396 | OperationState(operation_state), | |
397 | &operation, | |
398 | ) | |
382 | 399 | .await |
383 | 400 | .as_internal_error()?; |
384 | 401 | drop(repository_backend); |
@@ -394,14 +411,19 @@ pub async fn repository_commit_before( | ||
394 | 411 | backend: GiteratedStack, |
395 | 412 | requester: Option<AuthenticatedUser>, |
396 | 413 | ) -> Result<Commit, OperationError<RepositoryError>> { |
397 | let object = backend | |
414 | let mut object = backend | |
398 | 415 | .get_object::<Repository>(&object.to_string(), &operation_state) |
399 | 416 | .await |
400 | 417 | .unwrap(); |
401 | 418 | |
402 | 419 | let mut repository_backend = state.repository_backend.lock().await; |
403 | 420 | let file = repository_backend |
404 | .repository_commit_before(&requester, object.object(), &operation) | |
421 | .repository_commit_before( | |
422 | &requester, | |
423 | &mut object, | |
424 | OperationState(operation_state), | |
425 | &operation, | |
426 | ) | |
405 | 427 | .await |
406 | 428 | .as_internal_error()?; |
407 | 429 | drop(repository_backend); |