Get file content from optimized JSON data structure.
(json_data: dict, file_path: str, snapshot_type: str = "after")
| 31 | |
| 32 | |
| 33 | def get_file_content(json_data: dict, file_path: str, snapshot_type: str = "after") -> str: |
| 34 | """Get file content from optimized JSON data structure.""" |
| 35 | if not json_data or "content_manager" not in json_data: |
| 36 | return "" |
| 37 | |
| 38 | content_manager = json_data["content_manager"] |
| 39 | content_store = content_manager.get("content_store", {}) |
| 40 | |
| 41 | # Look through diffs to find the file in the specified snapshot type |
| 42 | for diff_data in json_data.get("diffs", []): |
| 43 | snapshot_data = diff_data.get(snapshot_type, {}) |
| 44 | file_hashes = snapshot_data.get("file_hashes", {}) |
| 45 | |
| 46 | # Get the content hash for this file from the snapshot |
| 47 | content_hash = file_hashes.get(file_path) |
| 48 | if content_hash: |
| 49 | return content_store.get(content_hash, "") |
| 50 | |
| 51 | return "" |
| 52 | |
| 53 | |
| 54 | def parse_diff_log(log_content: str) -> list[dict]: |