History

refactor

Sebastian Thiel committed 6 years ago

Commit 62a01fe1 parent d907ce83 files · +6 −29Browse files

Unified · Split

3 files
  1. git-odb/src/pack/index/write/error.rs +0 −9
  2. git-odb/src/pack/index/write/mod.rs +1 −15
  3. git-odb/tests/pack/tree.rs +5 −5
git-odb/src/pack/index/write/error.rs+0−9
@@ -24,21 +24,12 @@ quick_error! { · 23 unmodified lines
24 IteratorInvariantTrailer {24 IteratorInvariantTrailer {
25 display("The iterator failed to set a trailing hash over all prior pack entries in the last provided entry")25 display("The iterator failed to set a trailing hash over all prior pack entries in the last provided entry")
26 }26 }
27 IteratorInvariantNonEmpty {
28 display("Is there ever a need to create empty indices? If so, please post a PR.")
29 }
30 IteratorInvariantBasesPresent {27 IteratorInvariantBasesPresent {
31 display("Did not encounter a single base")28 display("Did not encounter a single base")
32 }29 }
33 IteratorInvariantBasesBeforeDeltasNeedThem(delta_pack_offset: u64, base_pack_offset: u64) {
34 display("The delta at pack offset {} could not find its base at {} - it should have been seen already", delta_pack_offset, base_pack_offset)
35 }
36 IteratorInvariantTooManyObjects(num_objects: usize) {30 IteratorInvariantTooManyObjects(num_objects: usize) {
37 display("Only u32::MAX objects can be stored in a pack, found {}", num_objects)31 display("Only u32::MAX objects can be stored in a pack, found {}", num_objects)
38 }32 }
39 IteratorInvariantIncreasingPackOffset(last_pack_offset: u64, pack_offset: u64) {
40 display("Pack offsets must only increment. The previous pack offset was {}, the current one is {}", last_pack_offset, pack_offset)
41 }
42 IteratorInvariantBaseOffset(pack_offset: u64, distance: u64) {33 IteratorInvariantBaseOffset(pack_offset: u64, distance: u64) {
43 display("{} is not a valid offset for pack offset {}", distance, pack_offset)34 display("{} is not a valid offset for pack offset {}", distance, pack_offset)
44 }35 }
git-odb/src/pack/index/write/mod.rs+1−15
@@ -37,14 +37,9 @@ impl pack::index::File { · 36 unmodified lines
37 let mut bytes_to_process = 0u64;37 let mut bytes_to_process = 0u64;
38 // This array starts out sorted by pack-offset38 // This array starts out sorted by pack-offset
39 let mut index_entries = Vec::with_capacity(entries.size_hint().0);39 let mut index_entries = Vec::with_capacity(entries.size_hint().0);
40 if index_entries.capacity() == 0 {
41 return Err(Error::IteratorInvariantNonEmpty);
42 }
43
44 let mut last_seen_trailer = None;40 let mut last_seen_trailer = None;
45 let mut last_base_index = None;41 let mut last_base_index = None;
46 let mut first_delta_index = None;42 let mut first_delta_index = None;
47 let mut last_pack_offset = 0;
48 let mut cache_by_offset = BTreeMap::<_, CacheEntry>::new();43 let mut cache_by_offset = BTreeMap::<_, CacheEntry>::new();
49 let mut tree = Tree::new(entries.size_hint().0)?;44 let mut tree = Tree::new(entries.size_hint().0)?;
50 let mut header_buf = [0u8; 16];45 let mut header_buf = [0u8; 16];
@@ -66,13 +61,6 @@ impl pack::index::File { · 15 unmodified lines
66 } = entry?;61 } = entry?;
67 62
68 let compressed_len = compressed.len();63 let compressed_len = compressed.len();
69 if pack_offset <= last_pack_offset {
70 return Err(Error::IteratorInvariantIncreasingPackOffset(
71 last_pack_offset,
72 pack_offset,
73 ));
74 }
75 last_pack_offset = pack_offset;
76 bytes_to_process += decompressed.len() as u64;64 bytes_to_process += decompressed.len() as u64;
77 let entry_len = header_size as usize + compressed_len;65 let entry_len = header_size as usize + compressed_len;
78 let crc32 = {66 let crc32 = {
@@ -117,9 +105,7 @@ impl pack::index::File { · 38 unmodified lines
117 )?;105 )?;
118 cache_by_offset106 cache_by_offset
119 .get_mut(&base_pack_offset)107 .get_mut(&base_pack_offset)
120 .ok_or_else(|| {108 .expect("this to work nice check is done in tree delete me")
121 Error::IteratorInvariantBasesBeforeDeltasNeedThem(pack_offset, base_pack_offset)
122 })?
123 .increment_child_count();109 .increment_child_count();
124 110
125 if first_delta_index.is_none() {111 if first_delta_index.is_none() {
git-odb/tests/pack/tree.rs+5−5
@@ -1,14 +1,14 @@
1#[test]1#[test]
2fn using_option_as_data_does_not_increase_size_in_memory() {2fn using_option_as_data_does_not_increase_size_in_memory() {
3 enum Cache {3 enum Cache {
4 Unset,4 _Unset,
5 Decompressed(Vec<u8>),5 _Decompressed(Vec<u8>),
6 /// compressed bytes + decompressed size6 /// compressed bytes + decompressed size
7 Compressed(Vec<u8>, usize),7 _Compressed(Vec<u8>, usize),
8 }8 }
9 enum ObjectKind {9 enum ObjectKind {
10 Base(git_object::Kind),10 _Base(git_object::Kind),
11 OfsDelta(u64),11 _OfsDelta(u64),
12 }12 }
13 struct Entry {13 struct Entry {
14 pub _pack_offset: u64,14 pub _pack_offset: u64,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t