aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controller.rs14
-rw-r--r--src/diff.rs12
-rw-r--r--src/get_routes.rs16
-rw-r--r--src/main.rs13
-rw-r--r--src/origins.rs2
-rw-r--r--src/post_routes.rs45
6 files changed, 45 insertions, 57 deletions
diff --git a/src/controller.rs b/src/controller.rs
index ba1f2de..55ff4c2 100644
--- a/src/controller.rs
+++ b/src/controller.rs
@@ -200,7 +200,7 @@ impl MultiUserController {
}
fn list_shares(&self, repo: &Repository, branch: &Branch, username: &str, out: &mut String) {
- self.with_shares_cache(&repo, branch.clone(), |shares| {
+ self.with_shares_cache(repo, branch.clone(), |shares| {
out.push_str("<a href=..>../</a>");
let exact_shares: Vec<_> = shares
.exact_rules
@@ -326,7 +326,7 @@ impl Controller for MultiUserController {
))));
}
if path == "/" {
- return Err(multi_user_startpage(&self, parts, repo));
+ return Err(multi_user_startpage(self, parts, repo));
}
let mut iter = path.splitn(3, '/');
@@ -351,7 +351,7 @@ impl Controller for MultiUserController {
}
};
if unsanitized_path.is_empty() {
- let username = username_from_parts(&parts).unwrap();
+ let username = username_from_parts(parts).unwrap();
if username != rev.0 {
let mut page = Page::default();
self.list_shares(repo, &rev, username, &mut page.body);
@@ -380,7 +380,7 @@ impl Controller for MultiUserController {
context: &Context,
parts: &Parts,
) {
- let username = username_from_parts(&parts).unwrap();
+ let username = username_from_parts(parts).unwrap();
if context.branch.0 == username {
if context.path.components().count() == 0 {
match tree {
@@ -427,7 +427,7 @@ impl Controller for MultiUserController {
}
fn may_write_path(&self, ctx: &Context, parts: &Parts) -> bool {
- let username = username_from_parts(&parts).unwrap();
+ let username = username_from_parts(parts).unwrap();
if ctx.branch.0 == username {
return true;
}
@@ -442,7 +442,7 @@ impl Controller for MultiUserController {
}
fn may_move_path(&self, ctx: &Context, parts: &Parts) -> bool {
- ctx.branch.0 == username_from_parts(&parts).unwrap()
+ ctx.branch.0 == username_from_parts(parts).unwrap()
}
fn edit_hint_html(&self, ctx: &Context) -> Option<String> {
@@ -493,7 +493,7 @@ impl Controller for MultiUserController {
}
fn access_info_html(&self, ctx: &Context, parts: &Parts) -> Option<String> {
- let own_username = username_from_parts(&parts).unwrap();
+ let own_username = username_from_parts(parts).unwrap();
if own_username != ctx.branch.0 {
return None;
}
diff --git a/src/diff.rs b/src/diff.rs
index 382c7db..442448f 100644
--- a/src/diff.rs
+++ b/src/diff.rs
@@ -9,7 +9,7 @@ pub fn diff(first: &str, second: &str) -> String {
return "<em>(no changes)</em>".into();
}
- let Changeset { diffs, .. } = Changeset::new(&first, &second, "\n");
+ let Changeset { diffs, .. } = Changeset::new(first, second, "\n");
let mut output = String::new();
@@ -31,14 +31,14 @@ pub fn diff(first: &str, second: &str) -> String {
Difference::Add(ref text) => {
output.push_str("<div class=addition>");
if i == 0 {
- output.push_str(&html_escape(text).replace("\n", "<br>"));
+ output.push_str(&html_escape(text).replace('\n', "<br>"));
} else {
match diffs.get(i - 1) {
Some(Difference::Rem(ref rem)) => {
word_diff(&mut output, rem, text, "ins");
}
_ => {
- output.push_str(&html_escape(text).replace("\n", "<br>"));
+ output.push_str(&html_escape(text).replace('\n', "<br>"));
}
}
}
@@ -51,7 +51,7 @@ pub fn diff(first: &str, second: &str) -> String {
word_diff(&mut output, add, text, "del");
}
_ => {
- output.push_str(&html_escape(text).replace("\n", "<br>"));
+ output.push_str(&html_escape(text).replace('\n', "<br>"));
}
}
output.push_str("\n</div>");
@@ -68,7 +68,7 @@ fn word_diff(out: &mut String, text1: &str, text2: &str, tagname: &str) {
for c in diffs {
match c {
Difference::Same(ref z) => {
- out.push_str(&html_escape(z).replace("\n", "<br>"));
+ out.push_str(&html_escape(z).replace('\n', "<br>"));
out.push(' ');
}
Difference::Add(ref z) => {
@@ -76,7 +76,7 @@ fn word_diff(out: &mut String, text1: &str, text2: &str, tagname: &str) {
out,
"<{0}>{1}</{0}> ",
tagname,
- html_escape(z).replace("\n", "<br>")
+ html_escape(z).replace('\n', "<br>")
)
.expect("write error");
}
diff --git a/src/get_routes.rs b/src/get_routes.rs
index 95d535d..112cf6b 100644
--- a/src/get_routes.rs
+++ b/src/get_routes.rs
@@ -107,7 +107,7 @@ fn edit_blob<C: Controller>(
}
let blob = ctx.repo.find_blob(entr.id()).unwrap();
if let Ok(text) = from_utf8(blob.content()) {
- return Ok(forms::edit_text_form(
+ Ok(forms::edit_text_form(
&forms::EditForm {
text: text.to_string(),
oid: Some(entr.id().to_string()),
@@ -118,7 +118,7 @@ fn edit_blob<C: Controller>(
&ctx,
parts,
)
- .into());
+ .into())
} else {
Ok(forms::upload_form(true, controller, &ctx, parts).into())
}
@@ -144,14 +144,14 @@ fn log_blob<C: Controller>(
walk.push(branch_head.id())?;
let mut prev_commit = branch_head;
- let mut prev_blobid = Some(prev_commit.tree()?.get_path(&ctx.path.as_ref())?.id());
+ let mut prev_blobid = Some(prev_commit.tree()?.get_path(ctx.path.as_ref())?.id());
let mut commits = Vec::new();
// TODO: paginate
for oid in walk.flatten().skip(1) {
let commit = ctx.repo.find_commit(oid)?;
- if let Ok(entr) = commit.tree()?.get_path(&ctx.path.as_ref()) {
+ if let Ok(entr) = commit.tree()?.get_path(ctx.path.as_ref()) {
let blobid = entr.id();
if Some(blobid) != prev_blobid {
commits.push(prev_commit);
@@ -166,7 +166,7 @@ fn log_blob<C: Controller>(
prev_blobid = None;
}
}
- if prev_commit.parent_count() == 0 && prev_commit.tree()?.get_path(&ctx.path.as_ref()).is_ok() {
+ if prev_commit.parent_count() == 0 && prev_commit.tree()?.get_path(ctx.path.as_ref()).is_ok() {
// the very first commit of the branch
commits.push(prev_commit);
}
@@ -249,7 +249,7 @@ fn diff_blob<C: Controller>(
commit.parents().next()
};
- let blob_id = if let Ok(entry) = commit.tree()?.get_path(&ctx.path.as_ref()) {
+ let blob_id = if let Ok(entry) = commit.tree()?.get_path(ctx.path.as_ref()) {
entry.id()
} else {
return Ok(Page {
@@ -262,7 +262,7 @@ fn diff_blob<C: Controller>(
};
let old_blob_id = old_commit
- .and_then(|p| p.tree().unwrap().get_path(&ctx.path.as_ref()).ok())
+ .and_then(|p| p.tree().unwrap().get_path(ctx.path.as_ref()).ok())
.map(|e| e.id());
if Some(blob_id) == old_blob_id {
@@ -301,7 +301,7 @@ fn diff_blob<C: Controller>(
} else {
page.body.push_str(&diff(
"",
- from_utf8(&ctx.repo.find_blob(blob_id)?.content())?,
+ from_utf8(ctx.repo.find_blob(blob_id)?.content())?,
));
}
page.body.push_str("</div>");
diff --git a/src/main.rs b/src/main.rs
index 1f3f890..be38348 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -185,7 +185,7 @@ async fn serve<C: Controller + Send + Sync + 'static>(controller: C, args: Args)
async move {
Ok::<_, hyper::Error>(service_fn(move |req| {
- service(&origin, controller.clone(), req)
+ service(origin, controller.clone(), req)
}))
}
});
@@ -202,7 +202,7 @@ async fn service<C: Controller>(
let (mut parts, body) = request.into_parts();
let mut script_csp = "'none'".into();
- let mut frame_csp = "'none'".into();
+ let mut frame_csp = "'none'";
let mut resp = build_response(origin, &*controller, &mut parts, body)
.await
@@ -323,8 +323,7 @@ async fn build_response<C: Controller>(
let repo = Repository::open_bare(env::current_dir().unwrap()).unwrap();
- let (rev, unsanitized_path) = match controller.parse_url_path(&unsanitized_path, &parts, &repo)
- {
+ let (rev, unsanitized_path) = match controller.parse_url_path(&unsanitized_path, parts, &repo) {
Ok(parsed) => parsed,
Err(res) => return res,
};
@@ -368,7 +367,7 @@ async fn build_response<C: Controller>(
.map(|r| r.into_commit().unwrap().tree().unwrap());
if ctx.path.components().next().is_some() {
- let entr = match tree.and_then(|t| t.get_path(&ctx.path.as_ref())) {
+ let entr = match tree.and_then(|t| t.get_path(ctx.path.as_ref())) {
Ok(entr) => entr,
Err(_) => {
if unsanitized_path.ends_with('/') {
@@ -411,7 +410,7 @@ async fn build_response<C: Controller>(
.unwrap()
.into());
}
- return get_routes::get_blob(entr, params, controller, ctx, &parts);
+ return get_routes::get_blob(entr, params, controller, ctx, parts);
}
tree = ctx.repo.find_tree(entr.id());
@@ -420,7 +419,7 @@ async fn build_response<C: Controller>(
}
}
- get_routes::view_tree(tree, controller, &ctx, &parts)
+ get_routes::view_tree(tree, controller, &ctx, parts)
}
fn render_link(name: &str, label: &str, active_action: &str) -> String {
diff --git a/src/origins.rs b/src/origins.rs
index c2a7dc1..0cc0bc2 100644
--- a/src/origins.rs
+++ b/src/origins.rs
@@ -23,7 +23,7 @@ impl FromStr for HttpOrigin {
return Err("expected http:// or https:// scheme");
}
if url.path() != "/" {
- return Err("path must be /".into());
+ return Err("path must be /");
}
Ok(HttpOrigin {
origin: url.origin().ascii_serialization(),
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())?;