From 5fcba2926c2c8caee488200fdb2cb82fa9f7692e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 18 Oct 2020 13:33:11 +0530 Subject: [PATCH] Start wiring up real data Signed-off-by: Harsh Shandilya --- src/main.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5df6857..580cd12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,15 @@ use git2::Repository; +use serde::{Deserialize, Serialize}; use std::path::Path; use walkdir::WalkDir; +#[derive(Debug, Serialize, Deserialize)] +struct PersistableRepo { + pub(crate) path: String, + pub(crate) remote_url: String, + pub(crate) head: String, +} + fn main() -> anyhow::Result<()> { let dir = match std::env::args().nth(1) { Some(d) => d, @@ -10,7 +18,7 @@ fn main() -> anyhow::Result<()> { return Ok(()); } }; - let mut items: Vec = Vec::new(); + let mut repos: Vec = Vec::new(); for entry in WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) { if entry.file_type().is_dir() { let path = format!("{}/.git", entry.path().display()); @@ -21,14 +29,19 @@ fn main() -> anyhow::Result<()> { continue; } - items.push(format!( - "{} = {}", - entry.path().to_string_lossy().to_string(), - repo.head()?.name().unwrap_or("None") - )); + let head = repo.head()?; + if let Some(head) = head.name() { + repos.push(PersistableRepo { + // Ideally we wanna do this, but it moves `dir`. + // path: entry.path().to_string_lossy().strip_prefix(dir).unwrap().to_string(), + path: entry.path().to_string_lossy().to_string(), + remote_url: repo.remotes()?.get(0).unwrap_or("None").to_string(), + head: head.to_string(), + }); + }; } }; } - println!("{:#x?}", items); + println!("{:#x?}", repos); Ok(()) }