Skip to content

Commit 0a25734

Browse files
committed
refresh a corpus repositories by updating all of them.
1 parent a4300c8 commit 0a25734

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

gitoxide-core/src/corpus/mod.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,34 @@ pub mod engine {
3939

4040
/// Run on the existing set of repositories we have already seen or obtain them from `path` if there is none yet.
4141
pub fn run(&mut self, corpus_path: PathBuf) -> anyhow::Result<()> {
42-
let corpus_path = gix::path::realpath(corpus_path)?;
43-
let corpus_id = self.corpus_id_or_insert(&corpus_path)?;
42+
let (corpus_path, corpus_id) = self.prepare_corpus_path(corpus_path)?;
4443
let _gitoxide_id = self.gitoxide_version_id_or_insert()?;
4544
let _runner_id = self.runner_id_or_insert()?;
4645
let _repos = self.find_repos_or_insert(&corpus_path, corpus_id)?;
4746
todo!("do run on repos")
4847
}
4948

49+
pub fn refresh(&mut self, corpus_path: PathBuf) -> anyhow::Result<()> {
50+
let (corpus_path, corpus_id) = self.prepare_corpus_path(corpus_path)?;
51+
let repos = self.refresh_repos(&corpus_path, corpus_id)?;
52+
self.progress.info(format!(
53+
"Added or updated {} repositories under {corpus_path:?}",
54+
repos.len()
55+
));
56+
Ok(())
57+
}
58+
}
59+
60+
impl<P> Engine<P>
61+
where
62+
P: gix::Progress,
63+
{
64+
fn prepare_corpus_path(&self, corpus_path: PathBuf) -> anyhow::Result<(PathBuf, Id)> {
65+
let corpus_path = gix::path::realpath(corpus_path)?;
66+
let corpus_id = self.corpus_id_or_insert(&corpus_path)?;
67+
Ok((corpus_path, corpus_id))
68+
}
69+
5070
fn find_repos(&mut self, corpus_id: Id) -> anyhow::Result<Vec<db::Repo>> {
5171
self.progress.set_name("query db-repos");
5272
self.progress.init(None, gix::progress::count("repos"));

src/plumbing/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ pub fn main() -> Result<()> {
139139
let mut engine = core::corpus::Engine::open_or_create(db, env!("GITOXIDE_VERSION").into(), progress)?;
140140
match cmd {
141141
crate::plumbing::options::corpus::SubCommands::Run => engine.run(path),
142+
crate::plumbing::options::corpus::SubCommands::Refresh => engine.refresh(path),
142143
}
143144
},
144145
),

src/plumbing/options/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ pub mod corpus {
145145
pub enum SubCommands {
146146
/// Perform a corpus run on all registered repositories.
147147
Run,
148+
/// Re-read all repositories under the corpus directory, and add or update them.
149+
Refresh,
148150
}
149151
}
150152

0 commit comments

Comments
 (0)