aboutsummaryrefslogtreecommitdiff
path: root/src/post_routes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/post_routes.rs')
-rw-r--r--src/post_routes.rs35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/post_routes.rs b/src/post_routes.rs
index 1b5d615..a542060 100644
--- a/src/post_routes.rs
+++ b/src/post_routes.rs
@@ -66,11 +66,16 @@ fn commit_file_update<C: Controller>(
let mut builder = TreeUpdateBuilder::new();
- builder.upsert(ctx.path.to_str().unwrap(), blob_id, FileMode::Blob);
+ builder.upsert(ctx.path.as_str(), blob_id, FileMode::Blob);
let (parent_tree, parent_commits) = if let Ok(commit) = ctx.branch_head() {
let parent_tree = commit.tree()?;
- if parent_tree.get_path(&ctx.path).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()));
}
@@ -90,12 +95,12 @@ fn commit_file_update<C: Controller>(
&msg.filter(|m| !m.trim().is_empty()).unwrap_or_else(|| {
format!(
"{} {}",
- if parent_tree.get_path(&ctx.path).is_ok() {
+ if parent_tree.get_path(&ctx.path.as_ref()).is_ok() {
"edit"
} else {
"create"
},
- ctx.path.to_str().unwrap()
+ ctx.path
)
}),
&ctx.repo.find_tree(new_tree_id)?,
@@ -123,7 +128,7 @@ async fn update_blob<C: Controller>(
let latest_oid = commit
.tree()
.unwrap()
- .get_path(&ctx.path)
+ .get_path(&ctx.path.as_ref())
.ok()
.map(|e| e.id().to_string());
@@ -219,7 +224,7 @@ async fn move_entry<C: Controller>(
));
}
let mut data: MoveForm = body.into_form().await?;
- let filename = ctx.path.file_name().unwrap().to_str().unwrap();
+ let filename = ctx.path.file_name().unwrap();
if ctx.path == Path::new(&data.dest) {
return move_form(
@@ -246,8 +251,8 @@ async fn move_entry<C: Controller>(
}
let mut builder = TreeUpdateBuilder::new();
- let entr = parent_tree.get_path(&ctx.path)?;
- builder.remove(&ctx.path);
+ let entr = parent_tree.get_path(&ctx.path.as_ref())?;
+ builder.remove(&ctx.path.as_str());
builder.upsert(
&data.dest,
entr.id(),
@@ -271,7 +276,7 @@ async fn move_entry<C: Controller>(
.msg
.take()
.filter(|m| !m.trim().is_empty())
- .unwrap_or_else(|| format!("move {} to {}", ctx.path.to_str().unwrap(), data.dest)),
+ .unwrap_or_else(|| format!("move {} to {}", ctx.path, data.dest)),
&ctx.repo.find_tree(new_tree_id)?,
&[&parent_commit],
)?;
@@ -305,7 +310,7 @@ async fn remove_entry<C: Controller>(
}
let data: RemoveForm = body.into_form().await?;
let mut builder = TreeUpdateBuilder::new();
- builder.remove(&ctx.path);
+ builder.remove(&ctx.path.as_str());
let parent_commit = ctx.branch_head()?;
let new_tree_id = builder.create_updated(&ctx.repo, &parent_commit.tree()?)?;
@@ -314,7 +319,7 @@ async fn remove_entry<C: Controller>(
&data
.msg
.filter(|m| !m.trim().is_empty())
- .unwrap_or_else(|| format!("remove {}", ctx.path.to_str().unwrap())),
+ .unwrap_or_else(|| format!("remove {}", ctx.path)),
&ctx.repo.find_tree(new_tree_id)?,
&[&parent_commit],
)?;
@@ -322,7 +327,7 @@ async fn remove_entry<C: Controller>(
.status(StatusCode::FOUND)
.header(
"location",
- controller.build_url_path(&ctx.branch, ctx.path.parent().unwrap().to_str().unwrap()),
+ controller.build_url_path(&ctx.branch, ctx.path.parent().unwrap().as_str()),
)
.body("redirecting".into())
.unwrap()
@@ -344,7 +349,11 @@ async fn diff_blob<C: Controller>(
let form: EditForm = body.into_form().await?;
let new_text = form.text.replace("\r\n", "\n");
- let entr = ctx.branch_head()?.tree().unwrap().get_path(&ctx.path)?;
+ let entr = ctx
+ .branch_head()?
+ .tree()
+ .unwrap()
+ .get_path(&ctx.path.as_ref())?;
let blob = ctx.repo.find_blob(entr.id()).unwrap();
let old_text = from_utf8(blob.content())?;