mirror of
https://github.com/msfjarvis/gitice
synced 2025-08-14 17:37:01 +05:30
Create lockfile from scanned repos
A hashmap was used instead of nested structs because I realized that this would still run into the problem of duplicate keys. Ergo, use a HashMap with the key set to a unique path Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
parent
05818aa251
commit
ed35930562
1 changed files with 16 additions and 10 deletions
26
src/main.rs
26
src/main.rs
|
@ -1,6 +1,6 @@
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::Path;
|
use std::{collections::HashMap, fs, path::Path};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
@ -18,11 +18,13 @@ fn main() -> anyhow::Result<()> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut repos: Vec<PersistableRepo> = Vec::new();
|
|
||||||
|
let mut repos: HashMap<String, PersistableRepo> = HashMap::new();
|
||||||
for entry in WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) {
|
for entry in WalkDir::new(dir).into_iter().filter_map(|e| e.ok()) {
|
||||||
if entry.file_type().is_dir() {
|
if entry.file_type().is_dir() {
|
||||||
let path = format!("{}/.git", entry.path().display());
|
let path = format!("{}/.git", entry.path().display());
|
||||||
let git_dir = Path::new(&path);
|
let git_dir = Path::new(&path);
|
||||||
|
|
||||||
if git_dir.exists() {
|
if git_dir.exists() {
|
||||||
let repo = Repository::open(git_dir)?;
|
let repo = Repository::open(git_dir)?;
|
||||||
if repo.is_empty()? {
|
if repo.is_empty()? {
|
||||||
|
@ -41,19 +43,23 @@ fn main() -> anyhow::Result<()> {
|
||||||
.split('/')
|
.split('/')
|
||||||
.collect::<Vec<&str>>()[2],
|
.collect::<Vec<&str>>()[2],
|
||||||
) {
|
) {
|
||||||
repos.push(PersistableRepo {
|
let path = entry.path().to_string_lossy().to_string();
|
||||||
// Ideally we wanna do this, but it moves `dir`.
|
repos.insert(
|
||||||
// path: entry.path().to_string_lossy().strip_prefix(dir).unwrap().to_string(),
|
path.clone(),
|
||||||
path: entry.path().to_string_lossy().to_string(),
|
PersistableRepo {
|
||||||
remote_url: remote.url().unwrap_or("None").to_owned(),
|
// Ideally we wanna do this, but it moves `dir`.
|
||||||
head: head.to_owned(),
|
// path: entry.path().to_string_lossy().strip_prefix(dir).unwrap().to_string(),
|
||||||
});
|
path,
|
||||||
|
remote_url: remote.url().unwrap_or("None").to_owned(),
|
||||||
|
head: head.to_owned(),
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
println!("{:#x?}", repos);
|
fs::write("gitice.lock", toml::to_string(&repos)?).expect("could not write to lockfile!");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue