mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 20:59:08 -04:00
feat(repository)!: add more aliases for api methods
BREAKING CHANGE: Make repository entry point for most operations
This commit is contained in:
parent
9205a3ad82
commit
3a0fa75929
51 changed files with 1380 additions and 1062 deletions
|
@ -9,7 +9,7 @@ import '../util.dart';
|
|||
/// Return a list of branches.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
List<String> list({
|
||||
List<Pointer<git_reference>> list({
|
||||
required Pointer<git_repository> repoPointer,
|
||||
required int flags,
|
||||
}) {
|
||||
|
@ -24,7 +24,7 @@ List<String> list({
|
|||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
var result = <String>[];
|
||||
var result = <Pointer<git_reference>>[];
|
||||
var error = 0;
|
||||
|
||||
while (error == 0) {
|
||||
|
@ -32,10 +32,8 @@ List<String> list({
|
|||
final refType = calloc<Int32>();
|
||||
error = libgit2.git_branch_next(reference, refType, iterator.value);
|
||||
if (error == 0) {
|
||||
final refName = reference_bindings.shorthand(reference.value);
|
||||
result.add(refName);
|
||||
result.add(reference.value);
|
||||
calloc.free(refType);
|
||||
calloc.free(reference);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -129,11 +127,8 @@ void delete(Pointer<git_reference> branch) {
|
|||
///
|
||||
/// The new branch name will be checked for validity.
|
||||
///
|
||||
/// Note that if the move succeeds, the old reference object will not be valid anymore,
|
||||
/// and will be freed immediately.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_reference> rename({
|
||||
void rename({
|
||||
required Pointer<git_reference> branchPointer,
|
||||
required String newBranchName,
|
||||
required bool force,
|
||||
|
@ -149,8 +144,7 @@ Pointer<git_reference> rename({
|
|||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
reference_bindings.free(branchPointer);
|
||||
return out.value;
|
||||
reference_bindings.free(out.value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'package:ffi/ffi.dart';
|
|||
import '../error.dart';
|
||||
import 'libgit2_bindings.dart';
|
||||
import '../util.dart';
|
||||
import 'oid.dart' as oid_bindings;
|
||||
|
||||
/// Lookup a commit object from a repository.
|
||||
///
|
||||
|
@ -92,26 +91,21 @@ Pointer<git_oid> create({
|
|||
required String message,
|
||||
required Pointer<git_tree> treePointer,
|
||||
required int parentCount,
|
||||
required List<String> parents,
|
||||
required List<Pointer<git_commit>> parents,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final updateRefC = updateRef?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||
final messageEncodingC =
|
||||
messageEncoding?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||
final messageC = message.toNativeUtf8().cast<Int8>();
|
||||
Pointer<Pointer<git_commit>> parentsC =
|
||||
calloc.call<Pointer<git_commit>>(parentCount);
|
||||
final parentsC = calloc<Pointer<git_commit>>(parentCount);
|
||||
|
||||
if (parents.isNotEmpty) {
|
||||
for (var i = 0; i < parentCount; i++) {
|
||||
final oid = oid_bindings.fromSHA(parents[i]);
|
||||
var commit = calloc<IntPtr>();
|
||||
commit = lookup(repoPointer: repoPointer, oidPointer: oid).cast();
|
||||
parentsC[i] = commit.cast();
|
||||
parentsC[i] = parents[i];
|
||||
}
|
||||
} else {
|
||||
final commit = calloc<IntPtr>();
|
||||
parentsC[0] = commit.cast();
|
||||
parentsC[0] = nullptr;
|
||||
}
|
||||
|
||||
final error = libgit2.git_commit_create(
|
||||
|
@ -130,9 +124,6 @@ Pointer<git_oid> create({
|
|||
calloc.free(updateRefC);
|
||||
calloc.free(messageEncodingC);
|
||||
calloc.free(messageC);
|
||||
for (var i = 0; i < parentCount; i++) {
|
||||
free(parentsC[i]);
|
||||
}
|
||||
calloc.free(parentsC);
|
||||
|
||||
if (error < 0) {
|
||||
|
|
|
@ -107,10 +107,10 @@ Pointer<git_oid> create({
|
|||
}
|
||||
}
|
||||
|
||||
/// Remove the note for an object.
|
||||
/// Delete the note for an object.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void remove({
|
||||
void delete({
|
||||
required Pointer<git_repository> repoPointer,
|
||||
String notesRef = 'refs/notes/commits',
|
||||
required Pointer<git_signature> authorPointer,
|
||||
|
|
|
@ -130,5 +130,5 @@ void remove({
|
|||
}
|
||||
}
|
||||
|
||||
/// Free a tree builder to release memory.
|
||||
/// Free a tree builder and all the entries to release memory.
|
||||
void free(Pointer<git_treebuilder> bld) => libgit2.git_treebuilder_free(bld);
|
||||
|
|
|
@ -20,13 +20,22 @@ Pointer<git_worktree> create({
|
|||
final out = calloc<Pointer<git_worktree>>();
|
||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||
final opts =
|
||||
calloc<git_worktree_add_options>(sizeOf<git_worktree_add_options>());
|
||||
opts.ref.version = 1;
|
||||
opts.ref.lock = 0;
|
||||
|
||||
final opts = calloc<git_worktree_add_options>();
|
||||
final optsError = libgit2.git_worktree_add_options_init(
|
||||
opts,
|
||||
GIT_WORKTREE_ADD_OPTIONS_VERSION,
|
||||
);
|
||||
|
||||
if (optsError < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
opts.ref.ref = nullptr;
|
||||
if (refPointer != null) {
|
||||
opts.ref.ref = refPointer;
|
||||
}
|
||||
|
||||
final error = libgit2.git_worktree_add(out, repoPointer, nameC, pathC, opts);
|
||||
|
||||
calloc.free(nameC);
|
||||
|
@ -82,6 +91,7 @@ List<String> list(Pointer<git_repository> repo) {
|
|||
final result = <String>[];
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
for (var i = 0; i < out.ref.count; i++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue