Skip to content

Commit ab250f7

Browse files
committed
[odb #190] Read all eligble packed refs, no "pack-" prefix needed
This allows to read packs which are differently named which is what git and libgit2 do, too.
1 parent fdc3678 commit ab250f7

File tree

12 files changed

+37
-4
lines changed

12 files changed

+37
-4
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ impl compound::Store {
3434
.filter_map(Result::ok)
3535
.filter_map(|e| e.metadata().map(|md| (e.path(), md)).ok())
3636
.filter(|(_, md)| md.file_type().is_file())
37-
.filter(|(p, _)| {
38-
p.extension().unwrap_or_default() == "idx"
39-
&& p.file_name().unwrap_or_default().to_string_lossy().starts_with("pack-")
40-
})
37+
.filter(|(p, _)| p.extension().unwrap_or_default() == "idx")
4138
// TODO: make this configurable, git for instance sorts by modification date
4239
// https://github.com/libgit2/libgit2/blob/main/src/odb_pack.c#L41-L158
4340
.map(|(p, md)| pack::Bundle::at(p).map(|b| (b, md.len())))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[core]
2+
bare = true
3+
repositoryformatversion = 0
4+
filemode = true
5+
ignorecase = true
6+
precomposeunicode = true
7+
logallrefupdates = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# File patterns to ignore; see `git help ignore` for more information.
2+
# Lines that start with '#' are comments.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ecc68100297fff843a7eef8df0d0fb80c1c8bac5

git-odb/tests/odb/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pub use git_testtools::{fixture_path, hex_to_id, scripted_fixture_repo_read_only
33
pub type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;
44

55
pub mod alternate;
6+
pub mod regression;
67
pub mod store;

git-odb/tests/odb/regression/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
mod repo_with_small_packs {
2+
use crate::odb::{fixture_path, hex_to_id};
3+
use git_odb::pack;
4+
5+
#[test]
6+
fn all_packed_objects_can_be_found() {
7+
let store = git_odb::linked::Store::at(fixture_path("repos/small-packs.git/objects")).unwrap();
8+
assert_eq!(store.dbs.len(), 1, "a simple repo");
9+
let db = &store.dbs[0];
10+
assert_eq!(db.bundles.len(), 2, "small packs");
11+
let mut buf = Vec::new();
12+
assert!(
13+
db.try_find(
14+
hex_to_id("ecc68100297fff843a7eef8df0d0fb80c1c8bac5"),
15+
&mut buf,
16+
&mut pack::cache::Never
17+
)
18+
.unwrap()
19+
.is_some(),
20+
"object is present and available"
21+
);
22+
}
23+
}

0 commit comments

Comments
 (0)