mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(note): add ability to pass notes location
Add ability to pass optional notes location to `Note.list(...)` method (defaults to "refs/notes/commits").
This commit is contained in:
parent
3d235f5ce4
commit
73320cf96e
2 changed files with 23 additions and 8 deletions
|
@ -10,10 +10,17 @@ import 'package:libgit2dart/src/util.dart';
|
||||||
/// [free].
|
/// [free].
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
List<Map<String, Pointer>> list({
|
||||||
final notesRef = 'refs/notes/commits'.toChar();
|
required Pointer<git_repository> repoPointer,
|
||||||
|
required String notesRef,
|
||||||
|
}) {
|
||||||
|
final notesRefC = notesRef.toChar();
|
||||||
final iterator = calloc<Pointer<git_iterator>>();
|
final iterator = calloc<Pointer<git_iterator>>();
|
||||||
final iteratorError = libgit2.git_note_iterator_new(iterator, repo, notesRef);
|
final iteratorError = libgit2.git_note_iterator_new(
|
||||||
|
iterator,
|
||||||
|
repoPointer,
|
||||||
|
notesRefC,
|
||||||
|
);
|
||||||
|
|
||||||
if (iteratorError < 0) {
|
if (iteratorError < 0) {
|
||||||
calloc.free(iterator);
|
calloc.free(iterator);
|
||||||
|
@ -29,7 +36,7 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
||||||
nextError = libgit2.git_note_next(noteOid, annotatedOid, iterator.value);
|
nextError = libgit2.git_note_next(noteOid, annotatedOid, iterator.value);
|
||||||
if (nextError >= 0) {
|
if (nextError >= 0) {
|
||||||
final out = calloc<Pointer<git_note>>();
|
final out = calloc<Pointer<git_note>>();
|
||||||
libgit2.git_note_read(out, repo, notesRef, annotatedOid);
|
libgit2.git_note_read(out, repoPointer, notesRefC, annotatedOid);
|
||||||
|
|
||||||
final note = out.value;
|
final note = out.value;
|
||||||
|
|
||||||
|
@ -42,7 +49,7 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
||||||
calloc.free(noteOid);
|
calloc.free(noteOid);
|
||||||
}
|
}
|
||||||
|
|
||||||
calloc.free(notesRef);
|
calloc.free(notesRefC);
|
||||||
libgit2.git_note_iterator_free(iterator.value);
|
libgit2.git_note_iterator_free(iterator.value);
|
||||||
calloc.free(iterator);
|
calloc.free(iterator);
|
||||||
|
|
||||||
|
@ -55,7 +62,7 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
||||||
Pointer<git_note> lookup({
|
Pointer<git_note> lookup({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required Pointer<git_oid> oidPointer,
|
required Pointer<git_oid> oidPointer,
|
||||||
String notesRef = 'refs/notes/commits',
|
required String notesRef,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_note>>();
|
final out = calloc<Pointer<git_note>>();
|
||||||
final notesRefC = notesRef.toChar();
|
final notesRefC = notesRef.toChar();
|
||||||
|
|
|
@ -114,9 +114,17 @@ class Note extends Equatable {
|
||||||
|
|
||||||
/// Returns list of notes for [repo]sitory.
|
/// Returns list of notes for [repo]sitory.
|
||||||
///
|
///
|
||||||
|
/// [notesRef] is the canonical name of the reference to use. Defaults to "refs/notes/commits".
|
||||||
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
static List<Note> list(Repository repo) {
|
static List<Note> list(
|
||||||
final notesPointers = bindings.list(repo.pointer);
|
Repository repo, {
|
||||||
|
String notesRef = 'refs/notes/commits',
|
||||||
|
}) {
|
||||||
|
final notesPointers = bindings.list(
|
||||||
|
repoPointer: repo.pointer,
|
||||||
|
notesRef: notesRef,
|
||||||
|
);
|
||||||
return notesPointers
|
return notesPointers
|
||||||
.map(
|
.map(
|
||||||
(e) => Note(
|
(e) => Note(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue