History

migrate hashing API users to fallible versions

Emily committed 1 year ago

Commit fbf6cc81 parent f2b07c032 files · +115 −84Browse files

Unified · Split

32 files
  1. gix-commitgraph/src/file/verify.rs +1 −1
  2. gix-diff/tests/diff/blob/pipeline.rs +14 −14
  3. gix-diff/tests/diff/blob/platform.rs +4 −4
  4. gix-diff/tests/diff/main.rs +3 −3
  5. gix-diff/tests/diff/rewrites/tracker.rs +11 −11
  6. gix-filter/src/ident.rs +1 −1
  7. gix-hash/src/hasher/io.rs +1 −1
  8. gix-index/src/extension/end_of_index_entry/decode.rs +1 −1
  9. gix-index/src/extension/end_of_index_entry/write.rs +1 −1
  10. gix-index/src/file/write.rs +1 −1
  11. gix-merge/tests/merge/blob/mod.rs +3 −3
  12. gix-merge/tests/merge/blob/pipeline.rs +6 −6
  13. gix-merge/tests/merge/blob/platform.rs +5 −5
  14. gix-object/benches/edit_tree.rs +1 −1
  15. gix-object/src/data.rs +1 −1
  16. gix-object/tests/object/main.rs +2 −2
  17. gix-object/tests/object/tree/editor.rs +1 −1
  18. gix-odb/src/memory.rs +1 −1
  19. gix-odb/src/sink.rs +1 −1
  20. gix-odb/src/store_impls/loose/verify.rs +5 −1
  21. gix-odb/src/store_impls/loose/write.rs +5 −1
  22. gix-pack/src/data/input/bytes_to_entries.rs +2 −2
  23. gix-pack/src/data/output/bytes.rs +6 −1
  24. gix-pack/src/index/encode.rs +1 −1
  25. gix-pack/src/index/write/mod.rs +10 −7
  26. gix-pack/src/multi_index/write.rs +1 −1
  27. gix-pack/src/verify.rs +2 −1
  28. gix-status/src/index_as_worktree/traits.rs +4 −2
  29. gix-status/src/index_as_worktree_with_renames/mod.rs +8 −3
  30. gix/src/repository/impls.rs +1 −1
  31. gix/src/repository/object.rs +6 −3
  32. tests/it/src/commands/git_to_sh.rs +5 −1
gix-commitgraph/src/file/verify.rs+1−1
@@ -156,7 +156,7 @@ impl File { · 155 unmodified lines
156156 let data_len_without_trailer = self.data.len() - self.hash_len;
157157 let mut hasher = gix_hash::hasher(self.object_hash());
158158 hasher.update(&self.data[..data_len_without_trailer]);
159− let actual = hasher.finalize();
159+ let actual = hasher.try_finalize()?;
160160 actual.verify(self.checksum())?;
161161 Ok(actual)
162162 }
gix-diff/tests/diff/blob/pipeline.rs+14−14
@@ -72,7 +72,7 @@ pub(crate) mod convert_to_diffable { · 71 unmodified lines
7272
7373 let mut db = ObjectDb::default();
7474 let b_content = "b-content";
75− let id = db.insert(b_content);
75+ let id = db.insert(b_content)?;
7676
7777 let out = filter.convert_to_diffable(
7878 &id,
@@ -129,7 +129,7 @@ pub(crate) mod convert_to_diffable { · 50 unmodified lines
129129 assert_eq!(buf.len(), 0, "it should avoid querying that data in the first place");
130130
131131 let mut db = ObjectDb::default();
132− let id = db.insert(large_content);
132+ let id = db.insert(large_content)?;
133133 let out = filter.convert_to_diffable(
134134 &id,
135135 EntryKind::Blob,
@@ -211,7 +211,7 @@ pub(crate) mod convert_to_diffable { · 75 unmodified lines
211211 drop(tmp);
212212
213213 let mut db = ObjectDb::default();
214− let id = db.insert(large_content);
214+ let id = db.insert(large_content)?;
215215
216216 let out = filter.convert_to_diffable(
217217 &id,
@@ -397,7 +397,7 @@ pub(crate) mod convert_to_diffable { · 179 unmodified lines
397397
398398 let mut db = ObjectDb::default();
399399 let b_content = "b-content\n";
400− let id = db.insert(b_content);
400+ let id = db.insert(b_content)?;
401401
402402 let out = filter.convert_to_diffable(
403403 &id,
@@ -416,7 +416,7 @@ pub(crate) mod convert_to_diffable { · 12 unmodified lines
416416
417417 let mut db = ObjectDb::default();
418418 let b_content = "b\n";
419− let id = db.insert(b_content);
419+ let id = db.insert(b_content)?;
420420 let out = filter.convert_to_diffable(
421421 &id,
422422 EntryKind::Blob,
@@ -490,7 +490,7 @@ pub(crate) mod convert_to_diffable { · 67 unmodified lines
490490
491491 let mut db = ObjectDb::default();
492492 let b_content = "b-co\0ntent\n";
493− let id = db.insert(b_content);
493+ let id = db.insert(b_content)?;
494494
495495 let out = filter.convert_to_diffable(
496496 &id,
@@ -509,7 +509,7 @@ pub(crate) mod convert_to_diffable { · 12 unmodified lines
509509
510510 let platform = attributes.at_entry("c", None, &gix_object::find::Never)?;
511511
512− let id = db.insert("b");
512+ let id = db.insert("b")?;
513513 let out = filter.convert_to_diffable(
514514 &id,
515515 EntryKind::Blob,
@@ -638,7 +638,7 @@ pub(crate) mod convert_to_diffable { · 122 unmodified lines
638638 assert_eq!(out.data, Some(pipeline::Data::Buffer { is_derived: false }));
639639 assert_eq!(buf.as_bstr(), "a\n", "unconditionally use git according to mode");
640640
641− let id = db.insert("a\n");
641+ let id = db.insert("a\n")?;
642642 for mode in worktree_modes {
643643 let out = filter.convert_to_diffable(
644644 &id,
@@ -714,7 +714,7 @@ pub(crate) mod convert_to_diffable { · 69 unmodified lines
714714 assert_eq!(buf.len(), 0, "always cleared");
715715
716716 buf.push(1);
717− let id = db.insert("link-target");
717+ let id = db.insert("link-target")?;
718718 let out = filter.convert_to_diffable(
719719 &id,
720720 EntryKind::Link,
@@ -761,7 +761,7 @@ pub(crate) mod convert_to_diffable { · 40 unmodified lines
761761 assert_eq!(buf.len(), 0, "it's always cleared before any potential use");
762762 }
763763
764− let id = db.insert("b\n");
764+ let id = db.insert("b\n")?;
765765 for mode in all_modes {
766766 buf.push(1);
767767 let out = filter.convert_to_diffable(
@@ -814,7 +814,7 @@ pub(crate) mod convert_to_diffable { · 46 unmodified lines
814814 );
815815 }
816816
817− let id = db.insert("c\n");
817+ let id = db.insert("c\n")?;
818818 for mode in worktree_modes {
819819 let out = filter.convert_to_diffable(
820820 &id,
@@ -863,7 +863,7 @@ pub(crate) mod convert_to_diffable { · 42 unmodified lines
863863 assert_eq!(buf.len(), 0);
864864 }
865865
866− let id = db.insert("unset\n");
866+ let id = db.insert("unset\n")?;
867867 for mode in all_modes {
868868 let out = filter.convert_to_diffable(
869869 &id,
@@ -890,7 +890,7 @@ pub(crate) mod convert_to_diffable { · 20 unmodified lines
890890 }
891891
892892 let platform = attributes.at_entry("d", None, &gix_object::find::Never)?;
893− let id = db.insert("d-in-db");
893+ let id = db.insert("d-in-db")?;
894894 for mode in worktree_modes {
895895 let out = filter.convert_to_diffable(
896896 &null,
@@ -959,7 +959,7 @@ pub(crate) mod convert_to_diffable { · 62 unmodified lines
959959 "no text filter, so git conversion was applied for worktree source"
960960 );
961961
962− let id = db.insert("e-in-db");
962+ let id = db.insert("e-in-db")?;
963963 let out = filter.convert_to_diffable(
964964 &id,
965965 EntryKind::Blob,
gix-diff/tests/diff/blob/platform.rs+4−4
@@ -30,7 +30,7 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result { · 29 unmodified lines
3030
3131 let mut db = ObjectDb::default();
3232 let a_content = "a-content";
33− let id = db.insert(a_content);
33+ let id = db.insert(a_content)?;
3434 platform.set_resource(
3535 id,
3636 EntryKind::BlobExecutable,
@@ -194,7 +194,7 @@ fn diff_binary() -> crate::Result { · 157 unmodified lines
194194
195195 let mut db = ObjectDb::default();
196196 let a_content = "b";
197− let id = db.insert(a_content);
197+ let id = db.insert(a_content)?;
198198 platform.set_resource(id, EntryKind::Blob, "b".into(), ResourceKind::NewOrDestination, &db)?;
199199
200200 let out = platform.prepare_diff()?;
@@ -235,7 +235,7 @@ fn diff_performed_despite_external_command() -> crate::Result { · 34 unmodified lines
235235
236236 let mut db = ObjectDb::default();
237237 let a_content = "b";
238− let id = db.insert(a_content);
238+ let id = db.insert(a_content)?;
239239 platform.set_resource(id, EntryKind::Blob, "b".into(), ResourceKind::NewOrDestination, &db)?;
240240
241241 let out = platform.prepare_diff()?;
@@ -277,7 +277,7 @@ fn diff_skipped_due_to_external_command_and_enabled_option() -> crate::Result { · 35 unmodified lines
277277
278278 let mut db = ObjectDb::default();
279279 let a_content = "b";
280− let id = db.insert(a_content);
280+ let id = db.insert(a_content)?;
281281 platform.set_resource(id, EntryKind::Blob, "b".into(), ResourceKind::NewOrDestination, &db)?;
282282
283283 let out = platform.prepare_diff()?;
gix-diff/tests/diff/main.rs+3−3
@@ -51,10 +51,10 @@ mod util { · 50 unmodified lines
5151
5252 impl ObjectDb {
5353 /// Insert `data` and return its hash. That can be used to find it again.
54− pub fn insert(&mut self, data: &str) -> gix_hash::ObjectId {
55− let id = gix_object::compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Blob, data.as_bytes());
54+ pub fn insert(&mut self, data: &str) -> Result<gix_hash::ObjectId, Error> {
55+ let id = gix_object::try_compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Blob, data.as_bytes())?;
5656 self.data_by_id.insert(id, data.into());
57− id
57+ Ok(id)
5858 }
5959 }
6060 }
gix-diff/tests/diff/rewrites/tracker.rs+11−11
@@ -92,7 +92,7 @@ fn copy_by_similarity_reports_limit_if_encountered() -> crate::Result { · 91 unmodified lines
9292 (Change::addition(), "a-cpy-2", "a"),
9393 (Change::modification(), "d", "ab"),
9494 ],
95− );
95+ )?;
9696
9797 let mut calls = 0;
9898 let out = util::assert_emit_with_objects(
@@ -145,7 +145,7 @@ fn copy_by_id() -> crate::Result { · 46 unmodified lines
145145 (Change::addition(), "a-cpy-2", "a"),
146146 (Change::modification(), "d", "a"),
147147 ],
148− );
148+ )?;
149149
150150 let mut calls = 0;
151151 let out = util::assert_emit_with_objects(
@@ -218,7 +218,7 @@ fn copy_by_id_search_in_all_sources() -> crate::Result { · 66 unmodified lines
218218 (Change::addition(), "a-cpy-1", "a"),
219219 (Change::addition(), "a-cpy-2", "a"),
220220 ],
221− );
221+ )?;
222222
223223 let mut calls = 0;
224224 let content_id = hex_to_id("2e65efe2a145dda7ee51d1741299f848e5bf752e");
@@ -299,7 +299,7 @@ fn copy_by_50_percent_similarity() -> crate::Result { · 74 unmodified lines
299299 (Change::addition(), "a-cpy-2", "a\nc"),
300300 (Change::modification(), "d", "a"),
301301 ],
302− );
302+ )?;
303303
304304 let mut calls = 0;
305305 let out = util::assert_emit_with_objects(
@@ -377,7 +377,7 @@ fn copy_by_id_in_additions_only() -> crate::Result { · 71 unmodified lines
377377 (Change::modification(), "a", "a"),
378378 (Change::modification(), "a-cpy-1", "a"),
379379 ],
380− );
380+ )?;
381381
382382 let mut calls = 0;
383383 let out = util::assert_emit_with_objects(
@@ -429,7 +429,7 @@ fn rename_by_similarity_reports_limit_if_encountered() -> crate::Result { · 45 unmodified lines
429429 (Change::addition(), "b", "firt\nsecond\n"),
430430 (Change::addition(), "c", "second\nunrelated\n"),
431431 ],
432− );
432+ )?;
433433
434434 let mut calls = 0;
435435 let out = util::assert_emit_with_objects(
@@ -475,7 +475,7 @@ fn rename_by_50_percent_similarity() -> crate::Result { · 39 unmodified lines
475475 (Change::addition(), "b", "firt\nsecond\n"),
476476 (Change::addition(), "c", "second\nunrelated\n"),
477477 ],
478− );
478+ )?;
479479
480480 let mut calls = 0;
481481 let out = util::assert_emit_with_objects(
@@ -596,7 +596,7 @@ fn directory_renames_by_id_can_fail_gracefully() -> crate::Result { · 114 unmodified lines
596596 (Change::deletion(), "a", "first\nsecond\n"),
597597 (Change::addition(), "b", "firt\nsecond\n"),
598598 ],
599− );
599+ )?;
600600
601601 let mut calls = 0;
602602 let out = util::assert_emit_with_objects(
@@ -803,16 +803,16 @@ mod util { · 200 unmodified lines
803803 pub fn add_retained_blobs<'a>(
804804 tracker: &mut rewrites::Tracker<Change>,
805805 blobs: impl IntoIterator<Item = (Change, &'a str, &'a str)>,
806− ) -> ObjectDb {
806+ ) -> crate::Result<ObjectDb> {
807807 let mut db = ObjectDb::default();
808808 for (mut change, location, data) in blobs {
809− change.id = db.insert(data);
809+ change.id = db.insert(data)?;
810810 assert!(
811811 tracker.try_push_change(change, location.into()).is_none(),
812812 "input changes must be tracked"
813813 );
814814 }
815− db
815+ Ok(db)
816816 }
817817
818818 pub fn assert_emit(
gix-filter/src/ident.rs+1−1
@@ -68,7 +68,7 @@ pub fn apply(src: &[u8], object_hash: gix_hash::Kind, buf: &mut Vec<u8>) -> Resu · 67 unmodified lines
6868 while let Some(pos) = src[ofs..].find(b"$Id$") {
6969 let id = match id {
7070 None => {
71− let new_id = gix_object::compute_hash(object_hash, gix_object::Kind::Blob, src);
71+ let new_id = gix_object::try_compute_hash(object_hash, gix_object::Kind::Blob, src)?;
7272 id = new_id.into();
7373 clear_and_set_capacity(buf, src.len() + HASH_LEN)?; // pre-allocate for one ID
7474 new_id
gix-hash/src/hasher/io.rs+1−1
@@ -76,7 +76,7 @@ pub fn bytes_with_hasher( · 75 unmodified lines
7676 }
7777 }
7878
79− let id = hasher.finalize();
79+ let id = hasher.try_finalize()?;
8080 progress.show_throughput(start);
8181 Ok(id)
8282 }
gix-index/src/extension/end_of_index_entry/decode.rs+1−1
@@ -44,7 +44,7 @@ pub fn decode(data: &[u8], object_hash: gix_hash::Kind) -> Result<Option<usize>, · 43 unmodified lines
4444 last_chunk = Some(chunk);
4545 }
4646
47− if hasher.finalize().verify(checksum).is_err() {
47+ if hasher.try_finalize()?.verify(checksum).is_err() {
4848 return Ok(None);
4949 }
5050 // The last-to-this chunk ends where ours starts
gix-index/src/extension/end_of_index_entry/write.rs+1−1
@@ -23,7 +23,7 @@ pub fn write_to( · 22 unmodified lines
2323 hasher.update(&signature);
2424 hasher.update(&size.to_be_bytes());
2525 }
26− out.write_all(hasher.finalize().as_slice())?;
26+ out.write_all(hasher.try_finalize()?.as_slice())?;
2727
2828 Ok(())
2929 }
gix-index/src/file/write.rs+1−1
@@ -31,7 +31,7 @@ impl File { · 30 unmodified lines
3131 let mut hasher = hasher::io::Write::new(&mut out, self.state.object_hash);
3232 let out: &mut dyn std::io::Write = &mut hasher;
3333 let version = self.state.write_to(out, options)?;
34− (version, hasher.hash.finalize())
34+ (version, hasher.hash.try_finalize()?)
3535 };
3636 out.write_all(hash.as_slice())?;
3737 Ok((version, hash))
gix-merge/tests/merge/blob/mod.rs+3−3
@@ -43,10 +43,10 @@ mod util { · 42 unmodified lines
4343
4444 impl ObjectDb {
4545 /// Insert `data` and return its hash. That can be used to find it again.
46− pub fn insert(&mut self, data: &str) -> gix_hash::ObjectId {
47− let id = gix_object::compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Blob, data.as_bytes());
46+ pub fn insert(&mut self, data: &str) -> Result<gix_hash::ObjectId, Error> {
47+ let id = gix_object::try_compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Blob, data.as_bytes())?;
4848 self.data_by_id.insert(id, data.into());
49− id
49+ Ok(id)
5050 }
5151 }
5252 }
gix-merge/tests/merge/blob/pipeline.rs+6−6
@@ -67,7 +67,7 @@ fn without_transformation() -> crate::Result { · 66 unmodified lines
6767
6868 let mut db = ObjectDb::default();
6969 let b_content = "b-content";
70− let id = db.insert(b_content);
70+ let id = db.insert(b_content)?;
7171
7272 let out = filter.convert_to_mergeable(
7373 &id,
@@ -148,7 +148,7 @@ fn binary_below_large_file_threshold() -> crate::Result { · 74 unmodified lines
148148 assert_eq!(buf.as_bstr(), binary_content);
149149
150150 let mut db = ObjectDb::default();
151− let id = db.insert(binary_content);
151+ let id = db.insert(binary_content)?;
152152 let out = filter.convert_to_mergeable(
153153 &id,
154154 EntryKind::Blob,
@@ -203,7 +203,7 @@ fn above_large_file_threshold() -> crate::Result { · 48 unmodified lines
203203
204204 drop(tmp);
205205 let mut db = ObjectDb::default();
206− let id = db.insert(large_content);
206+ let id = db.insert(large_content)?;
207207
208208 let out = filter.convert_to_mergeable(
209209 &id,
@@ -352,7 +352,7 @@ fn worktree_filter() -> crate::Result { · 142 unmodified lines
352352 "worktree files need to be converted back to what's stored in Git"
353353 );
354354
355− let id = db.insert(a_content);
355+ let id = db.insert(a_content)?;
356356 let out = filter.convert_to_mergeable(
357357 &id,
358358 EntryKind::Blob,
@@ -385,7 +385,7 @@ fn worktree_filter() -> crate::Result { · 26 unmodified lines
385385 drop(tmp);
386386
387387 let b_content = "b-content\n";
388− let id = db.insert(b_content);
388+ let id = db.insert(b_content)?;
389389
390390 let out = filter.convert_to_mergeable(
391391 &id,
@@ -403,7 +403,7 @@ fn worktree_filter() -> crate::Result { · 11 unmodified lines
403403
404404 let mut db = ObjectDb::default();
405405 let b_content = "b-content\r\n";
406− let id = db.insert(b_content);
406+ let id = db.insert(b_content)?;
407407 let out = filter.convert_to_mergeable(
408408 &id,
409409 EntryKind::Blob,
gix-merge/tests/merge/blob/platform.rs+5−5
@@ -31,7 +31,7 @@ mod merge { · 30 unmodified lines
3131 ("ours", ResourceKind::CurrentOrOurs),
3232 ("theirs\0", ResourceKind::OtherOrTheirs),
3333 ] {
34− let id = db.insert(content);
34+ let id = db.insert(content)?;
3535 platform.set_resource(
3636 id,
3737 EntryKind::Blob,
@@ -81,7 +81,7 @@ mod merge { · 43 unmodified lines
8181 ("any\0", ResourceKind::CurrentOrOurs),
8282 ("any\0", ResourceKind::OtherOrTheirs),
8383 ] {
84− let id = db.insert(content);
84+ let id = db.insert(content)?;
8585 platform.set_resource(
8686 id,
8787 EntryKind::Blob,
@@ -131,7 +131,7 @@ mod merge { · 43 unmodified lines
131131 ("ours", ResourceKind::CurrentOrOurs),
132132 ("theirs", ResourceKind::OtherOrTheirs),
133133 ] {
134− let id = db.insert(content);
134+ let id = db.insert(content)?;
135135 platform.set_resource(id, EntryKind::Blob, "b".into(), kind, &db)?;
136136 }
137137
@@ -284,7 +284,7 @@ theirs · 146 unmodified lines
284284 ("ours", ResourceKind::CurrentOrOurs),
285285 ("theirs", ResourceKind::OtherOrTheirs),
286286 ] {
287− let id = db.insert(content);
287+ let id = db.insert(content)?;
288288 platform.set_resource(id, EntryKind::Blob, "b".into(), kind, &db)?;
289289 }
290290
@@ -313,7 +313,7 @@ theirs · 22 unmodified lines
313313 "we handle word-splitting and definitely pick-up what's written into the %A buffer"
314314 );
315315
316− let id = db.insert("binary\0");
316+ let id = db.insert("binary\0")?;
317317 platform.set_resource(id, EntryKind::Blob, "b".into(), ResourceKind::OtherOrTheirs, &db)?;
318318 let platform_ref = platform.prepare_merge(&db, Default::default())?;
319319 let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
gix-object/benches/edit_tree.rs+1−1
@@ -147,7 +147,7 @@ fn new_inmemory_writes() -> ( · 146 unmodified lines
147147 move |tree: &Tree| {
148148 buf.clear();
149149 tree.write_to(&mut buf)?;
150− let id = gix_object::compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Tree, &buf);
150+ let id = gix_object::try_compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Tree, &buf)?;
151151 let mut borrowed = store.borrow_mut();
152152 match borrowed.entry(id) {
153153 Entry::Occupied(_) => {}
gix-object/src/data.rs+1−1
@@ -66,7 +66,7 @@ pub mod verify { · 65 unmodified lines
6666 /// If the hashes do not match, an [`Error`] is returned, containing the actual
6767 /// hash of `self`.
6868 pub fn verify_checksum(&self, expected: &gix_hash::oid) -> Result<gix_hash::ObjectId, Error> {
69− let actual = crate::compute_hash(expected.kind(), self.kind, self.data);
69+ let actual = crate::try_compute_hash(expected.kind(), self.kind, self.data)?;
7070 actual.verify(expected)?;
7171 Ok(actual)
7272 }
gix-object/tests/object/main.rs+2−2
@@ -12,11 +12,11 @@ mod tree; · 11 unmodified lines
1212 fn compute_hash() {
1313 let hk = gix_hash::Kind::Sha1;
1414 assert_eq!(
15− gix_object::compute_hash(hk, gix_object::Kind::Blob, &[]),
15+ gix_object::try_compute_hash(hk, gix_object::Kind::Blob, &[]).expect("empty hash doesn’t collide"),
1616 gix_hash::ObjectId::empty_blob(hk)
1717 );
1818 assert_eq!(
19− gix_object::compute_hash(hk, gix_object::Kind::Tree, &[]),
19+ gix_object::try_compute_hash(hk, gix_object::Kind::Tree, &[]).expect("empty hash doesn’t collide"),
2020 gix_hash::ObjectId::empty_tree(hk)
2121 );
2222 }
gix-object/tests/object/tree/editor.rs+1−1
@@ -805,7 +805,7 @@ mod utils { · 804 unmodified lines
805805 move |tree: &Tree| {
806806 buf.clear();
807807 tree.write_to(&mut buf)?;
808− let id = gix_object::compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Tree, &buf);
808+ let id = gix_object::try_compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Tree, &buf)?;
809809 store.borrow_mut().insert(id, tree.clone());
810810 let old = num_writes.get();
811811 num_writes.set(old + 1);
gix-odb/src/memory.rs+1−1
@@ -219,7 +219,7 @@ where · 218 unmodified lines
219219 let mut buf = Vec::new();
220220 from.read_to_end(&mut buf)?;
221221
222− let id = gix_object::compute_hash(self.object_hash, kind, &buf);
222+ let id = gix_object::try_compute_hash(self.object_hash, kind, &buf)?;
223223 map.borrow_mut().insert(id, (kind, buf));
224224 Ok(id)
225225 }
gix-odb/src/sink.rs+1−1
@@ -53,6 +53,6 @@ impl gix_object::Write for Sink { · 52 unmodified lines
5353 c.reset();
5454 }
5555
56− Ok(hasher.finalize())
56+ Ok(hasher.try_finalize()?)
5757 }
5858 }
gix-odb/src/store_impls/loose/verify.rs+5−1
@@ -85,7 +85,11 @@ impl Store { · 84 unmodified lines
8585 .map_err(|_| integrity::Error::Retry)?
8686 .ok_or(integrity::Error::Retry)?;
8787 sink.write_buf(object.kind, object.data)
88− .expect("sink never fails")
88+ .map_err(|err| integrity::Error::ObjectHasher {
89+ source: *err.downcast().expect("sink can only fail in hasher"),
90+ kind: object.kind,
91+ expected: id,
92+ })?
8993 .verify(&id)
9094 .map_err(|err| integrity::Error::ObjectEncodeMismatch {
9195 source: err,
gix-odb/src/store_impls/loose/write.rs+5−1
@@ -130,7 +130,11 @@ impl Store { · 129 unmodified lines
130130 &self,
131131 hasher::io::Write { hash, inner: file }: hasher::io::Write<CompressedTempfile>,
132132 ) -> Result<gix_hash::ObjectId, Error> {
133− let id = hash.finalize();
133+ let id = hash.try_finalize().map_err(|err| Error::Io {
134+ source: err.into(),
135+ message: "hash tempfile in",
136+ path: self.path.to_owned(),
137+ })?;
134138 let object_path = loose::hash_path(&id, self.path.clone());
135139 let object_dir = object_path
136140 .parent()
gix-pack/src/data/input/bytes_to_entries.rs+2−2
@@ -180,7 +180,7 @@ where · 179 unmodified lines
180180 }
181181
182182 if let Some(hash) = self.hash.take() {
183− let actual_id = hash.finalize();
183+ let actual_id = hash.try_finalize().map_err(hasher::io::Error::from)?;
184184 if self.mode == input::Mode::Restore {
185185 id = actual_id;
186186 } else {
@@ -190,7 +190,7 @@ where · 3 unmodified lines
190190 Some(id)
191191 } else if self.mode == input::Mode::Restore {
192192 let hash = self.hash.clone().expect("in restore mode a hash is set");
193− Some(hash.finalize())
193+ Some(hash.try_finalize().map_err(hasher::io::Error::from)?)
194194 } else {
195195 None
196196 })
gix-pack/src/data/output/bytes.rs+6−1
@@ -126,7 +126,12 @@ where · 125 unmodified lines
126126 }
127127 }
128128 None => {
129− let digest = self.output.hash.clone().finalize();
129+ let digest = self
130+ .output
131+ .hash
132+ .clone()
133+ .try_finalize()
134+ .map_err(hasher::io::Error::from)?;
130135 self.output
131136 .inner
132137 .write_all(digest.as_slice())
gix-pack/src/index/encode.rs+1−1
@@ -137,7 +137,7 @@ mod function { · 136 unmodified lines
137137
138138 let bytes_written_without_trailer = out.bytes;
139139 let out = out.inner.into_inner().map_err(io::Error::from)?;
140− let index_hash = out.hash.finalize();
140+ let index_hash = out.hash.try_finalize()?;
141141 out.inner.write_all(index_hash.as_slice())?;
142142 out.inner.flush()?;
143143
gix-pack/src/index/write/mod.rs+10−7
@@ -193,10 +193,7 @@ impl crate::index::File { · 192 unmodified lines
193193 entry,
194194 decompressed: bytes,
195195 ..
196− }| {
197− modify_base(data, entry, bytes, version.hash());
198− Ok::<_, Error>(())
199− },
196+ }| { modify_base(data, entry, bytes, version.hash()) },
200197 traverse::Options {
201198 object_progress: Box::new(
202199 root_progress.add_child_with_id("Resolving".into(), ProgressId::ResolveObjects.into()),
@@ -228,7 +225,7 @@ impl crate::index::File { · 25 unmodified lines
228225 let header = crate::data::header::encode(pack_version, 0);
229226 let mut hasher = gix_hash::hasher(object_hash);
230227 hasher.update(&header);
231− hasher.finalize()
228+ hasher.try_finalize().map_err(hasher::io::Error::from)?
232229 }
233230 None => return Err(Error::IteratorInvariantTrailer),
234231 };
@@ -254,8 +251,14 @@ impl crate::index::File { · 19 unmodified lines
254251 }
255252 }
256253
257−fn modify_base(entry: &mut TreeEntry, pack_entry: &crate::data::Entry, decompressed: &[u8], hash: gix_hash::Kind) {
254+fn modify_base(
255+ entry: &mut TreeEntry,
256+ pack_entry: &crate::data::Entry,
257+ decompressed: &[u8],
258+ hash: gix_hash::Kind,
259+) -> Result<(), hasher::Error> {
258260 let object_kind = pack_entry.header.as_kind().expect("base object as source of iteration");
259− let id = gix_object::compute_hash(hash, object_kind, decompressed);
261+ let id = gix_object::try_compute_hash(hash, object_kind, decompressed)?;
260262 entry.id = id;
263+ Ok(())
261264 }
gix-pack/src/multi_index/write.rs+1−1
@@ -218,7 +218,7 @@ impl multi_index::File { · 217 unmodified lines
218218 }
219219
220220 // write trailing checksum
221− let multi_index_checksum = out.inner.hash.finalize();
221+ let multi_index_checksum = out.inner.hash.try_finalize().map_err(hasher::io::Error::from)?;
222222 out.inner
223223 .inner
224224 .write_all(multi_index_checksum.as_slice())
gix-pack/src/verify.rs+2−1
@@ -54,8 +54,9 @@ pub fn checksum_on_disk_or_mmap( · 53 unmodified lines
5454 hasher.update(&data[..data_len_without_trailer]);
5555 progress.inc_by(data_len_without_trailer);
5656 progress.show_throughput(start);
57− hasher.finalize()
57+ hasher.try_finalize()?
5858 }
59+ Err(hasher::io::Error::Hasher(err)) => return Err(checksum::Error::Hasher(err)),
5960 };
6061
6162 actual.verify(&expected)?;
gix-status/src/index_as_worktree/traits.rs+4−2
@@ -143,14 +143,16 @@ impl CompareBlobs for HashEq { · 142 unmodified lines
143143 let mut stream = data.stream_worktree_file()?;
144144 match stream.as_bytes() {
145145 Some(buffer) => {
146− let file_hash = gix_object::compute_hash(entry.id.kind(), gix_object::Kind::Blob, buffer);
146+ let file_hash = gix_object::try_compute_hash(entry.id.kind(), gix_object::Kind::Blob, buffer)
147+ .map_err(hasher::io::Error::from)?;
147148 Ok((entry.id != file_hash).then_some(file_hash))
148149 }
149150 None => {
150151 let file_hash = match stream.size() {
151152 None => {
152153 stream.read_to_end(buf).map_err(hasher::io::Error::from)?;
153− gix_object::compute_hash(entry.id.kind(), gix_object::Kind::Blob, buf)
154+ gix_object::try_compute_hash(entry.id.kind(), gix_object::Kind::Blob, buf)
155+ .map_err(hasher::io::Error::from)?
154156 }
155157 Some(len) => gix_object::compute_stream_hash(
156158 entry.id.kind(),
gix-status/src/index_as_worktree_with_renames/mod.rs+8−3
@@ -536,18 +536,23 @@ pub(super) mod function { · 535 unmodified lines
536536 should_interrupt,
537537 )
538538 .map_err(Error::HashFile)?,
539− ToGitOutcome::Buffer(buf) => gix_object::compute_hash(object_hash, gix_object::Kind::Blob, buf),
539+ ToGitOutcome::Buffer(buf) => {
540+ gix_object::try_compute_hash(object_hash, gix_object::Kind::Blob, buf)
541+ .map_err(|err| Error::HashFile(err.into()))?
542+ }
540543 ToGitOutcome::Process(mut stream) => {
541544 buf.clear();
542545 stream.read_to_end(buf).map_err(|err| Error::HashFile(err.into()))?;
543− gix_object::compute_hash(object_hash, gix_object::Kind::Blob, buf)
546+ gix_object::try_compute_hash(object_hash, gix_object::Kind::Blob, buf)
547+ .map_err(|err| Error::HashFile(err.into()))?
544548 }
545549 }
546550 }
547551 Kind::Symlink => {
548552 let path = worktree_root.join(gix_path::from_bstr(rela_path));
549553 let target = gix_path::into_bstr(std::fs::read_link(path).map_err(Error::ReadLink)?);
550− gix_object::compute_hash(object_hash, gix_object::Kind::Blob, &target)
554+ gix_object::try_compute_hash(object_hash, gix_object::Kind::Blob, &target)
555+ .map_err(|err| Error::HashFile(err.into()))?
551556 }
552557 Kind::Directory | Kind::Repository => object_hash.null(),
553558 })
gix/src/repository/impls.rs+1−1
@@ -106,7 +106,7 @@ impl gix_object::Write for crate::Repository { · 105 unmodified lines
106106 }
107107
108108 fn write_buf(&self, object: gix_object::Kind, from: &[u8]) -> Result<gix_hash::ObjectId, gix_object::write::Error> {
109− let oid = gix_object::compute_hash(self.object_hash(), object, from);
109+ let oid = gix_object::try_compute_hash(self.object_hash(), object, from)?;
110110 if self.objects.exists(&oid) {
111111 return Ok(oid);
112112 }
gix/src/repository/object.rs+6−3
@@ -172,7 +172,8 @@ impl crate::Repository { · 171 unmodified lines
172172 }
173173
174174 fn write_object_inner(&self, buf: &[u8], kind: gix_object::Kind) -> Result<Id<'_>, object::write::Error> {
175− let oid = gix_object::compute_hash(self.object_hash(), kind, buf);
175+ let oid = gix_object::try_compute_hash(self.object_hash(), kind, buf)
176+ .map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync>)?;
176177 if self.objects.exists(&oid) {
177178 return Ok(oid.attach(self));
178179 }
@@ -189,7 +190,8 @@ impl crate::Repository { · 10 unmodified lines
189190 /// pre-hashing the data, and checking if the object is already present.
190191 pub fn write_blob(&self, bytes: impl AsRef<[u8]>) -> Result<Id<'_>, object::write::Error> {
191192 let bytes = bytes.as_ref();
192− let oid = gix_object::compute_hash(self.object_hash(), gix_object::Kind::Blob, bytes);
193+ let oid = gix_object::try_compute_hash(self.object_hash(), gix_object::Kind::Blob, bytes)
194+ .map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync>)?;
193195 if self.objects.exists(&oid) {
194196 return Ok(oid.attach(self));
195197 }
@@ -214,7 +216,8 @@ impl crate::Repository { · 18 unmodified lines
214216 }
215217
216218 fn write_blob_stream_inner(&self, buf: &[u8]) -> Result<Id<'_>, object::write::Error> {
217− let oid = gix_object::compute_hash(self.object_hash(), gix_object::Kind::Blob, buf);
219+ let oid = gix_object::try_compute_hash(self.object_hash(), gix_object::Kind::Blob, buf)
220+ .map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync>)?;
218221 if self.objects.exists(&oid) {
219222 return Ok(oid.attach(self));
220223 }
tests/it/src/commands/git_to_sh.rs+5−1
@@ -115,7 +115,11 @@ pub(super) mod function { · 114 unmodified lines
115115 })?;
116116 let mapped = crate::commands::copy_royal::remapped(data);
117117 (
118− gix::objs::compute_hash(repo.object_hash(), gix::object::Kind::Blob, mapped.as_bytes()),
118+ gix::objs::try_compute_hash(
119+ repo.object_hash(),
120+ gix::object::Kind::Blob,
121+ mapped.as_bytes(),
122+ )?,
119123 Cow::Owned(mapped.into()),
120124 )
121125 }

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