refactor(reflog): use Signature class instead of Map

This commit is contained in:
Aleksey Kulikov 2021-08-24 19:13:21 +03:00
parent dc5f510aa5
commit 0509895b72
4 changed files with 15 additions and 19 deletions

View file

@ -43,14 +43,9 @@ String entryMessage(Pointer<git_reflog_entry> entry) {
return result.cast<Utf8>().toDartString();
}
/// Get the committer of this entry (name, email, seconds from epoch).
Map<String, Object> entryCommiter(Pointer<git_reflog_entry> entry) {
final result = libgit2.git_reflog_entry_committer(entry);
var committer = <String, Object>{};
committer['name'] = result.ref.name.cast<Utf8>().toDartString();
committer['email'] = result.ref.email.cast<Utf8>().toDartString();
committer['when'] = result.ref.when.time;
return committer;
/// Get the committer of this entry.
Pointer<git_signature> entryCommiter(Pointer<git_reflog_entry> entry) {
return libgit2.git_reflog_entry_committer(entry);
}
/// Free the reflog.

View file

@ -2,6 +2,7 @@ import 'dart:ffi';
import 'bindings/libgit2_bindings.dart';
import 'bindings/reflog.dart' as bindings;
import 'reference.dart';
import 'signature.dart';
import 'util.dart';
class RefLog {
@ -58,6 +59,6 @@ class RefLogEntry {
/// Returns the log message.
String get message => bindings.entryMessage(_entryPointer);
/// Returns the committer of this entry (name, email, seconds from epoch).
Map<String, Object> get committer => bindings.entryCommiter(_entryPointer);
/// Returns the committer of this entry.
Signature get committer => Signature(bindings.entryCommiter(_entryPointer));
}

View file

@ -165,8 +165,8 @@ void main() {
final reflogEntry = reflog.entryAt(0);
expect(reflogEntry.message, 'log message');
expect(reflogEntry.committer['name'], 'name');
expect(reflogEntry.committer['email'], 'email');
expect(reflogEntry.committer.name, 'name');
expect(reflogEntry.committer.email, 'email');
reflog.free();
ref.free();
@ -300,8 +300,8 @@ void main() {
final reflogEntry = reflog.entryAt(0);
expect(reflogEntry.message, 'log message');
expect(reflogEntry.committer['name'], 'name');
expect(reflogEntry.committer['email'], 'email');
expect(reflogEntry.committer.name, 'name');
expect(reflogEntry.committer.email, 'email');
reflog.free();
ref.free();
@ -380,8 +380,8 @@ void main() {
expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
final reflog = ref.log;
expect(reflog.list().first.message, 'log message');
expect(reflog.list().first.committer['name'], 'name');
expect(reflog.list().first.committer['email'], 'email');
expect(reflog.list().first.committer.name, 'name');
expect(reflog.list().first.committer.email, 'email');
reflog.free();
ref.free();

View file

@ -49,9 +49,9 @@ void main() {
test('returns the committer of the entry', () {
final entry = reflog.entryAt(0);
expect(entry.committer['name'], 'Aleksey Kulikov');
expect(entry.committer['email'], 'skinny.mind@gmail.com');
expect(entry.committer['when'], 1626091184);
expect(entry.committer.name, 'Aleksey Kulikov');
expect(entry.committer.email, 'skinny.mind@gmail.com');
expect(entry.committer.time, 1626091184);
});
});
}