Skip to content

Commit

Permalink
refresh a corpus repositories by updating all of them.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jun 15, 2023
1 parent a4300c8 commit a0b4385
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
33 changes: 29 additions & 4 deletions gitoxide-core/src/corpus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,37 @@ pub mod engine {

/// Run on the existing set of repositories we have already seen or obtain them from `path` if there is none yet.
pub fn run(&mut self, corpus_path: PathBuf) -> anyhow::Result<()> {
let (corpus_path, corpus_id) = self.prepare_corpus_path(corpus_path)?;
let gitoxide_id = self.gitoxide_version_id_or_insert()?;
let runner_id = self.runner_id_or_insert()?;
let repos = self.find_repos_or_insert(&corpus_path, corpus_id)?;
self.perform_run(gitoxide_id, runner_id, repos)
}

pub fn refresh(&mut self, corpus_path: PathBuf) -> anyhow::Result<()> {
let (corpus_path, corpus_id) = self.prepare_corpus_path(corpus_path)?;
let repos = self.refresh_repos(&corpus_path, corpus_id)?;
self.progress.set_name("refresh repos");
self.progress.info(format!(
"Added or updated {} repositories under {corpus_path:?}",
repos.len()
));
Ok(())
}
}

impl<P> Engine<P>
where
P: gix::Progress,
{
fn perform_run(&self, _gitoxide_id: Id, _runner_id: Id, _repos: Vec<db::Repo>) -> anyhow::Result<()> {
todo!()
}

fn prepare_corpus_path(&self, corpus_path: PathBuf) -> anyhow::Result<(PathBuf, Id)> {
let corpus_path = gix::path::realpath(corpus_path)?;
let corpus_id = self.corpus_id_or_insert(&corpus_path)?;
let _gitoxide_id = self.gitoxide_version_id_or_insert()?;
let _runner_id = self.runner_id_or_insert()?;
let _repos = self.find_repos_or_insert(&corpus_path, corpus_id)?;
todo!("do run on repos")
Ok((corpus_path, corpus_id))
}

fn find_repos(&mut self, corpus_id: Id) -> anyhow::Result<Vec<db::Repo>> {
Expand Down
1 change: 1 addition & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub fn main() -> Result<()> {
let mut engine = core::corpus::Engine::open_or_create(db, env!("GITOXIDE_VERSION").into(), progress)?;
match cmd {
crate::plumbing::options::corpus::SubCommands::Run => engine.run(path),
crate::plumbing::options::corpus::SubCommands::Refresh => engine.refresh(path),
}
},
),
Expand Down
2 changes: 2 additions & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ pub mod corpus {
pub enum SubCommands {
/// Perform a corpus run on all registered repositories.
Run,
/// Re-read all repositories under the corpus directory, and add or update them.
Refresh,
}
}

Expand Down

0 comments on commit a0b4385

Please sign in to comment.