~aw/patches

mygit: configuration v1 APPLIED

Johann Galle
Updated some things regarding configuration:
* add default values for everything
* use names that gitweb uses (more comments in commit message)
* make file name for the export file configurable
  (previously always "git-daemon-export-ok")

Some of the defaults might be changed, e.g. gitweb by default
completely disables the export check and exports everything.
I don't know if that is a good precedent to follow.
Applied, thank you!

On Tue Mar 16, 2021 at 3:00 PM PDT, Johann Galle wrote:
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~aw/patches/patches/21229/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH mygit v1 1/3] use gitweb config names, add config for export file Export this patch

Johann Galle
From: Johann150 <johann@qwertqwefsday.eu>

As said on the mailing list earlier, I think it would be nice to be
more or less compatible with gitweb since others also orient themselves
on this. One point about this would be to use the same configuration
option names. Of course not all of them are good, e.g. projectroot
does not follow the naming convention, so we might want to change that.
Docs for gitweb config are at <https://git-scm.com/docs/gitweb.conf>.
---
 mygit.toml  |  7 ++++---
 src/main.rs | 10 ++++++----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/mygit.toml b/mygit.toml
index 63b2292..8b25b45 100644
--- a/mygit.toml
+++ b/mygit.toml
@@ -1,5 +1,6 @@
port = 8081
# Directory to store git repos
repo_directory = "repos"
# Directory to find git repos
projectroot = "repos"
emoji_favicon = "💻"
page_title = "My git repositories"
site_name = "My git repositories"
export_ok = "git-daemon-export-ok"
diff --git a/src/main.rs b/src/main.rs
index 342248f..a19fd07 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,8 +13,10 @@ use tide::Request;
#[derive(Deserialize, Debug)]
pub struct Config {
    port: u16,
    repo_directory: String,
    projectroot: String,
    emoji_favicon: String,
    site_name: String,
    export_ok: String,
}

const HELP: &str = "\
@@ -56,14 +58,14 @@ struct IndexTemplate {
}

async fn index(req: Request<()>) -> tide::Result {
    let repos = fs::read_dir(&CONFIG.repo_directory)
    let repos = fs::read_dir(&CONFIG.projectroot)
        .map(|entries| {
            entries
                .filter_map(|entry| Some(entry.ok()?.path()))
                .filter(|entry| {
                    // check for the export file
                    let mut path = entry.clone();
                    path.push("git-daemon-export-ok");
                    path.push(&CONFIG.export_ok);
                    path.exists()
                })
                .filter_map(|entry| Repository::open(entry).ok())
@@ -93,7 +95,7 @@ fn repo_from_request(repo_name: &str) -> Result<Repository> {
    let repo_name = percent_encoding::percent_decode_str(repo_name)
        .decode_utf8_lossy()
        .into_owned();
    let repo_path = Path::new(&CONFIG.repo_directory).join(repo_name);
    let repo_path = Path::new(&CONFIG.projectroot).join(repo_name);
    // TODO CLEAN PATH! VERY IMPORTANT! DONT FORGET!
    let r = Repository::open(repo_path)?;
    Ok(r)
-- 
2.20.1

[PATCH mygit v1 2/3] add defaults for configuration Export this patch

Johann Galle
From: Johann150 <johann@qwertqwefsday.eu>

Because there are defaults for everything, we can now also handle
an empty configuratino file without failing. A warning is emitted
if the configuration file does not exist.
---
 src/main.rs | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index a19fd07..cdc88ea 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,13 +12,38 @@ use tide::Request;

#[derive(Deserialize, Debug)]
pub struct Config {
    #[serde(default = "defaults::port")]
    port: u16,
    #[serde(default = "defaults::repo_directory")]
    projectroot: String,
    #[serde(default = "String::new")]
    emoji_favicon: String,
    #[serde(default = "defaults::site_name")]
    site_name: String,
    #[serde(default = "defaults::export_ok")]
    export_ok: String,
}

/// Defaults for the configuration options
// FIXME: simplify if https://github.com/serde-rs/serde/issues/368 is resolved
mod defaults {
    pub fn port() -> u16 {
        80
    }

    pub fn repo_directory() -> String {
        "repos".to_string()
    }

    pub fn site_name() -> String {
        "grifter".to_string()
    }

    pub fn export_ok() -> String {
        "git-daemon-export-ok".to_string()
    }
}

const HELP: &str = "\
mygit

@@ -40,8 +65,10 @@ fn args() -> Config {
        std::process::exit(0);
    }

    let toml_text =
        fs::read_to_string("mygit.toml").expect("expected configuration file mygit.toml");
    let toml_text = fs::read_to_string("mygit.toml").unwrap_or_else(|_| {
        tide::log::warn!("mygit.toml configuration file not found, using defaults");
        String::new()
    });
    match toml::from_str(&toml_text) {
        Ok(config) => config,
        Err(e) => {
-- 
2.20.1

[PATCH mygit v1 3/3] update Cargo.lock Export this patch

Johann Galle
From: Johann150 <johann@qwertqwefsday.eu>

---
 Cargo.lock | 253 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 235 insertions(+), 18 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 5b8f486..8fb88d3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -54,6 +54,15 @@ dependencies = [
 "opaque-debug",
]

[[package]]
name = "aho-corasick"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
dependencies = [
 "memchr",
]

[[package]]
name = "anyhow"
version = "1.0.38"
@@ -108,7 +117,7 @@ checksum = "2582b77e0f3c506ec4838a25fa8a5f97b9bed72bb6d3d272ea1c031d8bd373bc"
dependencies = [
 "askama_escape",
 "humansize",
 "nom",
 "nom 6.1.2",
 "num-traits",
 "percent-encoding",
 "proc-macro2",
@@ -438,6 +447,12 @@ dependencies = [
 "once_cell",
]

[[package]]
name = "bufstream"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8"

[[package]]
name = "bumpalo"
version = "3.6.1"
@@ -544,10 +559,26 @@ dependencies = [
 "percent-encoding",
 "rand 0.8.3",
 "sha2",
 "time 0.2.25",
 "time 0.2.26",
 "version_check",
]

[[package]]
name = "core-foundation"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62"
dependencies = [
 "core-foundation-sys",
 "libc",
]

[[package]]
name = "core-foundation-sys"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"

[[package]]
name = "cpuid-bool"
version = "0.1.2"
@@ -663,6 +694,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"

[[package]]
name = "email-parser"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd45adbcbe4247e0a92f13ae66d10b11a6fc05f6184a8f573755afab21f18799"

[[package]]
name = "event-listener"
version = "2.5.1"
@@ -700,6 +737,21 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"

[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
 "foreign-types-shared",
]

[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"

[[package]]
name = "form_urlencoded"
version = "1.0.1"
@@ -910,9 +962,9 @@ dependencies = [

[[package]]
name = "http-client"
version = "6.3.4"
version = "6.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98c12a6a451357392f3307325e9a15cbd27451abdaad96e74c30ea8786f615c4"
checksum = "5566ecc26bc6b04e773e680d66141fced78e091ad818e420d726c152b05a64ff"
dependencies = [
 "async-trait",
 "cfg-if 1.0.0",
@@ -966,6 +1018,31 @@ dependencies = [
 "unicode-normalization",
]

[[package]]
name = "imap"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c617c55def8c42129e0dd503f11d7ee39d73f5c7e01eff55768b3879ff1d107d"
dependencies = [
 "base64 0.13.0",
 "bufstream",
 "chrono",
 "imap-proto",
 "lazy_static",
 "native-tls",
 "nom 5.1.2",
 "regex",
]

[[package]]
name = "imap-proto"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16a6def1d5ac8975d70b3fd101d57953fe3278ef2ee5d7816cba54b1d1dfc22f"
dependencies = [
 "nom 5.1.2",
]

[[package]]
name = "indexmap"
version = "1.6.2"
@@ -1051,9 +1128,9 @@ dependencies = [

[[package]]
name = "libc"
version = "0.2.88"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a"
checksum = "538c092e5586f4cdd7dd8078c4a79220e3e168880218124dcbce860f0ea938c6"

[[package]]
name = "libgit2-sys"
@@ -1143,9 +1220,29 @@ version = "0.1.0"
dependencies = [
 "askama",
 "askama_tide",
 "email-parser",
 "imap",
 "tide",
]

[[package]]
name = "native-tls"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4"
dependencies = [
 "lazy_static",
 "libc",
 "log",
 "openssl",
 "openssl-probe",
 "openssl-sys",
 "schannel",
 "security-framework",
 "security-framework-sys",
 "tempfile",
]

[[package]]
name = "nb-connect"
version = "1.0.3"
@@ -1156,6 +1253,17 @@ dependencies = [
 "socket2",
]

[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
 "lexical-core",
 "memchr",
 "version_check",
]

[[package]]
name = "nom"
version = "6.1.2"
@@ -1232,6 +1340,39 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"

[[package]]
name = "openssl"
version = "0.10.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577"
dependencies = [
 "bitflags",
 "cfg-if 1.0.0",
 "foreign-types",
 "libc",
 "once_cell",
 "openssl-sys",
]

[[package]]
name = "openssl-probe"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"

[[package]]
name = "openssl-sys"
version = "0.9.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f"
dependencies = [
 "autocfg",
 "cc",
 "libc",
 "pkg-config",
 "vcpkg",
]

[[package]]
name = "parking"
version = "2.0.0"
@@ -1467,11 +1608,40 @@ dependencies = [
 "rand_core 0.6.2",
]

[[package]]
name = "redox_syscall"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9"
dependencies = [
 "bitflags",
]

[[package]]
name = "regex"
version = "1.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
dependencies = [
 "aho-corasick",
 "memchr",
 "regex-syntax",
]

[[package]]
name = "regex-syntax"
version = "0.6.22"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"

[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
 "winapi",
]

[[package]]
name = "route-recognizer"
@@ -1509,6 +1679,39 @@ dependencies = [
 "winapi-util",
]

[[package]]
name = "schannel"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
dependencies = [
 "lazy_static",
 "winapi",
]

[[package]]
name = "security-framework"
version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d"
dependencies = [
 "bitflags",
 "core-foundation",
 "core-foundation-sys",
 "libc",
 "security-framework-sys",
]

[[package]]
name = "security-framework-sys"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d"
dependencies = [
 "core-foundation-sys",
 "libc",
]

[[package]]
name = "semver"
version = "0.9.0"
@@ -1600,9 +1803,9 @@ dependencies = [

[[package]]
name = "signal-hook"
version = "0.3.6"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7f3f92a1da3d6b1d32245d0cbcbbab0cfc45996d8df619c42bccfa6d2bbb5f"
checksum = "6aa894ef3fade0ee7243422f4fbbd6c2b48e6de767e621d37ef65f2310f53cea"
dependencies = [
 "libc",
 "signal-hook-registry",
@@ -1727,9 +1930,9 @@ checksum = "45f6ee7c7b87caf59549e9fe45d6a69c75c8019e79e212a835c5da0e92f0ba08"

[[package]]
name = "syn"
version = "1.0.63"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd9bc7ccc2688b3344c2f48b9b546648b25ce0b20fc717ee7fa7981a8ca9717"
checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f"
dependencies = [
 "proc-macro2",
 "quote",
@@ -1761,6 +1964,20 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"

[[package]]
name = "tempfile"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
dependencies = [
 "cfg-if 1.0.0",
 "libc",
 "rand 0.8.3",
 "redox_syscall",
 "remove_dir_all",
 "winapi",
]

[[package]]
name = "thiserror"
version = "1.0.24"
@@ -1817,9 +2034,9 @@ dependencies = [

[[package]]
name = "time"
version = "0.2.25"
version = "0.2.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1195b046942c221454c2539395f85413b33383a067449d78aab2b7b052a142f7"
checksum = "08a8cbfbf47955132d0202d1662f49b2423ae35862aee471f3ba4b133358f372"
dependencies = [
 "const_fn",
 "libc",
@@ -1879,9 +2096,9 @@ dependencies = [

[[package]]
name = "typenum"
version = "1.12.0"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"

[[package]]
name = "unicase"
@@ -1969,9 +2186,9 @@ checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d"

[[package]]
name = "version_check"
version = "0.9.2"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"

[[package]]
name = "waker-fn"
-- 
2.20.1
Applied, thank you!

On Tue Mar 16, 2021 at 3:00 PM PDT, Johann Galle wrote: