Simplify git origin a bit
This commit is contained in:
parent
420f1ff42a
commit
4317d7f282
@ -4,13 +4,14 @@ use crate::origin::{self, store};
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{collections, fs, io, sync};
|
use std::{collections, fs, io, sync};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct Origin {
|
struct Origin {
|
||||||
descr: origin::Descr,
|
descr: origin::Descr,
|
||||||
repo: gix::ThreadSafeRepository,
|
repo: sync::Arc<gix::ThreadSafeRepository>,
|
||||||
tree_object_id: gix::ObjectId,
|
tree_object_id: gix::ObjectId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl origin::Origin for sync::Arc<Origin> {
|
impl origin::Origin for Origin {
|
||||||
fn descr(&self) -> &origin::Descr {
|
fn descr(&self) -> &origin::Descr {
|
||||||
&self.descr
|
&self.descr
|
||||||
}
|
}
|
||||||
@ -67,7 +68,7 @@ struct Store {
|
|||||||
// more than one origin to be syncing at a time
|
// more than one origin to be syncing at a time
|
||||||
sync_guard: sync::Mutex<collections::HashMap<origin::Descr, ()>>,
|
sync_guard: sync::Mutex<collections::HashMap<origin::Descr, ()>>,
|
||||||
|
|
||||||
origins: sync::RwLock<collections::HashMap<origin::Descr, sync::Arc<Origin>>>,
|
origins: sync::RwLock<collections::HashMap<origin::Descr, Origin>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(dir_path: PathBuf) -> io::Result<impl super::BoxedStore> {
|
pub fn new(dir_path: PathBuf) -> io::Result<impl super::BoxedStore> {
|
||||||
@ -96,7 +97,7 @@ impl Store {
|
|||||||
&self,
|
&self,
|
||||||
repo: gix::Repository,
|
repo: gix::Repository,
|
||||||
descr: origin::Descr,
|
descr: origin::Descr,
|
||||||
) -> Result<sync::Arc<Origin>, GetOriginError> {
|
) -> Result<Origin, GetOriginError> {
|
||||||
let origin::Descr::Git {
|
let origin::Descr::Git {
|
||||||
ref branch_name, ..
|
ref branch_name, ..
|
||||||
} = descr;
|
} = descr;
|
||||||
@ -118,11 +119,11 @@ impl Store {
|
|||||||
.map_unexpected_while(|| format!("parsing {commit_object_id} as commit"))?
|
.map_unexpected_while(|| format!("parsing {commit_object_id} as commit"))?
|
||||||
.tree();
|
.tree();
|
||||||
|
|
||||||
Ok(sync::Arc::from(Origin {
|
Ok(Origin {
|
||||||
descr,
|
descr,
|
||||||
repo: repo.into(),
|
repo: sync::Arc::new(repo.into()),
|
||||||
tree_object_id,
|
tree_object_id,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_inner(
|
fn sync_inner(
|
||||||
@ -210,7 +211,7 @@ impl Store {
|
|||||||
impl super::BoxedStore for sync::Arc<Store> {}
|
impl super::BoxedStore for sync::Arc<Store> {}
|
||||||
|
|
||||||
impl super::Store for sync::Arc<Store> {
|
impl super::Store for sync::Arc<Store> {
|
||||||
type Origin<'store> = sync::Arc<Origin>
|
type Origin<'store> = Origin
|
||||||
where Self: 'store;
|
where Self: 'store;
|
||||||
|
|
||||||
type AllDescrsIter<'store> = Box<dyn Iterator<Item = store::AllDescrsResult<origin::Descr>> + 'store>
|
type AllDescrsIter<'store> = Box<dyn Iterator<Item = store::AllDescrsResult<origin::Descr>> + 'store>
|
||||||
|
Loading…
Reference in New Issue
Block a user