Skip to content

Conversation

zhangfengcdt
Copy link
Owner

Exposes the get_keys_at_ref method to Python, allowing users to retrieve all key-value pairs at any historical reference point.

Changes

  • Added get_keys_at_ref method to PyVersionedKvStore in Python bindings
  • Method accepts a reference string (commit SHA, branch name, or HEAD) and returns all key-value pairs at that point
  • Added Python type hints in .pyi file for proper IDE support
  • Includes comprehensive test coverage for the new functionality

Use Cases

This feature enables Python users to:

  • Inspect database state at any historical commit
  • Compare data between different branches or commits
  • Build time-travel debugging tools
  • Implement audit trails and compliance features

Example Usage

# Get all keys at a specific commit
keys_at_commit = store.get_keys_at_ref("abc123def...")

# Get all keys on a branch
keys_on_branch = store.get_keys_at_ref("feature-branch")

# Get all keys at HEAD
current_keys = store.get_keys_at_ref("HEAD")

Expose the historical access functionality to Python, allowing users to
retrieve all key-value pairs at any git reference (commit, branch, or tag).

## Changes

### Python Bindings (src/python.rs)
- Add `get_keys_at_ref(reference: str) -> List[Tuple[bytes, bytes]]` method
- Properly handles HashMap to Python list of tuples conversion
- Thread-safe implementation with error handling

### Type Stubs (prollytree.pyi)
- Add complete type signature for `get_keys_at_ref`
- Include comprehensive documentation with examples
- Document all supported reference types (commits, branches, tags, HEAD~n, etc.)

### Testing
- Add comprehensive unit test `test_get_keys_at_ref`
- Verify access to historical states at different commits
- Test both commit hashes and symbolic references

## API Usage

```python
# Get all keys at a specific commit
pairs = store.get_keys_at_ref("abc123def")

# Get all keys from the main branch
pairs = store.get_keys_at_ref("main")

# Get all keys from current HEAD
pairs = store.get_keys_at_ref("HEAD")
```

This method is essential for time-travel debugging, auditing, and
understanding the complete state of the store at any point in history.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@zhangfengcdt zhangfengcdt force-pushed the feature/get_keys_at_ref branch from c19339f to a683b45 Compare August 26, 2025 15:09
- Added MAX_KEYS_LIMIT constant set to 1024
- Updated get_keys_at_ref to enforce limit with warning message
- Updated both PyVersionedKvStore and PyWorktreeVersionedKvStore list_keys methods
- Warning message suggests using more specific queries or pagination
- Prevents excessive memory usage when dealing with large datasets
@zhangfengcdt zhangfengcdt merged commit cc6cf7f into main Aug 26, 2025
5 checks passed
@zhangfengcdt zhangfengcdt deleted the feature/get_keys_at_ref branch August 29, 2025 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant