Skip to content

Commit 28ed260

Browse files
committed
[pack-gen] tag support for tree traversal
1 parent 5d7ee6a commit 28ed260

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

git-object/src/immutable/commit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ pub mod iter {
179179
/// Returns the object id of this commits tree if it is the first function called and if there is no error in decoding
180180
/// the data.
181181
///
182-
/// Note that this method must only be called once or else will always return None while consuming a single token by calling
183-
/// Errors are coerced into options, hiding whether there was an error or not. THe caller should assume an error if they
182+
/// Note that this method must only be called once or else will always return None while consuming a single token.
183+
/// Errors are coerced into options, hiding whether there was an error or not. The caller should assume an error if they
184184
/// call the method as intended. Such a squelched error cannot be recovered unless the objects data is retrieved and parsed again.
185185
/// `next()`.
186186
pub fn tree_id(&mut self) -> Option<ObjectId> {

git-object/src/immutable/tag.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ pub mod iter {
167167
state: State::default(),
168168
}
169169
}
170+
171+
/// Returns the target id of this tag if it is the first function called and if there is no error in decoding
172+
/// the data.
173+
///
174+
/// Note that this method must only be called once or else will always return None while consuming a single token.
175+
/// Errors are coerced into options, hiding whether there was an error or not. The caller should assume an error if they
176+
/// call the method as intended. Such a squelched error cannot be recovered unless the objects data is retrieved and parsed again.
177+
/// `next()`.
178+
pub fn target_id(&mut self) -> Option<ObjectId> {
179+
self.next().and_then(Result::ok).and_then(Token::into_id)
180+
}
170181
}
171182

172183
impl<'a> Iter<'a> {

git-odb/src/pack/data/output/objects_to_entries.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,24 @@ where
214214
break;
215215
}
216216
Commit => {
217-
let tree_id = immutable::CommitIter::from_bytes(obj.data)
217+
id = immutable::CommitIter::from_bytes(obj.data)
218218
.tree_id()
219219
.expect("every commit has a tree");
220-
obj = db.find_existing(tree_id, buf1, cache).map_err(|_| Error::NotFound {
221-
oid: tree_id.to_owned(),
222-
})?;
223-
id = tree_id;
220+
obj = db
221+
.find_existing(id, buf1, cache)
222+
.map_err(|_| Error::NotFound { oid: id.to_owned() })?;
224223
continue;
225224
}
226225
Blob => break,
227-
Tag => todo!("expand tag objects (here and in other places)"),
226+
Tag => {
227+
id = immutable::TagIter::from_bytes(obj.data)
228+
.target_id()
229+
.expect("every tag has a target");
230+
obj = db
231+
.find_existing(id, buf1, cache)
232+
.map_err(|_| Error::NotFound { oid: id.to_owned() })?;
233+
continue;
234+
}
228235
}
229236
}
230237
}

git-odb/tests/odb/pack/data/output.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,27 @@ mod entries {
6666
trees: usize,
6767
commits: usize,
6868
blobs: usize,
69+
tags: usize,
6970
}
7071
impl Count {
7172
fn total(&self) -> usize {
72-
self.trees + self.commits + self.blobs
73+
self.tags + self.trees + self.commits + self.blobs
7374
}
7475
fn add(&mut self, kind: git_object::Kind) {
7576
use git_object::Kind::*;
7677
match kind {
7778
Tree => self.trees += 1,
7879
Commit => self.commits += 1,
7980
Blob => self.blobs += 1,
80-
Tag => unreachable!("tags are not in our test repository"),
81+
Tag => self.tags += 1,
8182
}
8283
}
8384
}
8485
let whole_pack = Count {
85-
trees: 39,
86-
commits: 15,
87-
blobs: 810,
86+
trees: 40,
87+
commits: 16,
88+
blobs: 811,
89+
tags: 1,
8890
};
8991
for (expansion_mode, expected_count) in [
9092
(
@@ -93,6 +95,7 @@ mod entries {
9395
trees: 0,
9496
commits: 15,
9597
blobs: 0,
98+
tags: 1,
9699
},
97100
),
98101
(output::objects_to_entries::ObjectExpansion::TreeContents, whole_pack),

0 commit comments

Comments
 (0)