From 050d8afdf91939d8d282d5ee42681a39c3f15460 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 22 Apr 2020 01:08:08 -0500 Subject: [PATCH] restructure --- Cargo.lock | 45 ++++++++-------- Cargo.toml | 33 +----------- async-git/src/plumbing/mod.rs | 2 + async-git/src/plumbing/object.rs | 5 +- async-git/src/plumbing/ref.rs | 16 ++++++ async-git/src/plumbing/repo.rs | 51 ++++++++++++++----- async-git/src/porcelain/show.rs | 12 ++++- async-git/src/util.rs | 13 ++++- fedhub/Cargo.toml | 29 +++++++++++ build.rs => fedhub/build.rs | 0 {src => fedhub/src}/config.rs | 0 {src => fedhub/src}/gitutil.rs | 0 {src => fedhub/src}/lib.rs | 0 {src => fedhub/src}/main.rs | 0 {static => fedhub/static}/main.css | 0 {templates => fedhub/templates}/index.html | 0 {templates => fedhub/templates}/layout.html | 0 .../templates}/repo_blob.html | 0 .../templates}/repo_index.html | 0 .../templates}/repo_tree.html | 0 20 files changed, 133 insertions(+), 73 deletions(-) create mode 100644 async-git/src/plumbing/ref.rs create mode 100644 fedhub/Cargo.toml rename build.rs => fedhub/build.rs (100%) rename {src => fedhub/src}/config.rs (100%) rename {src => fedhub/src}/gitutil.rs (100%) rename {src => fedhub/src}/lib.rs (100%) rename {src => fedhub/src}/main.rs (100%) rename {static => fedhub/static}/main.css (100%) rename {templates => fedhub/templates}/index.html (100%) rename {templates => fedhub/templates}/layout.html (100%) rename {templates => fedhub/templates}/repo_blob.html (100%) rename {templates => fedhub/templates}/repo_index.html (100%) rename {templates => fedhub/templates}/repo_tree.html (100%) diff --git a/Cargo.lock b/Cargo.lock index 94eee97..e6507e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,9 +17,9 @@ checksum = "d9a60d744a80c30fcb657dfe2c1b22bcb3e814c1a1e3674f32bf5820b570fbff" [[package]] name = "arc-swap" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663a8e9a99154b5fb793032533f6328da35e23aac63d5c152279aa8ba356825" +checksum = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62" [[package]] name = "arrayvec" @@ -390,9 +390,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.13.0" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7da16ceafe24cedd9ba02c4463a2b506b6493baf4317c79c5acb553134a3c15" +checksum = "2cfb93ca10f2934069c3aaafb753fbe0663f08ee009a01b6d62e062391447b15" dependencies = [ "bitflags", "libc", @@ -461,9 +461,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.8" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" +checksum = "8a0d737e0f947a1864e93d33fdef4af8445a00d1ed8dc0c8ddb73139ea6abf15" dependencies = [ "libc", ] @@ -613,15 +613,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" +checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" [[package]] name = "libgit2-sys" -version = "0.12.0+0.99.0" +version = "0.12.3+1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05dff41ac39e7b653f5f1550886cf00ba52f8e7f57210b633cdeedb3de5b236c" +checksum = "7637dc15e7f05a16011723e0448655081fc01a374bcd368e2c9b9c7f5c5ab3ea" dependencies = [ "cc", "libc", @@ -807,9 +807,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ "hermit-abi", "libc", @@ -856,9 +856,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e136c1904604defe99ce5fd71a28d473fa60a12255d511aa78a9ddf11237aeb" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" dependencies = [ "cfg-if", "cloudabi", @@ -1168,9 +1168,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.48" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25" +checksum = "da07b57ee2623368351e9a0488bb0b261322a15a6e0ae53e243cbdc0f4208da9" dependencies = [ "itoa", "ryu", @@ -1213,9 +1213,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" +checksum = "05720e22615919e4734f6a99ceae50d00226c3c5aca406e102ebc33298214e0a" [[package]] name = "socket2" @@ -1336,12 +1336,11 @@ dependencies = [ [[package]] name = "time" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "redox_syscall", "winapi 0.3.8", ] @@ -1600,9 +1599,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi 0.3.8", ] diff --git a/Cargo.toml b/Cargo.toml index 8c1ea74..6fd6a75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,37 +1,8 @@ -[package] -name = "fedhub" -version = "0.1.0" -authors = ["Michael Zhang "] -edition = "2018" -license = "MIT/Apache-2.0" - [workspace] members = [ "async-git", "async-zlib", + "fedhub", "fedhub-shell", "fedhub-hooks", -] - -[dependencies] -anyhow = { version = "1.0.28", default-features = false, features = ["std"] } -async-git = { path = "async-git" } -comrak = { version = "0.7.0", default-features = false } -futures = { version = "0.3.4", default-features = false } -git2 = { version = "0.13.0", default-features = false } -hyper = { version = "0.13.5", default-features = false, features = ["runtime"] } -lazy_static = { version = "1.4.0", default-features = false } -packer = { version = "0.5.3", default-features = false } -parking_lot = { version = "0.10.2", default-features = false } -redis = { version = "0.15.1", default-features = false } -serde = { version = "1.0.105", default-features = false } -serde_derive = { version = "1.0.105", default-features = false } -serde_json = { version = "1.0.48", default-features = false } -structopt = { version = "0.3.13", default-features = false } -tera = { version = "1.2.0", default-features = false } -tokio = { version = "0.2.18", default-features = false, features = ["full"] } -toml = { version = "0.5.6", default-features = false } -walkdir = { version = "2.3.1", default-features = false } - -[build-dependencies] -rsass = "0.13.0" +] \ No newline at end of file diff --git a/async-git/src/plumbing/mod.rs b/async-git/src/plumbing/mod.rs index 2bfb3e8..ad93f4d 100644 --- a/async-git/src/plumbing/mod.rs +++ b/async-git/src/plumbing/mod.rs @@ -1,9 +1,11 @@ mod commit; mod hash_object; mod object; +mod r#ref; mod repo; pub use self::commit::Commit; pub use self::hash_object::hash_object; pub use self::object::{Object, Oid}; +pub use self::r#ref::Ref; pub use self::repo::Repository; diff --git a/async-git/src/plumbing/object.rs b/async-git/src/plumbing/object.rs index d2906b4..247fc5a 100644 --- a/async-git/src/plumbing/object.rs +++ b/async-git/src/plumbing/object.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; -use std::pin::Pin; + use std::str::FromStr; -use std::task::{Context, Poll}; use anyhow::Error; use async_zlib::ZlibDecoder; @@ -9,7 +8,7 @@ use tokio::{fs::File, io::AsyncReadExt}; use typenum::U19; use crate::plumbing::Commit; -use crate::util::{self, ZlibIO}; +use crate::util::{self}; pub struct Object { repo_path: PathBuf, diff --git a/async-git/src/plumbing/ref.rs b/async-git/src/plumbing/ref.rs new file mode 100644 index 0000000..b038749 --- /dev/null +++ b/async-git/src/plumbing/ref.rs @@ -0,0 +1,16 @@ +use anyhow::Result; + +use crate::plumbing::Oid; + +pub struct Ref { + target: Option, +} + +impl Ref { + pub fn parse(string: impl AsRef) -> Result { + let string = string.as_ref(); + if string.starts_with("ref") { + + } + } +} diff --git a/async-git/src/plumbing/repo.rs b/async-git/src/plumbing/repo.rs index 7d0b79d..9605a8e 100644 --- a/async-git/src/plumbing/repo.rs +++ b/async-git/src/plumbing/repo.rs @@ -1,22 +1,47 @@ -use std::path::Path; use std::env; +use std::path::PathBuf; use anyhow::Result; -pub struct Repository {} +use crate::plumbing::Ref; +use crate::util; + +pub struct Repository { + path: PathBuf, +} impl Repository { - pub async fn open(path: impl AsRef) {} -} + pub async fn open(path: PathBuf) -> Result { + if !Repository::is_repo(path.clone()).await? { + bail!("not a repository"); + } -pub async fn is_repo(path: impl AsRef) -> Result { - Ok(false) -} - -/// Find the closest repository that the current repository belongs to. -pub async fn find() -> Result> { - let mut cwd = env::current_dir()?; - loop { + Ok(Repository { path }) + } + + pub async fn head(self) -> Result { + let head_path = self.path.join("HEAD"); + let head_ref = util::file_to_string(head_path).await?.trim(); + Ok(Ref::parse(head_ref)?) + } + + pub async fn is_repo(path: PathBuf) -> Result { + unimplemented!() + } + + /// Find the closest repository that the current repository belongs to. + pub async fn find() -> Result> { + let mut cwd = env::current_dir()?; + + loop { + if Repository::is_repo(cwd.clone()).await? { + return Ok(Some(cwd)); + } + + cwd = match cwd.parent() { + Some(parent) => parent.to_path_buf(), + None => return Ok(None), + }; + } } - Ok(None) } diff --git a/async-git/src/porcelain/show.rs b/async-git/src/porcelain/show.rs index 3396f0e..3803665 100644 --- a/async-git/src/porcelain/show.rs +++ b/async-git/src/porcelain/show.rs @@ -1,4 +1,6 @@ -use crate::plumbing::Oid; +use anyhow::Result; + +use crate::plumbing::{Oid, Repository}; #[derive(Debug, StructOpt)] pub struct ShowOptions { @@ -6,8 +8,14 @@ pub struct ShowOptions { objects: Vec, } -pub async fn show_cmd(options: ShowOptions) { +pub async fn show_cmd(options: ShowOptions) -> Result<()> { let mut objects = options.objects; + let repo = match Repository::find().await? { + Some(path) => Repository::open(path), + None => bail!("not in a repository lmao"), + }; for id in objects {} + + Ok(()) } diff --git a/async-git/src/util.rs b/async-git/src/util.rs index 2455c80..bd25538 100644 --- a/async-git/src/util.rs +++ b/async-git/src/util.rs @@ -1,8 +1,12 @@ use std::io; use std::path::Path; +use std::path::PathBuf; use async_zlib::{ZlibDecoder, ZlibEncoder}; -use tokio::{fs::File, io::AsyncWriteExt}; +use tokio::{ + fs::File, + io::{AsyncReadExt, AsyncWriteExt}, +}; use typenum::Unsigned; /// Marker trait to ensure compression/decompression is already happening transparently. @@ -37,3 +41,10 @@ pub async fn init_file(path: impl AsRef, contents: impl AsRef) -> Res file.write_all(contents.as_ref().as_bytes()).await?; Ok(()) } + +pub async fn file_to_string(path: PathBuf) -> Result { + let mut file = File::open(path).await?; + let mut contents = String::new(); + file.read_to_string(&mut contents).await?; + Ok(contents) +} diff --git a/fedhub/Cargo.toml b/fedhub/Cargo.toml new file mode 100644 index 0000000..84385f3 --- /dev/null +++ b/fedhub/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "fedhub" +version = "0.1.0" +authors = ["Michael Zhang "] +edition = "2018" +license = "MIT/Apache-2.0" + +[dependencies] +anyhow = { version = "1.0.28", default-features = false, features = ["std"] } +async-git = { path = "../async-git" } +comrak = { version = "0.7.0", default-features = false } +futures = { version = "0.3.4", default-features = false } +git2 = { version = "0.13.0", default-features = false } +hyper = { version = "0.13.5", default-features = false, features = ["runtime"] } +lazy_static = { version = "1.4.0", default-features = false } +packer = { version = "0.5.3", default-features = false } +parking_lot = { version = "0.10.2", default-features = false } +redis = { version = "0.15.1", default-features = false } +serde = { version = "1.0.105", default-features = false } +serde_derive = { version = "1.0.105", default-features = false } +serde_json = { version = "1.0.48", default-features = false } +structopt = { version = "0.3.13", default-features = false } +tera = { version = "1.2.0", default-features = false } +tokio = { version = "0.2.18", default-features = false, features = ["full"] } +toml = { version = "0.5.6", default-features = false } +walkdir = { version = "2.3.1", default-features = false } + +[build-dependencies] +rsass = "0.13.0" diff --git a/build.rs b/fedhub/build.rs similarity index 100% rename from build.rs rename to fedhub/build.rs diff --git a/src/config.rs b/fedhub/src/config.rs similarity index 100% rename from src/config.rs rename to fedhub/src/config.rs diff --git a/src/gitutil.rs b/fedhub/src/gitutil.rs similarity index 100% rename from src/gitutil.rs rename to fedhub/src/gitutil.rs diff --git a/src/lib.rs b/fedhub/src/lib.rs similarity index 100% rename from src/lib.rs rename to fedhub/src/lib.rs diff --git a/src/main.rs b/fedhub/src/main.rs similarity index 100% rename from src/main.rs rename to fedhub/src/main.rs diff --git a/static/main.css b/fedhub/static/main.css similarity index 100% rename from static/main.css rename to fedhub/static/main.css diff --git a/templates/index.html b/fedhub/templates/index.html similarity index 100% rename from templates/index.html rename to fedhub/templates/index.html diff --git a/templates/layout.html b/fedhub/templates/layout.html similarity index 100% rename from templates/layout.html rename to fedhub/templates/layout.html diff --git a/templates/repo_blob.html b/fedhub/templates/repo_blob.html similarity index 100% rename from templates/repo_blob.html rename to fedhub/templates/repo_blob.html diff --git a/templates/repo_index.html b/fedhub/templates/repo_index.html similarity index 100% rename from templates/repo_index.html rename to fedhub/templates/repo_index.html diff --git a/templates/repo_tree.html b/fedhub/templates/repo_tree.html similarity index 100% rename from templates/repo_tree.html rename to fedhub/templates/repo_tree.html