~aw/patches

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH mygit 1/2] simplify code

Johann Galle
Details
Message ID
<20210317214420.11511-1-johann@qwertqwefsday.eu>
DKIM signature
pass
Download raw message
Patch: +2 -2
From: Johann150 <johann@qwertqwefsday.eu>

unnecessary to specify the name twice if it is identical to the field name
---
 src/main.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 5f2c741..754a0c6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -225,7 +225,7 @@ async fn repo_log(req: Request<()>) -> tide::Result {
    let tmpl = RepoLogTemplate {
        repo: &repo,
        commits,
        branch: branch,
        branch,
    };
    Ok(tmpl.into())
}
@@ -289,7 +289,7 @@ async fn repo_tree(req: Request<()>) -> tide::Result {
    let tmpl = RepoTreeTemplate {
        repo: &repo,
        tree,
        spec: spec,
        spec,
    };
    Ok(tmpl.into())
}
-- 
2.20.1

[PATCH mygit 2/2] handle repos without readme

Johann Galle
Details
Message ID
<20210317214420.11511-2-johann@qwertqwefsday.eu>
In-Reply-To
<20210317214420.11511-1-johann@qwertqwefsday.eu> (view parent)
DKIM signature
pass
Download raw message
Patch: +45 -38
From: Johann150 <johann@qwertqwefsday.eu>

---
 src/main.rs         | 77 +++++++++++++++++++++++----------------------
 templates/repo.html |  6 +++-
 2 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 754a0c6..f11d684 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -143,44 +143,47 @@ async fn repo_home(req: Request<()>) -> tide::Result {
        return Ok(RepoEmptyTemplate { repo }.into());
    }

    let readme_text = {
        let mut format = ReadmeFormat::Plaintext;
        let readme = repo
            .revparse_single("HEAD:README")
            .or_else(|_| repo.revparse_single("HEAD:README.txt"))
            .or_else(|_| {
                format = ReadmeFormat::Markdown;
                repo.revparse_single("HEAD:README.md")
            })
            .or_else(|_| repo.revparse_single("HEAD:README.mdown"))
            .or_else(|_| repo.revparse_single("HEAD:README.markdown"))
            .or_else(|_| {
                format = ReadmeFormat::Html;
                repo.revparse_single("HEAD:README.html")
            })
            .or_else(|_| repo.revparse_single("HEAD:README.htm"))?;
        let readme_text = str::from_utf8(readme.as_blob().unwrap().content())?;

        // render the file contents to HTML
        match format {
            // render plaintext as preformatted text
            ReadmeFormat::Plaintext => {
                let mut output = "<pre>".to_string();
                escape_html(&mut output, readme_text)?;
                output.push_str("</pre>");
                output
            }
            // already is HTML
            ReadmeFormat::Html => readme_text.to_string(),
            // render Markdown to HTML
            ReadmeFormat::Markdown => {
                let mut output = String::new();
                let parser = Parser::new_ext(readme_text, Options::empty());
                push_html(&mut output, parser);
                output
    let mut format = ReadmeFormat::Plaintext;
    let readme_text = repo
        .revparse_single("HEAD:README")
        .or_else(|_| repo.revparse_single("HEAD:README.txt"))
        .or_else(|_| {
            format = ReadmeFormat::Markdown;
            repo.revparse_single("HEAD:README.md")
        })
        .or_else(|_| repo.revparse_single("HEAD:README.mdown"))
        .or_else(|_| repo.revparse_single("HEAD:README.markdown"))
        .or_else(|_| {
            format = ReadmeFormat::Html;
            repo.revparse_single("HEAD:README.html")
        })
        .or_else(|_| repo.revparse_single("HEAD:README.htm"))
        .ok()
        .and_then(|readme| readme.into_blob().ok())
        .map(|blob| {
            let text = str::from_utf8(blob.content()).unwrap_or_default();

            // render the file contents to HTML
            match format {
                // render plaintext as preformatted text
                ReadmeFormat::Plaintext => {
                    let mut output = "<pre>".to_string();
                    escape_html(&mut output, text).unwrap();
                    output.push_str("</pre>");
                    output
                }
                // already is HTML
                ReadmeFormat::Html => text.to_string(),
                // render Markdown to HTML
                ReadmeFormat::Markdown => {
                    let mut output = String::new();
                    let parser = Parser::new_ext(text, Options::empty());
                    push_html(&mut output, parser);
                    output
                }
            }
        }
    };
        })
        .unwrap_or_default();

    Ok(RepoHomeTemplate { repo, readme_text }.into())
}
diff --git a/templates/repo.html b/templates/repo.html
index e2fcd0e..5598325 100644
--- a/templates/repo.html
+++ b/templates/repo.html
@@ -2,5 +2,9 @@

{% block content %}
  {% include "repo-navbar.html" %}
  {{ readme_text|safe }}
  {% if !readme_text.is_empty() -%}
    {{ readme_text|safe }}
  {% else -%}
    <em>(no README)</em>
  {%- endif %}
{% endblock %}
-- 
2.20.1

Re: [PATCH mygit 2/2] handle repos without readme

Details
Message ID
<CA01F67XP8O2.1ANJSDV1CZMTU@debian-alex>
In-Reply-To
<20210317214420.11511-2-johann@qwertqwefsday.eu> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
Applied, thank you! We're making some good progress -- I might be able
to dedicate a full day this weekend to getting an Alpha working

On Wed Mar 17, 2021 at 2:44 PM PDT, Johann Galle wrote:
> From: Johann150 <johann@qwertqwefsday.eu>
>
> ---
> src/main.rs | 77 +++++++++++++++++++++++----------------------
> templates/repo.html | 6 +++-
> 2 files changed, 45 insertions(+), 38 deletions(-)
>
> diff --git a/src/main.rs b/src/main.rs
> index 754a0c6..f11d684 100644
> --- a/src/main.rs
> +++ b/src/main.rs
> @@ -143,44 +143,47 @@ async fn repo_home(req: Request<()>) ->
> tide::Result {
> return Ok(RepoEmptyTemplate { repo }.into());
> }
>  
> - let readme_text = {
> - let mut format = ReadmeFormat::Plaintext;
> - let readme = repo
> - .revparse_single("HEAD:README")
> - .or_else(|_| repo.revparse_single("HEAD:README.txt"))
> - .or_else(|_| {
> - format = ReadmeFormat::Markdown;
> - repo.revparse_single("HEAD:README.md")
> - })
> - .or_else(|_| repo.revparse_single("HEAD:README.mdown"))
> - .or_else(|_| repo.revparse_single("HEAD:README.markdown"))
> - .or_else(|_| {
> - format = ReadmeFormat::Html;
> - repo.revparse_single("HEAD:README.html")
> - })
> - .or_else(|_| repo.revparse_single("HEAD:README.htm"))?;
> - let readme_text =
> str::from_utf8(readme.as_blob().unwrap().content())?;
> -
> - // render the file contents to HTML
> - match format {
> - // render plaintext as preformatted text
> - ReadmeFormat::Plaintext => {
> - let mut output = "<pre>".to_string();
> - escape_html(&mut output, readme_text)?;
> - output.push_str("</pre>");
> - output
> - }
> - // already is HTML
> - ReadmeFormat::Html => readme_text.to_string(),
> - // render Markdown to HTML
> - ReadmeFormat::Markdown => {
> - let mut output = String::new();
> - let parser = Parser::new_ext(readme_text, Options::empty());
> - push_html(&mut output, parser);
> - output
> + let mut format = ReadmeFormat::Plaintext;
> + let readme_text = repo
> + .revparse_single("HEAD:README")
> + .or_else(|_| repo.revparse_single("HEAD:README.txt"))
> + .or_else(|_| {
> + format = ReadmeFormat::Markdown;
> + repo.revparse_single("HEAD:README.md")
> + })
> + .or_else(|_| repo.revparse_single("HEAD:README.mdown"))
> + .or_else(|_| repo.revparse_single("HEAD:README.markdown"))
> + .or_else(|_| {
> + format = ReadmeFormat::Html;
> + repo.revparse_single("HEAD:README.html")
> + })
> + .or_else(|_| repo.revparse_single("HEAD:README.htm"))
> + .ok()
> + .and_then(|readme| readme.into_blob().ok())
> + .map(|blob| {
> + let text = str::from_utf8(blob.content()).unwrap_or_default();
> +
> + // render the file contents to HTML
> + match format {
> + // render plaintext as preformatted text
> + ReadmeFormat::Plaintext => {
> + let mut output = "<pre>".to_string();
> + escape_html(&mut output, text).unwrap();
> + output.push_str("</pre>");
> + output
> + }
> + // already is HTML
> + ReadmeFormat::Html => text.to_string(),
> + // render Markdown to HTML
> + ReadmeFormat::Markdown => {
> + let mut output = String::new();
> + let parser = Parser::new_ext(text, Options::empty());
> + push_html(&mut output, parser);
> + output
> + }
> }
> - }
> - };
> + })
> + .unwrap_or_default();
>  
> Ok(RepoHomeTemplate { repo, readme_text }.into())
> }
> diff --git a/templates/repo.html b/templates/repo.html
> index e2fcd0e..5598325 100644
> --- a/templates/repo.html
> +++ b/templates/repo.html
> @@ -2,5 +2,9 @@
>  
> {% block content %}
> {% include "repo-navbar.html" %}
> - {{ readme_text|safe }}
> + {% if !readme_text.is_empty() -%}
> + {{ readme_text|safe }}
> + {% else -%}
> + <em>(no README)</em>
> + {%- endif %}
> {% endblock %}
> --
> 2.20.1
Reply to thread Export thread (mbox)