( fileHistorySnapshots: FileHistorySnapshot[], onUpdateState: (newState: FileHistoryState) => void, )
| 886 | * Restores file history snapshot state for a given log option. |
| 887 | */ |
| 888 | export function fileHistoryRestoreStateFromLog( |
| 889 | fileHistorySnapshots: FileHistorySnapshot[], |
| 890 | onUpdateState: (newState: FileHistoryState) => void, |
| 891 | ): void { |
| 892 | if (!fileHistoryEnabled()) { |
| 893 | return |
| 894 | } |
| 895 | // Make a copy of the snapshots as we migrate from absolute path to |
| 896 | // shortened relative tracking path. |
| 897 | const snapshots: FileHistorySnapshot[] = [] |
| 898 | // Rebuild the tracked files from the snapshots |
| 899 | const trackedFiles = new Set<string>() |
| 900 | for (const snapshot of fileHistorySnapshots) { |
| 901 | const trackedFileBackups: Record<string, FileHistoryBackup> = {} |
| 902 | for (const [path, backup] of Object.entries(snapshot.trackedFileBackups)) { |
| 903 | const trackingPath = maybeShortenFilePath(path) |
| 904 | trackedFiles.add(trackingPath) |
| 905 | trackedFileBackups[trackingPath] = backup |
| 906 | } |
| 907 | snapshots.push({ |
| 908 | ...snapshot, |
| 909 | trackedFileBackups: trackedFileBackups, |
| 910 | }) |
| 911 | } |
| 912 | onUpdateState({ |
| 913 | snapshots: snapshots, |
| 914 | trackedFiles: trackedFiles, |
| 915 | snapshotSequence: snapshots.length, |
| 916 | }) |
| 917 | } |
| 918 | |
| 919 | /** |
| 920 | * Copy file history snapshots for a given log option. |
no test coverage detected