shortlog method

Future<List<AuthorStats>> shortlog({
  1. String? since,
  2. String? workDir,
})

Returns per-author commit counts.

Implementation

Future<List<AuthorStats>> shortlog({String? since, String? workDir}) async {
  final args = <String>['shortlog', '-sne', 'HEAD'];
  if (since != null) args.insert(2, '--since=$since');

  final result = await _runGit(args, workDir: workDir ?? defaultWorkDir);
  final output = (result.stdout as String).trim();
  if (output.isEmpty) return [];

  final stats = <AuthorStats>[];
  for (final line in LineSplitter.split(output)) {
    final match = RegExp(r'^\s*(\d+)\s+(.+?)\s+<(.+?)>\s*$').firstMatch(line);
    if (match != null) {
      stats.add(
        AuthorStats(
          name: match.group(2)!,
          email: match.group(3)!,
          commitCount: int.parse(match.group(1)!),
        ),
      );
    }
  }

  return stats;
}