gitHistorySource function
The real HistorySource: ONE git log over every resolved surface, through
the pack's existing GitRunner seam.
A non-zero git, or a record that does not split into SHA / ISO timestamp / subject, is EvidenceState.failed; an EMPTY successful log is EvidenceState.complete (a surface with no history is a real answer).
Implementation
HistorySource gitHistorySource(GitRunner runner) =>
(workspaceDir, paths) async {
final args = [
'log',
'--max-count=${kMaxHistoryCommits + 1}',
'--format=%H%x09%aI%x09%s',
'--',
...paths,
];
final command = 'git ${args.join(' ')}';
try {
final result = await runner.run(
workingDirectory: workspaceDir,
args: args,
);
if (!result.ok) {
return _history(
paths: paths,
command: command,
commits: const [],
error: 'exit ${result.exitCode}: ${result.output.trim()}',
);
}
final records = result.output
.split('\n')
.map((line) => line.trim())
.where((line) => line.isNotEmpty)
.toList();
final commits = <HistoryCommitEvidence>[];
for (final record in records.take(kMaxHistoryCommits)) {
final parts = record.split('\t');
if (parts.length != 3) {
return _history(
paths: paths,
command: command,
commits: const [],
error: 'unparseable log record: $record',
);
}
commits.add(
HistoryCommitEvidence(
id: boundDiscoveryEvidence(
kind: 'history-commit',
subject: parts[0],
source: command,
fullText: record,
).id,
sha: parts[0],
authoredAt: parts[1],
subject: parts[2],
),
);
}
return _history(
paths: paths,
command: command,
commits: commits,
truncated: records.length > kMaxHistoryCommits,
);
} catch (e) {
return _history(
paths: paths,
command: command,
commits: const [],
error: '$e',
);
}
};