feat(reference): add ability to get log of reference

This commit is contained in:
Aleksey Kulikov 2021-08-06 12:31:07 +03:00
parent a97dcaa0d3
commit 58fa54f24a
5 changed files with 30 additions and 7 deletions

View file

@ -43,12 +43,13 @@ String entryMessage(Pointer<git_reflog_entry> entry) {
return result.cast<Utf8>().toDartString();
}
/// Get the committer of this entry.
Map<String, String> entryCommiter(Pointer<git_reflog_entry> entry) {
/// 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, String>{};
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;
}

View file

@ -2,6 +2,7 @@ import 'dart:ffi';
import 'bindings/libgit2_bindings.dart';
import 'bindings/reference.dart' as bindings;
import 'oid.dart';
import 'reflog.dart';
import 'util.dart';
enum ReferenceType { direct, symbolic }
@ -145,6 +146,18 @@ class Reference {
return bindings.hasLog(repo, name);
}
/// Returns a list with entries of reference log.
List<RefLogEntry> get log {
final reflog = RefLog(this);
var log = <RefLogEntry>[];
for (var i = 0; i < reflog.count; i++) {
log.add(reflog.entryAt(i));
}
return log;
}
/// Checks if a reference is a local branch.
bool get isBranch => bindings.isBranch(_refPointer);

View file

@ -47,6 +47,6 @@ class RefLogEntry {
/// Returns the log message.
String get message => bindings.entryMessage(_entryPointer);
/// Returns the committer of this entry.
Map<String, String> get committer => bindings.entryCommiter(_entryPointer);
/// Returns the committer of this entry (name, email, seconds from epoch).
Map<String, Object> get committer => bindings.entryCommiter(_entryPointer);
}