formatDriveChanges function

String formatDriveChanges(
  1. DriveChanges c, {
  2. required String mountId,
})

Renders a DriveChanges for omnyshell drive conflicts: the diverging paths grouped by which side changed, with true conflicts first. mountId tags the header.

Implementation

String formatDriveChanges(DriveChanges c, {required String mountId}) {
  if (c.isEmpty) return 'mount $mountId: in sync — no differences.';
  final buf = StringBuffer(
    'mount $mountId: ${c.total} diverging path${c.total == 1 ? '' : 's'}',
  );
  void section(String title, List<String> paths, String mark) {
    if (paths.isEmpty) return;
    buf.write('\n$title (${paths.length}):');
    for (final p in paths) {
      buf.write('\n  $mark $p');
    }
  }

  section(
    'conflicts — changed on both sides, resolve before sync',
    c.conflicts,
    '!',
  );
  section('changed only locally — sync will push', c.localOnly, '→');
  section('changed only on the node — sync will pull', c.remoteOnly, '←');
  section('differ — baseline unknown, run a sync to classify', c.unknown, '?');
  // When per-file diffs were requested, render each below the summary
  // (conflicts first, then unclassified paths), separated by a horizontal rule.
  for (final path in [...c.conflicts, ...c.unknown]) {
    final d = c.diffs[path];
    if (d == null) continue;
    buf
      ..write('\n\n')
      ..write(_diffDivider)
      ..write('\n')
      ..write(formatFileDiff(d).trimRight());
  }
  return buf.toString();
}