diff options
author | Martin Fischer <martin@push-f.com> | 2021-06-24 10:50:40 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-06-24 11:26:46 +0200 |
commit | 6646e71936960583e7046dfeff165d3e98688b61 (patch) | |
tree | 635148a14f08f99efab4e2298a95f0f64d742311 | |
parent | b0cd90369a57187c35b2835b665645ba060e3ec7 (diff) |
refactor diff_blob
-rw-r--r-- | src/get_routes.rs | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/get_routes.rs b/src/get_routes.rs index b209cab..7576d60 100644 --- a/src/get_routes.rs +++ b/src/get_routes.rs @@ -230,7 +230,6 @@ fn diff_blob<C: Controller>( .into()); }; - // TODO: if UTF-8 decoding fails, link ?action=raw&rev= // TODO: what if there are multiple parents? let old_blob_id = commit .parents() @@ -238,35 +237,36 @@ fn diff_blob<C: Controller>( .and_then(|p| p.tree().unwrap().get_path(&ctx.path).ok()) .map(|e| e.id()); - if Some(blob_id) != old_blob_id { - let mut page = Page { - title: format!("Commit for {}", ctx.file_name().unwrap()), - header: Some(action_links(¶ms.action, controller, &ctx)), - body: format!( - "<h1>{}</h1>{} committed on {}", - html_escape(commit.summary().unwrap_or_default()), - html_escape(commit.author().name().unwrap_or_default()), - NaiveDateTime::from_timestamp(commit.time().seconds(), 0) - .format("%b %d, %Y, %H:%M") - ), - controller, - parts: &ctx.parts, - }; - if let Some(old_blob_id) = old_blob_id { - page.body.push_str(&diff( - from_utf8(ctx.repo.find_blob(old_blob_id)?.content())?, - from_utf8(ctx.repo.find_blob(blob_id)?.content())?, - )) - } else { - page.body.push_str(&diff( - "", - from_utf8(&ctx.repo.find_blob(blob_id)?.content())?, - )); - } - Ok(page.into()) + if Some(blob_id) == old_blob_id { + return Err(Error::NotFound("commit not found".into())); + } + + let mut page = Page { + title: format!("Commit for {}", ctx.file_name().unwrap()), + header: Some(action_links(¶ms.action, controller, &ctx)), + body: format!( + "<h1>{}</h1>{} committed on {}", + html_escape(commit.summary().unwrap_or_default()), + html_escape(commit.author().name().unwrap_or_default()), + NaiveDateTime::from_timestamp(commit.time().seconds(), 0).format("%b %d, %Y, %H:%M") + ), + controller, + parts: &ctx.parts, + }; + + // TODO: if UTF-8 decoding fails, link ?action=raw&rev= + if let Some(old_blob_id) = old_blob_id { + page.body.push_str(&diff( + from_utf8(ctx.repo.find_blob(old_blob_id)?.content())?, + from_utf8(ctx.repo.find_blob(blob_id)?.content())?, + )) } else { - Err(Error::NotFound("commit not found".into())) + page.body.push_str(&diff( + "", + from_utf8(&ctx.repo.find_blob(blob_id)?.content())?, + )); } + Ok(page.into()) } fn raw_blob<C: Controller>( |