From 5739de545bab4d7e8ec208c12ae3d60869378348 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Mon, 30 May 2022 15:29:40 +0300 Subject: [PATCH] feat(note): add ability to pass notes location (#63) Add ability to pass optional notes location to `Note.list(...)` method (defaults to "refs/notes/commits"). --- lib/src/bindings/note.dart | 19 +++++++++++++------ lib/src/note.dart | 12 ++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/src/bindings/note.dart b/lib/src/bindings/note.dart index f060554..bf7f58a 100644 --- a/lib/src/bindings/note.dart +++ b/lib/src/bindings/note.dart @@ -10,10 +10,17 @@ import 'package:libgit2dart/src/util.dart'; /// [free]. /// /// Throws a [LibGit2Error] if error occured. -List> list(Pointer repo) { - final notesRef = 'refs/notes/commits'.toChar(); +List> list({ + required Pointer repoPointer, + required String notesRef, +}) { + final notesRefC = notesRef.toChar(); final iterator = calloc>(); - final iteratorError = libgit2.git_note_iterator_new(iterator, repo, notesRef); + final iteratorError = libgit2.git_note_iterator_new( + iterator, + repoPointer, + notesRefC, + ); if (iteratorError < 0) { calloc.free(iterator); @@ -29,7 +36,7 @@ List> list(Pointer repo) { nextError = libgit2.git_note_next(noteOid, annotatedOid, iterator.value); if (nextError >= 0) { final out = calloc>(); - libgit2.git_note_read(out, repo, notesRef, annotatedOid); + libgit2.git_note_read(out, repoPointer, notesRefC, annotatedOid); final note = out.value; @@ -42,7 +49,7 @@ List> list(Pointer repo) { calloc.free(noteOid); } - calloc.free(notesRef); + calloc.free(notesRefC); libgit2.git_note_iterator_free(iterator.value); calloc.free(iterator); @@ -55,7 +62,7 @@ List> list(Pointer repo) { Pointer lookup({ required Pointer repoPointer, required Pointer oidPointer, - String notesRef = 'refs/notes/commits', + required String notesRef, }) { final out = calloc>(); final notesRefC = notesRef.toChar(); diff --git a/lib/src/note.dart b/lib/src/note.dart index 6ba83c2..1dd874b 100644 --- a/lib/src/note.dart +++ b/lib/src/note.dart @@ -114,9 +114,17 @@ class Note extends Equatable { /// 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. - static List list(Repository repo) { - final notesPointers = bindings.list(repo.pointer); + static List list( + Repository repo, { + String notesRef = 'refs/notes/commits', + }) { + final notesPointers = bindings.list( + repoPointer: repo.pointer, + notesRef: notesRef, + ); return notesPointers .map( (e) => Note(