|
| 1 | +use gix_odb::Header; |
| 2 | +use gix_pack::Find; |
1 | 3 | use gix_testtools::tempfile;
|
2 | 4 |
|
3 | 5 | use crate::util::named_subrepo_opts;
|
@@ -538,77 +540,44 @@ mod find {
|
538 | 540 | }),
|
539 | 541 | "empty blob is considered a loose object"
|
540 | 542 | );
|
541 |
| - |
542 |
| - // Note: Unlike empty tree, empty blobs might actually exist in the repository. |
543 |
| - // The key point is that has_object() should always return true for empty blobs, |
544 |
| - // regardless of whether they are physically stored or not. |
545 | 543 | Ok(())
|
546 | 544 | }
|
547 | 545 | }
|
548 | 546 |
|
549 | 547 | #[test]
|
550 |
| -fn empty_blob_is_always_considered_present() -> crate::Result { |
551 |
| - use gix_object::Find; |
552 |
| - |
553 |
| - // Test with an empty in-memory repository to ensure empty blob is considered present |
554 |
| - // even when it doesn't physically exist |
555 |
| - let repo = empty_bare_in_memory_repo()?; |
556 |
| - let empty_blob = gix::hash::ObjectId::empty_blob(repo.object_hash()); |
557 |
| - |
558 |
| - // The key behavior being tested: has_object should return true for empty blob |
559 |
| - assert!(repo.has_object(empty_blob), "empty blob should always be considered present"); |
560 |
| - |
561 |
| - // Verify that the lower-level object database doesn't have it |
562 |
| - let mut buf = Vec::new(); |
563 |
| - let lower_level_result = repo.objects.try_find(&empty_blob, &mut buf)?; |
564 |
| - |
565 |
| - // Empty blob might or might not exist at the lower level - that's implementation dependent |
566 |
| - // But has_object should always return true regardless |
567 |
| - match lower_level_result { |
568 |
| - Some(_) => { |
569 |
| - // If it exists at the lower level, that's fine |
570 |
| - } |
571 |
| - None => { |
572 |
| - // If it doesn't exist at the lower level, has_object should still return true |
573 |
| - // thanks to our special handling |
574 |
| - } |
575 |
| - } |
576 |
| - |
577 |
| - Ok(()) |
578 |
| -} |
579 |
| - |
580 |
| -#[test] |
581 |
| -fn empty_blob_edge_cases() -> crate::Result { |
| 548 | +fn empty_objects_are_always_present_but_not_in_plumbing() -> crate::Result { |
582 | 549 | let repo = empty_bare_in_memory_repo()?;
|
583 | 550 | let empty_blob_id = gix::hash::ObjectId::empty_blob(repo.object_hash());
|
584 |
| - |
585 |
| - // Test all the related methods for empty blobs |
586 |
| - assert!(repo.has_object(&empty_blob_id), "has_object should return true"); |
587 |
| - |
588 |
| - // Test find_header |
| 551 | + |
| 552 | + assert!( |
| 553 | + repo.has_object(empty_blob_id), |
| 554 | + "empty object is always present even if it's not" |
| 555 | + ); |
| 556 | + assert!(!repo.objects.contains(&empty_blob_id)); |
| 557 | + |
589 | 558 | let header = repo.find_header(empty_blob_id)?;
|
590 | 559 | assert_eq!(header.kind(), gix_object::Kind::Blob);
|
591 | 560 | assert_eq!(header.size(), 0);
|
592 |
| - |
593 |
| - // Test try_find_header |
| 561 | + assert_eq!(repo.objects.try_header(&empty_blob_id)?, None); |
| 562 | + |
594 | 563 | let header = repo.try_find_header(empty_blob_id)?.expect("should find header");
|
595 | 564 | assert_eq!(header.kind(), gix_object::Kind::Blob);
|
596 | 565 | assert_eq!(header.size(), 0);
|
597 |
| - |
598 |
| - // Test find_object |
| 566 | + |
599 | 567 | let obj = repo.find_object(empty_blob_id)?;
|
600 | 568 | assert_eq!(obj.kind, gix_object::Kind::Blob);
|
601 | 569 | assert_eq!(obj.data.len(), 0);
|
602 |
| - |
603 |
| - // Test try_find_object |
| 570 | + |
| 571 | + let mut buf = Vec::new(); |
| 572 | + assert_eq!(repo.objects.try_find(&empty_blob_id, &mut buf)?, None); |
| 573 | + |
604 | 574 | let obj = repo.try_find_object(empty_blob_id)?.expect("should find object");
|
605 | 575 | assert_eq!(obj.kind, gix_object::Kind::Blob);
|
606 | 576 | assert_eq!(obj.data.len(), 0);
|
607 |
| - |
608 |
| - // Test that we can get a blob from the object |
609 |
| - let blob = obj.into_blob(); |
| 577 | + |
| 578 | + let blob = obj.try_into_blob()?; |
610 | 579 | assert_eq!(blob.data.len(), 0);
|
611 |
| - |
| 580 | + |
612 | 581 | Ok(())
|
613 | 582 | }
|
614 | 583 |
|
|
0 commit comments