History

frame for a pack iterator

Sebastian Thiel committed 6 years ago

Commit 07d10961 parent 45c35206 files · +51 −6Browse files

Unified · Split

6 files
  1. README.md +5 −4
  2. git-odb/src/pack/data/iter.rs +33 −0
  3. git-odb/src/pack/data/mod.rs +2 −0
  4. git-odb/src/pack/index/mod.rs +2 −0
  5. git-odb/tests/pack/file.rs +8 −2
  6. git-odb/tests/pack/index.rs +1 −0
README.md+5−4
@@ -21,7 +21,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili · 20 unmodified lines
2121 * [x] [pack verify](https://asciinema.org/a/346975)
2222 * [x] [pack index verify](https://asciinema.org/a/346976) including each object sha1 and statistics
2323 * [x] pack explode, useful for transforming packs into loose objects for inspection or restoration
24− * [ ] verify written objects (by reading them back from disk)
24+ * [x] verify written objects (by reading them back from disk)
2525 * **git-object**
2626 * *decode (zero-copy)* borrowed objects
2727 * [x] commit
@@ -46,7 +46,8 @@ Please see _'Development Status'_ for a listing of all crates and their capabili · 18 unmodified lines
4646 * [x] traverse pack index
4747 * [x] object abstraction
4848 * [x] decode (zero copy)
49− * [x] verify
49+ * [x] verify checksum
50+ * [x] easy and fast pack traversal
5051 * [x] decode
5152 * [x] full objects
5253 * [x] deltified objects
@@ -57,8 +58,8 @@ Please see _'Development Status'_ for a listing of all crates and their capabili · 4 unmodified lines
5758 * [ ] create new pack
5859 * [ ] create 'thin' pack
5960 * [x] verify pack with statistics
60− * [ ] brute force - less memory
61− * [ ] indexed - more memory
61+ * [x] brute force - less memory
62+ * [x] indexed - more memory
6263 * [ ] pack streaming (i.e. indexing + resolution)
6364 * [ ] API documentation with examples
6465 * **sink**
git-odb/src/pack/data/iter.rs+33−0
@@ -0,0 +1,33 @@
1+use crate::pack;
2+use std::{fs, io};
3+
4+#[derive(Debug)]
5+pub struct Iter<R> {
6+ read: R,
7+}
8+
9+impl<R> Iter<R>
10+where
11+ R: io::Read,
12+{
13+ pub fn new(read: R) -> Self {
14+ Iter { read }
15+ }
16+}
17+
18+impl<R> Iterator for Iter<R>
19+where
20+ R: io::Read,
21+{
22+ type Item = ();
23+
24+ fn next(&mut self) -> Option<Self::Item> {
25+ unimplemented!("iter")
26+ }
27+}
28+
29+impl pack::data::File {
30+ pub fn iter(&self) -> io::Result<impl Iterator<Item = ()>> {
31+ Ok(Iter::new(io::BufReader::new(fs::File::open(&self.path)?)))
32+ }
33+}
git-odb/src/pack/data/mod.rs+2−0
@@ -1,3 +1,4 @@
1+//! data within a pack file
12 use filebuffer::FileBuffer;
23 use std::path::Path;
34
@@ -6,6 +7,7 @@ mod decoded; · 2 unmodified lines
67 pub use decoded::*;
78
89 pub mod init;
10+pub mod iter;
911 pub mod parse;
1012 pub mod verify;
1113
git-odb/src/pack/index/mod.rs+2−0
@@ -1,3 +1,5 @@
1+//! an index into the pack file
2+//!
13 /// From itertools
24 /// Create an iterator running multiple iterators in lockstep.
35 ///
git-odb/tests/pack/file.rs+8−2
@@ -7,8 +7,7 @@ fn pack_at(at: &str) -> pack::data::File { · 6 unmodified lines
77 }
88
99 mod method {
10− use crate::pack::file::pack_at;
11− use crate::pack::SMALL_PACK;
10+ use crate::{pack::file::pack_at, pack::SMALL_PACK};
1211
1312 #[test]
1413 fn checksum() {
@@ -24,6 +23,13 @@ mod method { · 9 unmodified lines
2423 let p = pack_at(SMALL_PACK);
2524 assert_eq!(p.verify_checksum().unwrap(), p.checksum());
2625 }
26+
27+ #[test]
28+ fn iter() {
29+ let pack = pack_at(SMALL_PACK);
30+ let it = pack.iter().unwrap();
31+ assert_eq!(it.count(), pack.num_objects() as usize);
32+ }
2733 }
2834
2935 /// All hardcoded offsets are obtained via `git pack-verify --verbose tests/fixtures/packs/pack-a2bf8e71d8c18879e499335762dd95119d93d9f1.idx`
git-odb/tests/pack/index.rs+1−0
@@ -187,6 +187,7 @@ fn pack_lookup() { · 186 unmodified lines
187187 assert_ne!(pack_entry.data_offset, idx_entry.pack_offset);
188188 assert!(sorted_offsets.binary_search(&idx_entry.pack_offset).is_ok());
189189 }
190+ // TODO: test iteration by sorted offsets yields the correct result when using the pack iterator
190191 }
191192 }
192193

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