node: Use `StagedRepository` to know what to do

To know whether or not we're cloning, use `StagedRepository` instead
of checking manually.
This commit is contained in:
Alexis Sellier 2023-04-13 12:58:44 +02:00
parent 3e05939d14
commit 9729a23559
No known key found for this signature in database
2 changed files with 9 additions and 4 deletions

View File

@ -389,7 +389,7 @@ impl Worker {
fn _fetch<S>( fn _fetch<S>(
&self, &self,
repo: &storage::git::Repository, repo: &fetch::StagedRepository,
remote: NodeId, remote: NodeId,
specs: S, specs: S,
stream: StreamId, stream: StreamId,
@ -414,17 +414,16 @@ impl Worker {
cmd.arg("--atomic"); cmd.arg("--atomic");
} }
let is_clone = repo.head().is_err();
let namespace = self.nid.to_namespace(); let namespace = self.nid.to_namespace();
let mut fetchspecs = specs let mut fetchspecs = specs
.into_refspecs() .into_refspecs()
.into_iter() .into_iter()
// Filter out our own refs, if we aren't cloning. // Filter out our own refs, if we aren't cloning.
.filter(|fs| is_clone || !fs.dst.starts_with(namespace.as_str())) .filter(|fs| repo.is_cloning() || !fs.dst.starts_with(namespace.as_str()))
.map(|spec| spec.to_string()) .map(|spec| spec.to_string())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if !is_clone { if !repo.is_cloning() {
// Make sure we don't fetch our own refs via a glob pattern. // Make sure we don't fetch our own refs via a glob pattern.
fetchspecs.push(format!("^refs/namespaces/{}/*", self.nid)); fetchspecs.push(format!("^refs/namespaces/{}/*", self.nid));
} }

View File

@ -40,6 +40,12 @@ pub enum StagedRepository {
Fetching(Repository), Fetching(Repository),
} }
impl StagedRepository {
pub fn is_cloning(&self) -> bool {
matches!(self, Self::Cloning(_))
}
}
impl Deref for StagedRepository { impl Deref for StagedRepository {
type Target = Repository; type Target = Repository;