MCPcopy
hub / github.com/codeaashu/claude-code / fileHistoryRestoreStateFromLog

Function fileHistoryRestoreStateFromLog

src/utils/fileHistory.ts:888–917  ·  view source on GitHub ↗
(
  fileHistorySnapshots: FileHistorySnapshot[],
  onUpdateState: (newState: FileHistoryState) => void,
)

Source from the content-addressed store, hash-verified

886 * Restores file history snapshot state for a given log option.
887 */
888export 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.

Callers 2

Calls 5

fileHistoryEnabledFunction · 0.85
maybeShortenFilePathFunction · 0.85
entriesMethod · 0.80
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected