computeDirectoryDiff method
Compute diffs for every file that differs between oldDir and newDir.
Implementation
Future<List<FileDiff>> computeDirectoryDiff(
String oldDir,
String newDir,
) async {
final oldFiles = await _listFiles(oldDir);
final newFiles = await _listFiles(newDir);
final allRelative = <String>{...oldFiles, ...newFiles};
final diffs = <FileDiff>[];
for (final rel in allRelative) {
final oldPath = '$oldDir/$rel';
final newPath = '$newDir/$rel';
final oldFile = File(oldPath);
final newFile = File(newPath);
final oldText = await oldFile.exists()
? await oldFile.readAsString()
: '';
final newText = await newFile.exists()
? await newFile.readAsString()
: '';
if (oldText == newText) continue;
final hunks = computeDiff(oldText, newText);
final stats = _computeStats(hunks);
diffs.add(FileDiff(path: rel, oldPath: rel, hunks: hunks, stats: stats));
}
return diffs;
}