Skip to content

Week 4 - M1: Object-store hardening + packfile groundwork #22

Description

@aman-a-shah

Owner: @mahis1067
Files: minigit/objects.py, tests/test_objects.py, docs/packfiles.md
Depends on: #16
Branch: week4/m1-object-store-hardening

Make corrupt objects fail clearly. Prepare the storage code for Week 5 packfiles.

Steps

  1. Start from updated main after Week 3 - M1: Tree object serialization #16 merges. Keep the existing object API and byte formats.
  2. Tighten read_object validation. Reject broken zlib data, malformed headers, unknown types, bad lengths, and hash mismatches with ObjectCorruptError.
    • Length means bytes, including for UTF-8 content.
    • Missing objects still raise ObjectNotFoundError.
  3. Validate hashes before building disk paths. Accept full 40-character lowercase hex hashes. Reject other input with ObjectNotFoundError.
  4. Make loose-object writes atomic: write a temporary file beside the destination, then rename it into place.
    • Clean up the temporary file on failure.
    • A duplicate write must validate the existing object before returning its hash.
    • An existing corrupt object raises ObjectCorruptError.
  5. Add has_object(hash: str) -> bool for M4.
    • Use read_object. Return False only for ObjectNotFoundError.
    • Let corruption errors reach the caller.
  6. Keep loose-file lookup in a private helper. Write a short docs/packfiles.md proposal covering record format, hash-to-offset lookup, and loose-file fallback. Packfile implementation starts in Week 5.
  7. Run scripts/quality-check.sh. Open a PR linked to this issue and request a teammate review.

Tests

  • Round-trip empty and binary blobs, trees, and commits through a fresh store.
  • Corrupt the header, length, payload, and compressed stream separately.
  • Check Unicode byte lengths and invalid hashes.
  • Simulate a failed write: no partial object at the final path; retry succeeds.
  • Check valid duplicates, corrupt duplicates, and all three has_object outcomes.
  • Use tmp_path for every test, including CLI tests.

Done when

  • Bad objects raise the shared errors.
  • Failed writes leave no partial object at its final path.
  • M4 can check object presence through has_object.
  • Packfile proposal is ready for review.
  • Quality check passes; PR open and review requested.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

module-1Object storageweek-4Week 4 - branching and checkout

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions