summaryrefslogtreecommitdiffstats
path: root/src/model/repo.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/repo.rs')
-rw-r--r--src/model/repo.rs73
1 files changed, 24 insertions, 49 deletions
diff --git a/src/model/repo.rs b/src/model/repo.rs
index 2a33280..a656bac 100644
--- a/src/model/repo.rs
+++ b/src/model/repo.rs
@@ -1,10 +1,11 @@
use std::path::Path;
+use std::sync::Mutex;
use anyhow::Result;
use anyhow::anyhow;
-use cached::Return;
-use cached::TimedSizedCache;
-use cached::proc_macro::cached;
+
+use crate::model::backend::worker::BackendWorker;
+use crate::model::backend::fassade::BackendFassade;
#[derive(getset::Getters)]
pub struct Repo {
@@ -13,6 +14,8 @@ pub struct Repo {
#[getset(get = "pub")]
repo: git2::Repository,
+
+ backend: BackendFassade,
}
impl Repo {
@@ -24,70 +27,42 @@ impl Repo {
.ok_or_else(|| anyhow!("Not valid UTF-8, cannot process: {}", path.as_ref().display()))?;
log::info!("Opening {} = {}", name, path.as_ref().display());
- let repo = git2::Repository::open(path)?;
+ let repo = git2::Repository::open(&path)?;
+ let repo2 = git2::Repository::open(&path)?; // TODO: Remove duplicated open()
+
+ let (sender, receiver) = crossbeam::channel::unbounded();
+ let worker = BackendWorker::new(name.clone(), Mutex::new(repo2), receiver);
+ let backend = BackendFassade::new(sender);
- Ok(Repo { name, repo })
+ std::thread::spawn(move || {
+ worker.run()
+ });
+
+ Ok(Repo { name, repo, backend })
}
pub async fn stat(&self) -> Result<cached::Return<RepositoryStat>> {
let (branches, tags) = futures::try_join!(self.branch_names(), self.tag_names())?;
Ok(cached::Return::new(RepositoryStat {
- branches: branches.value,
- tags: tags.value,
+ branches: branches,
+ tags: tags,
}))
}
- pub async fn branch_names(&self) -> Result<cached::Return<Vec<String>>> {
- get_branch_names(&self.name, &self.repo)
+ pub async fn branch_names(&self) -> Result<Vec<String>> {
+ self.backend.get_branch_list().await
}
- pub async fn tag_names(&self) -> Result<cached::Return<Vec<String>>> {
- get_tag_names(&self.name, &self.repo)
+ pub async fn tag_names(&self) -> Result<Vec<String>> {
+ self.backend.get_tag_list().await
}
}
+
#[derive(Clone)]
pub struct RepositoryStat {
pub branches: Vec<String>,
pub tags: Vec<String>,
}
-#[cached(
- type = "TimedSizedCache<String, Return<Vec<String>>>",
- create = "{ TimedSizedCache::with_size_and_lifespan(1, 60) }",
- convert = r#"{ _repo_name.to_owned() }"#,
- with_cached_flag = true,
- result = true,
-)]
-fn get_branch_names(_repo_name: &str, repo: &git2::Repository) -> Result<cached::Return<Vec<String>>> {
- repo.branches(None)?
- .map(|branch| {
- let branch = branch?.0;
- branch.name()?
- .ok_or_else(|| anyhow!("Branch name is not valid UTF8: {:?}", branch.name()))
- .map(String::from)
- })
- .collect::<Result<Vec<String>>>()
- .map(cached::Return::new)
-}
-
-#[cached(
- type = "TimedSizedCache<String, Return<Vec<String>>>",
- create = "{ TimedSizedCache::with_size_and_lifespan(1, 60) }",
- convert = r#"{ _repo_name.to_owned() }"#,
- with_cached_flag = true,
- result = true,
-)]
-fn get_tag_names(_repo_name: &str, repo: &git2::Repository) -> Result<cached::Return<Vec<String>>> {
- repo.tag_names(None)?
- .into_iter()
- .map(|tag| {
- tag.ok_or_else(|| anyhow!("Tag name is not valid UTF8: {:?}", tag))
- .map(String::from)
- })
- .collect::<Result<Vec<String>>>()
- .map(cached::Return::new)
-}
-
-