parse static method
Implementation
static GitCommit? parse(Uint8List rawData, GitHash? hash) {
var map = kvlmParse(rawData);
var requiredKeys = ['author', 'committer', 'tree', '_'];
for (var key in requiredKeys) {
if (!map.containsKey(key)) {
// FIXME: At least log the error?
return null;
}
}
var message = map['_'] ?? '';
var author = GitAuthor.parse(map['author'])!;
var committer = GitAuthor.parse(map['committer'])!;
var parents = <GitHash>[];
if (map.containsKey('parent')) {
var parent = map['parent'];
if (parent is List) {
parent.forEach((p) => parents.add(GitHash(p as String)));
} else if (parent is String) {
parents.add(GitHash(parent));
} else {
// FIXME: At least log the error?
return null;
}
}
var treeHash = GitHash(map['tree']);
var gpgSig = map['gpgsig'] ?? '';
return GitCommit.create(
author: author,
committer: committer,
message: message,
treeHash: treeHash,
parents: parents,
gpgSig: gpgSig,
);
}