From 0509895b723832a8e5461bd920397d054332cddb Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Tue, 24 Aug 2021 19:13:21 +0300 Subject: [PATCH] refactor(reflog): use Signature class instead of Map --- lib/src/bindings/reflog.dart | 11 +++-------- lib/src/reflog.dart | 5 +++-- test/reference_test.dart | 12 ++++++------ test/reflog_test.dart | 6 +++--- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/src/bindings/reflog.dart b/lib/src/bindings/reflog.dart index 690ca44..ba6cb88 100644 --- a/lib/src/bindings/reflog.dart +++ b/lib/src/bindings/reflog.dart @@ -43,14 +43,9 @@ String entryMessage(Pointer entry) { return result.cast().toDartString(); } -/// Get the committer of this entry (name, email, seconds from epoch). -Map entryCommiter(Pointer entry) { - final result = libgit2.git_reflog_entry_committer(entry); - var committer = {}; - committer['name'] = result.ref.name.cast().toDartString(); - committer['email'] = result.ref.email.cast().toDartString(); - committer['when'] = result.ref.when.time; - return committer; +/// Get the committer of this entry. +Pointer entryCommiter(Pointer entry) { + return libgit2.git_reflog_entry_committer(entry); } /// Free the reflog. diff --git a/lib/src/reflog.dart b/lib/src/reflog.dart index 9de7019..3eba9aa 100644 --- a/lib/src/reflog.dart +++ b/lib/src/reflog.dart @@ -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 get committer => bindings.entryCommiter(_entryPointer); + /// Returns the committer of this entry. + Signature get committer => Signature(bindings.entryCommiter(_entryPointer)); } diff --git a/test/reference_test.dart b/test/reference_test.dart index 2713129..815745a 100644 --- a/test/reference_test.dart +++ b/test/reference_test.dart @@ -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(); diff --git a/test/reflog_test.dart b/test/reflog_test.dart index 17f26b9..da136cd 100644 --- a/test/reflog_test.dart +++ b/test/reflog_test.dart @@ -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); }); }); }