trackBulkFileChanges method
AttributionState
trackBulkFileChanges({
- required AttributionState attrState,
- required List<
FileChange> changes,
Track multiple file changes in bulk, mutating a single Map copy.
Implementation
AttributionState trackBulkFileChanges({
required AttributionState attrState,
required List<FileChange> changes,
}) {
final newFileStates = Map<String, FileAttributionState>.from(
attrState.fileStates,
);
for (final change in changes) {
final effectiveMtime =
change.mtime ?? DateTime.now().millisecondsSinceEpoch;
if (change.type == 'deleted') {
final normalizedPath = normalizeFilePath(change.path);
final existingState = newFileStates[normalizedPath];
final existingContribution = existingState?.neomageContribution ?? 0;
final deletedChars = change.oldContent.length;
newFileStates[normalizedPath] = FileAttributionState(
contentHash: '',
neomageContribution: existingContribution + deletedChars,
mtime: effectiveMtime,
);
} else {
final newFileState = _computeFileModificationState(
existingFileStates: newFileStates,
filePath: change.path,
oldContent: change.oldContent,
newContent: change.newContent,
mtime: effectiveMtime,
);
if (newFileState != null) {
final normalizedPath = normalizeFilePath(change.path);
newFileStates[normalizedPath] = newFileState;
}
}
}
return attrState.copyWith(fileStates: newFileStates);
}