diff options
author | Martin Fischer <martin@push-f.com> | 2022-07-27 15:22:26 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-07-27 15:23:28 +0200 |
commit | 2d9d1f7fa444204a9045f08e19af763f465af383 (patch) | |
tree | f29061a67ffc1ceb1b9b802bdd75f46942d302ab /src/post_routes.rs | |
parent | 98b0f80bdd1a0d5cebabf093651f66623a39cbd9 (diff) |
refactor: remove needless borrows / returns
Diffstat (limited to 'src/post_routes.rs')
-rw-r--r-- | src/post_routes.rs | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/post_routes.rs b/src/post_routes.rs index a542060..51b35ec 100644 --- a/src/post_routes.rs +++ b/src/post_routes.rs @@ -45,13 +45,13 @@ pub(crate) async fn build_response<C: Controller>( ))); } match params.action.as_ref() { - "edit" => return update_blob(body, controller, ctx, parts).await, - "upload" => return upload_blob(body, controller, ctx, parts).await, - "move" => return move_entry(body, controller, ctx, parts).await, - "remove" => return remove_entry(body, controller, ctx, parts).await, - "diff" => return diff_blob(body, controller, ctx, parts).await, - "preview" => return preview_edit(body, controller, ctx, parts).await, - _ => return Err(Error::BadRequest("unknown POST action".into())), + "edit" => update_blob(body, controller, ctx, parts).await, + "upload" => upload_blob(body, controller, ctx, parts).await, + "move" => move_entry(body, controller, ctx, parts).await, + "remove" => remove_entry(body, controller, ctx, parts).await, + "diff" => diff_blob(body, controller, ctx, parts).await, + "preview" => preview_edit(body, controller, ctx, parts).await, + _ => Err(Error::BadRequest("unknown POST action".into())), } } @@ -70,12 +70,7 @@ fn commit_file_update<C: Controller>( let (parent_tree, parent_commits) = if let Ok(commit) = ctx.branch_head() { let parent_tree = commit.tree()?; - if parent_tree - .get_path(&ctx.path.as_ref()) - .ok() - .map(|e| e.id()) - == Some(blob_id) - { + if parent_tree.get_path(ctx.path.as_ref()).ok().map(|e| e.id()) == Some(blob_id) { // nothing changed, don't create an empty commit return Err(Error::Redirect(parts.uri.path().to_string())); } @@ -89,13 +84,13 @@ fn commit_file_update<C: Controller>( let new_tree_id = builder.create_updated(&ctx.repo, &parent_tree)?; - let signature = controller.signature(&ctx.repo, &parts)?; + let signature = controller.signature(&ctx.repo, parts)?; ctx.commit( &signature, &msg.filter(|m| !m.trim().is_empty()).unwrap_or_else(|| { format!( "{} {}", - if parent_tree.get_path(&ctx.path.as_ref()).is_ok() { + if parent_tree.get_path(ctx.path.as_ref()).is_ok() { "edit" } else { "create" @@ -128,7 +123,7 @@ async fn update_blob<C: Controller>( let latest_oid = commit .tree() .unwrap() - .get_path(&ctx.path.as_ref()) + .get_path(ctx.path.as_ref()) .ok() .map(|e| e.id().to_string()); @@ -150,7 +145,7 @@ async fn update_blob<C: Controller>( return Ok(edit_text_form(&data, Some(&error), controller, &ctx, parts).into()); } - commit_file_update(text.as_bytes(), data.msg, controller, &ctx, &parts)?; + commit_file_update(text.as_bytes(), data.msg, controller, &ctx, parts)?; controller.after_write(&ctx, parts); @@ -189,13 +184,7 @@ async fn upload_blob<C: Controller>( { if field.name() == Some("file") { // TODO: make commit message customizable - commit_file_update( - &field.bytes().await.unwrap(), - None, - controller, - &ctx, - &parts, - )?; + commit_file_update(&field.bytes().await.unwrap(), None, controller, &ctx, parts)?; controller.after_write(&ctx, parts); @@ -251,7 +240,7 @@ async fn move_entry<C: Controller>( } let mut builder = TreeUpdateBuilder::new(); - let entr = parent_tree.get_path(&ctx.path.as_ref())?; + let entr = parent_tree.get_path(ctx.path.as_ref())?; builder.remove(&ctx.path.as_str()); builder.upsert( &data.dest, @@ -271,7 +260,7 @@ async fn move_entry<C: Controller>( let new_tree_id = builder.create_updated(&ctx.repo, &parent_commit.tree()?)?; ctx.commit( - &controller.signature(&ctx.repo, &parts)?, + &controller.signature(&ctx.repo, parts)?, &data .msg .take() @@ -315,7 +304,7 @@ async fn remove_entry<C: Controller>( let new_tree_id = builder.create_updated(&ctx.repo, &parent_commit.tree()?)?; ctx.commit( - &controller.signature(&ctx.repo, &parts)?, + &controller.signature(&ctx.repo, parts)?, &data .msg .filter(|m| !m.trim().is_empty()) @@ -353,7 +342,7 @@ async fn diff_blob<C: Controller>( .branch_head()? .tree() .unwrap() - .get_path(&ctx.path.as_ref())?; + .get_path(ctx.path.as_ref())?; let blob = ctx.repo.find_blob(entr.id()).unwrap(); let old_text = from_utf8(blob.content())?; |