Skip to content

Commit 41ce55c

Browse files
codexByron
andcommitted
Adapt to changes in gix-object
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
1 parent 3521fdb commit 41ce55c

10 files changed

Lines changed: 76 additions & 50 deletions

File tree

gitoxide-core/src/hours/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ fn parse_trailer_identity(trailer: gix::objs::commit::message::body::TrailerRef<
8383
/// Return `(commit_author, [commit_author, co_authors...])`. Use the `commit_author` for easy access to the commit author itself.
8484
fn commit_author_identities(
8585
commit_data: &[u8],
86+
hash_kind: gix::hash::Kind,
8687
) -> Result<(gix::actor::SignatureRef<'_>, SmallVec<[ParsedIdentity<'_>; 2]>), gix::objs::decode::Error> {
87-
let commit = gix::objs::CommitRef::from_bytes(commit_data)?;
88+
let commit = gix::objs::CommitRef::from_bytes(commit_data, hash_kind)?;
8889
let author = commit.author()?.trim();
8990
let mut authors = smallvec![ParsedIdentity::Borrowed(gix::actor::IdentityRef::from(author))];
9091
authors.extend(commit.co_authored_by_trailers().filter_map(parse_trailer_identity));
@@ -130,7 +131,7 @@ where
130131
let extract_signatures = scope.spawn(move || -> anyhow::Result<Vec<_>> {
131132
let mut out = Vec::new();
132133
for (commit_idx, commit_data) in rx {
133-
if let Ok((commit_author, authors)) = commit_author_identities(&commit_data) {
134+
if let Ok((commit_author, authors)) = commit_author_identities(&commit_data, commit_id.kind()) {
134135
let mut string_ref = |s: &[u8]| -> &'static BStr {
135136
match string_heap.get(s) {
136137
Some(n) => n.as_bstr(),
@@ -445,7 +446,7 @@ body\n\
445446
\n\
446447
Co-authored-by: Second Author <second@example.com>\n\
447448
Co-authored-by: Third Author <third@example.com>\n";
448-
let (author, authors) = commit_author_identities(commit).expect("valid commit");
449+
let (author, authors) = commit_author_identities(commit, gix::hash::Kind::Sha1).expect("valid commit");
449450
assert_eq!(author.time, "1710000000 +0000");
450451
assert_eq!(
451452
authors
@@ -478,7 +479,7 @@ committer Main Author <main@example.com> 1710000000 +0000\n\
478479
subject\n\
479480
\n\
480481
Co-authored-by: not a signature\n";
481-
let (_, authors) = commit_author_identities(commit).expect("valid commit");
482+
let (_, authors) = commit_author_identities(commit, gix::hash::Kind::Sha1).expect("valid commit");
482483
assert_eq!(authors.len(), 1);
483484
assert_eq!(authors[0].name(), "Main Author".as_bytes().as_bstr());
484485
assert_eq!(authors[0].email(), "main@example.com".as_bytes().as_bstr());

gitoxide-core/src/query/engine/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ pub fn update(
395395
self.progress.inc();
396396
if self.known_commits.binary_search(&id.to_owned()).is_err() {
397397
let res = {
398-
let mut parents = gix::objs::CommitRefIter::from_bytes(obj.data).parent_ids();
398+
let mut parents = gix::objs::CommitRefIter::from_bytes(obj.data, obj.hash_kind).parent_ids();
399399
let res = parents.next().map(|first_parent| (Some(first_parent), id.to_owned()));
400400
match parents.next() {
401401
Some(_) => None,

gix-pack/src/data/output/count/objects/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ mod expand {
175175
match obj.kind {
176176
Tree | Blob => break,
177177
Tag => {
178-
id = TagRefIter::from_bytes(obj.data)
178+
id = TagRefIter::from_bytes(obj.data, obj.hash_kind)
179179
.target_id()
180180
.expect("every tag has a target");
181181
let tmp = db.find(&id, buf1)?;
@@ -188,7 +188,7 @@ mod expand {
188188
}
189189
Commit => {
190190
let current_tree_iter = {
191-
let mut commit_iter = CommitRefIter::from_bytes(obj.data);
191+
let mut commit_iter = CommitRefIter::from_bytes(obj.data, obj.hash_kind);
192192
let tree_id = commit_iter.tree_id().expect("every commit has a tree");
193193
parent_commit_ids.clear();
194194
for token in commit_iter {
@@ -227,9 +227,12 @@ mod expand {
227227
push_obj_count_unique(
228228
&mut out, seen_objs, commit_id, location, objects, stats, true,
229229
);
230-
CommitRefIter::from_bytes(parent_commit_obj.data)
231-
.tree_id()
232-
.expect("every commit has a tree")
230+
CommitRefIter::from_bytes(
231+
parent_commit_obj.data,
232+
parent_commit_obj.hash_kind,
233+
)
234+
.tree_id()
235+
.expect("every commit has a tree")
233236
};
234237
let parent_tree = {
235238
let (parent_tree_obj, location) = db.find(&parent_tree_id, buf2)?;
@@ -296,7 +299,7 @@ mod expand {
296299
break;
297300
}
298301
Commit => {
299-
id = CommitRefIter::from_bytes(obj.0.data)
302+
id = CommitRefIter::from_bytes(obj.0.data, obj.0.hash_kind)
300303
.tree_id()
301304
.expect("every commit has a tree");
302305
stats.expanded_objects += 1;
@@ -305,7 +308,7 @@ mod expand {
305308
}
306309
Blob => break,
307310
Tag => {
308-
id = TagRefIter::from_bytes(obj.0.data)
311+
id = TagRefIter::from_bytes(obj.0.data, obj.0.hash_kind)
309312
.target_id()
310313
.expect("every tag has a target");
311314
stats.expanded_objects += 1;

gix-ref/src/store/file/raw_ext.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,21 @@ impl ReferenceExt for Reference {
160160
let mut oid = self.follow_to_object_packed(store, packed)?;
161161
let mut buf = Vec::new();
162162
let peeled_id = loop {
163-
let gix_object::Data {
164-
kind,
165-
data,
166-
hash_kind: _,
167-
} = objects
168-
.try_find(&oid, &mut buf)?
169-
.ok_or_else(|| peel::to_id::Error::NotFound {
170-
oid,
171-
name: self.name.0.clone(),
172-
})?;
163+
let gix_object::Data { kind, data, hash_kind } =
164+
objects
165+
.try_find(&oid, &mut buf)?
166+
.ok_or_else(|| peel::to_id::Error::NotFound {
167+
oid,
168+
name: self.name.0.clone(),
169+
})?;
173170
match kind {
174171
gix_object::Kind::Tag => {
175-
oid = gix_object::TagRefIter::from_bytes(data).target_id().map_err(|_err| {
176-
peel::to_id::Error::NotFound {
172+
oid = gix_object::TagRefIter::from_bytes(data, hash_kind)
173+
.target_id()
174+
.map_err(|_err| peel::to_id::Error::NotFound {
177175
oid,
178176
name: self.name.0.clone(),
179-
}
180-
})?;
177+
})?;
181178
}
182179
_ => break oid,
183180
}

gix-ref/src/store/packed/transaction.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,20 @@ impl packed::Transaction {
107107
{
108108
let mut next_id = new;
109109
edit.peeled = loop {
110-
let kind = objects.try_find(&next_id, &mut buf)?.map(|d| d.kind);
111-
match kind {
112-
Some(gix_object::Kind::Tag) => {
113-
next_id = gix_object::TagRefIter::from_bytes(&buf).target_id().map_err(|_| {
114-
prepare::Error::Resolve(
115-
format!("Couldn't get target object id from tag {next_id}").into(),
116-
)
117-
})?;
110+
let data = objects.try_find(&next_id, &mut buf)?;
111+
match data {
112+
Some(gix_object::Data {
113+
kind: gix_object::Kind::Tag,
114+
data,
115+
hash_kind,
116+
}) => {
117+
next_id = gix_object::TagRefIter::from_bytes(data, hash_kind)
118+
.target_id()
119+
.map_err(|_| {
120+
prepare::Error::Resolve(
121+
format!("Couldn't get target object id from tag {next_id}").into(),
122+
)
123+
})?;
118124
}
119125
Some(_) => {
120126
break if next_id == new { None } else { Some(next_id) };

gix-revwalk/src/graph/commit.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl<'graph, 'cache> LazyCommit<'graph, 'cache> {
88
/// Return an iterator over the parents of this commit.
99
pub fn iter_parents(&self) -> Parents<'graph, 'cache> {
1010
let backing = match &self.backing {
11-
Either::Left(buf) => Either::Left(gix_object::CommitRefIter::from_bytes(buf)),
11+
Either::Left(buf) => Either::Left(gix_object::CommitRefIter::from_bytes(buf, self.hash_kind)),
1212
Either::Right((cache, pos)) => Either::Right((*cache, cache.commit_at(*pos).iter_parents())),
1313
};
1414
Parents { backing }
@@ -20,7 +20,9 @@ impl<'graph, 'cache> LazyCommit<'graph, 'cache> {
2020
/// Note that this can only fail if the commit is backed by the object database *and* parsing fails.
2121
pub fn committer_timestamp(&self) -> Result<SecondsSinceUnixEpoch, gix_object::decode::Error> {
2222
Ok(match &self.backing {
23-
Either::Left(buf) => gix_object::CommitRefIter::from_bytes(buf).committer()?.seconds(),
23+
Either::Left(buf) => gix_object::CommitRefIter::from_bytes(buf, self.hash_kind)
24+
.committer()?
25+
.seconds(),
2426
Either::Right((cache, pos)) => cache.commit_at(*pos).committer_timestamp() as SecondsSinceUnixEpoch, // a cast as we cannot represent the error and trying seems overkill
2527
})
2628
}
@@ -38,7 +40,12 @@ impl<'graph, 'cache> LazyCommit<'graph, 'cache> {
3840
&self,
3941
) -> Result<(Option<Generation>, SecondsSinceUnixEpoch), gix_object::decode::Error> {
4042
Ok(match &self.backing {
41-
Either::Left(buf) => (None, gix_object::CommitRefIter::from_bytes(buf).committer()?.seconds()),
43+
Either::Left(buf) => (
44+
None,
45+
gix_object::CommitRefIter::from_bytes(buf, self.hash_kind)
46+
.committer()?
47+
.seconds(),
48+
),
4249
Either::Right((cache, pos)) => {
4350
let commit = cache.commit_at(*pos);
4451
(
@@ -57,7 +64,7 @@ impl<'graph, 'cache> LazyCommit<'graph, 'cache> {
5764
Ok(match &self.backing {
5865
Either::Left(buf) => {
5966
use gix_object::commit::ref_iter::Token;
60-
let iter = gix_object::CommitRefIter::from_bytes(buf);
67+
let iter = gix_object::CommitRefIter::from_bytes(buf, self.hash_kind);
6168
let mut parents = SmallVec::default();
6269
let mut timestamp = None;
6370
for token in iter {

gix-revwalk/src/graph/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ fn try_lookup<'graph, 'cache>(
369369
if let Some(cache) = cache {
370370
if let Some(pos) = cache.lookup(id) {
371371
return Ok(Some(LazyCommit {
372+
hash_kind: id.kind(),
372373
backing: Either::Right((cache, pos)),
373374
}));
374375
}
@@ -380,6 +381,7 @@ fn try_lookup<'graph, 'cache>(
380381
.map_err(gix_object::find::existing_iter::Error::Find)?
381382
{
382383
Some(data) => data.kind.is_commit().then_some(LazyCommit {
384+
hash_kind: data.hash_kind,
383385
backing: Either::Left(buf),
384386
}),
385387
None => None,
@@ -439,6 +441,7 @@ where
439441
///
440442
/// The owned version of this type is called [`Commit`] and can be obtained by calling [`LazyCommit::to_owned()`].
441443
pub struct LazyCommit<'graph, 'cache> {
444+
hash_kind: gix_hash::Kind,
442445
backing: Either<&'graph [u8], (&'cache gix_commitgraph::Graph, gix_commitgraph::Position)>,
443446
}
444447

gix-traverse/src/commit/simple.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ pub(super) struct State {
138138
queue: CommitDateQueue,
139139
/// Backing storage for the currently yielded commit.
140140
buf: Vec<u8>,
141+
/// The object hash kind of the currently yielded commit data in `buf`.
142+
/// It's used to know the kind of hash to expect when a new iterator is returned from `buf`
143+
/// via `Simple::commit_iter()`.
144+
object_hash: gix_hash::Kind,
141145
/// Set of commits that were already enqueued for the visible traversal, for cycle-checking.
142146
seen: gix_hashtable::HashSet<ObjectId>,
143147
/// Hidden frontier commits that must not be yielded or crossed during traversal.
@@ -247,6 +251,7 @@ mod init {
247251
next: Default::default(),
248252
queue: gix_revwalk::PriorityQueue::new(),
249253
buf: vec![],
254+
object_hash: gix_hash::Kind::Sha1,
250255
seen: Default::default(),
251256
hidden: Default::default(),
252257
hidden_tips: Vec::new(),
@@ -262,6 +267,7 @@ mod init {
262267
next,
263268
queue,
264269
buf,
270+
object_hash,
265271
seen,
266272
hidden,
267273
hidden_tips,
@@ -271,6 +277,7 @@ mod init {
271277
next.clear();
272278
queue.clear();
273279
buf.clear();
280+
*object_hash = gix_hash::Kind::Sha1;
274281
seen.clear();
275282
hidden.clear();
276283
hidden_tips.clear();
@@ -464,7 +471,7 @@ mod init {
464471
impl<Find, Predicate> Simple<Find, Predicate> {
465472
/// Return an iterator for accessing data of the current commit, parsed lazily.
466473
pub fn commit_iter(&self) -> CommitRefIter<'_> {
467-
CommitRefIter::from_bytes(self.commit_data())
474+
CommitRefIter::from_bytes(self.commit_data(), self.state.object_hash)
468475
}
469476

470477
/// Return the current commits' raw data, which can be parsed using [`gix_object::CommitRef::from_bytes()`].
@@ -519,6 +526,7 @@ mod init {
519526
let (commit_time, oid) = match next.pop()? {
520527
(Ok(t) | Err(Reverse(t)), o) => (t, o),
521528
};
529+
state.object_hash = oid.kind();
522530
if state.hidden.contains_key(&oid) {
523531
continue;
524532
}
@@ -592,6 +600,7 @@ mod init {
592600

593601
loop {
594602
let oid = next.pop_front()?;
603+
state.object_hash = oid.kind();
595604
if state.hidden.contains_key(&oid) {
596605
continue;
597606
}

gix/src/object/commit.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'repo> Commit<'repo> {
8686
/// # Ok(()) }
8787
/// ```
8888
pub fn message_raw(&self) -> Result<&'_ BStr, gix_object::decode::Error> {
89-
gix_object::CommitRefIter::from_bytes(&self.data).message()
89+
gix_object::CommitRefIter::from_bytes(&self.data, self.id.kind()).message()
9090
}
9191
/// Obtain the message by using intricate knowledge about the encoding, which is fastest and
9292
/// can't fail at the expense of error handling.
@@ -114,24 +114,24 @@ impl<'repo> Commit<'repo> {
114114
/// used for successive calls to string-ish information to avoid decoding the object
115115
/// more than once.
116116
pub fn decode(&self) -> Result<gix_object::CommitRef<'_>, gix_object::decode::Error> {
117-
gix_object::CommitRef::from_bytes(&self.data)
117+
gix_object::CommitRef::from_bytes(&self.data, self.id.kind())
118118
}
119119

120120
/// Return an iterator over tokens, representing this commit piece by piece.
121121
pub fn iter(&self) -> gix_object::CommitRefIter<'_> {
122-
gix_object::CommitRefIter::from_bytes(&self.data)
122+
gix_object::CommitRefIter::from_bytes(&self.data, self.id.kind())
123123
}
124124

125125
/// Return the commits author, with surrounding whitespace trimmed.
126126
pub fn author(&self) -> Result<gix_actor::SignatureRef<'_>, gix_object::decode::Error> {
127-
gix_object::CommitRefIter::from_bytes(&self.data)
127+
gix_object::CommitRefIter::from_bytes(&self.data, self.id.kind())
128128
.author()
129129
.map(|s| s.trim())
130130
}
131131

132132
/// Return the commits committer. with surrounding whitespace trimmed.
133133
pub fn committer(&self) -> Result<gix_actor::SignatureRef<'_>, gix_object::decode::Error> {
134-
gix_object::CommitRefIter::from_bytes(&self.data)
134+
gix_object::CommitRefIter::from_bytes(&self.data, self.id.kind())
135135
.committer()
136136
.map(|s| s.trim())
137137
}
@@ -153,7 +153,7 @@ impl<'repo> Commit<'repo> {
153153
pub fn parent_ids(&self) -> impl Iterator<Item = crate::Id<'repo>> + '_ {
154154
use crate::ext::ObjectIdExt;
155155
let repo = self.repo;
156-
gix_object::CommitRefIter::from_bytes(&self.data)
156+
gix_object::CommitRefIter::from_bytes(&self.data, self.id.kind())
157157
.parent_ids()
158158
.map(move |id| id.attach(repo))
159159
}
@@ -181,7 +181,7 @@ impl<'repo> Commit<'repo> {
181181

182182
/// Parse the commit and return the tree id it points to.
183183
pub fn tree_id(&self) -> Result<crate::Id<'repo>, gix_object::decode::Error> {
184-
gix_object::CommitRefIter::from_bytes(&self.data)
184+
gix_object::CommitRefIter::from_bytes(&self.data, self.id.kind())
185185
.tree_id()
186186
.map(|id| crate::Id::from_id(id, self.repo))
187187
}
@@ -217,7 +217,7 @@ impl<'repo> Commit<'repo> {
217217
&self,
218218
) -> Result<Option<(std::borrow::Cow<'_, BStr>, gix_object::commit::SignedData<'_>)>, gix_object::decode::Error>
219219
{
220-
gix_object::CommitRefIter::signature(&self.data)
220+
gix_object::CommitRefIter::signature(&self.data, self.id.kind())
221221
}
222222
}
223223

gix/src/object/tag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ impl<'repo> Tag<'repo> {
99
/// used for successive calls to string-ish information to avoid decoding the object
1010
/// more than once.
1111
pub fn decode(&self) -> Result<gix_object::TagRef<'_>, gix_object::decode::Error> {
12-
gix_object::TagRef::from_bytes(&self.data)
12+
gix_object::TagRef::from_bytes(&self.data, self.id.kind())
1313
}
1414

1515
/// Decode this tag partially and return the id of its target.
1616
pub fn target_id(&self) -> Result<crate::Id<'repo>, gix_object::decode::Error> {
17-
gix_object::TagRefIter::from_bytes(&self.data)
17+
gix_object::TagRefIter::from_bytes(&self.data, self.id.kind())
1818
.target_id()
1919
.map(|id| id.attach(self.repo))
2020
}
2121

2222
/// Decode this tag partially and return the tagger, if the field exists.
2323
pub fn tagger(&self) -> Result<Option<gix_actor::SignatureRef<'_>>, gix_object::decode::Error> {
24-
gix_object::TagRefIter::from_bytes(&self.data).tagger()
24+
gix_object::TagRefIter::from_bytes(&self.data, self.id.kind()).tagger()
2525
}
2626
}
2727

0 commit comments

Comments
 (0)