~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
3

[PATCH mygit 1/4] check for export file in correct directory

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

The export directory should not be in the workdir for non-bare repos,
instead always check the git directory, i.e. the repo for bare repos or
the .git directory for non-bare repos.
---
 src/main.rs | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index fe97363..21b620d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -106,13 +106,12 @@ async fn index(_req: Request<()>) -> tide::Result {
        .map(|entries| {
            entries
                .filter_map(|entry| Some(entry.ok()?.path()))
                .filter(|entry| {
                    // check for the export file
                    let mut path = entry.clone();
                    path.push(&CONFIG.export_ok);
                    path.exists()
                })
                .filter_map(|entry| Repository::open(entry).ok())
                .filter(|repo| {
                    // check for the export file in the git directory
                    // (the .git subfolder for non-bare repos)
                    repo.path().join(&CONFIG.export_ok).exists()
                })
                .collect::<Vec<_>>()
        })
        .map_err(|e| tide::log::warn!("can not read repositories: {}", e))
-- 
2.20.1

[PATCH mygit 2/4] remove empty repo template

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

now that we can handle repos without readme correctly, this is no longer necessary
---
 src/main.rs               | 10 ----------
 templates/repo-empty.html |  6 ------
 2 files changed, 16 deletions(-)
 delete mode 100644 templates/repo-empty.html

diff --git a/src/main.rs b/src/main.rs
index 21b620d..167ba95 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -128,12 +128,6 @@ struct RepoHomeTemplate {
    readme_text: String,
}

#[derive(Template)]
#[template(path = "repo-empty.html")]
struct RepoEmptyTemplate {
    repo: Repository,
}

fn repo_from_request(repo_name: &str) -> Result<Repository> {
    let repo_name = percent_encoding::percent_decode_str(repo_name)
        .decode_utf8_lossy()
@@ -154,10 +148,6 @@ async fn repo_home(req: Request<()>) -> tide::Result {
    }

    let repo = repo_from_request(&req.param("repo_name")?)?;
    if repo.is_empty().unwrap() {
        // we would not be able to find HEAD
        return Ok(RepoEmptyTemplate { repo }.into());
    }

    let mut format = ReadmeFormat::Plaintext;
    let readme_text = repo
diff --git a/templates/repo-empty.html b/templates/repo-empty.html
deleted file mode 100644
index 70760c3..0000000
--- a/templates/repo-empty.html
@@ -1,6 +0,0 @@
{% extends "base.html" %}

{% block content %}
  {% include "repo-navbar.html" %}
  <em>(This repository is empty.)</em>
{% endblock %}
-- 
2.20.1

[PATCH mygit 3/4] use actual repository description

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

---
 src/main.rs                | 10 ++++++++++
 templates/index.html       |  2 +-
 templates/repo-navbar.html |  2 +-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 167ba95..6d40372 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -449,6 +449,16 @@ mod filters {
            .to_str()
            .ok_or(askama::Error::Fmt(std::fmt::Error))
    }

    pub fn description(repo: &Repository) -> askama::Result<String> {
        Ok(fs::read_to_string(repo.path().join("description"))
            .unwrap_or_default()
            // only use first line
            .lines()
            .next()
            .unwrap_or_default()
            .to_string())
    }
}

#[async_std::main]
diff --git a/templates/index.html b/templates/index.html
index c27ce87..8027812 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -7,7 +7,7 @@
  {% for repo in repos %}
  <tr>
    <td class="repo-link"><a href="{{repo|repo_name|urlencode_strict}}">{{repo|repo_name}}</a></td>
    <td class="repo-description">a cool repository</td>
    <td class="repo-description">{{repo|description}}</td>
    <td class="repo-last-updated">updated 2021-02-01</td>
  </tr>
  {% endfor %}
diff --git a/templates/repo-navbar.html b/templates/repo-navbar.html
index e902449..ddc875a 100644
--- a/templates/repo-navbar.html
+++ b/templates/repo-navbar.html
@@ -1,5 +1,5 @@
<h1><a href="/">index</a>/{{repo|repo_name}}</h1>
<div>My cool repo</div>
<div>{{repo|description}}</div>
<div class="clone-url">git clone git.alexwennerberg.com/repo </div>
<div class="navbar"><a href="/{{repo|repo_name|urlencode_strict}}">README</a> |  <a href="/{{repo|repo_name|urlencode_strict}}/tree">tree</a> |  <a href="/{{repo|repo_name|urlencode_strict}}/log">log</a> |  <a href="/{{repo|repo_name|urlencode_strict}}/refs">refs</a></div>
<hr class='thin'>
-- 
2.20.1

[PATCH mygit 4/4] parameterize title and clone url

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

---
 mygit.toml                 | 3 +++
 src/main.rs                | 2 ++
 templates/base.html        | 2 +-
 templates/repo-navbar.html | 2 +-
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/mygit.toml b/mygit.toml
index 8b25b45..de7cce9 100644
--- a/mygit.toml
+++ b/mygit.toml
@@ -3,4 +3,7 @@ port = 8081
projectroot = "repos"
emoji_favicon = "💻"
site_name = "My git repositories"
# file to check for in the .git directory to decide wether to publicly show a repo
export_ok = "git-daemon-export-ok"
# base directory to clone repositories from
clone_base = "https://git.alexwennerberg.com"
diff --git a/src/main.rs b/src/main.rs
index 6d40372..317f00b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,6 +25,8 @@ pub struct Config {
    site_name: String,
    #[serde(default = "defaults::export_ok")]
    export_ok: String,
    #[serde(default = "String::new")]
    clone_base: String,
}

/// Defaults for the configuration options
diff --git a/templates/base.html b/templates/base.html
index 151515e..637a281 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -6,7 +6,7 @@
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=0" />
    <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>{{crate::CONFIG.emoji_favicon}}</text></svg>">
    <meta name="description" content="My self-hosted git repositories">
    <title>{% block title %}My Site{% endblock %}</title>
    <title>{{crate::CONFIG.site_name}}</title>
    {% block head %}{% endblock %}
  </head>
  <body>
diff --git a/templates/repo-navbar.html b/templates/repo-navbar.html
index ddc875a..628dcad 100644
--- a/templates/repo-navbar.html
+++ b/templates/repo-navbar.html
@@ -1,5 +1,5 @@
<h1><a href="/">index</a>/{{repo|repo_name}}</h1>
<div>{{repo|description}}</div>
<div class="clone-url">git clone git.alexwennerberg.com/repo </div>
<div class="clone-url">git clone {{crate::CONFIG.clone_base}}/{{repo|repo_name}} </div>
<div class="navbar"><a href="/{{repo|repo_name|urlencode_strict}}">README</a> |  <a href="/{{repo|repo_name|urlencode_strict}}/tree">tree</a> |  <a href="/{{repo|repo_name|urlencode_strict}}/log">log</a> |  <a href="/{{repo|repo_name|urlencode_strict}}/refs">refs</a></div>
<hr class='thin'>
-- 
2.20.1
Reply to thread Export thread (mbox)