Skip to content

Commit 2958145

Browse files
committed
[git-odb] refactor
1 parent 1eab15d commit 2958145

File tree

29 files changed

+115
-118
lines changed

29 files changed

+115
-118
lines changed

experiments/diffing/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn main() -> anyhow::Result<()> {
5353
d.push("objects");
5454
d
5555
};
56-
let db = git_odb::store::linked::Db::at(&repo_objects_dir)?;
56+
let db = git_odb::linked::Store::at(&repo_objects_dir)?;
5757

5858
let start = Instant::now();
5959
let all_commits = commit::Ancestors::new(Some(commit_id), commit::ancestors::State::default(), |oid, buf| {
@@ -83,7 +83,7 @@ fn main() -> anyhow::Result<()> {
8383
oid: &oid,
8484
buf: &'b mut Vec<u8>,
8585
obj_cache: &mut memory_lru::MemoryLruCache<ObjectId, ObjectInfo>,
86-
db: &git_odb::store::linked::Db,
86+
db: &git_odb::linked::Store,
8787
pack_cache: &mut impl git_odb::pack::cache::DecodeEntry,
8888
) -> Option<git_odb::data::Object<'b>> {
8989
let oid = oid.to_owned();

experiments/object-access/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() -> anyhow::Result<()> {
3131
};
3232

3333
let hashes = {
34-
let db = git_odb::store::linked::Db::at(&repo_objects_dir)?;
34+
let db = git_odb::linked::Store::at(&repo_objects_dir)?;
3535
let start = Instant::now();
3636
let hashes = db.iter().collect::<Result<Vec<_>, _>>()?;
3737
let elapsed = start.elapsed();
@@ -174,7 +174,7 @@ fn do_gitoxide<C>(hashes: &[ObjectId], objects_dir: &Path, new_cache: impl FnOnc
174174
where
175175
C: git_odb::pack::cache::DecodeEntry,
176176
{
177-
let odb = git_odb::store::linked::Db::at(objects_dir)?;
177+
let odb = git_odb::linked::Store::at(objects_dir)?;
178178
let mut buf = Vec::new();
179179
let mut bytes = 0u64;
180180
let mut cache = new_cache();
@@ -194,7 +194,7 @@ where
194194
C: git_odb::pack::cache::DecodeEntry,
195195
{
196196
use rayon::prelude::*;
197-
let odb = git_odb::store::linked::Db::at(objects_dir)?;
197+
let odb = git_odb::linked::Store::at(objects_dir)?;
198198
let bytes = std::sync::atomic::AtomicU64::default();
199199
hashes.par_iter().try_for_each_init::<_, _, _, anyhow::Result<_>>(
200200
|| (Vec::new(), new_cache()),

experiments/traversal/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() -> anyhow::Result<()> {
4747
d.push("objects");
4848
d
4949
};
50-
let db = git_odb::store::linked::Db::at(&repo_objects_dir)?;
50+
let db = git_odb::linked::Store::at(&repo_objects_dir)?;
5151

5252
let start = Instant::now();
5353
let all_commits = commit::Ancestors::new(Some(commit_id), commit::ancestors::State::default(), |oid, buf| {
@@ -155,7 +155,7 @@ fn main() -> anyhow::Result<()> {
155155

156156
fn do_gitoxide_commit_graph_traversal<C>(
157157
tip: ObjectId,
158-
db: &git_odb::store::linked::Db,
158+
db: &git_odb::linked::Store,
159159
new_cache: impl FnOnce() -> C,
160160
) -> anyhow::Result<usize>
161161
where
@@ -181,7 +181,7 @@ enum Computation {
181181

182182
fn do_gitoxide_tree_dag_traversal<C>(
183183
commits: &[ObjectId],
184-
db: &git_odb::store::linked::Db,
184+
db: &git_odb::linked::Store,
185185
new_cache: impl Fn() -> C + Sync + Send,
186186
mode: Computation,
187187
) -> anyhow::Result<(usize, u64)>

git-diff/tests/visit/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ mod changes {
33
use git_diff::tree::{recorder, recorder::Change::*};
44
use git_hash::{oid, ObjectId};
55
use git_object::{bstr::ByteSlice, immutable, tree::EntryMode};
6-
use git_odb::store::linked;
6+
use git_odb::linked;
77
use git_odb::{pack, Find};
88

99
use crate::hex_to_id;
1010

1111
type Changes = Vec<recorder::Change>;
1212

13-
fn db(args: impl IntoIterator<Item = &'static str>) -> crate::Result<linked::Db> {
14-
linked::Db::at(
13+
fn db(args: impl IntoIterator<Item = &'static str>) -> crate::Result<linked::Store> {
14+
linked::Store::at(
1515
git_testtools::scripted_fixture_repo_read_only_with_args("make_diff_repo.sh", args)?
1616
.join(".git")
1717
.join("objects"),
@@ -20,7 +20,7 @@ mod changes {
2020
}
2121

2222
fn locate_tree_by_commit<'a>(
23-
db: &linked::Db,
23+
db: &linked::Store,
2424
commit: &oid,
2525
buf: &'a mut Vec<u8>,
2626
) -> crate::Result<immutable::TreeIter<'a>> {
@@ -39,7 +39,7 @@ mod changes {
3939
.expect("id to be a tree"))
4040
}
4141

42-
fn diff_commits(db: &linked::Db, lhs: impl Into<Option<ObjectId>>, rhs: &oid) -> crate::Result<Changes> {
42+
fn diff_commits(db: &linked::Store, lhs: impl Into<Option<ObjectId>>, rhs: &oid) -> crate::Result<Changes> {
4343
let mut buf = Vec::new();
4444
let lhs_tree = lhs
4545
.into()
@@ -61,7 +61,7 @@ mod changes {
6161
Ok(recorder.records)
6262
}
6363

64-
fn diff_with_previous_commit_from(db: &linked::Db, commit_id: &oid) -> crate::Result<Changes> {
64+
fn diff_with_previous_commit_from(db: &linked::Store, commit_id: &oid) -> crate::Result<Changes> {
6565
let mut buf = Vec::new();
6666
let (main_tree_id, parent_commit_id) = {
6767
let commit = db
@@ -107,7 +107,7 @@ mod changes {
107107
Ok(recorder.records)
108108
}
109109

110-
fn head_of(db: &linked::Db) -> ObjectId {
110+
fn head_of(db: &linked::Store) -> ObjectId {
111111
ObjectId::from_hex(
112112
&std::fs::read(
113113
db.dbs[0]
@@ -126,7 +126,7 @@ mod changes {
126126
.expect("valid hex id")
127127
}
128128

129-
fn all_commits(db: &linked::Db) -> Vec<ObjectId> {
129+
fn all_commits(db: &linked::Store) -> Vec<ObjectId> {
130130
use git_traverse::commit;
131131

132132
let head = head_of(db);

git-odb/src/lib.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@
66
//!
77
//! There are various flavours of object databases, all of which supporting iteration, reading and possibly writing.
88
//!
9-
//! * [`store::loose::Backend`]
9+
//! * [`loose::Store`]
1010
//! * A database storing one object per file, named by its hash, using zlib compression.
1111
//! * O(1) reads and writes, bound by IO operations per second
12-
//! * [`pack::Bundle`]
13-
//! * A database storing multiple objects within an indexed pack file, reaching compression ratios of 60 to 1 or more.
14-
//! * Slow writes and fast reads
15-
//! * [`store::compound::Backend`]
16-
//! * A database using a [`store::loose::Backend`] for writes and multiple [`pack::Bundle`]s for object reading. It can also refer to multiple
17-
//! additional [`store::compound::Backend`] instances using git-alternates.
12+
//! * [`compound::Store`]
13+
//! * A database using a [`loose::Store`] for writes and multiple [`pack::Bundle`]s for object reading. It can also refer to multiple
14+
//! additional [`compound::Store`] instances using git-alternates.
1815
//! * This is the database closely resembling the object database in a git repository, and probably what most people would want to use.
19-
//! * [`store::linked::Db`]
20-
//! * A database containing various [`compound::Backends`][store::compound::Backend] as gathered from `alternates` files.
16+
//! * [linked::Store`]
17+
//! * A database containing various [`compound::Stores`][compound::Store] as gathered from `alternates` files.
2118
pub use git_pack as pack;
2219
pub use pack::{data, Find, FindExt};
2320

24-
///
25-
pub mod store;
21+
mod store;
22+
pub use store::*;
2623

2724
pub mod alternate;
2825
///

git-odb/src/store/compound/find.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
};
55
use git_pack::data;
66

7-
/// Returned by [`compound::Backend::find()`]
7+
/// Returned by [`compound::Store::find()`]
88
#[derive(thiserror::Error, Debug)]
99
#[allow(missing_docs)]
1010
pub enum Error {
@@ -20,7 +20,7 @@ pub(crate) struct PackLocation {
2020
pub entry_index: u32,
2121
}
2222

23-
impl compound::Backend {
23+
impl compound::Store {
2424
/// Find an object as identified by [`ObjectId`][git_hash::ObjectId] and store its data in full in the provided `buffer`.
2525
/// This will search the object in all contained object databases.
2626
/// Use a `pack_cache` to accelerate pack access by reducing the amount of work duplication, or [`pack::cache::Never`] to disable any caching.
@@ -44,7 +44,7 @@ impl compound::Backend {
4444
}
4545

4646
/// Internal-use function to look up a packed object index or loose object.
47-
/// Used to avoid double-lookups in linked::Db::locate.
47+
/// Used to avoid double-lookups in linked::Store::locate.
4848
/// (The polonius borrow-checker would support this via the locate
4949
/// function, so this can be [simplified](https://github.com/Byron/gitoxide/blob/0c5f4043da4615820cb180804a81c2d4fe75fe5e/git-odb/src/compound/locate.rs#L47)
5050
/// once polonius is stable.)
@@ -73,7 +73,7 @@ impl compound::Backend {
7373
}
7474

7575
/// Special-use function to look up an object index. Used to avoid double-lookups in
76-
/// [compound::Backend::find()][crate::store::compound::Backend::find()]. (The polonius borrow-checker would support this via the 'find'
76+
/// [compound::Store::find()][crate::store::compound::Store::find()]. (The polonius borrow-checker would support this via the 'find'
7777
/// function, so this can be [simplified](https://github.com/Byron/gitoxide/blob/0c5f4043da4615820cb180804a81c2d4fe75fe5e/git-odb/src/compound/locate.rs#L47)
7878
/// once polonius is stable.)
7979
pub fn find_pack_index(bundle: &git_pack::Bundle, id: &git_hash::oid) -> Option<u32> {

git-odb/src/store/compound/init.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
store::{compound, loose},
66
};
77

8-
/// Returned by [`compound::Backend::at()`]
8+
/// Returned by [`compound::Store::at()`]
99
#[derive(thiserror::Error, Debug)]
1010
#[allow(missing_docs)]
1111
pub enum Error {
@@ -18,12 +18,12 @@ pub enum Error {
1818
}
1919

2020
/// Instantiation
21-
impl compound::Backend {
21+
impl compound::Store {
2222
/// Returns a compound database as initialized from the given git `objects_directory`, commonly `.git/objects`.
2323
///
24-
/// Only loose and packed objects will be considered. See the [linked Db][crate::store::linked::Db] for a database with
24+
/// Only loose and packed objects will be considered. See the [linked Db][crate::store::linked::Store] for a database with
2525
/// support for _git alternates_, i.e. linking to other repositories.
26-
pub fn at(objects_directory: impl Into<PathBuf>) -> Result<compound::Backend, Error> {
26+
pub fn at(objects_directory: impl Into<PathBuf>) -> Result<compound::Store, Error> {
2727
let loose_objects = objects_directory.into();
2828
if !loose_objects.is_dir() {
2929
return Err(Error::Inaccessible(loose_objects));
@@ -46,8 +46,8 @@ impl compound::Backend {
4646
Err(_) => Vec::new(),
4747
};
4848

49-
Ok(compound::Backend {
50-
loose: loose::Backend::at(loose_objects),
49+
Ok(compound::Store {
50+
loose: loose::Store::at(loose_objects),
5151
bundles: packs,
5252
})
5353
}

git-odb/src/store/compound/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ mod write;
99

1010
/// An object database with tiered lookup packs and loose objects.
1111
/// This is a typical git database as used in git repositories, sans 'alternates'.
12-
pub struct Backend {
12+
pub struct Store {
1313
/// A loose object database into which new objects are written
14-
pub loose: loose::Backend,
14+
pub loose: loose::Store,
1515
/// All packs in the `objects/packs` directory
1616
pub bundles: Vec<pack::Bundle>,
1717
}

git-odb/src/store/compound/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::Read;
33
use crate::store::{compound, loose};
44
use git_object::{mutable, Kind};
55

6-
impl crate::write::Write for compound::Backend {
6+
impl crate::write::Write for compound::Store {
77
type Error = loose::write::Error;
88

99
fn write(&self, object: &mutable::Object, hash: git_hash::Kind) -> Result<git_hash::ObjectId, Self::Error> {

git-odb/src/store/linked/find.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
};
99
use git_pack::{data::Object, find::PackEntry};
1010

11-
impl crate::Find for linked::Db {
11+
impl crate::Find for linked::Store {
1212
type Error = compound::find::Error;
1313

1414
fn find<'a>(
@@ -86,7 +86,7 @@ impl crate::Find for linked::Db {
8686
}
8787
}
8888

89-
impl crate::Find for &linked::Db {
89+
impl crate::Find for &linked::Store {
9090
type Error = compound::find::Error;
9191

9292
fn find<'a>(

git-odb/src/store/linked/init.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33
use crate::alternate;
44
use crate::store::{compound, linked};
55

6-
/// The error returned by [`linked::Db::at()`]
6+
/// The error returned by [`linked::Store::at()`]
77
#[derive(Debug, thiserror::Error)]
88
#[allow(missing_docs)]
99
pub enum Error {
@@ -13,27 +13,27 @@ pub enum Error {
1313
AlternateResolve(#[from] alternate::Error),
1414
}
1515

16-
impl linked::Db {
16+
impl linked::Store {
1717
/// Instantiate an instance at the given `objects_directory`, commonly `.git/objects`.
1818
///
19-
/// _git alternate_ files will be traversed to build a chain of [`compound::Backend`] instances.
19+
/// _git alternate_ files will be traversed to build a chain of [`compound::Store`] instances.
2020
pub fn at(objects_directory: impl Into<PathBuf>) -> Result<Self, Error> {
21-
let mut dbs = vec![compound::Backend::at(objects_directory.into())?];
21+
let mut dbs = vec![compound::Store::at(objects_directory.into())?];
2222
for object_path in alternate::resolve(dbs[0].loose.path.clone())?.into_iter() {
23-
dbs.push(compound::Backend::at(object_path)?);
23+
dbs.push(compound::Store::at(object_path)?);
2424
}
2525
assert!(
2626
!dbs.is_empty(),
2727
"we can rely on at least one compound database to be present"
2828
);
29-
Ok(linked::Db { dbs })
29+
Ok(linked::Store { dbs })
3030
}
3131
}
3232

33-
impl std::convert::TryFrom<PathBuf> for linked::Db {
33+
impl std::convert::TryFrom<PathBuf> for linked::Store {
3434
type Error = Error;
3535

3636
fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
37-
linked::Db::at(value)
37+
linked::Store::at(value)
3838
}
3939
}

git-odb/src/store/linked/iter.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct AllObjects<Db> {
2828

2929
impl<Db> AllObjects<Db>
3030
where
31-
Db: Borrow<linked::Db>,
31+
Db: Borrow<linked::Store>,
3232
{
3333
/// Create a new iterator from a linked database
3434
pub fn new(db: Db) -> Self {
@@ -38,7 +38,7 @@ where
3838
.borrow()
3939
.dbs
4040
.get(db_index)
41-
.expect("at least one db or no linked::Db at all");
41+
.expect("at least one db or no linked::Store at all");
4242
if db.bundles.is_empty() {
4343
DbState::Loose { iter: db.loose.iter() }
4444
} else {
@@ -51,7 +51,7 @@ where
5151

5252
impl<Db> Iterator for AllObjects<Db>
5353
where
54-
Db: Borrow<linked::Db>,
54+
Db: Borrow<linked::Store>,
5555
{
5656
type Item = Result<ObjectId, loose::iter::Error>;
5757

@@ -108,18 +108,18 @@ where
108108
}
109109
}
110110

111-
impl linked::Db {
111+
impl linked::Store {
112112
/// Return an iterator over all objects in all linked databases, database after database, first packed
113113
/// objects with the 'best' packs first, followed by loose objects.
114114
/// For specialized iterations, use the `dbs` fields directly as all databases are accessible.
115-
pub fn iter(&self) -> AllObjects<&linked::Db> {
115+
pub fn iter(&self) -> AllObjects<&linked::Store> {
116116
AllObjects::new(self)
117117
}
118118

119-
/// Like [`iter()`][linked::Db::iter()] but works with this instance living in an [`Arc`]
119+
/// Like [`iter()`][linked::Store::iter()] but works with this instance living in an [`Arc`]
120120
///
121121
/// Useful in conjunction with `'static threads`.
122-
pub fn arc_iter(self: &Arc<linked::Db>) -> AllObjects<Arc<linked::Db>> {
122+
pub fn arc_iter(self: &Arc<linked::Store>) -> AllObjects<Arc<linked::Store>> {
123123
AllObjects::new(Arc::clone(&self))
124124
}
125125
}

git-odb/src/store/linked/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//! An object database representing a list of [compound databases][compound::Backend] commonly created using _git alternates_.
1+
//! An object database representing a list of [compound databases][compound::Store] commonly created using _git alternates_.
22
use crate::store::compound;
33

4-
/// A database with a list of [compound databases][compound::Backend] created by traversing git `alternates` files.
4+
/// A database with a list of [compound databases][compound::Store] created by traversing git `alternates` files.
55
///
66
/// It does not contain any objects itself.
7-
pub struct Db {
7+
pub struct Store {
88
/// The compound databases containing the actual objects.
9-
pub dbs: Vec<compound::Backend>,
9+
pub dbs: Vec<compound::Store>,
1010
}
1111

1212
///

git-odb/src/store/linked/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::Read;
33

44
use crate::store::{linked, loose};
55

6-
impl crate::write::Write for linked::Db {
6+
impl crate::write::Write for linked::Store {
77
type Error = loose::write::Error;
88

99
fn write(&self, object: &mutable::Object, hash: git_hash::Kind) -> Result<git_hash::ObjectId, Self::Error> {

0 commit comments

Comments
 (0)