Read the content of the file in the specified commit.
(config: EvoGitConfig, commit: str, mode: str = "text")
| 459 | |
| 460 | |
| 461 | def read_file(config: EvoGitConfig, commit: str, mode: str = "text") -> str | bytes: |
| 462 | """Read the content of the file in the specified commit.""" |
| 463 | completed_proc = subprocess.run( |
| 464 | ["git", "show", f"{commit}:{config.filename}"], |
| 465 | cwd=config.git_dir, |
| 466 | check=True, |
| 467 | capture_output=True, |
| 468 | ) |
| 469 | |
| 470 | if mode == "text": |
| 471 | return completed_proc.stdout.decode("utf-8") |
| 472 | elif mode == "binary": |
| 473 | return completed_proc.stdout |
| 474 | else: |
| 475 | raise ValueError("mode must be either 'text' or 'binary'.") |
| 476 | |
| 477 | |
| 478 | def batch_read_files(config: EvoGitConfig, commits: list[str]) -> list[str]: |