gitLog method

  1. @override
Future<List<GitCommit>> gitLog({
  1. int? limit,
  2. String? path,
})
override

Implementation

@override
Future<List<GitCommit>> gitLog({int? limit, String? path}) async {
  // Unit-separated fields, record-separated commits, to parse robustly.
  const fmt = '%H%x1f%an%x1f%aI%x1f%s';
  final args = <String>[
    'log',
    '--pretty=format:$fmt',
    if (limit != null) '-n$limit',
    if (path != null) ...['--', normalizeRepoPath(path)],
  ];
  final out = (await _git(args)).stdout as String;
  final commits = <GitCommit>[];
  for (final line in const LineSplitter().convert(out)) {
    if (line.isEmpty) continue;
    final f = line.split('\x1f');
    if (f.length < 4) continue;
    commits.add(
      GitCommit(hash: f[0], author: f[1], date: f[2], subject: f[3]),
    );
  }
  return commits;
}