EasyRepository SystemsPython 3

Repository Diff

Compare two repository snapshots and produce deterministic added, removed, and modified file changes.

30m3 sample tests5 hidden tests

Implement diff_repositories(old_files, new_files), a deterministic file-level diff between two repository snapshots.

Requirements

  • Inputs are dictionaries from path to content hash.
  • Return a list of (status, path) pairs.
  • Status must be "ADDED", "REMOVED", or "MODIFIED".
  • Unchanged files must not appear.
  • Output must be sorted by path. At most one event is emitted per path, so a secondary status sort never changes order.
  • Treat renames as remove plus add.
  • Raise ValueError for invalid paths with empty segments, . segments, or .. traversal (validate keys in both old_files and new_files).
  • Leave old_files and new_files unchanged.

Example

python
1old = {"README.md": "a", "src/app.py": "1"} 2new = {"README.md": "a", "src/app.py": "2", "src/test.py": "3"} 3 4assert diff_repositories(old, new) == [ 5 ("MODIFIED", "src/app.py"), 6 ("ADDED", "src/test.py"), 7]

Constraints

  • Keep the implementation deterministic.
  • Use the provided content hashes directly.
  • Don't try to infer renames unless a follow-up asks for it.

Editor