Skip to content
Clone

refactor: streamline context handling by replacing space and repo name parameters with context references for improved clarity and consistency

ZhenYi committed
parent db73d56 commit 1098df8 Browse files

135 files changed

+426 −862

File tree 135
Modified lib/git/src/handler/analysis/code_activity.rs View lib/git/src/handler/analysis/code_activity.rs
@@ -29,7 +29,7 @@
2929 Path(path): Path<crate::handler::RepoPath>,
3030 Query(q): Query<CodeActivityQuery>,
3131) -> Result<AppResponseData<CodeActivityDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .analysis_code_activity(path.space_name, path.repo_name, q.branch)
40 .analysis_code_activity(&ctx, q.branch)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/analysis/contributors.rs View lib/git/src/handler/analysis/contributors.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<crate::handler::RepoPath>,
2424) -> Result<AppResponseData<Vec<ContributorStatDto>>, ApiError> {
25 let _ = handler::resolve_reader(
25 let (ctx, _) = handler::resolve_reader(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .analysis_contributors(path.space_name, path.repo_name)
33 .analysis_contributors(&ctx)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/analysis/languages.rs View lib/git/src/handler/analysis/languages.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<crate::handler::RepoPath>,
2424) -> Result<AppResponseData<Vec<LanguageStatDto>>, ApiError> {
25 let (_ctx, _uid) = handler::require_writer(
25 let (ctx, _uid) = handler::require_writer(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .analysis_languages(path.space_name, path.repo_name)
33 .analysis_languages(&ctx)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/analysis/languages_read.rs View lib/git/src/handler/analysis/languages_read.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<crate::handler::RepoPath>,
2424) -> Result<AppResponseData<Vec<LanguageStatDto>>, ApiError> {
25 let _ = handler::resolve_reader(
25 let (ctx, _) = handler::resolve_reader(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .analysis_languages_read(path.space_name, path.repo_name)
33 .analysis_languages_read(&ctx)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/archives/create.rs View lib/git/src/handler/archives/create.rs
@@ -52,7 +52,7 @@
5252 Path(path): Path<RepoPath>,
5353 Json(cmd): Json<ArchiveCreateCmd>,
5454) -> Result<AppResponseData<ArchiveResultDto>, ApiError> {
55 require_writer(
55 let (ctx, _) = require_writer(
5656 &service,
5757 &session,
5858 path.space_name.clone(),
@@ -64,7 +64,7 @@
6464 path_filter: cmd.path_filter,
6565 };
6666 let out = service
67 .archive_create(path.space_name, path.repo_name, cmd.revision, opts)
67 .archive_create(&ctx, cmd.revision, opts)
6868 .await
6969 .map_err(GitApiError::from)?;
7070 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/archives/create_bundle.rs View lib/git/src/handler/archives/create_bundle.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<RepoPath>,
2424) -> Result<AppResponseData<ArchiveResultDto>, ApiError> {
25 require_writer(
25 let (ctx, _) = require_writer(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .archive_create_bundle(path.space_name, path.repo_name)
33 .archive_create_bundle(&ctx)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/archives/download.rs View lib/git/src/handler/archives/download.rs
@@ -27,7 +27,7 @@
2727 Path(path): Path<RepoPathRev>,
2828 Query(opts): Query<ArchiveOptionsDto>,
2929) -> Result<AppResponseData<ArchiveResultDto>, ApiError> {
30 resolve_reader(
30 let (ctx, _) = resolve_reader(
3131 &service,
3232 &session,
3333 path.space_name.clone(),
@@ -35,7 +35,7 @@
3535 )
3636 .await?;
3737 let out = service
38 .archive_download(path.space_name, path.repo_name, path.revision, opts)
38 .archive_download(&ctx, path.revision, opts)
3939 .await
4040 .map_err(GitApiError::from)?;
4141 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/blobs/content.rs View lib/git/src/handler/blobs/content.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<BlobPath>,
3131) -> Result<AppResponseData<BlobContentDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .blob_content(path.space_name, path.repo_name, path.oid)
40 .blob_content(&ctx, path.oid)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/blobs/list_lfs_pointers.rs View lib/git/src/handler/blobs/list_lfs_pointers.rs
@@ -39,7 +39,7 @@
3939 Path(path): Path<RepoQuery>,
4040 Query(q): Query<LfsPointerQuery>,
4141) -> Result<AppResponseData<Vec<LfsPointerDto>>, ApiError> {
42 let _ = handler::resolve_reader(
42 let (ctx, _) = handler::resolve_reader(
4343 &service,
4444 &session,
4545 path.space_name.clone(),
@@ -47,7 +47,7 @@
4747 )
4848 .await?;
4949 let out = service
50 .list_lfs_pointers(path.space_name, path.repo_name, q.revision, q.limit)
50 .list_lfs_pointers(&ctx, q.revision, q.limit)
5151 .await
5252 .map_err(GitApiError::from)?;
5353 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/blobs/metadata.rs View lib/git/src/handler/blobs/metadata.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<BlobPath>,
3131) -> Result<AppResponseData<BlobMetaDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .blob_metadata(path.space_name, path.repo_name, path.oid)
40 .blob_metadata(&ctx, path.oid)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/branch_protection/create_policy.rs View lib/git/src/handler/branch_protection/create_policy.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<RepoPath>,
2525 Json(cmd): Json<CreateBranchPolicyCmd>,
2626) -> Result<AppResponseData<BranchPolicyDto>, ApiError> {
27 let _ = require_repo_admin(
27 let (ctx, _) = require_repo_admin(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -32,7 +32,7 @@
3232 )
3333 .await?;
3434 let out = service
35 .create_branch_policy(path.space_name, path.repo_name, cmd)
35 .create_branch_policy(&ctx, cmd)
3636 .await
3737 .map_err(GitApiError::from)?;
3838 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/branch_protection/delete_policy.rs View lib/git/src/handler/branch_protection/delete_policy.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<PolicyPath>,
2424) -> Result<AppResponseData<NoData>, ApiError> {
25 let _ = handler::require_repo_admin(
25 let (ctx, _) = handler::require_repo_admin(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 service
33 .delete_branch_policy(path.space_name, path.repo_name, path.policy_id)
33 .delete_branch_policy(&ctx, path.policy_id)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/branch_protection/get_policy.rs View lib/git/src/handler/branch_protection/get_policy.rs
@@ -23,7 +23,7 @@
2323 session: Session,
2424 Path(path): Path<PolicyPath>,
2525) -> Result<AppResponseData<BranchPolicyDto>, ApiError> {
26 let _ = handler::require_repo_admin(
26 let (ctx, _) = handler::require_repo_admin(
2727 &service,
2828 &session,
2929 path.space_name.clone(),
@@ -31,7 +31,7 @@
3131 )
3232 .await?;
3333 let out = service
34 .get_branch_policy(path.space_name, path.repo_name, path.policy_id)
34 .get_branch_policy(&ctx, path.policy_id)
3535 .await
3636 .map_err(GitApiError::from)?;
3737 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/branch_protection/list_policies.rs View lib/git/src/handler/branch_protection/list_policies.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<RepoPath>,
2424) -> Result<AppResponseData<Vec<BranchPolicyDto>>, ApiError> {
25 let _ = require_repo_admin(
25 let (ctx, _) = require_repo_admin(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .list_branch_policies(path.space_name, path.repo_name)
33 .list_branch_policies(&ctx)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/branch_protection/update_policy.rs View lib/git/src/handler/branch_protection/update_policy.rs
@@ -25,7 +25,7 @@
2525 Path(path): Path<PolicyPath>,
2626 Json(cmd): Json<UpdateBranchPolicyCmd>,
2727) -> Result<AppResponseData<BranchPolicyDto>, ApiError> {
28 let _ = handler::require_repo_admin(
28 let (ctx, _) = handler::require_repo_admin(
2929 &service,
3030 &session,
3131 path.space_name.clone(),
@@ -33,7 +33,7 @@
3333 )
3434 .await?;
3535 let out = service
36 .update_branch_policy(path.space_name, path.repo_name, path.policy_id, cmd)
36 .update_branch_policy(&ctx, path.policy_id, cmd)
3737 .await
3838 .map_err(GitApiError::from)?;
3939 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/branches/create.rs View lib/git/src/handler/branches/create.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<crate::handler::RepoPath>,
2525 Json(cmd): Json<CreateBranchCmd>,
2626) -> Result<AppResponseData<BranchDto>, ApiError> {
27 let _ = handler::require_writer(
27 let (ctx, _) = handler::require_writer(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -32,7 +32,7 @@
3232 )
3333 .await?;
3434 let out = service
35 .create_branch(path.space_name, path.repo_name, cmd)
35 .create_branch(&ctx, cmd)
3636 .await
3737 .map_err(GitApiError::from)?;
3838 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/branches/delete.rs View lib/git/src/handler/branches/delete.rs
@@ -35,7 +35,7 @@
3535 Path(path): Path<BranchPath>,
3636 Query(query): Query<DeleteBranchQuery>,
3737) -> Result<AppResponseData<NoData>, ApiError> {
38 let _ = handler::require_writer(
38 let (ctx, _) = handler::require_writer(
3939 &service,
4040 &session,
4141 path.space_name.clone(),
@@ -43,12 +43,7 @@
4343 )
4444 .await?;
4545 service
46 .delete_branch(
47 path.space_name,
48 path.repo_name,
49 path.name,
50 query.force.unwrap_or(false),
51 )
46 .delete_branch(&ctx, path.name, query.force.unwrap_or(false))
5247 .await
5348 .map_err(GitApiError::from)?;
5449 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/branches/get.rs View lib/git/src/handler/branches/get.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<BranchPath>,
3131) -> Result<AppResponseData<BranchDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .get_branch(path.space_name, path.repo_name, path.name)
40 .get_branch(&ctx, path.name)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/branches/list.rs View lib/git/src/handler/branches/list.rs
@@ -23,7 +23,7 @@
2323 Path(path): Path<crate::handler::RepoPath>,
2424 Query(page): Query<export::pagination::PageQuery>,
2525) -> Result<AppResponseData<export::pagination::Page<BranchDto>>, ApiError> {
26 let _ = handler::resolve_reader(
26 let (ctx, _) = handler::resolve_reader(
2727 &service,
2828 &session,
2929 path.space_name.clone(),
@@ -31,7 +31,7 @@
3131 )
3232 .await?;
3333 let all = service
34 .list_branches(path.space_name, path.repo_name)
34 .list_branches(&ctx)
3535 .await
3636 .map_err(GitApiError::from)?;
3737 let total = all.len() as i64;
Modified lib/git/src/handler/branches/rename.rs View lib/git/src/handler/branches/rename.rs
@@ -35,7 +35,7 @@
3535 Path(path): Path<BranchPath>,
3636 Json(cmd): Json<RenameBranchCmd>,
3737) -> Result<AppResponseData<NoData>, ApiError> {
38 let _ = handler::require_writer(
38 let (ctx, _) = handler::require_writer(
3939 &service,
4040 &session,
4141 path.space_name.clone(),
@@ -43,7 +43,7 @@
4343 )
4444 .await?;
4545 service
46 .rename_branch(path.space_name, path.repo_name, path.name, cmd.new_name)
46 .rename_branch(&ctx, path.name, cmd.new_name)
4747 .await
4848 .map_err(GitApiError::from)?;
4949 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/branches/set_default.rs View lib/git/src/handler/branches/set_default.rs
@@ -28,7 +28,7 @@
2828 session: Session,
2929 Path(path): Path<BranchPath>,
3030) -> Result<AppResponseData<NoData>, ApiError> {
31 let _ = handler::require_writer(
31 let (ctx, _) = handler::require_writer(
3232 &service,
3333 &session,
3434 path.space_name.clone(),
@@ -36,7 +36,7 @@
3636 )
3737 .await?;
3838 service
39 .set_default_branch(path.space_name, path.repo_name, path.name)
39 .set_default_branch(&ctx, path.name)
4040 .await
4141 .map_err(GitApiError::from)?;
4242 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/code_comments/create_code_comment.rs View lib/git/src/handler/code_comments/create_code_comment.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<crate::handler::RepoPath>,
2525 Json(cmd): Json<CreateCodeCommentCmd>,
2626) -> Result<AppResponseData<CodeCommentDto>, ApiError> {
27 let (_ctx, uid) = handler::require_writer(
27 let (ctx, uid) = handler::require_writer(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -32,7 +32,7 @@
3232 )
3333 .await?;
3434 let out = service
35 .create_code_comment(path.space_name, path.repo_name, uid, cmd)
35 .create_code_comment(&ctx, uid, cmd)
3636 .await
3737 .map_err(GitApiError::from)?;
3838 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/code_comments/list_code_comments.rs View lib/git/src/handler/code_comments/list_code_comments.rs
@@ -23,7 +23,7 @@
2323 Path(path): Path<crate::handler::RepoPath>,
2424 Query(query): Query<ListCodeCommentsQuery>,
2525) -> Result<AppResponseData<CodeCommentPage>, ApiError> {
26 let _ = handler::resolve_reader(
26 let (ctx, _) = handler::resolve_reader(
2727 &service,
2828 &session,
2929 path.space_name.clone(),
@@ -31,7 +31,7 @@
3131 )
3232 .await?;
3333 let out = service
34 .list_code_comments(path.space_name, path.repo_name, query)
34 .list_code_comments(&ctx, query)
3535 .await
3636 .map_err(GitApiError::from)?;
3737 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/code_comments/modify.rs View lib/git/src/handler/code_comments/modify.rs
@@ -32,7 +32,7 @@
3232 Path(path): Path<CodeCommentPath>,
3333 Json(cmd): Json<UpdateCodeCommentCmd>,
3434) -> Result<AppResponseData<CodeCommentDto>, ApiError> {
35 let (_ctx, uid) = require_writer(
35 let (ctx, uid) = require_writer(
3636 &service,
3737 &session,
3838 path.space_name.clone(),
@@ -48,14 +48,7 @@
4848 .await
4949 .is_ok();
5050 let out = service
51 .update_code_comment(
52 path.space_name,
53 path.repo_name,
54 path.comment_id,
55 uid,
56 admin,
57 cmd,
58 )
51 .update_code_comment(&ctx, path.comment_id, uid, admin, cmd)
5952 .await
6053 .map_err(GitApiError::from)?;
6154 Ok(AppResponseData::ok(out))
@@ -76,7 +69,7 @@
7669 session: Session,
7770 Path(path): Path<CodeCommentPath>,
7871) -> Result<AppResponseData<NoData>, ApiError> {
79 let (_ctx, uid) = require_writer(
72 let (ctx, uid) = require_writer(
8073 &service,
8174 &session,
8275 path.space_name.clone(),
@@ -92,7 +85,7 @@
9285 .await
9386 .is_ok();
9487 service
95 .delete_code_comment(path.space_name, path.repo_name, path.comment_id, uid, admin)
88 .delete_code_comment(&ctx, path.comment_id, uid, admin)
9689 .await
9790 .map_err(GitApiError::from)?;
9891 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/code_comments/resolve_code_comment.rs View lib/git/src/handler/code_comments/resolve_code_comment.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<super::modify::CodeCommentPath>,
2424) -> Result<AppResponseData<CodeCommentDto>, ApiError> {
25 let (_ctx, uid) = handler::require_writer(
25 let (ctx, uid) = handler::require_writer(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .set_code_comment_resolved(path.space_name, path.repo_name, path.comment_id, uid, true)
33 .set_code_comment_resolved(&ctx, path.comment_id, uid, true)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
@@ -51,7 +51,7 @@
5151 session: Session,
5252 Path(path): Path<super::modify::CodeCommentPath>,
5353) -> Result<AppResponseData<CodeCommentDto>, ApiError> {
54 let (_ctx, uid) = handler::require_writer(
54 let (ctx, uid) = handler::require_writer(
5555 &service,
5656 &session,
5757 path.space_name.clone(),
@@ -59,7 +59,7 @@
5959 )
6060 .await?;
6161 let out = service
62 .set_code_comment_resolved(path.space_name, path.repo_name, path.comment_id, uid, false)
62 .set_code_comment_resolved(&ctx, path.comment_id, uid, false)
6363 .await
6464 .map_err(GitApiError::from)?;
6565 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/commits/get.rs View lib/git/src/handler/commits/get.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<CommitPath>,
3131) -> Result<AppResponseData<CommitInfo>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .get_commit(path.space_name, path.repo_name, path.revision)
40 .get_commit(&ctx, path.revision)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/commits/is_ancestor.rs View lib/git/src/handler/commits/is_ancestor.rs
@@ -34,7 +34,7 @@
3434 Path(path): Path<crate::handler::RepoPath>,
3535 Query(query): Query<AncestorQuery>,
3636) -> Result<AppResponseData<IsAncestorResponse>, ApiError> {
37 let _ = handler::resolve_reader(
37 let (ctx, _) = handler::resolve_reader(
3838 &service,
3939 &session,
4040 path.space_name.clone(),
@@ -42,12 +42,7 @@
4242 )
4343 .await?;
4444 let is_ancestor = service
45 .is_ancestor(
46 path.space_name,
47 path.repo_name,
48 query.ancestor,
49 query.descendant,
50 )
45 .is_ancestor(&ctx, query.ancestor, query.descendant)
5146 .await
5247 .map_err(GitApiError::from)?;
5348 Ok(AppResponseData::ok(IsAncestorResponse { is_ancestor }))
Modified lib/git/src/handler/commits/list.rs View lib/git/src/handler/commits/list.rs
@@ -32,7 +32,7 @@
3232 Path(path): Path<crate::handler::RepoPath>,
3333 Query(cmd): Query<ListCommitsCmd>,
3434) -> Result<AppResponseData<CommitsPageDto>, ApiError> {
35 let (_, viewer) = handler::resolve_reader(
35 let (ctx, viewer) = handler::resolve_reader(
3636 &service,
3737 &session,
3838 path.space_name.clone(),
@@ -40,7 +40,7 @@
4040 )
4141 .await?;
4242 let out = service
43 .list_commits(path.space_name, path.repo_name, cmd, viewer)
43 .list_commits(&ctx, cmd, viewer)
4444 .await
4545 .map_err(GitApiError::from)?;
4646 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/commits/list_commit_statuses.rs View lib/git/src/handler/commits/list_commit_statuses.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<StatusPath>,
3131) -> Result<AppResponseData<Vec<CommitStatusDto>>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .list_commit_statuses(path.space_name, path.repo_name, path.sha)
40 .list_commit_statuses(&ctx, path.sha)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/commits/rev_parse.rs View lib/git/src/handler/commits/rev_parse.rs
@@ -28,7 +28,7 @@
2828 session: Session,
2929 Path(path): Path<RevPath>,
3030) -> Result<AppResponseData<String>, ApiError> {
31 let _ = handler::resolve_reader(
31 let (ctx, _) = handler::resolve_reader(
3232 &service,
3333 &session,
3434 path.space_name.clone(),
@@ -36,7 +36,7 @@
3636 )
3737 .await?;
3838 let out = service
39 .rev_parse(path.space_name, path.repo_name, path.revision)
39 .rev_parse(&ctx, path.revision)
4040 .await
4141 .map_err(GitApiError::from)?;
4242 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/commits/set_commit_status.rs View lib/git/src/handler/commits/set_commit_status.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<crate::handler::RepoPath>,
2525 Json(cmd): Json<SetCommitStatusCmd>,
2626) -> Result<AppResponseData<CommitStatusDto>, ApiError> {
27 let (_ctx, uid) = handler::require_writer(
27 let (ctx, uid) = handler::require_writer(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -32,7 +32,7 @@
3232 )
3333 .await?;
3434 let out = service
35 .set_commit_status(path.space_name, path.repo_name, uid, cmd)
35 .set_commit_status(&ctx, uid, cmd)
3636 .await
3737 .map_err(GitApiError::from)?;
3838 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/commits/stats.rs View lib/git/src/handler/commits/stats.rs
@@ -32,7 +32,7 @@
3232 Path(path): Path<crate::handler::RepoPath>,
3333 Query(query): Query<StatsQuery>,
3434) -> Result<AppResponseData<CommitStats>, ApiError> {
35 let _ = handler::resolve_reader(
35 let (ctx, _) = handler::resolve_reader(
3636 &service,
3737 &session,
3838 path.space_name.clone(),
@@ -40,12 +40,7 @@
4040 )
4141 .await?;
4242 let out = service
43 .commit_stats(
44 path.space_name,
45 path.repo_name,
46 query.revision,
47 query.path.map(PathBuf::from),
48 )
43 .commit_stats(&ctx, query.revision, query.path.map(PathBuf::from))
4944 .await
5045 .map_err(GitApiError::from)?;
5146 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/commits/sync_commit.rs View lib/git/src/handler/commits/sync_commit.rs
@@ -35,8 +35,13 @@
3535 session: Session,
3636 Path(path): Path<CommitPath>,
3737) -> Result<AppResponseData<CommitSyncResponse>, ApiError> {
38 let (ctx, _uid) =
39 handler::require_writer(&service, &session, path.space_name, path.repo_name).await?;
38 let (ctx, _uid) = handler::require_writer(
39 &service,
40 &session,
41 path.space_name.clone(),
42 path.repo_name.clone(),
43 )
44 .await?;
4045 let row = service
4146 .sync_commit(&ctx, &path.revision)
4247 .await
Modified lib/git/src/handler/conflicts/detail.rs View lib/git/src/handler/conflicts/detail.rs
@@ -30,7 +30,7 @@
3030 Path(path): Path<crate::handler::RepoPath>,
3131 Query(q): Query<ConflictDetailQuery>,
3232) -> Result<AppResponseData<ConflictDetailDto>, ApiError> {
33 let _ = handler::resolve_reader(
33 let (ctx, _) = handler::resolve_reader(
3434 &service,
3535 &session,
3636 path.space_name.clone(),
@@ -38,7 +38,7 @@
3838 )
3939 .await?;
4040 let out = service
41 .conflict_detail(path.space_name, path.repo_name, q.base, q.head, q.path)
41 .conflict_detail(&ctx, q.base, q.head, q.path)
4242 .await
4343 .map_err(GitApiError::from)?;
4444 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/conflicts/get_conflicts.rs View lib/git/src/handler/conflicts/get_conflicts.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<crate::handler::RepoPath>,
3232 Query(q): Query<GetConflictsQuery>,
3333) -> Result<AppResponseData<MergeStatusDto>, ApiError> {
34 let _ = handler::resolve_reader(
34 let (ctx, _) = handler::resolve_reader(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -41,14 +41,10 @@
4141 let out = match q.ancestor {
4242 Some(ancestor) => {
4343 service
44 .conflict_check_threeway(path.space_name, path.repo_name, q.base, q.head, ancestor)
45 .await
46 }
47 None => {
48 service
49 .conflict_check(path.space_name, path.repo_name, q.base, q.head)
44 .conflict_check_threeway(&ctx, q.base, q.head, ancestor)
5045 .await
5146 }
47 None => service.conflict_check(&ctx, q.base, q.head).await,
5248 }
5349 .map_err(GitApiError::from)?;
5450 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/diffs/for_commit.rs View lib/git/src/handler/diffs/for_commit.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<CommitPath>,
3131) -> Result<AppResponseData<Vec<ChangedPath>>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .diff_for_commit(path.space_name, path.repo_name, path.commit)
40 .diff_for_commit(&ctx, path.commit)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/diffs/get_diff.rs View lib/git/src/handler/diffs/get_diff.rs
@@ -55,7 +55,7 @@
5555 Path(path): Path<crate::handler::RepoPath>,
5656 Query(q): Query<GetDiffQuery>,
5757) -> Result<AppResponseData<serde_json::Value>, ApiError> {
58 let _ = handler::resolve_reader(
58 let (ctx, _) = handler::resolve_reader(
5959 &service,
6060 &session,
6161 path.space_name.clone(),
@@ -65,40 +65,28 @@
6565 let out = match q.view {
6666 DiffView::Shortstat => {
6767 let s = service
68 .diff_short_stat(path.space_name, path.repo_name, q.base, q.head)
68 .diff_short_stat(&ctx, q.base, q.head)
6969 .await
7070 .map_err(GitApiError::from)?;
7171 serde_json::to_value(s).map_err(json_err)?
7272 }
7373 DiffView::Numstat => {
7474 let s = service
75 .diff_stats(
76 path.space_name,
77 path.repo_name,
78 q.base,
79 q.head,
80 DiffOptionsDto::default(),
81 )
75 .diff_stats(&ctx, q.base, q.head, DiffOptionsDto::default())
8276 .await
8377 .map_err(GitApiError::from)?;
8478 serde_json::to_value(s).map_err(json_err)?
8579 }
8680 DiffView::Files => {
8781 let f = service
88 .diff_files_changed_between(path.space_name, path.repo_name, q.base, q.head)
82 .diff_files_changed_between(&ctx, q.base, q.head)
8983 .await
9084 .map_err(GitApiError::from)?;
9185 serde_json::to_value(f).map_err(json_err)?
9286 }
9387 DiffView::Tree => {
9488 let t = service
95 .diff_tree(
96 path.space_name,
97 path.repo_name,
98 q.base,
99 q.head,
100 q.use_merge_base,
101 )
89 .diff_tree(&ctx, q.base, q.head, q.use_merge_base)
10290 .await
10391 .map_err(GitApiError::from)?;
10492 serde_json::to_value(t).map_err(json_err)?
Modified lib/git/src/handler/diffs/range_diff.rs View lib/git/src/handler/diffs/range_diff.rs
@@ -35,7 +35,7 @@
3535 Some(base) => RangeDiffSpec::BaseWithRevisions(base, q.from, q.to),
3636 None => RangeDiffSpec::RevisionRange(q.from, q.to),
3737 };
38 let _ = handler::resolve_reader(
38 let (ctx, _) = handler::resolve_reader(
3939 &service,
4040 &session,
4141 path.space_name.clone(),
@@ -43,7 +43,7 @@
4343 )
4444 .await?;
4545 let out = service
46 .range_diff(path.space_name, path.repo_name, body)
46 .range_diff(&ctx, body)
4747 .await
4848 .map_err(GitApiError::from)?;
4949 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/diffs/raw.rs View lib/git/src/handler/diffs/raw.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<crate::handler::RepoPath>,
3232 Query(q): Query<DiffBaseHeadQuery>,
3333) -> Result<AppResponseData<String>, ApiError> {
34 let _ = handler::resolve_reader(
34 let (ctx, _) = handler::resolve_reader(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -39,7 +39,7 @@
3939 )
4040 .await?;
4141 let out = service
42 .diff_raw(path.space_name, path.repo_name, q.base, q.head)
42 .diff_raw(&ctx, q.base, q.head)
4343 .await
4444 .map_err(GitApiError::from)?;
4545 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/hooks/execute_script.rs View lib/git/src/handler/hooks/execute_script.rs
@@ -37,7 +37,7 @@
3737 Path(path): Path<HookScriptPath>,
3838 Json(body): Json<HookExecBody>,
3939) -> Result<AppResponseData<ScriptOutputDto>, ApiError> {
40 handler::require_writer(
40 let (ctx, _) = handler::require_writer(
4141 &service,
4242 &session,
4343 path.space_name.clone(),
@@ -45,7 +45,7 @@
4545 )
4646 .await?;
4747 let out = service
48 .hook_execute_script(path.space_name, path.repo_name, path.script, body.args)
48 .hook_execute_script(&ctx, path.script, body.args)
4949 .await
5050 .map_err(GitApiError::from)?;
5151 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/html/blame.rs View lib/git/src/handler/html/blame.rs
@@ -46,8 +46,7 @@
4646
4747 let blame_ranges = match service
4848 .blame(
49 ctx.space_name.clone(),
50 ctx.repo_name.clone(),
49 &ctx.ctx,
5150 revision.clone(),
5251 PathBuf::from(clean_path.clone()),
5352 None,
@@ -71,14 +70,7 @@
7170 Ok(_) => return error::html_err(404, "blob not found"),
7271 Err(_) => return error::html_err(404, "blob not found"),
7372 };
74 let blob = match service
75 .blob_content(
76 ctx.space_name.clone(),
77 ctx.repo_name.clone(),
78 entry.oid.to_string(),
79 )
80 .await
81 {
73 let blob = match service.blob_content(&ctx.ctx, entry.oid.to_string()).await {
8274 Ok(b) => b,
8375 Err(_) => return error::html_err(404, "failed to read blob"),
8476 };
Modified lib/git/src/handler/html/blob_content.rs View lib/git/src/handler/html/blob_content.rs
@@ -58,14 +58,7 @@
5858 Err(_) => return error::html_err(404, "path not found"),
5959 };
6060
61 let blob = match service
62 .blob_content(
63 ctx.space_name.clone(),
64 ctx.repo_name.clone(),
65 entry.oid.to_string(),
66 )
67 .await
68 {
61 let blob = match service.blob_content(&ctx.ctx, entry.oid.to_string()).await {
6962 Ok(b) => b,
7063 Err(_) => return error::html_err(404, "failed to load blob content"),
7164 };
Modified lib/git/src/handler/html/commits.rs View lib/git/src/handler/html/commits.rs
@@ -64,10 +64,17 @@
6464 first_parent: false,
6565 };
6666
67 let page = match service
68 .list_commits(ctx.space_name.clone(), ctx.repo_name.clone(), cmd, ctx.uid)
67 let repo_ctx = match service
68 .context(ctx.space_name.clone(), ctx.repo_name.clone())
6969 .await
7070 {
71 Ok(c) => c,
72 Err(e) => {
73 tracing::warn!(error = %e, "commits context internal");
74 return error::html_err(500, "internal");
75 }
76 };
77 let page = match service.list_commits(&repo_ctx, cmd, ctx.uid).await {
7178 Ok(p) => p,
7279 Err(e) => {
7380 tracing::warn!(error = %e, "commits list internal");
Modified lib/git/src/handler/html/languages.rs View lib/git/src/handler/html/languages.rs
@@ -28,13 +28,13 @@
2828 };
2929
3030 let mut langs = service
31 .analysis_languages_read(ctx.space_name.clone(), ctx.repo_name.clone())
31 .analysis_languages_read(&ctx.ctx)
3232 .await
3333 .unwrap_or_default();
3434
3535 if langs.is_empty() {
3636 langs = service
37 .analysis_languages(ctx.space_name.clone(), ctx.repo_name.clone())
37 .analysis_languages(&ctx.ctx)
3838 .await
3939 .unwrap_or_default();
4040 }
Modified lib/git/src/handler/html/readme.rs View lib/git/src/handler/html/readme.rs
@@ -78,14 +78,7 @@
7878 None => return error::html_err(404, "readme not found"),
7979 };
8080
81 let blob = match service
82 .blob_content(
83 ctx.space_name.clone(),
84 ctx.repo_name.clone(),
85 entry.oid.to_string(),
86 )
87 .await
88 {
81 let blob = match service.blob_content(&ctx.ctx, entry.oid.to_string()).await {
8982 Ok(b) => b,
9083 Err(_) => return error::html_err(404, "failed to load readme blob"),
9184 };
Modified lib/git/src/handler/html/refs_dropdown.rs View lib/git/src/handler/html/refs_dropdown.rs
@@ -40,14 +40,18 @@
4040 .filter(|r| validate::validate_revision(r).is_ok())
4141 .unwrap_or(ctx.dto.default_branch.as_str());
4242
43 let branches = service
44 .list_branches(ctx.space_name.clone(), ctx.repo_name.clone())
43 let repo_ctx = service
44 .context(ctx.space_name.clone(), ctx.repo_name.clone())
4545 .await
46 .unwrap_or_default();
47 let tags = service
48 .list_tags(ctx.space_name.clone(), ctx.repo_name.clone())
49 .await
50 .unwrap_or_default();
46 .ok();
47 let branches = match repo_ctx.as_ref() {
48 Some(repo_ctx) => service.list_branches(repo_ctx).await.unwrap_or_default(),
49 None => Vec::new(),
50 };
51 let tags = match repo_ctx.as_ref() {
52 Some(repo_ctx) => service.list_tags(repo_ctx).await.unwrap_or_default(),
53 None => Vec::new(),
54 };
5155
5256 let base = "git-refs-dropdown relative inline-flex w-full max-w-xs flex-col";
5357 let cls = archived_class(&ctx.dto, base);
Modified lib/git/src/handler/lfs/cleanup_unreferenced.rs View lib/git/src/handler/lfs/cleanup_unreferenced.rs
@@ -26,7 +26,7 @@
2626 session: Session,
2727 Path(path): Path<RepoPath>,
2828) -> Result<AppResponseData<LfsCleanupResponse>, ApiError> {
29 require_writer(
29 let (ctx, _) = require_writer(
3030 &service,
3131 &session,
3232 path.space_name.clone(),
@@ -34,7 +34,7 @@
3434 )
3535 .await?;
3636 let removed = service
37 .lfs_cleanup_unreferenced(path.space_name, path.repo_name)
37 .lfs_cleanup_unreferenced(&ctx)
3838 .await
3939 .map_err(GitApiError::from)?;
4040 Ok(AppResponseData::ok(LfsCleanupResponse { removed }))
Modified lib/git/src/handler/lfs/list_locks.rs View lib/git/src/handler/lfs/list_locks.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<RepoPath>,
3232 Query(query): Query<LfsListLocksQuery>,
3333) -> Result<AppResponseData<LfsLockListResponse>, ApiError> {
34 resolve_reader(
34 let (ctx, _) = resolve_reader(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -39,12 +39,7 @@
3939 )
4040 .await?;
4141 let out = service
42 .lfs_list_locks(
43 path.space_name,
44 path.repo_name,
45 query.cursor,
46 query.limit.unwrap_or(0),
47 )
42 .lfs_list_locks(&ctx, query.cursor, query.limit.unwrap_or(0))
4843 .await
4944 .map_err(GitApiError::from)?;
5045 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/lfs/lock.rs View lib/git/src/handler/lfs/lock.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<RepoPath>,
3232 Json(body): Json<LfsLockBody>,
3333) -> Result<AppResponseData<LfsLock>, ApiError> {
34 let (_ctx, uid) = require_writer(
34 let (ctx, uid) = require_writer(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -39,7 +39,7 @@
3939 )
4040 .await?;
4141 let out = service
42 .lfs_lock(path.space_name, path.repo_name, uid, body.path, body.oid)
42 .lfs_lock(&ctx, uid, body.path, body.oid)
4343 .await
4444 .map_err(GitApiError::from)?;
4545 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/lfs/mod.rs View lib/git/src/handler/lfs/mod.rs
@@ -17,14 +17,10 @@
1717 space_name: String,
1818 repo_name: String,
1919 force: bool,
20) -> Result<i64, ApiError> {
20) -> Result<(crate::context::facade::GitContext, i64), ApiError> {
2121 if force {
22 Ok(require_repo_admin(service, session, space_name, repo_name)
23 .await?
24 .1)
22 require_repo_admin(service, session, space_name, repo_name).await
2523 } else {
26 Ok(require_writer(service, session, space_name, repo_name)
27 .await?
28 .1)
24 require_writer(service, session, space_name, repo_name).await
2925 }
3026}
Modified lib/git/src/handler/lfs/unlock.rs View lib/git/src/handler/lfs/unlock.rs
@@ -30,7 +30,7 @@
3030 Query(q): Query<LfsUnlockPathQuery>,
3131) -> Result<AppResponseData<NoData>, ApiError> {
3232 let force = q.force.unwrap_or(false);
33 let uid = lfs::unlock_actor(
33 let (ctx, uid) = lfs::unlock_actor(
3434 &service,
3535 &session,
3636 path.space_name.clone(),
@@ -39,7 +39,7 @@
3939 )
4040 .await?;
4141 service
42 .lfs_unlock(path.space_name, path.repo_name, uid, q.path, force)
42 .lfs_unlock(&ctx, uid, q.path, force)
4343 .await
4444 .map_err(GitApiError::from)?;
4545 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/lfs/unlock_by_id.rs View lib/git/src/handler/lfs/unlock_by_id.rs
@@ -36,7 +36,7 @@
3636 Query(q): Query<LfsUnlockQuery>,
3737) -> Result<AppResponseData<NoData>, ApiError> {
3838 let force = q.force.unwrap_or(false);
39 let uid = lfs::unlock_actor(
39 let (ctx, uid) = lfs::unlock_actor(
4040 &service,
4141 &session,
4242 path.space_name.clone(),
@@ -45,7 +45,7 @@
4545 )
4646 .await?;
4747 service
48 .lfs_unlock_by_id(path.space_name, path.repo_name, uid, path.lock_id, force)
48 .lfs_unlock_by_id(&ctx, uid, path.lock_id, force)
4949 .await
5050 .map_err(GitApiError::from)?;
5151 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/lfs/verify_locks.rs View lib/git/src/handler/lfs/verify_locks.rs
@@ -29,7 +29,7 @@
2929 Path(path): Path<RepoPath>,
3030 Query(query): Query<LfsVerifyLocksQuery>,
3131) -> Result<AppResponseData<LfsVerifyLocksResponse>, ApiError> {
32 let (_ctx, uid) = require_writer(
32 let (ctx, uid) = require_writer(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,12 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .lfs_verify_locks(
41 path.space_name,
42 path.repo_name,
43 uid,
44 query.limit.unwrap_or(0),
45 )
40 .lfs_verify_locks(&ctx, uid, query.limit.unwrap_or(0))
4641 .await
4742 .map_err(GitApiError::from)?;
4843 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/maintenance/fsck.rs View lib/git/src/handler/maintenance/fsck.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<RepoPath>,
2424) -> Result<AppResponseData<FsckDto>, ApiError> {
25 require_writer(
25 let (ctx, _) = require_writer(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .maintenance_fsck(path.space_name, path.repo_name)
33 .maintenance_fsck(&ctx)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/maintenance/prune.rs View lib/git/src/handler/maintenance/prune.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<RepoPath>,
2424) -> Result<AppResponseData<PruneResultDto>, ApiError> {
25 require_writer(
25 let (ctx, _) = require_writer(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .maintenance_prune(path.space_name, path.repo_name)
33 .maintenance_prune(&ctx)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/packs/ingest.rs View lib/git/src/handler/packs/ingest.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<RepoPath>,
2525 body: Bytes,
2626) -> Result<AppResponseData<IngestPackDto>, ApiError> {
27 require_writer(
27 let (ctx, _) = require_writer(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -32,7 +32,7 @@
3232 )
3333 .await?;
3434 let out = service
35 .pack_ingest(path.space_name, path.repo_name, body.to_vec())
35 .pack_ingest(&ctx, body.to_vec())
3636 .await
3737 .map_err(GitApiError::from)?;
3838 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/packs/repack.rs View lib/git/src/handler/packs/repack.rs
@@ -21,16 +21,13 @@
2121 session: Session,
2222 Path(path): Path<RepoPath>,
2323) -> Result<AppResponseData<NoData>, ApiError> {
24 require_writer(
24 let (ctx, _) = require_writer(
2525 &service,
2626 &session,
2727 path.space_name.clone(),
2828 path.repo_name.clone(),
2929 )
3030 .await?;
31 service
32 .pack_repack(path.space_name, path.repo_name)
33 .await
34 .map_err(GitApiError::from)?;
31 service.pack_repack(&ctx).await.map_err(GitApiError::from)?;
3532 Ok(AppResponseData::ok(NoData))
3633}
Modified lib/git/src/handler/packs/stats.rs View lib/git/src/handler/packs/stats.rs
@@ -22,16 +22,13 @@
2222 session: Session,
2323 Path(path): Path<RepoPath>,
2424) -> Result<AppResponseData<PackStatsDto>, ApiError> {
25 resolve_reader(
25 let (ctx, _) = resolve_reader(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
2929 path.repo_name.clone(),
3030 )
3131 .await?;
32 let out = service
33 .pack_stats(path.space_name, path.repo_name)
34 .await
35 .map_err(GitApiError::from)?;
32 let out = service.pack_stats(&ctx).await.map_err(GitApiError::from)?;
3633 Ok(AppResponseData::ok(out))
3734}
Modified lib/git/src/handler/patches/apply.rs View lib/git/src/handler/patches/apply.rs
@@ -30,7 +30,7 @@
3030 Path(path): Path<crate::handler::RepoPath>,
3131 Json(body): Json<PatchApplyBody>,
3232) -> Result<AppResponseData<AppliedPatchDto>, ApiError> {
33 let _ = handler::resolve_reader(
33 let (ctx, _) = handler::resolve_reader(
3434 &service,
3535 &session,
3636 path.space_name.clone(),
@@ -38,7 +38,7 @@
3838 )
3939 .await?;
4040 let out = service
41 .patch_apply(path.space_name, path.repo_name, body.patch, body.base)
41 .patch_apply(&ctx, body.patch, body.base)
4242 .await
4343 .map_err(GitApiError::from)?;
4444 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/patches/generate.rs View lib/git/src/handler/patches/generate.rs
@@ -29,7 +29,7 @@
2929 Path(path): Path<crate::handler::RepoPath>,
3030 Query(q): Query<PatchGenerateQuery>,
3131) -> Result<AppResponseData<PatchDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .patch_generate(path.space_name, path.repo_name, q.base, q.head)
40 .patch_generate(&ctx, q.base, q.head)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/refs/branches.rs View lib/git/src/handler/refs/branches.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<crate::handler::RepoPath>,
3232 Query(query): Query<RefsBranchesQuery>,
3333) -> Result<AppResponseData<Vec<BranchInfoDto>>, ApiError> {
34 let _ = handler::resolve_reader(
34 let (ctx, _) = handler::resolve_reader(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -39,12 +39,7 @@
3939 )
4040 .await?;
4141 let out = service
42 .refs_branches(
43 path.space_name,
44 path.repo_name,
45 query.skip.unwrap_or(0),
46 query.limit.unwrap_or(0),
47 )
42 .refs_branches(&ctx, query.skip.unwrap_or(0), query.limit.unwrap_or(0))
4843 .await
4944 .map_err(GitApiError::from)?;
5045 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/refs/delete.rs View lib/git/src/handler/refs/delete.rs
@@ -28,7 +28,7 @@
2828 session: Session,
2929 Path(path): Path<RefPath>,
3030) -> Result<AppResponseData<NoData>, ApiError> {
31 let _ = handler::require_writer(
31 let (ctx, _) = handler::require_writer(
3232 &service,
3333 &session,
3434 path.space_name.clone(),
@@ -36,7 +36,7 @@
3636 )
3737 .await?;
3838 service
39 .refs_delete(path.space_name, path.repo_name, path.name)
39 .refs_delete(&ctx, path.name)
4040 .await
4141 .map_err(GitApiError::from)?;
4242 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/refs/filtered.rs View lib/git/src/handler/refs/filtered.rs
@@ -28,7 +28,7 @@
2828 Path(path): Path<crate::handler::RepoPath>,
2929 Query(query): Query<RefsFilteredQuery>,
3030) -> Result<AppResponseData<Vec<RefInfo>>, ApiError> {
31 let _ = handler::resolve_reader(
31 let (ctx, _) = handler::resolve_reader(
3232 &service,
3333 &session,
3434 path.space_name.clone(),
@@ -36,7 +36,7 @@
3636 )
3737 .await?;
3838 let out = service
39 .refs_list_filtered(path.space_name, path.repo_name, query.pattern)
39 .refs_list_filtered(&ctx, query.pattern)
4040 .await
4141 .map_err(GitApiError::from)?;
4242 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/refs/get.rs View lib/git/src/handler/refs/get.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<RefPath>,
3131) -> Result<AppResponseData<RefInfo>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .refs_get(path.space_name, path.repo_name, path.name)
40 .refs_get(&ctx, path.name)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/refs/head.rs View lib/git/src/handler/refs/head.rs
@@ -22,16 +22,13 @@
2222 session: Session,
2323 Path(path): Path<crate::handler::RepoPath>,
2424) -> Result<AppResponseData<HeadInfoDto>, ApiError> {
25 let _ = handler::resolve_reader(
25 let (ctx, _) = handler::resolve_reader(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
2929 path.repo_name.clone(),
3030 )
3131 .await?;
32 let out = service
33 .refs_head(path.space_name, path.repo_name)
34 .await
35 .map_err(GitApiError::from)?;
32 let out = service.refs_head(&ctx).await.map_err(GitApiError::from)?;
3633 Ok(AppResponseData::ok(out))
3734}
Modified lib/git/src/handler/refs/is_object_in_ref.rs View lib/git/src/handler/refs/is_object_in_ref.rs
@@ -34,7 +34,7 @@
3434 Path(path): Path<crate::handler::RepoPath>,
3535 Query(query): Query<ContainsQuery>,
3636) -> Result<AppResponseData<IsObjectInRefResponse>, ApiError> {
37 let _ = handler::resolve_reader(
37 let (ctx, _) = handler::resolve_reader(
3838 &service,
3939 &session,
4040 path.space_name.clone(),
@@ -42,7 +42,7 @@
4242 )
4343 .await?;
4444 let contains = service
45 .refs_is_object_in_ref(path.space_name, path.repo_name, query.object, query.refname)
45 .refs_is_object_in_ref(&ctx, query.object, query.refname)
4646 .await
4747 .map_err(GitApiError::from)?;
4848 Ok(AppResponseData::ok(IsObjectInRefResponse { contains }))
Modified lib/git/src/handler/refs/list.rs View lib/git/src/handler/refs/list.rs
@@ -22,16 +22,13 @@
2222 session: Session,
2323 Path(path): Path<crate::handler::RepoPath>,
2424) -> Result<AppResponseData<Vec<RefInfo>>, ApiError> {
25 let _ = handler::resolve_reader(
25 let (ctx, _) = handler::resolve_reader(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
2929 path.repo_name.clone(),
3030 )
3131 .await?;
32 let out = service
33 .refs_list(path.space_name, path.repo_name)
34 .await
35 .map_err(GitApiError::from)?;
32 let out = service.refs_list(&ctx).await.map_err(GitApiError::from)?;
3633 Ok(AppResponseData::ok(out))
3734}
Modified lib/git/src/handler/refs/resolve.rs View lib/git/src/handler/refs/resolve.rs
@@ -28,7 +28,7 @@
2828 session: Session,
2929 Path(path): Path<RefPath>,
3030) -> Result<AppResponseData<String>, ApiError> {
31 let _ = handler::resolve_reader(
31 let (ctx, _) = handler::resolve_reader(
3232 &service,
3333 &session,
3434 path.space_name.clone(),
@@ -36,7 +36,7 @@
3636 )
3737 .await?;
3838 let out = service
39 .refs_resolve(path.space_name, path.repo_name, path.name)
39 .refs_resolve(&ctx, path.name)
4040 .await
4141 .map_err(GitApiError::from)?;
4242 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/refs/update.rs View lib/git/src/handler/refs/update.rs
@@ -38,7 +38,7 @@
3838 Path(path): Path<RefPath>,
3939 Json(body): Json<RefUpdateBody>,
4040) -> Result<AppResponseData<UpdateRefResultDto>, ApiError> {
41 let _ = handler::require_writer(
41 let (ctx, _) = handler::require_writer(
4242 &service,
4343 &session,
4444 path.space_name.clone(),
@@ -46,13 +46,7 @@
4646 )
4747 .await?;
4848 let out = service
49 .refs_update(
50 path.space_name,
51 path.repo_name,
52 path.name,
53 body.new_oid,
54 body.expected_oid,
55 )
49 .refs_update(&ctx, path.name, body.new_oid, body.expected_oid)
5650 .await
5751 .map_err(GitApiError::from)?;
5852 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/releases/create_release.rs View lib/git/src/handler/releases/create_release.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<crate::handler::RepoPath>,
2525 Json(cmd): Json<CreateReleaseCmd>,
2626) -> Result<AppResponseData<ReleaseDto>, ApiError> {
27 let (_ctx, uid) = handler::require_writer(
27 let (ctx, uid) = handler::require_writer(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -32,7 +32,7 @@
3232 )
3333 .await?;
3434 let out = service
35 .create_release(path.space_name, path.repo_name, uid, cmd)
35 .create_release(&ctx, uid, cmd)
3636 .await
3737 .map_err(GitApiError::from)?;
3838 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/releases/delete_release.rs View lib/git/src/handler/releases/delete_release.rs
@@ -21,7 +21,7 @@
2121 session: Session,
2222 Path(path): Path<crate::handler::releases::get_release::ReleasePath>,
2323) -> Result<AppResponseData<NoData>, ApiError> {
24 let (_ctx, uid) = require_writer(
24 let (ctx, uid) = require_writer(
2525 &service,
2626 &session,
2727 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 .await
3838 .is_ok();
3939 service
40 .delete_release(path.space_name, path.repo_name, path.tag, uid, admin)
40 .delete_release(&ctx, path.tag, uid, admin)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/releases/get_release.rs View lib/git/src/handler/releases/get_release.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<ReleasePath>,
3131) -> Result<AppResponseData<ReleaseDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .get_release(path.space_name, path.repo_name, path.tag)
40 .get_release(&ctx, path.tag)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/releases/list_releases.rs View lib/git/src/handler/releases/list_releases.rs
@@ -23,7 +23,7 @@
2323 Path(path): Path<crate::handler::RepoPath>,
2424 Query(query): Query<ListReleasesQuery>,
2525) -> Result<AppResponseData<ReleasePage>, ApiError> {
26 let _ = handler::resolve_reader(
26 let (ctx, _) = handler::resolve_reader(
2727 &service,
2828 &session,
2929 path.space_name.clone(),
@@ -31,7 +31,7 @@
3131 )
3232 .await?;
3333 let out = service
34 .list_releases(path.space_name, path.repo_name, query)
34 .list_releases(&ctx, query)
3535 .await
3636 .map_err(GitApiError::from)?;
3737 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/releases/update_release.rs View lib/git/src/handler/releases/update_release.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<crate::handler::releases::get_release::ReleasePath>,
2525 Json(cmd): Json<UpdateReleaseCmd>,
2626) -> Result<AppResponseData<ReleaseDto>, ApiError> {
27 let (_ctx, uid) = require_writer(
27 let (ctx, uid) = require_writer(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -40,7 +40,7 @@
4040 .await
4141 .is_ok();
4242 let out = service
43 .update_release(path.space_name, path.repo_name, path.tag, uid, admin, cmd)
43 .update_release(&ctx, path.tag, uid, admin, cmd)
4444 .await
4545 .map_err(GitApiError::from)?;
4646 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/remotes/add.rs View lib/git/src/handler/remotes/add.rs
@@ -35,7 +35,7 @@
3535 Path(path): Path<RemotePath>,
3636 Json(body): Json<RemoteAddBody>,
3737) -> Result<AppResponseData<NoData>, ApiError> {
38 handler::require_writer(
38 let (ctx, _) = handler::require_writer(
3939 &service,
4040 &session,
4141 path.space_name.clone(),
@@ -43,7 +43,7 @@
4343 )
4444 .await?;
4545 service
46 .remote_upsert(path.space_name, path.repo_name, path.name, body.url)
46 .remote_upsert(&ctx, path.name, body.url)
4747 .await
4848 .map_err(GitApiError::from)?;
4949 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/remotes/clone_import.rs View lib/git/src/handler/remotes/clone_import.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<RepoPath>,
3232 Json(body): Json<RemoteImportBody>,
3333) -> Result<AppResponseData<ImportResultDto>, ApiError> {
34 require_writer(
34 let (ctx, _) = require_writer(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -39,7 +39,7 @@
3939 )
4040 .await?;
4141 let out = service
42 .remote_clone_import(path.space_name, path.repo_name, body.url, body.auth)
42 .remote_clone_import(&ctx, body.url, body.auth)
4343 .await
4444 .map_err(GitApiError::from)?;
4545 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/remotes/fetch.rs View lib/git/src/handler/remotes/fetch.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<RepoPath>,
3232 Json(body): Json<RemoteFetchBody>,
3333) -> Result<AppResponseData<FetchResultDto>, ApiError> {
34 require_writer(
34 let (ctx, _) = require_writer(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -39,7 +39,7 @@
3939 )
4040 .await?;
4141 let out = service
42 .remote_fetch(path.space_name, path.repo_name, body.remote, body.auth)
42 .remote_fetch(&ctx, body.remote, body.auth)
4343 .await
4444 .map_err(GitApiError::from)?;
4545 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/remotes/list.rs View lib/git/src/handler/remotes/list.rs
@@ -27,9 +27,6 @@
2727 .await
2828 .map_err(GitApiError::from)?;
2929 ensure_read_access(&service, &session, &ctx).await?;
30 let rows = service
31 .remote_list(path.space_name, path.repo_name)
32 .await
33 .map_err(GitApiError::from)?;
30 let rows = service.remote_list(&ctx).await.map_err(GitApiError::from)?;
3431 Ok(AppResponseData::ok(rows))
3532}
Modified lib/git/src/handler/remotes/push.rs View lib/git/src/handler/remotes/push.rs
@@ -33,7 +33,7 @@
3333 Path(path): Path<RepoPath>,
3434 Json(body): Json<RemotePushBody>,
3535) -> Result<AppResponseData<PushResultDto>, ApiError> {
36 require_writer(
36 let (ctx, _) = require_writer(
3737 &service,
3838 &session,
3939 path.space_name.clone(),
@@ -41,13 +41,7 @@
4141 )
4242 .await?;
4343 let out = service
44 .remote_push(
45 path.space_name,
46 path.repo_name,
47 body.remote,
48 body.refspec,
49 body.auth,
50 )
44 .remote_push(&ctx, body.remote, body.refspec, body.auth)
5145 .await
5246 .map_err(GitApiError::from)?;
5347 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/remotes/remove.rs View lib/git/src/handler/remotes/remove.rs
@@ -28,7 +28,7 @@
2828 session: Session,
2929 Path(path): Path<RemotePath>,
3030) -> Result<AppResponseData<NoData>, ApiError> {
31 handler::require_writer(
31 let (ctx, _) = handler::require_writer(
3232 &service,
3333 &session,
3434 path.space_name.clone(),
@@ -36,7 +36,7 @@
3636 )
3737 .await?;
3838 service
39 .remote_remove(path.space_name, path.repo_name, path.name)
39 .remote_remove(&ctx, path.name)
4040 .await
4141 .map_err(GitApiError::from)?;
4242 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/repos/archive.rs View lib/git/src/handler/repos/archive.rs
@@ -23,8 +23,12 @@
2323 Path(path): Path<RepoPath>,
2424) -> Result<AppResponseData<RepoDto>, ApiError> {
2525 let caller = ensure_caller(&session)?;
26 let ctx = service
27 .context(path.space_name, path.repo_name)
28 .await
29 .map_err(GitApiError::from)?;
2630 let out = service
27 .set_repo_archived(path.space_name, path.repo_name, caller, true)
31 .set_repo_archived(&ctx, caller, true)
2832 .await
2933 .map_err(GitApiError::from)?;
3034 Ok(AppResponseData::ok(out))
@@ -46,8 +50,12 @@
4650 Path(path): Path<RepoPath>,
4751) -> Result<AppResponseData<RepoDto>, ApiError> {
4852 let caller = ensure_caller(&session)?;
53 let ctx = service
54 .context(path.space_name, path.repo_name)
55 .await
56 .map_err(GitApiError::from)?;
4957 let out = service
50 .set_repo_archived(path.space_name, path.repo_name, caller, false)
58 .set_repo_archived(&ctx, caller, false)
5159 .await
5260 .map_err(GitApiError::from)?;
5361 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/repos/get.rs View lib/git/src/handler/repos/get.rs
@@ -29,10 +29,7 @@
2929 path.repo_name.clone(),
3030 )
3131 .await?;
32 let mut out = service
33 .get_repo(path.space_name, path.repo_name)
34 .await
35 .map_err(GitApiError::from)?;
32 let mut out = service.get_repo(&ctx).await.map_err(GitApiError::from)?;
3633 if let Some(uid) = viewer {
3734 out.me = Some(
3835 service
Modified lib/git/src/handler/repos/update.rs View lib/git/src/handler/repos/update.rs
@@ -25,8 +25,12 @@
2525 Json(cmd): Json<UpdateRepoCmd>,
2626) -> Result<AppResponseData<RepoDto>, ApiError> {
2727 let caller = ensure_caller(&session)?;
28 let ctx = service
29 .context(path.space_name, path.repo_name)
30 .await
31 .map_err(GitApiError::from)?;
2832 let out = service
29 .update_repo(path.space_name, path.repo_name, caller, cmd)
33 .update_repo(&ctx, caller, cmd)
3034 .await
3135 .map_err(GitApiError::from)?;
3236 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/signatures/verify_commit.rs View lib/git/src/handler/signatures/verify_commit.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<CommitShaPath>,
3131) -> Result<AppResponseData<VerifyResultDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .signature_verify_commit(path.space_name, path.repo_name, path.sha)
40 .signature_verify_commit(&ctx, path.sha)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/signatures/verify_tag.rs View lib/git/src/handler/signatures/verify_tag.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<TagNamePath>,
3131) -> Result<AppResponseData<VerifyResultDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .signature_verify_tag(path.space_name, path.repo_name, path.name)
40 .signature_verify_tag(&ctx, path.name)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/submodules/list.rs View lib/git/src/handler/submodules/list.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<crate::handler::RepoPath>,
3232 Query(q): Query<SubmoduleListQuery>,
3333) -> Result<AppResponseData<Vec<SubmoduleDto>>, ApiError> {
34 let _ = handler::resolve_reader(
34 let (ctx, _) = handler::resolve_reader(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -39,7 +39,7 @@
3939 )
4040 .await?;
4141 let out = service
42 .submodule_list(path.space_name, path.repo_name, q.revision)
42 .submodule_list(&ctx, q.revision)
4343 .await
4444 .map_err(GitApiError::from)?;
4545 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/submodules/resolve.rs View lib/git/src/handler/submodules/resolve.rs
@@ -31,7 +31,7 @@
3131 Path(path): Path<crate::handler::RepoPath>,
3232 Query(q): Query<SubmoduleResolveQuery>,
3333) -> Result<AppResponseData<String>, ApiError> {
34 let _ = handler::resolve_reader(
34 let (ctx, _) = handler::resolve_reader(
3535 &service,
3636 &session,
3737 path.space_name.clone(),
@@ -39,7 +39,7 @@
3939 )
4040 .await?;
4141 let out = service
42 .submodule_resolve(path.space_name, path.repo_name, q.revision, q.path)
42 .submodule_resolve(&ctx, q.revision, q.path)
4343 .await
4444 .map_err(GitApiError::from)?;
4545 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/tag_protection/create_policy.rs View lib/git/src/handler/tag_protection/create_policy.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<RepoPath>,
2525 Json(cmd): Json<CreateTagPolicyCmd>,
2626) -> Result<AppResponseData<TagPolicyDto>, ApiError> {
27 let _ = require_repo_admin(
27 let (ctx, _) = require_repo_admin(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -32,7 +32,7 @@
3232 )
3333 .await?;
3434 let out = service
35 .create_tag_policy(path.space_name, path.repo_name, cmd)
35 .create_tag_policy(&ctx, cmd)
3636 .await
3737 .map_err(GitApiError::from)?;
3838 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/tag_protection/delete_policy.rs View lib/git/src/handler/tag_protection/delete_policy.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<PolicyPath>,
2424) -> Result<AppResponseData<NoData>, ApiError> {
25 let _ = handler::require_repo_admin(
25 let (ctx, _) = handler::require_repo_admin(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 service
33 .delete_tag_policy(path.space_name, path.repo_name, path.policy_id)
33 .delete_tag_policy(&ctx, path.policy_id)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/tag_protection/get_policy.rs View lib/git/src/handler/tag_protection/get_policy.rs
@@ -23,7 +23,7 @@
2323 session: Session,
2424 Path(path): Path<PolicyPath>,
2525) -> Result<AppResponseData<TagPolicyDto>, ApiError> {
26 let _ = handler::require_repo_admin(
26 let (ctx, _) = handler::require_repo_admin(
2727 &service,
2828 &session,
2929 path.space_name.clone(),
@@ -31,7 +31,7 @@
3131 )
3232 .await?;
3333 let out = service
34 .get_tag_policy(path.space_name, path.repo_name, path.policy_id)
34 .get_tag_policy(&ctx, path.policy_id)
3535 .await
3636 .map_err(GitApiError::from)?;
3737 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/tag_protection/list_policies.rs View lib/git/src/handler/tag_protection/list_policies.rs
@@ -22,7 +22,7 @@
2222 session: Session,
2323 Path(path): Path<RepoPath>,
2424) -> Result<AppResponseData<Vec<TagPolicyDto>>, ApiError> {
25 let _ = require_repo_admin(
25 let (ctx, _) = require_repo_admin(
2626 &service,
2727 &session,
2828 path.space_name.clone(),
@@ -30,7 +30,7 @@
3030 )
3131 .await?;
3232 let out = service
33 .list_tag_policies(path.space_name, path.repo_name)
33 .list_tag_policies(&ctx)
3434 .await
3535 .map_err(GitApiError::from)?;
3636 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/tag_protection/update_policy.rs View lib/git/src/handler/tag_protection/update_policy.rs
@@ -25,7 +25,7 @@
2525 Path(path): Path<PolicyPath>,
2626 Json(cmd): Json<UpdateTagPolicyCmd>,
2727) -> Result<AppResponseData<TagPolicyDto>, ApiError> {
28 let _ = handler::require_repo_admin(
28 let (ctx, _) = handler::require_repo_admin(
2929 &service,
3030 &session,
3131 path.space_name.clone(),
@@ -33,7 +33,7 @@
3333 )
3434 .await?;
3535 let out = service
36 .update_tag_policy(path.space_name, path.repo_name, path.policy_id, cmd)
36 .update_tag_policy(&ctx, path.policy_id, cmd)
3737 .await
3838 .map_err(GitApiError::from)?;
3939 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/tags/create.rs View lib/git/src/handler/tags/create.rs
@@ -24,7 +24,7 @@
2424 Path(path): Path<crate::handler::RepoPath>,
2525 Json(cmd): Json<CreateTagCmd>,
2626) -> Result<AppResponseData<TagDto>, ApiError> {
27 let _ = handler::require_writer(
27 let (ctx, _) = handler::require_writer(
2828 &service,
2929 &session,
3030 path.space_name.clone(),
@@ -32,7 +32,7 @@
3232 )
3333 .await?;
3434 let out = service
35 .create_tag(path.space_name, path.repo_name, cmd)
35 .create_tag(&ctx, cmd)
3636 .await
3737 .map_err(GitApiError::from)?;
3838 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/tags/delete.rs View lib/git/src/handler/tags/delete.rs
@@ -28,7 +28,7 @@
2828 session: Session,
2929 Path(path): Path<TagPath>,
3030) -> Result<AppResponseData<NoData>, ApiError> {
31 let _ = handler::require_writer(
31 let (ctx, _) = handler::require_writer(
3232 &service,
3333 &session,
3434 path.space_name.clone(),
@@ -36,7 +36,7 @@
3636 )
3737 .await?;
3838 service
39 .delete_tag(path.space_name, path.repo_name, path.name)
39 .delete_tag(&ctx, path.name)
4040 .await
4141 .map_err(GitApiError::from)?;
4242 Ok(AppResponseData::ok(NoData))
Modified lib/git/src/handler/tags/get.rs View lib/git/src/handler/tags/get.rs
@@ -29,7 +29,7 @@
2929 session: Session,
3030 Path(path): Path<TagPath>,
3131) -> Result<AppResponseData<TagDto>, ApiError> {
32 let _ = handler::resolve_reader(
32 let (ctx, _) = handler::resolve_reader(
3333 &service,
3434 &session,
3535 path.space_name.clone(),
@@ -37,7 +37,7 @@
3737 )
3838 .await?;
3939 let out = service
40 .get_tag(path.space_name, path.repo_name, path.name)
40 .get_tag(&ctx, path.name)
4141 .await
4242 .map_err(GitApiError::from)?;
4343 Ok(AppResponseData::ok(out))
Modified lib/git/src/handler/tags/list.rs View lib/git/src/handler/tags/list.rs
@@ -23,17 +23,14 @@
2323 Path(path): Path<crate::handler::RepoPath>,
2424 Query(page): Query<export::pagination::PageQuery>,
2525) -> Result<AppResponseData<export::pagination::Page<TagDto>>, ApiError> {
26 let _ = handler::resolve_reader(
26 let (ctx, _) = handler::resolve_reader(
2727 &service,
2828 &session,
2929 path.space_name.clone(),
3030 path.repo_name.clone(),
3131 )
3232 .await?;
33 let all = service
34 .list_tags(path.space_name, path.repo_name)
35 .await
36 .map_err(GitApiError::from)?;
33 let all = service.list_tags(&ctx).await.map_err(GitApiError::from)?;
3734 let total = all.len() as i64;
3835 let (limit, offset) = page.page();
3936 let items = all
Modified lib/git/src/handler/trees/read.rs View lib/git/src/handler/trees/read.rs
@@ -50,7 +50,7 @@
5050 Path(path): Path<crate::handler::RepoPathRev>,
5151 Query(q): Query<GetTreeQuery>,
5252) -> Result<AppResponseData<serde_json::Value>, ApiError> {
53 let _ = handler::resolve_reader(
53 let (ctx, _) = handler::resolve_reader(
5454 &service,
5555 &session,
5656 path.space_name.clone(),
@@ -61,7 +61,7 @@
6161 Some(TreeView::LastUpdated) => {
6262 let p = (!q.path.is_empty()).then(|| q.path.clone());
6363 let rows = service
64 .tree_last_updated(path.space_name, path.repo_name, path.revision, p)
64 .tree_last_updated(&ctx, path.revision, p)
6565 .await
6666 .map_err(GitApiError::from)?;
6767 serde_json::to_value(rows).map_err(json_err)?
@@ -69,7 +69,7 @@
6969 _ => {
7070 if q.resolve && !q.path.is_empty() {
7171 let (entry, target, resolved) = service
72 .tree_follow(path.space_name, path.repo_name, path.revision, q.path)
72 .tree_follow(&ctx, path.revision, q.path)
7373 .await
7474 .map_err(GitApiError::from)?;
7575 serde_json::json!({
@@ -79,24 +79,13 @@
7979 })
8080 } else if q.recurse {
8181 let entries = service
82 .tree_walk(
83 path.space_name,
84 path.repo_name,
85 path.revision,
86 true,
87 q.show_trees,
88 )
82 .tree_walk(&ctx, path.revision, true, q.show_trees)
8983 .await
9084 .map_err(GitApiError::from)?;
9185 serde_json::to_value(entries).map_err(json_err)?
9286 } else {
9387 let entries = service
94 .tree_read(
95 path.space_name,
96 path.repo_name,
97 path.revision,
98 PathBuf::from(&q.path),
99 )
88 .tree_read(&ctx, path.revision, PathBuf::from(&q.path))
10089 .await
10190 .map_err(GitApiError::from)?;
10291 serde_json::to_value(entries).map_err(json_err)?
Modified lib/git/src/handler/blame.rs View lib/git/src/handler/blame.rs
@@ -36,7 +36,7 @@
3636 Path(path): Path<crate::handler::RepoPath>,
3737 Query(q): Query<BlameQuery>,
3838) -> Result<AppResponseData<Vec<BlameRangeDto>>, ApiError> {
39 let _ = handler::resolve_reader(
39 let (ctx, _) = handler::resolve_reader(
4040 &service,
4141 &session,
4242 path.space_name.clone(),
@@ -45,8 +45,7 @@
4545 .await?;
4646 let ranges = service
4747 .blame(
48 path.space_name,
49 path.repo_name,
48 &ctx,
5049 q.revision,
5150 std::path::PathBuf::from(q.path),
5251 q.range_start,
Modified lib/git/src/handler/path_log.rs View lib/git/src/handler/path_log.rs
@@ -32,7 +32,7 @@
3232 Path(path): Path<crate::handler::RepoPath>,
3333 Query(q): Query<PathLogQuery>,
3434) -> Result<AppResponseData<Vec<PathLogEntryDto>>, ApiError> {
35 let _ = handler::resolve_reader(
35 let (ctx, _) = handler::resolve_reader(
3636 &service,
3737 &session,
3838 path.space_name.clone(),
@@ -40,12 +40,7 @@
4040 )
4141 .await?;
4242 let entries = service
43 .path_log(
44 path.space_name,
45 path.repo_name,
46 q.commit_hash,
47 std::path::PathBuf::from(q.target_dir),
48 )
43 .path_log(&ctx, q.commit_hash, std::path::PathBuf::from(q.target_dir))
4944 .await
5045 .map_err(GitApiError::from)?;
5146 Ok(AppResponseData::ok(entries))
Modified lib/git/src/lfs/lock.rs View lib/git/src/lfs/lock.rs
@@ -5,6 +5,7 @@
55use time::OffsetDateTime;
66use uuid::Uuid;
77
8use crate::context::facade::GitContext;
89use crate::lfs::types::{LfsLock, LfsLockListResponse, LfsLockOwner, LfsVerifyLocksResponse};
910use crate::lfs::validate::{canonical_oid, validate_lock_path};
1011use crate::service::GitService;
@@ -15,13 +16,11 @@
1516
1617pub async fn create(
1718 svc: &GitService,
18 space_name: String,
19 repo_name: String,
19 ctx: &GitContext,
2020 caller: i64,
2121 path: String,
2222 oid: Option<String>,
2323) -> Result<LfsLock, GitError> {
24 let ctx = svc.context(space_name, repo_name).await?;
2524 if !ctx.model.enable_lfs {
2625 return Err(GitError::NotFound);
2726 }
@@ -52,13 +51,11 @@
5251
5352pub async fn unlock(
5453 svc: &GitService,
55 space_name: String,
56 repo_name: String,
54 ctx: &GitContext,
5755 caller: i64,
5856 path: String,
5957 force: bool,
6058) -> Result<(), GitError> {
61 let ctx = svc.context(space_name, repo_name).await?;
6259 let row = git_lfs_lock::Entity::find()
6360 .filter(git_lfs_lock::Column::RepoId.eq(ctx.model.id))
6461 .filter(git_lfs_lock::Column::Path.eq(&path))
@@ -78,13 +75,11 @@
7875/// `POST locks/{id}/unlock`). Same ownership/`force` rules as [`unlock`].
7976pub async fn unlock_by_id(
8077 svc: &GitService,
81 space_name: String,
82 repo_name: String,
78 ctx: &GitContext,
8379 caller: i64,
8480 lock_id: String,
8581 force: bool,
8682) -> Result<(), GitError> {
87 let ctx = svc.context(space_name, repo_name).await?;
8883 let id = Uuid::parse_str(&lock_id).map_err(|_| GitError::NotFound)?;
8984 let row = git_lfs_lock::Entity::find()
9085 .filter(git_lfs_lock::Column::RepoId.eq(ctx.model.id))
@@ -106,12 +101,10 @@
106101/// the client can page forward.
107102pub async fn list(
108103 svc: &GitService,
109 space_name: String,
110 repo_name: String,
104 ctx: &GitContext,
111105 cursor: Option<String>,
112106 limit: u64,
113107) -> Result<LfsLockListResponse, GitError> {
114 let ctx = svc.context(space_name, repo_name).await?;
115108 let limit = normalize_limit(limit);
116109 let mut find = git_lfs_lock::Entity::find()
117110 .filter(git_lfs_lock::Column::RepoId.eq(ctx.model.id))
@@ -135,12 +128,10 @@
135128/// Split this repo's locks into `ours` (locked by the caller) and `theirs`.
136129pub async fn verify_locks(
137130 svc: &GitService,
138 space_name: String,
139 repo_name: String,
131 ctx: &GitContext,
140132 caller: i64,
141133 limit: u64,
142134) -> Result<LfsVerifyLocksResponse, GitError> {
143 let ctx = svc.context(space_name, repo_name).await?;
144135 let rows = git_lfs_lock::Entity::find()
145136 .filter(git_lfs_lock::Column::RepoId.eq(ctx.model.id))
146137 .order_by_asc(git_lfs_lock::Column::CreatedAt)
Modified lib/git/src/service/analysis.rs View lib/git/src/service/analysis.rs
@@ -11,6 +11,7 @@
1111use time::OffsetDateTime;
1212use uuid::Uuid;
1313
14use crate::context::facade::GitContext;
1415use crate::service::GitService;
1516use crate::service::cache::{self, ANALYSIS_TTL};
1617use crate::share::errors::{GitError, map_baby};
@@ -100,10 +101,8 @@
100101 /// `git_language` (percentage in basis points) + `repos.primary_language`.
101102 pub async fn analysis_languages(
102103 &self,
103 space_name: String,
104 repo_name: String,
104 ctx: &GitContext,
105105 ) -> Result<Vec<LanguageStatDto>, GitError> {
106 let ctx = self.context(space_name, repo_name).await?;
107106 if ctx.repo_uninitialized() {
108107 return Ok(Vec::new());
109108 }
@@ -187,10 +186,8 @@
187186
188187 pub async fn analysis_languages_read(
189188 &self,
190 space_name: String,
191 repo_name: String,
189 ctx: &GitContext,
192190 ) -> Result<Vec<LanguageStatDto>, GitError> {
193 let ctx = self.context(space_name, repo_name).await?;
194191 let rows = git_languages::Entity::find()
195192 .filter(git_languages::Column::RepoId.eq(ctx.model.id))
196193 .order_by_desc(git_languages::Column::Size)
@@ -210,10 +207,8 @@
210207
211208 pub async fn analysis_contributors(
212209 &self,
213 space_name: String,
214 repo_name: String,
210 ctx: &GitContext,
215211 ) -> Result<Vec<ContributorStatDto>, GitError> {
216 let ctx = self.context(space_name, repo_name).await?;
217212 if ctx.repo_uninitialized() {
218213 return Ok(Vec::new());
219214 }
@@ -256,11 +251,9 @@
256251
257252 pub async fn analysis_code_activity(
258253 &self,
259 space_name: String,
260 repo_name: String,
254 ctx: &GitContext,
261255 branch: Option<String>,
262256 ) -> Result<CodeActivityDto, GitError> {
263 let ctx = self.context(space_name, repo_name).await?;
264257 let baby = self.baby(&ctx);
265258 let Some(revision) =
266259 resolve_analysis_revision(&baby, branch.as_deref(), &ctx.model.default_branch).await?
Modified lib/git/src/service/archives.rs View lib/git/src/service/archives.rs
@@ -2,6 +2,7 @@
22use serde::{Deserialize, Serialize};
33use uuid::Uuid;
44
5use crate::context::facade::GitContext;
56use crate::rpcgit::archive::types::ArchiveFormat;
67use crate::service::GitService;
78use crate::service::rpc::{rpc_error, wait_job};
@@ -44,13 +45,11 @@
4445impl GitService {
4546 pub async fn archive_create(
4647 &self,
47 space_name: String,
48 repo_name: String,
48 ctx: &GitContext,
4949 revision: String,
5050 opts: ArchiveOptionsDto,
5151 ) -> Result<ArchiveResultDto, GitError> {
5252 validate::validate_revision(&revision)?;
53 let ctx = self.context(space_name, repo_name).await?;
5453 let mut client = ctx.ks.archive();
5554 let job = client
5655 .start_archive(pb::StartArchiveRequest {
@@ -85,13 +84,11 @@
8584
8685 pub async fn archive_download(
8786 &self,
88 space_name: String,
89 repo_name: String,
87 ctx: &GitContext,
9088 revision: String,
9189 opts: ArchiveOptionsDto,
9290 ) -> Result<ArchiveResultDto, GitError> {
9391 validate::validate_revision(&revision)?;
94 let ctx = self.context(space_name, repo_name).await?;
9592 let mut client = ctx.ks.archive();
9693 let artifact = client
9794 .get_archive_artifact(pb::GetArchiveArtifactRequest {
@@ -115,10 +112,8 @@
115112
116113 pub async fn archive_create_bundle(
117114 &self,
118 space_name: String,
119 repo_name: String,
115 ctx: &GitContext,
120116 ) -> Result<ArchiveResultDto, GitError> {
121 let ctx = self.context(space_name, repo_name).await?;
122117 let mut client = ctx.ks.archive();
123118 let job = client
124119 .start_archive_bundle(pb::StartArchiveBundleRequest {
Modified lib/git/src/service/blame.rs View lib/git/src/service/blame.rs
@@ -1,6 +1,7 @@
11use crate::rpcgit::blame::types::{BlameHunk, BlameOptions, Range};
22use serde::{Deserialize, Serialize};
33
4use crate::context::facade::GitContext;
45use crate::service::GitService;
56use crate::service::cache::{self, IMMUTABLE_TTL};
67use crate::share::errors::{GitError, map_baby};
@@ -35,8 +36,7 @@
3536impl GitService {
3637 pub async fn blame(
3738 &self,
38 space_name: String,
39 repo_name: String,
39 ctx: &GitContext,
4040 revision: String,
4141 path: std::path::PathBuf,
4242 range_start: Option<u32>,
@@ -53,7 +53,6 @@
5353 path.display()
5454 )));
5555 }
56 let ctx = self.context(space_name, repo_name).await?;
5756 let baby = self.baby(&ctx);
5857 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
5958 let key = format!(
Modified lib/git/src/service/blobs.rs View lib/git/src/service/blobs.rs
@@ -1,6 +1,7 @@
11use crate::rpcgit::oid::ObjectId;
22use serde::{Deserialize, Serialize};
33
4use crate::context::facade::GitContext;
45use crate::service::GitService;
56use crate::service::cache::{self, IMMUTABLE_TTL};
67use crate::share::errors::{GitError, map_baby};
@@ -92,12 +93,10 @@
9293
9394 pub async fn blob_metadata(
9495 &self,
95 space_name: String,
96 repo_name: String,
96 ctx: &GitContext,
9797 oid: String,
9898 ) -> Result<BlobMetaDto, GitError> {
9999 let object_id = parse_oid(&oid)?;
100 let ctx = self.context(space_name, repo_name).await?;
101100 let key = format!("repo.{}.blob_meta.{}", ctx.model.id, object_id);
102101 cache::cached_fetch(&ctx.cache, &key, IMMUTABLE_TTL, || async {
103102 let (size, sniff) = self.blob_sniff(&ctx, &object_id).await?;
@@ -115,12 +114,10 @@
115114
116115 pub async fn blob_content(
117116 &self,
118 space_name: String,
119 repo_name: String,
117 ctx: &GitContext,
120118 oid: String,
121119 ) -> Result<BlobContentDto, GitError> {
122120 let object_id = parse_oid(&oid)?;
123 let ctx = self.context(space_name, repo_name).await?;
124121 let max_blob = self.state.config.git.max_blob_size;
125122 let key = format!(
126123 "repo.{}.blob_content.{}:{}",
@@ -158,12 +155,10 @@
158155
159156 pub async fn blob_raw_download(
160157 &self,
161 space_name: String,
162 repo_name: String,
158 ctx: &GitContext,
163159 oid: String,
164160 ) -> Result<RawDownloadDto, GitError> {
165161 let object_id = parse_oid(&oid)?;
166 let ctx = self.context(space_name, repo_name).await?;
167162 let key = format!("repo.{}.blob_raw_download.{}", ctx.model.id, object_id);
168163 cache::cached_fetch(&ctx.cache, &key, IMMUTABLE_TTL, || async {
169164 let (size, sniff) = self.blob_sniff(&ctx, &object_id).await?;
@@ -178,12 +173,10 @@
178173
179174 pub async fn list_lfs_pointers(
180175 &self,
181 space_name: String,
182 repo_name: String,
176 ctx: &GitContext,
183177 revision: String,
184178 limit: Option<u32>,
185179 ) -> Result<Vec<LfsPointerDto>, GitError> {
186 let ctx = self.context(space_name, repo_name).await?;
187180 let baby = self.baby(&ctx);
188181 let pointers = baby
189182 .list_lfs_pointers(crate::rpcgit::blob::types::ListLFSPointersOptions {
Modified lib/git/src/service/branches.rs View lib/git/src/service/branches.rs
@@ -57,12 +57,7 @@
5757 Ok(rows.into_iter().map(|r| (r.name.clone(), r)).collect())
5858 }
5959
60 pub async fn list_branches(
61 &self,
62 space_name: String,
63 repo_name: String,
64 ) -> Result<Vec<BranchDto>, GitError> {
65 let ctx = self.context(space_name, repo_name).await?;
60 pub async fn list_branches(&self, ctx: &GitContext) -> Result<Vec<BranchDto>, GitError> {
6661 if ctx.repo_uninitialized() {
6762 return Ok(Vec::new());
6863 }
@@ -117,14 +112,8 @@
117112 Ok(out)
118113 }
119114
120 pub async fn get_branch(
121 &self,
122 space_name: String,
123 repo_name: String,
124 name: String,
125 ) -> Result<BranchDto, GitError> {
115 pub async fn get_branch(&self, ctx: &GitContext, name: String) -> Result<BranchDto, GitError> {
126116 validate::validate_branch_name(&name)?;
127 let ctx = self.context(space_name, repo_name).await?;
128117 let baby = self.baby(&ctx);
129118 let info = baby.find_branch(&name).await.map_err(map_baby)?;
130119 let rows = self.branch_rows(&ctx).await?;
@@ -144,8 +133,7 @@
144133
145134 pub async fn create_branch(
146135 &self,
147 space_name: String,
148 repo_name: String,
136 ctx: &GitContext,
149137 cmd: CreateBranchCmd,
150138 ) -> Result<BranchDto, GitError> {
151139 let name = validate::validate_branch_name(&cmd.name)?;
@@ -156,7 +144,6 @@
156144 "invalid start point `{sp}`"
157145 )));
158146 }
159 let ctx = self.context(space_name, repo_name).await?;
160147 let baby = self.baby(&ctx);
161148 baby.create_branch(&name, cmd.start_point.as_deref())
162149 .await
@@ -198,14 +185,12 @@
198185
199186 pub async fn rename_branch(
200187 &self,
201 space_name: String,
202 repo_name: String,
188 ctx: &GitContext,
203189 from: String,
204190 to: String,
205191 ) -> Result<(), GitError> {
206192 validate::validate_branch_name(&from)?;
207193 let to = validate::validate_branch_name(&to)?;
208 let ctx = self.context(space_name, repo_name).await?;
209194 let baby = self.baby(&ctx);
210195 baby.rename_branch(&from, &to).await.map_err(map_baby)?;
211196 let product = git_branches::Entity::find()
@@ -228,13 +213,11 @@
228213
229214 pub async fn delete_branch(
230215 &self,
231 space_name: String,
232 repo_name: String,
216 ctx: &GitContext,
233217 name: String,
234218 force: bool,
235219 ) -> Result<(), GitError> {
236220 let name = validate::validate_branch_name(&name)?;
237 let ctx = self.context(space_name, repo_name).await?;
238221 let policy = load_branch_policy(&self.state.database, ctx.model.id).await?;
239222 if policy.is_match(&name) {
240223 return Err(GitError::Forbidden);
@@ -275,14 +258,8 @@
275258 Ok(())
276259 }
277260
278 pub async fn set_default_branch(
279 &self,
280 space_name: String,
281 repo_name: String,
282 name: String,
283 ) -> Result<(), GitError> {
261 pub async fn set_default_branch(&self, ctx: &GitContext, name: String) -> Result<(), GitError> {
284262 let name = validate::validate_branch_name(&name)?;
285 let ctx = self.context(space_name, repo_name).await?;
286263 let baby = self.baby(&ctx);
287264 baby.set_default_branch(&name).await.map_err(map_baby)?;
288265 let am = repos::ActiveModel {
Modified lib/git/src/service/code_comments.rs View lib/git/src/service/code_comments.rs
@@ -72,11 +72,9 @@
7272impl super::GitService {
7373 pub async fn list_code_comments(
7474 &self,
75 space_name: String,
76 repo_name: String,
75 ctx: &GitContext,
7776 query: ListCodeCommentsQuery,
7877 ) -> Result<CodeCommentPage, GitError> {
79 let ctx = self.context(space_name, repo_name).await?;
8078 let limit = query.limit.unwrap_or(50).clamp(1, 200);
8179 let offset = query.offset.unwrap_or(0);
8280 let mut select =
@@ -128,8 +126,7 @@
128126
129127 pub async fn create_code_comment(
130128 &self,
131 space_name: String,
132 repo_name: String,
129 ctx: &GitContext,
133130 author: i64,
134131 cmd: CreateCodeCommentCmd,
135132 ) -> Result<CodeCommentDto, GitError> {
@@ -144,7 +141,6 @@
144141 if cmd.body.trim().is_empty() || cmd.body.chars().count() > MAX_BODY_LEN {
145142 return Err(GitError::InvalidArgument("invalid body".to_string()));
146143 }
147 let ctx = self.context(space_name, repo_name).await?;
148144 let anchor = match cmd
149145 .commit_sha
150146 .as_deref()
@@ -194,8 +190,7 @@
194190
195191 pub async fn update_code_comment(
196192 &self,
197 space_name: String,
198 repo_name: String,
193 ctx: &GitContext,
199194 comment_id: Uuid,
200195 actor: i64,
201196 admin: bool,
@@ -204,7 +199,6 @@
204199 if cmd.body.trim().is_empty() || cmd.body.chars().count() > MAX_BODY_LEN {
205200 return Err(GitError::InvalidArgument("invalid body".to_string()));
206201 }
207 let ctx = self.context(space_name, repo_name).await?;
208202 let row = self.find_code_comment(ctx.model.id, comment_id).await?;
209203 if row.author_id != actor && !admin {
210204 return Err(GitError::Forbidden);
@@ -219,13 +213,11 @@
219213
220214 pub async fn delete_code_comment(
221215 &self,
222 space_name: String,
223 repo_name: String,
216 ctx: &GitContext,
224217 comment_id: Uuid,
225218 actor: i64,
226219 admin: bool,
227220 ) -> Result<(), GitError> {
228 let ctx = self.context(space_name, repo_name).await?;
229221 let row = self.find_code_comment(ctx.model.id, comment_id).await?;
230222 if row.author_id != actor && !admin {
231223 return Err(GitError::Forbidden);
@@ -245,13 +237,11 @@
245237
246238 pub async fn set_code_comment_resolved(
247239 &self,
248 space_name: String,
249 repo_name: String,
240 ctx: &GitContext,
250241 comment_id: Uuid,
251242 actor: i64,
252243 resolved: bool,
253244 ) -> Result<CodeCommentDto, GitError> {
254 let ctx = self.context(space_name, repo_name).await?;
255245 let row = self.find_code_comment(ctx.model.id, comment_id).await?;
256246 let mut model: code_comment::ActiveModel = row.into();
257247 model.resolved_at = Set(if resolved {
Modified lib/git/src/service/commits.rs View lib/git/src/service/commits.rs
@@ -156,11 +156,9 @@
156156impl GitService {
157157 pub async fn get_commit(
158158 &self,
159 space_name: String,
160 repo_name: String,
159 ctx: &GitContext,
161160 revision: String,
162161 ) -> Result<CommitInfo, GitError> {
163 let ctx = self.context(space_name, repo_name).await?;
164162 let baby = self.baby(&ctx);
165163 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
166164 let key = format!("repo.{}.commit.{}", ctx.model.id, rev_oid);
@@ -172,12 +170,10 @@
172170
173171 pub async fn list_commits(
174172 &self,
175 space_name: String,
176 repo_name: String,
173 ctx: &GitContext,
177174 cmd: ListCommitsCmd,
178175 viewer: Option<i64>,
179176 ) -> Result<CommitsPageDto, GitError> {
180 let ctx = self.context(space_name, repo_name).await?;
181177 let baby = self.baby(&ctx);
182178 let limit = cmd.max_count.unwrap_or(50);
183179 let skip = cmd.skip.unwrap_or(0);
@@ -257,12 +253,10 @@
257253
258254 pub async fn commit_stats(
259255 &self,
260 space_name: String,
261 repo_name: String,
256 ctx: &GitContext,
262257 revision: String,
263258 path: Option<PathBuf>,
264259 ) -> Result<CommitStats, GitError> {
265 let ctx = self.context(space_name, repo_name).await?;
266260 let baby = self.baby(&ctx);
267261 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
268262 let path_str = path
@@ -283,25 +277,17 @@
283277
284278 pub async fn get_tree_entries(
285279 &self,
286 space_name: String,
287 repo_name: String,
280 ctx: &GitContext,
288281 revision: String,
289282 path: PathBuf,
290283 ) -> Result<Vec<TreeEntry>, GitError> {
291 let ctx = self.context(space_name, repo_name).await?;
292284 let baby = self.baby(&ctx);
293285 baby.get_tree_entries(&revision, &path)
294286 .await
295287 .map_err(map_baby)
296288 }
297289
298 pub async fn rev_parse(
299 &self,
300 space_name: String,
301 repo_name: String,
302 revision: String,
303 ) -> Result<String, GitError> {
304 let ctx = self.context(space_name, repo_name).await?;
290 pub async fn rev_parse(&self, ctx: &GitContext, revision: String) -> Result<String, GitError> {
305291 let baby = self.baby(&ctx);
306292 baby.rev_parse(&revision)
307293 .await
@@ -311,12 +297,10 @@
311297
312298 pub async fn is_ancestor(
313299 &self,
314 space_name: String,
315 repo_name: String,
300 ctx: &GitContext,
316301 ancestor: String,
317302 descendant: String,
318303 ) -> Result<bool, GitError> {
319 let ctx = self.context(space_name, repo_name).await?;
320304 let baby = self.baby(&ctx);
321305 baby.is_ancestor(&ancestor, &descendant)
322306 .await
@@ -377,8 +361,7 @@
377361
378362 pub async fn set_commit_status(
379363 &self,
380 space_name: String,
381 repo_name: String,
364 ctx: &GitContext,
382365 creator: i64,
383366 cmd: SetCommitStatusCmd,
384367 ) -> Result<CommitStatusDto, GitError> {
@@ -388,7 +371,6 @@
388371 if cmd.context.trim().is_empty() || cmd.context.chars().count() > 255 {
389372 return Err(GitError::InvalidArgument("invalid context".to_string()));
390373 }
391 let ctx = self.context(space_name, repo_name).await?;
392374 self.baby(&ctx)
393375 .rev_parse(cmd.sha.trim())
394376 .await
@@ -436,14 +418,12 @@
436418
437419 pub async fn list_commit_statuses(
438420 &self,
439 space_name: String,
440 repo_name: String,
421 ctx: &GitContext,
441422 sha: String,
442423 ) -> Result<Vec<CommitStatusDto>, GitError> {
443424 if sha.trim().is_empty() {
444425 return Err(GitError::InvalidArgument("empty sha".to_string()));
445426 }
446 let ctx = self.context(space_name, repo_name).await?;
447427 let rows = git_commit_status::Entity::find()
448428 .filter(git_commit_status::Column::RepoId.eq(ctx.model.id))
449429 .filter(git_commit_status::Column::Sha.eq(sha.trim()))
Modified lib/git/src/service/conflicts.rs View lib/git/src/service/conflicts.rs
@@ -1,6 +1,7 @@
11use crate::rpcgit::conflict::types::{ConflictFile, ListConflictOptions};
22use serde::{Deserialize, Serialize};
33
4use crate::context::facade::GitContext;
45use crate::service::GitService;
56use crate::service::cache::{self, IMMUTABLE_TTL};
67use crate::share::errors::{GitError, map_baby};
@@ -33,12 +34,10 @@
3334
3435 pub async fn conflict_check(
3536 &self,
36 space_name: String,
37 repo_name: String,
37 ctx: &GitContext,
3838 base: String,
3939 head: String,
4040 ) -> Result<MergeStatusDto, GitError> {
41 let ctx = self.context(space_name, repo_name).await?;
4241 let (our_oid, their_oid) = self.resolve_pair(&ctx, &base, &head).await?;
4342 let key = format!(
4443 "repo.{}.conflict_check.{}.{}",
@@ -84,12 +83,10 @@
8483
8584 pub async fn conflict_conflicted_files(
8685 &self,
87 space_name: String,
88 repo_name: String,
86 ctx: &GitContext,
8987 base: String,
9088 head: String,
9189 ) -> Result<Vec<String>, GitError> {
92 let ctx = self.context(space_name, repo_name).await?;
9390 let (our_oid, their_oid) = self.resolve_pair(&ctx, &base, &head).await?;
9491 let key = format!(
9592 "repo.{}.conflict_files.{}.{}",
@@ -115,13 +112,11 @@
115112
116113 pub async fn conflict_detail(
117114 &self,
118 space_name: String,
119 repo_name: String,
115 ctx: &GitContext,
120116 base: String,
121117 head: String,
122118 path: String,
123119 ) -> Result<ConflictDetailDto, GitError> {
124 let ctx = self.context(space_name, repo_name).await?;
125120 let (our_oid, their_oid) = self.resolve_pair(&ctx, &base, &head).await?;
126121 let key = format!(
127122 "repo.{}.conflict_detail.{}.{}.{}",
@@ -158,13 +153,11 @@
158153
159154 pub async fn conflict_check_threeway(
160155 &self,
161 space_name: String,
162 repo_name: String,
156 ctx: &GitContext,
163157 ours: String,
164158 theirs: String,
165159 ancestor: String,
166160 ) -> Result<MergeStatusDto, GitError> {
167 let ctx = self.context(space_name, repo_name).await?;
168161 let (our_oid, their_oid) = self.resolve_pair(&ctx, &ours, &theirs).await?;
169162 let ancestor_oid = self
170163 .baby(&ctx)
Modified lib/git/src/service/diffs.rs View lib/git/src/service/diffs.rs
@@ -5,6 +5,7 @@
55use crate::rpcgit::oid::ObjectId;
66use serde::{Deserialize, Serialize};
77
8use crate::context::facade::GitContext;
89use crate::service::GitService;
910use crate::service::cache::{self, IMMUTABLE_TTL};
1011use crate::share::errors::{GitError, map_baby};
@@ -117,12 +118,10 @@
117118
118119 pub async fn diff_raw(
119120 &self,
120 space_name: String,
121 repo_name: String,
121 ctx: &GitContext,
122122 base: String,
123123 head: String,
124124 ) -> Result<String, GitError> {
125 let ctx = self.context(space_name, repo_name).await?;
126125 let req = self.diff_request(&ctx, &base, &head).await?;
127126 let key = format!("repo.{}.diff_raw.{}.{}", ctx.model.id, req.left, req.right);
128127 cache::cached_fetch(&ctx.cache, &key, IMMUTABLE_TTL, || async {
@@ -133,12 +132,10 @@
133132
134133 pub async fn diff_files_changed_between(
135134 &self,
136 space_name: String,
137 repo_name: String,
135 ctx: &GitContext,
138136 base: String,
139137 head: String,
140138 ) -> Result<Vec<String>, GitError> {
141 let ctx = self.context(space_name, repo_name).await?;
142139 let baby = self.baby(&ctx);
143140 let left = baby.rev_parse(&base).await.map_err(map_baby)?;
144141 let right = baby.rev_parse(&head).await.map_err(map_baby)?;
@@ -166,12 +163,10 @@
166163
167164 pub async fn diff_short_stat(
168165 &self,
169 space_name: String,
170 repo_name: String,
166 ctx: &GitContext,
171167 base: String,
172168 head: String,
173169 ) -> Result<ShortStat, GitError> {
174 let ctx = self.context(space_name, repo_name).await?;
175170 let req = self.diff_request(&ctx, &base, &head).await?;
176171 let key = format!(
177172 "repo.{}.diff_short_stat.{}.{}",
@@ -188,13 +183,11 @@
188183
189184 pub async fn diff_stats(
190185 &self,
191 space_name: String,
192 repo_name: String,
186 ctx: &GitContext,
193187 base: String,
194188 head: String,
195189 opts: DiffOptionsDto,
196190 ) -> Result<Vec<NumStat>, GitError> {
197 let ctx = self.context(space_name, repo_name).await?;
198191 let req = self.diff_request(&ctx, &base, &head).await?;
199192 let key = format!(
200193 "repo.{}.diff_stats.{}.{}:{:?}",
@@ -211,13 +204,11 @@
211204
212205 pub async fn diff_files(
213206 &self,
214 space_name: String,
215 repo_name: String,
207 ctx: &GitContext,
216208 base: String,
217209 head: String,
218210 opts: DiffOptionsDto,
219211 ) -> Result<Vec<ChangedPathDiffDto>, GitError> {
220 let ctx = self.context(space_name, repo_name).await?;
221212 let req = self.diff_request(&ctx, &base, &head).await?;
222213 let key = format!(
223214 "repo.{}.diff_files_dto.{}.{}:{:?}",
@@ -275,11 +266,9 @@
275266
276267 pub async fn diff_for_commit(
277268 &self,
278 space_name: String,
279 repo_name: String,
269 ctx: &GitContext,
280270 commit: String,
281271 ) -> Result<Vec<ChangedPath>, GitError> {
282 let ctx = self.context(space_name, repo_name).await?;
283272 let oid = parse_oid(&commit)?;
284273 let key = format!("repo.{}.diff_for_commit.{}", ctx.model.id, oid);
285274 cache::cached_fetch(&ctx.cache, &key, IMMUTABLE_TTL, || async {
@@ -293,13 +282,11 @@
293282
294283 pub async fn diff_tree(
295284 &self,
296 space_name: String,
297 repo_name: String,
285 ctx: &GitContext,
298286 base: String,
299287 head: String,
300288 use_merge_base: bool,
301289 ) -> Result<Vec<DiffTreeRecordDto>, GitError> {
302 let ctx = self.context(space_name, repo_name).await?;
303290 let baby = self.baby(&ctx);
304291 let left = if use_merge_base {
305292 let mb = baby.merge_base(&base, &head).await.map_err(map_baby)?;
@@ -345,11 +332,9 @@
345332
346333 pub async fn range_diff(
347334 &self,
348 space_name: String,
349 repo_name: String,
335 ctx: &GitContext,
350336 spec: RangeDiffSpec,
351337 ) -> Result<String, GitError> {
352 let ctx = self.context(space_name, repo_name).await?;
353338 self.baby(&ctx)
354339 .range_diff(&spec, &DiffOptions::default(), None)
355340 .await
Modified lib/git/src/service/hooks.rs View lib/git/src/service/hooks.rs
@@ -1,5 +1,6 @@
11use serde::{Deserialize, Serialize};
22
3use crate::context::facade::GitContext;
34use crate::service::GitService;
45use crate::share::errors::GitError;
56
@@ -64,8 +65,7 @@
6465
6566 pub async fn hook_execute_script(
6667 &self,
67 _space_name: String,
68 _repo_name: String,
68 _ctx: &GitContext,
6969 _script: HookEventKind,
7070 _args: Vec<String>,
7171 ) -> Result<ScriptOutputDto, GitError> {
Modified lib/git/src/service/lfs.rs View lib/git/src/service/lfs.rs
@@ -1,3 +1,4 @@
1use crate::context::facade::GitContext;
12use crate::lfs;
23pub use crate::lfs::types::*;
34use crate::service::GitService;
@@ -6,8 +7,7 @@
67impl GitService {
78 pub async fn lfs_batch(
89 &self,
9 _space_name: String,
10 _repo_name: String,
10 _ctx: &GitContext,
1111 _req: LfsBatchRequest,
1212 ) -> Result<LfsBatchResponse, GitError> {
1313 Err(GitError::Unimplemented(
@@ -89,62 +89,53 @@
8989
9090 pub async fn lfs_lock(
9191 &self,
92 space_name: String,
93 repo_name: String,
92 ctx: &GitContext,
9493 owner: i64,
9594 path: String,
9695 oid: Option<String>,
9796 ) -> Result<LfsLock, GitError> {
98 lfs::create_lock(self, space_name, repo_name, owner, path, oid).await
97 lfs::create_lock(self, ctx, owner, path, oid).await
9998 }
10099
101100 pub async fn lfs_unlock(
102101 &self,
103 space_name: String,
104 repo_name: String,
102 ctx: &GitContext,
105103 owner: i64,
106104 path: String,
107105 force: bool,
108106 ) -> Result<(), GitError> {
109 lfs::unlock(self, space_name, repo_name, owner, path, force).await
107 lfs::unlock(self, ctx, owner, path, force).await
110108 }
111109
112110 pub async fn lfs_unlock_by_id(
113111 &self,
114 space_name: String,
115 repo_name: String,
112 ctx: &GitContext,
116113 owner: i64,
117114 lock_id: String,
118115 force: bool,
119116 ) -> Result<(), GitError> {
120 lfs::unlock_by_id(self, space_name, repo_name, owner, lock_id, force).await
117 lfs::unlock_by_id(self, ctx, owner, lock_id, force).await
121118 }
122119
123120 pub async fn lfs_list_locks(
124121 &self,
125 space_name: String,
126 repo_name: String,
122 ctx: &GitContext,
127123 cursor: Option<String>,
128124 limit: u64,
129125 ) -> Result<LfsLockListResponse, GitError> {
130 lfs::list_locks(self, space_name, repo_name, cursor, limit).await
126 lfs::list_locks(self, ctx, cursor, limit).await
131127 }
132128
133129 pub async fn lfs_verify_locks(
134130 &self,
135 space_name: String,
136 repo_name: String,
131 ctx: &GitContext,
137132 caller: i64,
138133 limit: u64,
139134 ) -> Result<LfsVerifyLocksResponse, GitError> {
140 lfs::verify_locks(self, space_name, repo_name, caller, limit).await
135 lfs::verify_locks(self, ctx, caller, limit).await
141136 }
142137
143 pub async fn lfs_cleanup_unreferenced(
144 &self,
145 _space_name: String,
146 _repo_name: String,
147 ) -> Result<i64, GitError> {
138 pub async fn lfs_cleanup_unreferenced(&self, _ctx: &GitContext) -> Result<i64, GitError> {
148139 Err(GitError::Unimplemented("LFS cleanup is served by KenShell"))
149140 }
150141}
Modified lib/git/src/service/logs.rs View lib/git/src/service/logs.rs
@@ -1,6 +1,7 @@
11use crate::rpcgit::commit::types::{CommitInfo, ListCommitsOptions};
22use serde::{Deserialize, Serialize};
33
4use crate::context::facade::GitContext;
45use crate::service::GitService;
56use crate::service::cache::{self, IMMUTABLE_TTL};
67use crate::share::errors::{GitError, map_baby};
@@ -34,8 +35,7 @@
3435impl GitService {
3536 pub async fn log_list(
3637 &self,
37 space_name: String,
38 repo_name: String,
38 ctx: &GitContext,
3939 opts: LogOptions,
4040 ) -> Result<LogListDto, GitError> {
4141 let limit = opts
@@ -44,7 +44,6 @@
4444 .clamp(1, MAX_LOG_LIMIT);
4545 let skip = opts.skip.unwrap_or(0);
4646 let revision = opts.revision.clone().unwrap_or_else(|| "HEAD".to_string());
47 let ctx = self.context(space_name, repo_name).await?;
4847 let baby = self.baby(&ctx);
4948 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
5049
@@ -85,14 +84,12 @@
8584
8685 pub async fn log_commits_between(
8786 &self,
88 space_name: String,
89 repo_name: String,
87 ctx: &GitContext,
9088 after: String,
9189 before: String,
9290 limit: u64,
9391 ) -> Result<LogListDto, GitError> {
9492 let limit = limit.clamp(1, MAX_LOG_LIMIT);
95 let ctx = self.context(space_name, repo_name).await?;
9693 let baby = self.baby(&ctx);
9794 let after_oid = baby.rev_parse(&after).await.map_err(map_baby)?;
9895 let before_oid = baby.rev_parse(&before).await.map_err(map_baby)?;
@@ -121,11 +118,9 @@
121118
122119 pub async fn log_last_commit(
123120 &self,
124 space_name: String,
125 repo_name: String,
121 ctx: &GitContext,
126122 branch: String,
127123 ) -> Result<CommitInfo, GitError> {
128 let ctx = self.context(space_name, repo_name).await?;
129124 let baby = self.baby(&ctx);
130125 let rev_oid = baby.rev_parse(&branch).await.map_err(map_baby)?;
131126 let key = format!("repo.{}.commit.{}", ctx.model.id, rev_oid);
Modified lib/git/src/service/maintenance.rs View lib/git/src/service/maintenance.rs
@@ -1,5 +1,6 @@
11use serde::Serialize;
22
3use crate::context::facade::GitContext;
34use crate::service::GitService;
45use crate::share::errors::GitError;
56
@@ -18,21 +19,13 @@
1819}
1920
2021impl GitService {
21 pub async fn maintenance_prune(
22 &self,
23 _space_name: String,
24 _repo_name: String,
25 ) -> Result<PruneResultDto, GitError> {
22 pub async fn maintenance_prune(&self, _ctx: &GitContext) -> Result<PruneResultDto, GitError> {
2623 Err(GitError::Unimplemented(
2724 "repository prune is served by KenShell",
2825 ))
2926 }
3027
31 pub async fn maintenance_fsck(
32 &self,
33 _space_name: String,
34 _repo_name: String,
35 ) -> Result<FsckDto, GitError> {
28 pub async fn maintenance_fsck(&self, _ctx: &GitContext) -> Result<FsckDto, GitError> {
3629 Err(GitError::Unimplemented(
3730 "repository fsck is served by KenShell",
3831 ))
Modified lib/git/src/service/merge.rs View lib/git/src/service/merge.rs
@@ -103,24 +103,21 @@
103103 /// `base..head` 的提交列表(正序,最多 200 条)。
104104 pub async fn merge_commits(
105105 &self,
106 space_name: String,
107 repo_name: String,
106 ctx: &GitContext,
108107 base: &str,
109108 head: &str,
110109 ) -> Result<Vec<MergeCommitDto>, GitError> {
111 self.commits_between(space_name, repo_name, base, head, MAX_LISTED_COMMITS)
110 self.commits_between(ctx, base, head, MAX_LISTED_COMMITS)
112111 .await
113112 }
114113
115114 pub async fn recent_commits(
116115 &self,
117 space_name: String,
118 repo_name: String,
116 ctx: &GitContext,
119117 revision: Option<&str>,
120118 limit: u32,
121119 skip: u32,
122120 ) -> Result<Vec<MergeCommitDto>, GitError> {
123 let ctx = self.context(space_name, repo_name).await?;
124121 let reference = match revision.map(str::trim).filter(|value| !value.is_empty()) {
125122 Some(value) => value.to_string(),
126123 None => format!("refs/heads/{}", ctx.model.default_branch),
@@ -140,13 +137,11 @@
140137
141138 pub async fn commits_between(
142139 &self,
143 space_name: String,
144 repo_name: String,
140 ctx: &GitContext,
145141 base: &str,
146142 head: &str,
147143 limit: u32,
148144 ) -> Result<Vec<MergeCommitDto>, GitError> {
149 let ctx = self.context(space_name, repo_name).await?;
150145 let baby = self.baby(&ctx);
151146 let base_oid = baby.rev_parse(base).await.map_err(map_baby)?;
152147 let head_oid = baby.rev_parse(head).await.map_err(map_baby)?;
@@ -183,11 +178,9 @@
183178
184179 pub async fn default_branch_base(
185180 &self,
186 space_name: String,
187 repo_name: String,
181 ctx: &GitContext,
188182 depth: u32,
189183 ) -> Result<Option<String>, GitError> {
190 let ctx = self.context(space_name, repo_name).await?;
191184 let baby = self.baby(&ctx);
192185 let head = baby
193186 .rev_parse(&format!("refs/heads/{}", ctx.model.default_branch))
Modified lib/git/src/service/packs.rs View lib/git/src/service/packs.rs
@@ -1,5 +1,6 @@
11use serde::Serialize;
22
3use crate::context::facade::GitContext;
34use crate::service::GitService;
45use crate::share::errors::GitError;
56
@@ -18,26 +19,17 @@
1819impl GitService {
1920 pub async fn pack_ingest(
2021 &self,
21 _space_name: String,
22 _repo_name: String,
22 _ctx: &GitContext,
2323 _pack: Vec<u8>,
2424 ) -> Result<IngestPackDto, GitError> {
2525 Err(GitError::Unimplemented("pack ingest is served by KenShell"))
2626 }
2727
28 pub async fn pack_repack(
29 &self,
30 _space_name: String,
31 _repo_name: String,
32 ) -> Result<(), GitError> {
28 pub async fn pack_repack(&self, _ctx: &GitContext) -> Result<(), GitError> {
3329 Err(GitError::Unimplemented("pack repack is served by KenShell"))
3430 }
3531
36 pub async fn pack_stats(
37 &self,
38 _space_name: String,
39 _repo_name: String,
40 ) -> Result<PackStatsDto, GitError> {
32 pub async fn pack_stats(&self, _ctx: &GitContext) -> Result<PackStatsDto, GitError> {
4133 Err(GitError::Unimplemented("pack stats are served by KenShell"))
4234 }
4335}
Modified lib/git/src/service/patches.rs View lib/git/src/service/patches.rs
@@ -1,5 +1,6 @@
11use serde::{Deserialize, Serialize};
22
3use crate::context::facade::GitContext;
34use crate::service::GitService;
45use crate::service::cache::{self, IMMUTABLE_TTL};
56use crate::share::errors::{GitError, map_baby};
@@ -26,12 +27,10 @@
2627impl GitService {
2728 pub async fn patch_generate(
2829 &self,
29 space_name: String,
30 repo_name: String,
30 ctx: &GitContext,
3131 base: String,
3232 head: String,
3333 ) -> Result<PatchDto, GitError> {
34 let ctx = self.context(space_name, repo_name).await?;
3534 let baby = self.baby(&ctx);
3635 let left = baby.rev_parse(&base).await.map_err(map_baby)?;
3736 let right = baby.rev_parse(&head).await.map_err(map_baby)?;
@@ -83,8 +82,7 @@
8382
8483 pub async fn patch_apply(
8584 &self,
86 _space_name: String,
87 _repo_name: String,
85 _ctx: &GitContext,
8886 _patch: String,
8987 _base: String,
9088 ) -> Result<AppliedPatchDto, GitError> {
Modified lib/git/src/service/path_log.rs View lib/git/src/service/path_log.rs
@@ -3,6 +3,7 @@
33use crate::rpcgit::commit::types::ListCommitsOptions;
44use serde::{Deserialize, Serialize};
55
6use crate::context::facade::GitContext;
67use crate::service::GitService;
78use crate::service::cache::{self, IMMUTABLE_TTL};
89use crate::share::errors::{GitError, map_baby};
@@ -69,8 +70,7 @@
6970impl GitService {
7071 pub async fn path_log(
7172 &self,
72 space_name: String,
73 repo_name: String,
73 ctx: &GitContext,
7474 commit_hash: String,
7575 target_dir: PathBuf,
7676 ) -> Result<Vec<PathLogEntryDto>, GitError> {
@@ -81,7 +81,6 @@
8181 ));
8282 }
8383
84 let ctx = self.context(space_name, repo_name).await?;
8584 let baby = self.baby(&ctx);
8685
8786 let oid = baby
Modified lib/git/src/service/protection.rs View lib/git/src/service/protection.rs
@@ -8,6 +8,7 @@
88use time::OffsetDateTime;
99use uuid::Uuid;
1010
11use crate::context::facade::GitContext;
1112use crate::service::GitService;
1213use crate::share::errors::{GitError, is_unique_violation};
1314
@@ -245,10 +246,8 @@
245246impl GitService {
246247 pub async fn list_branch_policies(
247248 &self,
248 space_name: String,
249 repo_name: String,
249 ctx: &GitContext,
250250 ) -> Result<Vec<BranchPolicyDto>, GitError> {
251 let ctx = self.context(space_name, repo_name).await?;
252251 let rows = repo_branch_protection_policy::Entity::find()
253252 .filter(repo_branch_protection_policy::Column::RepoId.eq(ctx.model.id))
254253 .order_by_asc(repo_branch_protection_policy::Column::BranchPattern)
@@ -259,11 +258,9 @@
259258
260259 pub async fn get_branch_policy(
261260 &self,
262 space_name: String,
263 repo_name: String,
261 ctx: &GitContext,
264262 policy_id: Uuid,
265263 ) -> Result<BranchPolicyDto, GitError> {
266 let ctx = self.context(space_name, repo_name).await?;
267264 let row = repo_branch_protection_policy::Entity::find_by_id(policy_id)
268265 .filter(repo_branch_protection_policy::Column::RepoId.eq(ctx.model.id))
269266 .one(self.db_read())
@@ -274,11 +271,9 @@
274271
275272 pub async fn create_branch_policy(
276273 &self,
277 space_name: String,
278 repo_name: String,
274 ctx: &GitContext,
279275 cmd: CreateBranchPolicyCmd,
280276 ) -> Result<BranchPolicyDto, GitError> {
281 let ctx = self.context(space_name, repo_name).await?;
282277 validate_pattern(&cmd.branch_pattern)?;
283278 let flags = cmd.flags();
284279 let required = flags.required_approvals.unwrap_or(0);
@@ -326,12 +321,10 @@
326321
327322 pub async fn update_branch_policy(
328323 &self,
329 space_name: String,
330 repo_name: String,
324 ctx: &GitContext,
331325 policy_id: Uuid,
332326 cmd: UpdateBranchPolicyCmd,
333327 ) -> Result<BranchPolicyDto, GitError> {
334 let ctx = self.context(space_name, repo_name).await?;
335328 let row = repo_branch_protection_policy::Entity::find_by_id(policy_id)
336329 .filter(repo_branch_protection_policy::Column::RepoId.eq(ctx.model.id))
337330 .one(self.db_read())
@@ -410,11 +403,9 @@
410403
411404 pub async fn delete_branch_policy(
412405 &self,
413 space_name: String,
414 repo_name: String,
406 ctx: &GitContext,
415407 policy_id: Uuid,
416408 ) -> Result<(), GitError> {
417 let ctx = self.context(space_name, repo_name).await?;
418409 let deleted = repo_branch_protection_policy::Entity::delete_many()
419410 .filter(repo_branch_protection_policy::Column::Id.eq(policy_id))
420411 .filter(repo_branch_protection_policy::Column::RepoId.eq(ctx.model.id))
@@ -472,12 +463,7 @@
472463}
473464
474465impl GitService {
475 pub async fn list_tag_policies(
476 &self,
477 space_name: String,
478 repo_name: String,
479 ) -> Result<Vec<TagPolicyDto>, GitError> {
480 let ctx = self.context(space_name, repo_name).await?;
466 pub async fn list_tag_policies(&self, ctx: &GitContext) -> Result<Vec<TagPolicyDto>, GitError> {
481467 let rows = repo_tag_protection_policy::Entity::find()
482468 .filter(repo_tag_protection_policy::Column::RepoId.eq(ctx.model.id))
483469 .order_by_asc(repo_tag_protection_policy::Column::NamePattern)
@@ -488,11 +474,9 @@
488474
489475 pub async fn get_tag_policy(
490476 &self,
491 space_name: String,
492 repo_name: String,
477 ctx: &GitContext,
493478 policy_id: Uuid,
494479 ) -> Result<TagPolicyDto, GitError> {
495 let ctx = self.context(space_name, repo_name).await?;
496480 let row = repo_tag_protection_policy::Entity::find_by_id(policy_id)
497481 .filter(repo_tag_protection_policy::Column::RepoId.eq(ctx.model.id))
498482 .one(self.db_read())
@@ -503,11 +487,9 @@
503487
504488 pub async fn create_tag_policy(
505489 &self,
506 space_name: String,
507 repo_name: String,
490 ctx: &GitContext,
508491 cmd: CreateTagPolicyCmd,
509492 ) -> Result<TagPolicyDto, GitError> {
510 let ctx = self.context(space_name, repo_name).await?;
511493 validate_tag_pattern(&cmd.name_pattern)?;
512494 let now = OffsetDateTime::now_utc();
513495 let row = repo_tag_protection_policy::ActiveModel {
@@ -531,12 +513,10 @@
531513
532514 pub async fn update_tag_policy(
533515 &self,
534 space_name: String,
535 repo_name: String,
516 ctx: &GitContext,
536517 policy_id: Uuid,
537518 cmd: UpdateTagPolicyCmd,
538519 ) -> Result<TagPolicyDto, GitError> {
539 let ctx = self.context(space_name, repo_name).await?;
540520 let row = repo_tag_protection_policy::Entity::find_by_id(policy_id)
541521 .filter(repo_tag_protection_policy::Column::RepoId.eq(ctx.model.id))
542522 .one(self.db_read())
@@ -562,11 +542,9 @@
562542
563543 pub async fn delete_tag_policy(
564544 &self,
565 space_name: String,
566 repo_name: String,
545 ctx: &GitContext,
567546 policy_id: Uuid,
568547 ) -> Result<(), GitError> {
569 let ctx = self.context(space_name, repo_name).await?;
570548 repo_tag_protection_whitelists::Entity::delete_many()
571549 .filter(repo_tag_protection_whitelists::Column::PolicyId.eq(policy_id))
572550 .exec(self.db_write())
Modified lib/git/src/service/refs.rs View lib/git/src/service/refs.rs
@@ -1,6 +1,7 @@
11use crate::rpcgit::refs::types::{ListRefsOptions, RefInfo, RefType};
22use serde::Serialize;
33
4use crate::context::facade::GitContext;
45use crate::service::GitService;
56use crate::share::errors::{GitError, map_baby};
67use crate::share::policy::load_branch_policy;
@@ -31,12 +32,7 @@
3132}
3233
3334impl GitService {
34 pub async fn refs_list(
35 &self,
36 space_name: String,
37 repo_name: String,
38 ) -> Result<Vec<RefInfo>, GitError> {
39 let ctx = self.context(space_name, repo_name).await?;
35 pub async fn refs_list(&self, ctx: &GitContext) -> Result<Vec<RefInfo>, GitError> {
4036 self.baby(&ctx)
4137 .list_refs(ListRefsOptions::default())
4238 .await
@@ -45,11 +41,9 @@
4541
4642 pub async fn refs_list_filtered(
4743 &self,
48 space_name: String,
49 repo_name: String,
44 ctx: &GitContext,
5045 pattern: String,
5146 ) -> Result<Vec<RefInfo>, GitError> {
52 let ctx = self.context(space_name, repo_name).await?;
5347 self.baby(&ctx)
5448 .list_refs(ListRefsOptions {
5549 patterns: vec![pattern],
@@ -59,13 +53,7 @@
5953 .map_err(map_baby)
6054 }
6155
62 pub async fn refs_get(
63 &self,
64 space_name: String,
65 repo_name: String,
66 name: String,
67 ) -> Result<RefInfo, GitError> {
68 let ctx = self.context(space_name, repo_name).await?;
56 pub async fn refs_get(&self, ctx: &GitContext, name: String) -> Result<RefInfo, GitError> {
6957 let refs = self
7058 .baby(&ctx)
7159 .list_refs(ListRefsOptions {
@@ -77,13 +65,7 @@
7765 refs.into_iter().next().ok_or(GitError::NotFound)
7866 }
7967
80 pub async fn refs_resolve(
81 &self,
82 space_name: String,
83 repo_name: String,
84 name: String,
85 ) -> Result<String, GitError> {
86 let ctx = self.context(space_name, repo_name).await?;
68 pub async fn refs_resolve(&self, ctx: &GitContext, name: String) -> Result<String, GitError> {
8769 self.baby(&ctx)
8870 .resolve_revision(&name)
8971 .await
@@ -91,12 +73,7 @@
9173 .map_err(map_baby)
9274 }
9375
94 pub async fn refs_head(
95 &self,
96 space_name: String,
97 repo_name: String,
98 ) -> Result<HeadInfoDto, GitError> {
99 let ctx = self.context(space_name, repo_name).await?;
76 pub async fn refs_head(&self, ctx: &GitContext) -> Result<HeadInfoDto, GitError> {
10077 let baby = self.baby(&ctx);
10178 let name = baby.get_default_branch().await.map_err(map_baby)?;
10279 let object = baby
@@ -114,12 +91,10 @@
11491
11592 pub async fn refs_branches(
11693 &self,
117 space_name: String,
118 repo_name: String,
94 ctx: &GitContext,
11995 skip: u64,
12096 limit: u64,
12197 ) -> Result<Vec<BranchInfoDto>, GitError> {
122 let ctx = self.context(space_name, repo_name).await?;
12398 let baby = self.baby(&ctx);
12499 let branches = baby
125100 .list_branches(crate::rpcgit::branch::ListBranchesOptions::default())
@@ -147,14 +122,12 @@
147122
148123 pub async fn refs_update(
149124 &self,
150 space_name: String,
151 repo_name: String,
125 ctx: &GitContext,
152126 name: String,
153127 new_oid: String,
154128 expected_oid: Option<String>,
155129 ) -> Result<UpdateRefResultDto, GitError> {
156130 validate::validate_qualified_ref(&name)?;
157 let ctx = self.context(space_name, repo_name).await?;
158131 if self.ref_protected(&ctx, &name).await? {
159132 return Err(GitError::Forbidden);
160133 }
@@ -175,14 +148,8 @@
175148 })
176149 }
177150
178 pub async fn refs_delete(
179 &self,
180 space_name: String,
181 repo_name: String,
182 name: String,
183 ) -> Result<(), GitError> {
151 pub async fn refs_delete(&self, ctx: &GitContext, name: String) -> Result<(), GitError> {
184152 validate::validate_qualified_ref(&name)?;
185 let ctx = self.context(space_name, repo_name).await?;
186153 if self.ref_protected(&ctx, &name).await? {
187154 return Err(GitError::Forbidden);
188155 }
@@ -191,12 +158,10 @@
191158
192159 pub async fn refs_is_object_in_ref(
193160 &self,
194 space_name: String,
195 repo_name: String,
161 ctx: &GitContext,
196162 object: String,
197163 refname: String,
198164 ) -> Result<bool, GitError> {
199 let ctx = self.context(space_name, repo_name).await?;
200165 let oid = crate::service::diffs::parse_oid(&object)?;
201166 let refs = self
202167 .baby(&ctx)
Modified lib/git/src/service/releases.rs View lib/git/src/service/releases.rs
@@ -11,6 +11,7 @@
1111use utoipa::{IntoParams, ToSchema};
1212use uuid::Uuid;
1313
14use crate::context::facade::GitContext;
1415use crate::share::errors::GitError;
1516
1617const MAX_TITLE_LEN: usize = 255;
@@ -76,11 +77,9 @@
7677impl super::GitService {
7778 pub async fn list_releases(
7879 &self,
79 space_name: String,
80 repo_name: String,
80 ctx: &GitContext,
8181 query: ListReleasesQuery,
8282 ) -> Result<ReleasePage, GitError> {
83 let ctx = self.context(space_name, repo_name).await?;
8483 let limit = query.limit.unwrap_or(20).clamp(1, 100);
8584 let offset = query.offset.unwrap_or(0);
8685 let mut select =
@@ -104,13 +103,7 @@
104103 })
105104 }
106105
107 pub async fn get_release(
108 &self,
109 space_name: String,
110 repo_name: String,
111 tag: String,
112 ) -> Result<ReleaseDto, GitError> {
113 let ctx = self.context(space_name, repo_name).await?;
106 pub async fn get_release(&self, ctx: &GitContext, tag: String) -> Result<ReleaseDto, GitError> {
114107 let row = self.find_release(ctx.model.id, &tag).await?;
115108 let mut out = self.releases_dto(std::slice::from_ref(&row)).await?;
116109 out.pop().ok_or(GitError::NotFound)
@@ -118,8 +111,7 @@
118111
119112 pub async fn create_release(
120113 &self,
121 space_name: String,
122 repo_name: String,
114 ctx: &GitContext,
123115 publisher: i64,
124116 cmd: CreateReleaseCmd,
125117 ) -> Result<ReleaseDto, GitError> {
@@ -132,7 +124,6 @@
132124 if let Some(content) = cmd.content.as_deref() {
133125 validate_len(content, MAX_CONTENT_LEN, "release content")?;
134126 }
135 let ctx = self.context(space_name, repo_name).await?;
136127 if self
137128 .find_release_optional(ctx.model.id, tag)
138129 .await?
@@ -191,14 +182,12 @@
191182
192183 pub async fn update_release(
193184 &self,
194 space_name: String,
195 repo_name: String,
185 ctx: &GitContext,
196186 tag: String,
197187 actor: i64,
198188 admin: bool,
199189 cmd: UpdateReleaseCmd,
200190 ) -> Result<ReleaseDto, GitError> {
201 let ctx = self.context(space_name, repo_name).await?;
202191 let row = self.find_release(ctx.model.id, &tag).await?;
203192 if row.publisher_id != actor && !admin {
204193 return Err(GitError::Forbidden);
@@ -249,13 +238,11 @@
249238
250239 pub async fn delete_release(
251240 &self,
252 space_name: String,
253 repo_name: String,
241 ctx: &GitContext,
254242 tag: String,
255243 actor: i64,
256244 admin: bool,
257245 ) -> Result<(), GitError> {
258 let ctx = self.context(space_name, repo_name).await?;
259246 let row = self.find_release(ctx.model.id, &tag).await?;
260247 if row.publisher_id != actor && !admin {
261248 return Err(GitError::Forbidden);
Modified lib/git/src/service/remotes.rs View lib/git/src/service/remotes.rs
@@ -1,6 +1,7 @@
11use proto::kenshell::v1 as pb;
22use serde::{Deserialize, Serialize};
33
4use crate::context::facade::GitContext;
45use crate::service::GitService;
56use crate::service::rpc::{rpc_error, wait_job};
67use crate::share::errors::GitError;
@@ -68,13 +69,11 @@
6869impl GitService {
6970 pub async fn remote_clone_import(
7071 &self,
71 space_name: String,
72 repo_name: String,
72 ctx: &GitContext,
7373 url: String,
7474 auth: Option<RemoteAuthDto>,
7575 ) -> Result<ImportResultDto, GitError> {
7676 validate_remote_url(&url)?;
77 let ctx = self.context(space_name, repo_name).await?;
7877 let mut client = ctx.ks.remote();
7978 let job = client
8079 .start_remote_import(pb::StartRemoteImportRequest {
@@ -101,13 +100,11 @@
101100
102101 pub async fn remote_fetch(
103102 &self,
104 space_name: String,
105 repo_name: String,
103 ctx: &GitContext,
106104 remote: String,
107105 auth: Option<RemoteAuthDto>,
108106 ) -> Result<FetchResultDto, GitError> {
109107 validate_remote_name(&remote)?;
110 let ctx = self.context(space_name, repo_name).await?;
111108 let mut client = ctx.ks.remote();
112109 let job = client
113110 .start_remote_fetch(pb::StartRemoteFetchRequest {
@@ -134,8 +131,7 @@
134131
135132 pub async fn remote_push(
136133 &self,
137 space_name: String,
138 repo_name: String,
134 ctx: &GitContext,
139135 remote: String,
140136 refspec: Option<String>,
141137 auth: Option<RemoteAuthDto>,
@@ -144,7 +140,6 @@
144140 if let Some(refspec) = refspec.as_deref() {
145141 validate_refspec(refspec)?;
146142 }
147 let ctx = self.context(space_name, repo_name).await?;
148143 let mut client = ctx.ks.remote();
149144 let job = client
150145 .start_remote_push(pb::StartRemotePushRequest {
@@ -173,14 +168,12 @@
173168
174169 pub async fn remote_add(
175170 &self,
176 space_name: String,
177 repo_name: String,
171 ctx: &GitContext,
178172 name: String,
179173 url: String,
180174 ) -> Result<(), GitError> {
181175 validate_remote_name(&name)?;
182176 validate_remote_url(&url)?;
183 let ctx = self.context(space_name, repo_name).await?;
184177 let mut client = ctx.ks.remote();
185178 client
186179 .upsert_remote(pb::UpsertRemoteRequest {
@@ -197,20 +190,14 @@
197190
198191 pub async fn remote_upsert(
199192 &self,
200 space_name: String,
201 repo_name: String,
193 ctx: &GitContext,
202194 name: String,
203195 url: String,
204196 ) -> Result<(), GitError> {
205 self.remote_add(space_name, repo_name, name, url).await
197 self.remote_add(ctx, name, url).await
206198 }
207199
208 pub async fn remote_list(
209 &self,
210 space_name: String,
211 repo_name: String,
212 ) -> Result<Vec<RemoteDto>, GitError> {
213 let ctx = self.context(space_name, repo_name).await?;
200 pub async fn remote_list(&self, ctx: &GitContext) -> Result<Vec<RemoteDto>, GitError> {
214201 let mut client = ctx.ks.remote();
215202 let response = client
216203 .list_remotes(pb::ListRemotesRequest {
@@ -232,14 +219,8 @@
232219 Ok(rows)
233220 }
234221
235 pub async fn remote_remove(
236 &self,
237 space_name: String,
238 repo_name: String,
239 name: String,
240 ) -> Result<(), GitError> {
222 pub async fn remote_remove(&self, ctx: &GitContext, name: String) -> Result<(), GitError> {
241223 validate_remote_name(&name)?;
242 let ctx = self.context(space_name, repo_name).await?;
243224 let mut client = ctx.ks.remote();
244225 client
245226 .remove_remote(pb::RemoveRemoteRequest {
Modified lib/git/src/service/repos.rs View lib/git/src/service/repos.rs
@@ -459,13 +459,8 @@
459459 Ok(dto)
460460 }
461461
462 pub async fn get_repo(
463 &self,
464 space_name: String,
465 repo_name: String,
466 ) -> Result<RepoDto, GitError> {
467 let ctx = self.context(space_name, repo_name).await?;
468 self.repo_dto(ctx.model).await
462 pub async fn get_repo(&self, ctx: &GitContext) -> Result<RepoDto, GitError> {
463 self.repo_dto(ctx.model.clone()).await
469464 }
470465
471466 pub async fn repo_viewer_state(&self, repo_id: Uuid, uid: i64) -> Result<RepoMeDto, GitError> {
@@ -554,12 +549,10 @@
554549
555550 pub async fn update_repo(
556551 &self,
557 space_name: String,
558 repo_name: String,
552 ctx: &GitContext,
559553 caller: i64,
560554 cmd: UpdateRepoCmd,
561555 ) -> Result<RepoDto, GitError> {
562 let ctx = self.context(space_name, repo_name).await?;
563556 let space = self.repo_space(&ctx).await?;
564557 if space.owner_id != caller {
565558 return Err(GitError::Forbidden);
@@ -621,12 +614,10 @@
621614
622615 pub async fn set_repo_archived(
623616 &self,
624 space_name: String,
625 repo_name: String,
617 ctx: &GitContext,
626618 caller: i64,
627619 archived: bool,
628620 ) -> Result<RepoDto, GitError> {
629 let ctx = self.context(space_name, repo_name).await?;
630621 let space = self.repo_space(&ctx).await?;
631622 if space.owner_id != caller {
632623 return Err(GitError::Forbidden);
Modified lib/git/src/service/signatures.rs View lib/git/src/service/signatures.rs
@@ -1,5 +1,6 @@
11use serde::{Deserialize, Serialize};
22
3use crate::context::facade::GitContext;
34use crate::service::GitService;
45use crate::share::errors::GitError;
56
@@ -15,8 +16,7 @@
1516impl GitService {
1617 pub async fn signature_verify_commit(
1718 &self,
18 _space_name: String,
19 _repo_name: String,
19 _ctx: &GitContext,
2020 _sha: String,
2121 ) -> Result<VerifyResultDto, GitError> {
2222 Err(GitError::Unimplemented(
@@ -26,8 +26,7 @@
2626
2727 pub async fn signature_verify_tag(
2828 &self,
29 _space_name: String,
30 _repo_name: String,
29 _ctx: &GitContext,
3130 _name: String,
3231 ) -> Result<VerifyResultDto, GitError> {
3332 Err(GitError::Unimplemented(
Modified lib/git/src/service/submodules.rs View lib/git/src/service/submodules.rs
@@ -3,6 +3,7 @@
33use crate::rpcgit::commit::types::TreeEntryMode;
44use serde::{Deserialize, Serialize};
55
6use crate::context::facade::GitContext;
67use crate::service::GitService;
78use crate::service::cache::{self, IMMUTABLE_TTL};
89use crate::share::errors::{GitError, map_baby};
@@ -18,11 +19,9 @@
1819impl GitService {
1920 pub async fn submodule_list(
2021 &self,
21 space_name: String,
22 repo_name: String,
22 ctx: &GitContext,
2323 revision: String,
2424 ) -> Result<Vec<SubmoduleDto>, GitError> {
25 let ctx = self.context(space_name, repo_name).await?;
2625 let baby = self.baby(&ctx);
2726 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
2827 let key = format!("repo.{}.submodules.{}", ctx.model.id, rev_oid);
@@ -58,12 +57,10 @@
5857
5958 pub async fn submodule_resolve(
6059 &self,
61 space_name: String,
62 repo_name: String,
60 ctx: &GitContext,
6361 revision: String,
6462 path: String,
6563 ) -> Result<String, GitError> {
66 let ctx = self.context(space_name, repo_name).await?;
6764 let baby = self.baby(&ctx);
6865 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
6966 let key = format!(
Modified lib/git/src/service/tags.rs View lib/git/src/service/tags.rs
@@ -65,8 +65,7 @@
6565impl GitService {
6666 pub async fn create_tag(
6767 &self,
68 space_name: String,
69 repo_name: String,
68 ctx: &GitContext,
7069 cmd: CreateTagCmd,
7170 ) -> Result<TagDto, GitError> {
7271 if cmd.name.trim().is_empty()
@@ -77,7 +76,6 @@
7776 "invalid tag name or target".to_string(),
7877 ));
7978 }
80 let ctx = self.context(space_name, repo_name).await?;
8179 let tag_policy = policy::load_tag_policy(&self.state.database, ctx.model.id).await?;
8280 if tag_policy.is_match(&cmd.name) {
8381 return Err(GitError::Forbidden);
@@ -130,12 +128,7 @@
130128 })
131129 }
132130
133 pub async fn list_tags(
134 &self,
135 space_name: String,
136 repo_name: String,
137 ) -> Result<Vec<TagDto>, GitError> {
138 let ctx = self.context(space_name, repo_name).await?;
131 pub async fn list_tags(&self, ctx: &GitContext) -> Result<Vec<TagDto>, GitError> {
139132 if ctx.repo_uninitialized() {
140133 return Ok(Vec::new());
141134 }
@@ -176,16 +169,10 @@
176169 Ok(out)
177170 }
178171
179 pub async fn get_tag(
180 &self,
181 space_name: String,
182 repo_name: String,
183 name: String,
184 ) -> Result<TagDto, GitError> {
172 pub async fn get_tag(&self, ctx: &GitContext, name: String) -> Result<TagDto, GitError> {
185173 if name.trim().is_empty() || name.contains(['\0', '\n', '\r', ' ']) {
186174 return Err(GitError::InvalidArgument("invalid tag name".to_string()));
187175 }
188 let ctx = self.context(space_name, repo_name).await?;
189176 let meta = read_tag_meta(&ctx, &name).await?;
190177 let row = git_tags::Entity::find()
191178 .filter(git_tags::Column::RepoId.eq(ctx.model.id))
@@ -209,22 +196,14 @@
209196
210197 pub async fn verify_tag(
211198 &self,
212 space_name: String,
213 repo_name: String,
199 ctx: &GitContext,
214200 name: String,
215201 ) -> Result<TagVerifyResult, GitError> {
216 let ctx = self.context(space_name, repo_name).await?;
217202 let baby = self.baby(&ctx);
218203 baby.verify_tag_signature(&name).await.map_err(map_baby)
219204 }
220205
221 pub async fn delete_tag(
222 &self,
223 space_name: String,
224 repo_name: String,
225 name: String,
226 ) -> Result<(), GitError> {
227 let ctx = self.context(space_name, repo_name).await?;
206 pub async fn delete_tag(&self, ctx: &GitContext, name: String) -> Result<(), GitError> {
228207 let tag_policy = policy::load_tag_policy(&self.state.database, ctx.model.id).await?;
229208 if tag_policy.is_match(&name) {
230209 return Err(GitError::Forbidden);
Modified lib/git/src/service/trees.rs View lib/git/src/service/trees.rs
@@ -4,6 +4,7 @@
44use crate::rpcgit::tree::types::WalkTreeOptions;
55use serde::{Deserialize, Serialize};
66
7use crate::context::facade::GitContext;
78use crate::service::GitService;
89use crate::service::cache::{self, IMMUTABLE_TTL};
910use crate::share::errors::{GitError, map_baby};
@@ -28,13 +29,11 @@
2829impl GitService {
2930 pub async fn tree_read(
3031 &self,
31 space_name: String,
32 repo_name: String,
32 ctx: &GitContext,
3333 revision: String,
3434 path: PathBuf,
3535 ) -> Result<Vec<TreeEntry>, GitError> {
3636 validate::validate_revision(&revision)?;
37 let ctx = self.context(space_name, repo_name).await?;
3837 let baby = self.baby(&ctx);
3938 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
4039 let key = format!(
@@ -53,13 +52,11 @@
5352
5453 pub async fn tree_resolve_path(
5554 &self,
56 space_name: String,
57 repo_name: String,
55 ctx: &GitContext,
5856 revision: String,
5957 path: String,
6058 ) -> Result<TreeEntry, GitError> {
6159 validate::validate_revision(&revision)?;
62 let ctx = self.context(space_name, repo_name).await?;
6360 let baby = self.baby(&ctx);
6461 let name = path.trim().trim_start_matches("./").to_string();
6562 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
@@ -75,14 +72,12 @@
7572
7673 pub async fn tree_walk(
7774 &self,
78 space_name: String,
79 repo_name: String,
75 ctx: &GitContext,
8076 revision: String,
8177 recurse: bool,
8278 show_trees: bool,
8379 ) -> Result<Vec<TreeEntry>, GitError> {
8480 validate::validate_revision(&revision)?;
85 let ctx = self.context(space_name, repo_name).await?;
8681 let baby = self.baby(&ctx);
8782 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
8883 let key = format!(
@@ -106,24 +101,15 @@
106101
107102 pub async fn tree_follow(
108103 &self,
109 space_name: String,
110 repo_name: String,
104 ctx: &GitContext,
111105 revision: String,
112106 path: String,
113107 ) -> Result<(TreeEntry, Option<String>, Option<TreeEntry>), GitError> {
114108 validate::validate_revision(&revision)?;
115 let entry = self
116 .tree_resolve_path(
117 space_name.clone(),
118 repo_name.clone(),
119 revision.clone(),
120 path,
121 )
122 .await?;
109 let entry = self.tree_resolve_path(ctx, revision.clone(), path).await?;
123110 if entry.mode != TreeEntryMode::Symlink {
124111 return Ok((entry, None, None));
125112 }
126 let ctx = self.context(space_name, repo_name).await?;
127113 let baby = self.baby(&ctx);
128114 let blob = baby
129115 .get_blob(
@@ -152,13 +138,11 @@
152138
153139 pub async fn tree_last_updated(
154140 &self,
155 space_name: String,
156 repo_name: String,
141 ctx: &GitContext,
157142 revision: String,
158143 path: Option<String>,
159144 ) -> Result<Vec<PathLastUpdated>, GitError> {
160145 validate::validate_revision(&revision)?;
161 let ctx = self.context(space_name, repo_name).await?;
162146 let baby = self.baby(&ctx);
163147 let rev_oid = baby.rev_parse(&revision).await.map_err(map_baby)?;
164148 let path_str = path.as_deref().unwrap_or("");
Modified lib/pulls/src/handlers/checks/get_pull_gate.rs View lib/pulls/src/handlers/checks/get_pull_gate.rs
@@ -33,14 +33,7 @@
3333 )
3434 .await?;
3535 let gate = service
36 .pull_gate(
37 path.space_name,
38 path.repo_name,
39 &handle.ctx,
40 &handle.pull,
41 handle.caller,
42 handle.admin,
43 )
36 .pull_gate(&handle.ctx, &handle.pull, handle.caller, handle.admin)
4437 .await?;
4538 Ok(AppResponseData::ok(gate))
4639}
Modified lib/pulls/src/handlers/pulls/get_pull_files.rs View lib/pulls/src/handlers/pulls/get_pull_files.rs
@@ -32,8 +32,6 @@
3232 false,
3333 )
3434 .await?;
35 let files = service
36 .pull_files(&handle.ctx, path.space_name, path.repo_name, &handle.pull)
37 .await?;
35 let files = service.pull_files(&handle.ctx, &handle.pull).await?;
3836 Ok(AppResponseData::ok(files))
3937}
Modified lib/pulls/src/handlers/pulls/get_pull_patch.rs View lib/pulls/src/handlers/pulls/get_pull_patch.rs
@@ -31,9 +31,7 @@
3131 false,
3232 )
3333 .await?;
34 let patch = service
35 .pull_patch(&handle.ctx, path.space_name, path.repo_name, &handle.pull)
36 .await?;
34 let patch = service.pull_patch(&handle.ctx, &handle.pull).await?;
3735 Ok(actix_web::HttpResponse::Ok()
3836 .insert_header((CONTENT_TYPE, "text/plain; charset=utf-8"))
3937 .body(patch))
Modified lib/pulls/src/services/approvals.rs View lib/pulls/src/services/approvals.rs
@@ -109,11 +109,8 @@
109109 .await? as i32)
110110 }
111111
112 #[allow(clippy::too_many_arguments)]
113112 pub async fn merge_gate(
114113 &self,
115 space_name: String,
116 repo_name: String,
117114 ctx: &GitContext,
118115 pull: &pull_requests::Model,
119116 caller: i64,
@@ -200,8 +197,7 @@
200197 let commits = self
201198 .git
202199 .merge_commits(
203 space_name.clone(),
204 repo_name.clone(),
200 ctx,
205201 &format!("refs/heads/{}", pull.base_branch),
206202 &summary.head_sha,
207203 )
@@ -214,11 +210,7 @@
214210 for commit in &commits {
215211 let verify = self
216212 .git
217 .signature_verify_commit(
218 space_name.clone(),
219 repo_name.clone(),
220 commit.sha.clone(),
221 )
213 .signature_verify_commit(ctx, commit.sha.clone())
222214 .await?;
223215 if !verify.signed || !verify.valid {
224216 reasons.push(format!("commit {} is not validly signed", commit.sha));
@@ -241,11 +233,7 @@
241233 if !required_contexts.is_empty() {
242234 let statuses = self
243235 .git
244 .list_commit_statuses(
245 space_name.clone(),
246 repo_name.clone(),
247 summary.head_sha.clone(),
248 )
236 .list_commit_statuses(ctx, summary.head_sha.clone())
249237 .await?;
250238 for context in &required_contexts {
251239 let state = statuses
@@ -288,12 +276,7 @@
288276 .unwrap_or_else(|| summary.base_sha.clone());
289277 let changed = self
290278 .git
291 .diff_files_changed_between(
292 space_name.clone(),
293 repo_name.clone(),
294 from,
295 summary.head_sha.clone(),
296 )
279 .diff_files_changed_between(ctx, from, summary.head_sha.clone())
297280 .await?;
298281 let protected = build_glob_set(&protected_raw)?;
299282 let unprotected = build_glob_set(&unprotected_raw)?;
Modified lib/pulls/src/services/changes.rs View lib/pulls/src/services/changes.rs
@@ -50,17 +50,13 @@
5050 pull: &pull_requests::Model,
5151 ) -> Result<Vec<MergeCommitDto>, PullError> {
5252 let (base_ref, head) = Self::revisions(pull);
53 Ok(self
54 .git
55 .merge_commits(space_name, repo_name, &base_ref, &head)
56 .await?)
53 let ctx = self.git.context(space_name, repo_name).await?;
54 Ok(self.git.merge_commits(&ctx, &base_ref, &head).await?)
5755 }
5856
5957 pub async fn pull_files(
6058 &self,
6159 ctx: &GitContext,
62 space_name: String,
63 repo_name: String,
6460 pull: &pull_requests::Model,
6561 ) -> Result<Vec<ChangedPathDiffDto>, PullError> {
6662 let plan = self.plan_for(ctx, pull).await?;
@@ -70,21 +66,13 @@
7066 .unwrap_or_else(|| plan.base_sha.clone());
7167 Ok(self
7268 .git
73 .diff_files(
74 space_name,
75 repo_name,
76 from,
77 plan.head_sha.clone(),
78 DiffOptionsDto::default(),
79 )
69 .diff_files(ctx, from, plan.head_sha.clone(), DiffOptionsDto::default())
8070 .await?)
8171 }
8272
8373 pub async fn pull_patch(
8474 &self,
8575 ctx: &GitContext,
86 space_name: String,
87 repo_name: String,
8876 pull: &pull_requests::Model,
8977 ) -> Result<String, PullError> {
9078 let plan = self.plan_for(ctx, pull).await?;
@@ -92,10 +80,7 @@
9280 .merge_base
9381 .clone()
9482 .unwrap_or_else(|| plan.base_sha.clone());
95 Ok(self
96 .git
97 .diff_raw(space_name, repo_name, from, plan.head_sha.clone())
98 .await?)
83 Ok(self.git.diff_raw(ctx, from, plan.head_sha.clone()).await?)
9984 }
10085
10186 /// 重新对齐 head/base 快照并重算行数与冲突状态。
@@ -106,12 +91,12 @@
10691 pull: &pull_requests::Model,
10792 actor: Option<i64>,
10893 ) -> Result<(pull_requests::Model, PullSummaryDto), PullError> {
109 let head_ref = format!("refs/heads/{}", pull.head_branch);
110 let head_now = match self
94 let repo_ctx = self
11195 .git
112 .rev_parse(space_name.clone(), repo_name.clone(), head_ref)
113 .await
114 {
96 .context(space_name.clone(), repo_name.clone())
97 .await?;
98 let head_ref = format!("refs/heads/{}", pull.head_branch);
99 let head_now = match self.git.rev_parse(&repo_ctx, head_ref).await {
115100 Ok(sha) => Some(sha),
116101 Err(git::share::errors::GitError::NotFound) => None,
117102 Err(other) => return Err(PullError::from(other)),
@@ -121,10 +106,7 @@
121106 let plan = self
122107 .git
123108 .merge_plan(
124 &self
125 .git
126 .context(space_name.clone(), repo_name.clone())
127 .await?,
109 &repo_ctx,
128110 &format!("refs/heads/{}", pull.base_branch),
129111 &head,
130112 )
Modified lib/pulls/src/services/checks.rs View lib/pulls/src/services/checks.rs
@@ -30,9 +30,10 @@
3030 repo_name: String,
3131 pull: &pull_requests::Model,
3232 ) -> Result<PullChecksDto, PullError> {
33 let repo_ctx = self.git.context(space_name, repo_name).await?;
3334 let statuses = self
3435 .git
35 .list_commit_statuses(space_name, repo_name, pull.head_sha.clone())
36 .list_commit_statuses(&repo_ctx, pull.head_sha.clone())
3637 .await?;
3738 Ok(PullChecksDto {
3839 head_sha: pull.head_sha.clone(),
@@ -43,8 +44,6 @@
4344 /// 合并门禁预览:不改动任何数据。
4445 pub async fn pull_gate(
4546 &self,
46 space_name: String,
47 repo_name: String,
4847 ctx: &GitContext,
4948 pull: &pull_requests::Model,
5049 caller: Option<i64>,
@@ -69,9 +68,7 @@
6968 files_changed: pull.files_changed,
7069 };
7170 let caller = caller.ok_or(PullError::Unauthorized)?;
72 let gate = self
73 .merge_gate(space_name, repo_name, ctx, pull, caller, admin, &summary)
74 .await?;
71 let gate = self.merge_gate(ctx, pull, caller, admin, &summary).await?;
7572 let pending = self.pending_requests(pull.id).await?;
7673 Ok(PullGateDto {
7774 head_sha: plan.head_sha,
Modified lib/pulls/src/services/merge.rs View lib/pulls/src/services/merge.rs
@@ -90,15 +90,7 @@
9090 )));
9191 }
9292 let gate = self
93 .merge_gate(
94 space_name.clone(),
95 repo_name.clone(),
96 ctx,
97 &current,
98 caller,
99 admin,
100 &summary,
101 )
93 .merge_gate(ctx, &current, caller, admin, &summary)
10294 .await?;
10395 if !gate.allowed {
10496 return Err(PullError::Conflict(gate.reasons.join("; ")));
@@ -156,12 +148,7 @@
156148 && merged.head_branch != ctx.model.default_branch
157149 && let Err(error) = self
158150 .git
159 .delete_branch(
160 space_name.clone(),
161 repo_name.clone(),
162 merged.head_branch.clone(),
163 false,
164 )
151 .delete_branch(&ctx, merged.head_branch.clone(), false)
165152 .await
166153 {
167154 tracing::warn!(
Modified lib/pulls/src/services/pulls.rs View lib/pulls/src/services/pulls.rs
@@ -630,14 +630,13 @@
630630 .merge_base
631631 .clone()
632632 .unwrap_or_else(|| plan.base_sha.clone());
633 let repo_ctx = self
634 .git
635 .context(space_name.to_string(), repo_name.to_string())
636 .await?;
633637 let stat = self
634638 .git
635 .diff_short_stat(
636 space_name.to_string(),
637 repo_name.to_string(),
638 from,
639 head.to_string(),
640 )
639 .diff_short_stat(&repo_ctx, from, head.to_string())
641640 .await?;
642641 Ok((
643642 stat.additions as i32,
Modified lib/webapi/src/cleanup.rs View lib/webapi/src/cleanup.rs
@@ -398,9 +398,14 @@
398398 is_private: Some(cmd.is_private),
399399 ..Default::default()
400400 };
401 let ctx = state
402 .git
403 .context(space_name.clone(), repo.name.clone())
404 .await
405 .map_err(map_git)?;
401406 state
402407 .git
403 .update_repo(space_name.clone(), repo.name, uid, update)
408 .update_repo(&ctx, uid, update)
404409 .await
405410 .map_err(map_git)?;
406411 }
@@ -450,9 +455,14 @@
450455 return Err(ApiError::bad_request("only repositories support archiving"));
451456 }
452457 let repo = repo_row_by_dir(state.space.db().read(), object_id).await?;
458 let ctx = state
459 .git
460 .context(space_name.clone(), repo.name.clone())
461 .await
462 .map_err(map_git)?;
453463 state
454464 .git
455 .set_repo_archived(space_name.clone(), repo.name, uid, cmd.archived)
465 .set_repo_archived(&ctx, uid, cmd.archived)
456466 .await
457467 .map_err(map_git)?;
458468 Ok(AppResponseData::empty())