gitBlame method
Implementation
@override
Future<List<GitBlameLine>> gitBlame(String path) async {
final out =
(await _git([
'blame',
'--line-porcelain',
'--',
normalizeRepoPath(path),
])).stdout
as String;
final lines = <GitBlameLine>[];
final blocks = const LineSplitter().convert(out);
String hash = '';
String author = '';
var lineNo = 0;
for (final l in blocks) {
if (RegExp(r'^[0-9a-f]{40} ').hasMatch(l)) {
final parts = l.split(' ');
hash = parts[0].substring(0, 8);
lineNo = int.tryParse(parts[2]) ?? (lineNo + 1);
} else if (l.startsWith('author ')) {
author = l.substring('author '.length);
} else if (l.startsWith('\t')) {
lines.add(
GitBlameLine(
line: lineNo,
hash: hash,
author: author,
content: l.substring(1),
),
);
}
}
return lines;
}