Skip to content

Commit

Permalink
Assure pack-ids are actually unique, the simple way…(#67)
Browse files Browse the repository at this point in the history
…we could also double-check the produced crc32 values, but
assigning consecutive numbers seems like it's doing the job.
  • Loading branch information
Byron committed Sep 21, 2021
1 parent 6a97bfa commit 0509b4f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion git-odb/src/store/compound/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ impl compound::Store {
.filter(|(p, _)| p.extension().unwrap_or_default() == "idx")
// TODO: make this configurable, git for instance sorts by modification date
// https://github.com/libgit2/libgit2/blob/main/src/odb_pack.c#L41-L158
.map(|(p, md)| pack::Bundle::at(p).map(|b| (b, md.len())))
.enumerate()
.map(|(idx, (p, md))| {
pack::Bundle::at(p).map(|mut b| {
(
{
// don't rely on crc32 for producing non-clashing ids. It's the kind of bug we don't want
b.pack.id = idx as u32;
b
},
md.len(),
)
})
})
.collect::<Result<Vec<_>, _>>()?;
packs_and_sizes.sort_by_key(|e| e.1);
packs_and_sizes.into_iter().rev().map(|(b, _)| b).collect()
Expand Down

0 comments on commit 0509b4f

Please sign in to comment.