mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 12:19:09 -04:00
refactor: use extensions (#62)
This commit is contained in:
parent
4aea9a306a
commit
3d235f5ce4
47 changed files with 386 additions and 355 deletions
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Creates an annotated commit from the given commit id. The returned
|
||||
|
@ -76,7 +77,7 @@ Pointer<git_annotated_commit> fromRevSpec({
|
|||
required String revspec,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_annotated_commit>>();
|
||||
final revspecC = revspec.toNativeUtf8().cast<Char>();
|
||||
final revspecC = revspec.toChar();
|
||||
final error = libgit2.git_annotated_commit_from_revspec(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -106,8 +107,8 @@ Pointer<git_annotated_commit> fromFetchHead({
|
|||
required Pointer<git_oid> oid,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_annotated_commit>>();
|
||||
final branchNameC = branchName.toNativeUtf8().cast<Char>();
|
||||
final remoteUrlC = remoteUrl.toNativeUtf8().cast<Char>();
|
||||
final branchNameC = branchName.toChar();
|
||||
final remoteUrlC = remoteUrl.toChar();
|
||||
final error = libgit2.git_annotated_commit_from_fetchhead(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -136,7 +137,7 @@ Pointer<git_oid> oid(Pointer<git_annotated_commit> commit) =>
|
|||
/// Get the refname that the given annotated commit refers to.
|
||||
String refName(Pointer<git_annotated_commit> commit) {
|
||||
final result = libgit2.git_annotated_commit_ref(commit);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Frees an annotated commit.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Look up the value of one git attribute for path.
|
||||
|
@ -15,8 +16,8 @@ Object? getAttribute({
|
|||
required String name,
|
||||
}) {
|
||||
final out = calloc<Pointer<Char>>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final nameC = name.toChar();
|
||||
libgit2.git_attr_get(out, repoPointer, flags, pathC, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -37,7 +38,7 @@ Object? getAttribute({
|
|||
return false;
|
||||
}
|
||||
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_STRING) {
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return result.toDartString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/oid.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
|
@ -20,7 +21,7 @@ Pointer<git_blame> file({
|
|||
int? maxLine,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_blame>>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final options = calloc<git_blame_options>();
|
||||
libgit2.git_blame_options_init(options, GIT_BLAME_OPTIONS_VERSION);
|
||||
|
||||
|
@ -77,7 +78,7 @@ Pointer<git_blame> buffer({
|
|||
required String buffer,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_blame>>();
|
||||
final bufferC = buffer.toNativeUtf8().cast<Char>();
|
||||
final bufferC = buffer.toChar();
|
||||
final error = libgit2.git_blame_buffer(
|
||||
out,
|
||||
reference,
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
|||
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Lookup a blob object from a repository. The returned blob must be freed
|
||||
|
@ -84,7 +85,7 @@ Pointer<git_oid> createFromWorkdir({
|
|||
required String relativePath,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final relativePathC = relativePath.toNativeUtf8().cast<Char>();
|
||||
final relativePathC = relativePath.toChar();
|
||||
final error = libgit2.git_blob_create_from_workdir(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -110,7 +111,7 @@ Pointer<git_oid> createFromDisk({
|
|||
required String path,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final error = libgit2.git_blob_create_from_disk(out, repoPointer, pathC);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
@ -150,7 +151,7 @@ String filterContent({
|
|||
git_oid? attributesCommit,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final asPathC = asPath.toNativeUtf8().cast<Char>();
|
||||
final asPathC = asPath.toChar();
|
||||
final opts = calloc<git_blob_filter_options>();
|
||||
libgit2.git_blob_filter_options_init(opts, GIT_BLOB_FILTER_OPTIONS_VERSION);
|
||||
opts.ref.flags = flags;
|
||||
|
@ -162,7 +163,7 @@ String filterContent({
|
|||
|
||||
late final String result;
|
||||
if (out.ref.ptr != nullptr) {
|
||||
result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
}
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/libgit2dart.dart';
|
|||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/bindings/reference.dart' as reference_bindings;
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Return a list of branches. The returned references must be freed with
|
||||
|
@ -60,7 +61,7 @@ Pointer<git_reference> lookup({
|
|||
required int branchType,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final branchNameC = branchName.toNativeUtf8().cast<Char>();
|
||||
final branchNameC = branchName.toChar();
|
||||
final error = libgit2.git_branch_lookup(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -97,7 +98,7 @@ Pointer<git_reference> create({
|
|||
required bool force,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final branchNameC = branchName.toNativeUtf8().cast<Char>();
|
||||
final branchNameC = branchName.toChar();
|
||||
final forceC = force ? 1 : 0;
|
||||
final error = libgit2.git_branch_create(
|
||||
out,
|
||||
|
@ -147,7 +148,7 @@ void rename({
|
|||
required bool force,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final newBranchNameC = newBranchName.toNativeUtf8().cast<Char>();
|
||||
final newBranchNameC = newBranchName.toChar();
|
||||
final forceC = force ? 1 : 0;
|
||||
final error = libgit2.git_branch_move(
|
||||
out,
|
||||
|
@ -212,7 +213,7 @@ String name(Pointer<git_reference> ref) {
|
|||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return result.toDartString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,10 +230,10 @@ String remoteName({
|
|||
required String branchName,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final branchNameC = branchName.toNativeUtf8().cast<Char>();
|
||||
final branchNameC = branchName.toChar();
|
||||
final error = libgit2.git_branch_remote_name(out, repoPointer, branchNameC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -281,7 +282,7 @@ void setUpstream({
|
|||
required Pointer<git_reference> branchPointer,
|
||||
required String? branchName,
|
||||
}) {
|
||||
final branchNameC = branchName?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final branchNameC = branchName?.toChar() ?? nullptr;
|
||||
final error = libgit2.git_branch_set_upstream(branchPointer, branchNameC);
|
||||
|
||||
calloc.free(branchNameC);
|
||||
|
@ -303,10 +304,10 @@ String upstreamName({
|
|||
required String branchName,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final branchNameC = branchName.toNativeUtf8().cast<Char>();
|
||||
final branchNameC = branchName.toChar();
|
||||
final error = libgit2.git_branch_upstream_name(out, repoPointer, branchNameC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -330,14 +331,14 @@ String upstreamRemote({
|
|||
required String branchName,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final branchNameC = branchName.toNativeUtf8().cast<Char>();
|
||||
final branchNameC = branchName.toChar();
|
||||
final error = libgit2.git_branch_upstream_remote(
|
||||
out,
|
||||
repoPointer,
|
||||
branchNameC,
|
||||
);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -361,14 +362,14 @@ String upstreamMerge({
|
|||
required String branchName,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final branchNameC = branchName.toNativeUtf8().cast<Char>();
|
||||
final branchNameC = branchName.toChar();
|
||||
final error = libgit2.git_branch_upstream_merge(
|
||||
out,
|
||||
repoPointer,
|
||||
branchNameC,
|
||||
);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Updates files in the index and the working tree to match the content of the
|
||||
|
@ -127,13 +128,13 @@ List<Object> initOptions({
|
|||
optsC.ref.checkout_strategy = strategy;
|
||||
|
||||
if (directory != null) {
|
||||
optsC.ref.target_directory = directory.toNativeUtf8().cast<Char>();
|
||||
optsC.ref.target_directory = directory.toChar();
|
||||
}
|
||||
|
||||
var pathPointers = <Pointer<Char>>[];
|
||||
Pointer<Pointer<Char>> strArray = nullptr;
|
||||
if (paths != null) {
|
||||
pathPointers = paths.map((e) => e.toNativeUtf8().cast<Char>()).toList();
|
||||
pathPointers = paths.map((e) => e.toChar()).toList();
|
||||
strArray = calloc(paths.length);
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
strArray[i] = pathPointers[i];
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Lookup a commit object from a repository. The returned commit must be
|
||||
|
@ -45,10 +46,9 @@ Pointer<git_oid> create({
|
|||
required List<Pointer<git_commit>> parents,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final updateRefC = updateRef.toNativeUtf8().cast<Char>();
|
||||
final messageEncodingC =
|
||||
messageEncoding?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final messageC = message.toNativeUtf8().cast<Char>();
|
||||
final updateRefC = updateRef.toChar();
|
||||
final messageEncodingC = messageEncoding?.toChar() ?? nullptr;
|
||||
final messageC = message.toChar();
|
||||
final parentsC = calloc<Pointer<git_commit>>(parentCount);
|
||||
|
||||
if (parents.isNotEmpty) {
|
||||
|
@ -103,10 +103,9 @@ String createBuffer({
|
|||
required List<Pointer<git_commit>> parents,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final updateRefC = updateRef.toNativeUtf8().cast<Char>();
|
||||
final messageEncodingC =
|
||||
messageEncoding?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final messageC = message.toNativeUtf8().cast<Char>();
|
||||
final updateRefC = updateRef.toChar();
|
||||
final messageEncodingC = messageEncoding?.toChar() ?? nullptr;
|
||||
final messageC = message.toChar();
|
||||
final parentsC = calloc<Pointer<git_commit>>(parentCount);
|
||||
|
||||
if (parents.isNotEmpty) {
|
||||
|
@ -129,7 +128,7 @@ String createBuffer({
|
|||
parentsC,
|
||||
);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -169,10 +168,9 @@ Pointer<git_oid> amend({
|
|||
required Pointer<git_tree>? treePointer,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final updateRefC = updateRef?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final messageEncodingC =
|
||||
messageEncoding?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final messageC = message?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final updateRefC = updateRef?.toChar() ?? nullptr;
|
||||
final messageEncodingC = messageEncoding?.toChar() ?? nullptr;
|
||||
final messageC = message?.toChar() ?? nullptr;
|
||||
|
||||
final error = libgit2.git_commit_amend(
|
||||
out,
|
||||
|
@ -216,7 +214,7 @@ Pointer<git_commit> duplicate(Pointer<git_commit> source) {
|
|||
/// If the encoding header in the commit is missing UTF-8 is assumed.
|
||||
String messageEncoding(Pointer<git_commit> commit) {
|
||||
final result = libgit2.git_commit_message_encoding(commit);
|
||||
return result == nullptr ? 'utf-8' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? 'utf-8' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Get the full message of a commit.
|
||||
|
@ -224,7 +222,7 @@ String messageEncoding(Pointer<git_commit> commit) {
|
|||
/// The returned message will be slightly prettified by removing any potential
|
||||
/// leading newlines.
|
||||
String message(Pointer<git_commit> commit) {
|
||||
return libgit2.git_commit_message(commit).cast<Utf8>().toDartString();
|
||||
return libgit2.git_commit_message(commit).toDartString();
|
||||
}
|
||||
|
||||
/// Get the short "summary" of the git commit message.
|
||||
|
@ -239,7 +237,7 @@ String summary(Pointer<git_commit> commit) {
|
|||
if (result == nullptr) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return result.cast<Utf8>().toDartString();
|
||||
return result.toDartString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,7 +248,7 @@ String summary(Pointer<git_commit> commit) {
|
|||
/// trimmed.
|
||||
String body(Pointer<git_commit> commit) {
|
||||
final result = libgit2.git_commit_body(commit);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Get an arbitrary header field.
|
||||
|
@ -261,10 +259,10 @@ String headerField({
|
|||
required String field,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final fieldC = field.toNativeUtf8().cast<Char>();
|
||||
final fieldC = field.toChar();
|
||||
final error = libgit2.git_commit_header_field(out, commitPointer, fieldC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
|
|
@ -5,13 +5,14 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Create a new config instance containing a single on-disk file. The returned
|
||||
/// config must be freed with [free].
|
||||
Pointer<git_config> open(String path) {
|
||||
final out = calloc<Pointer<git_config>>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
libgit2.git_config_open_ondisk(out, pathC);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
@ -59,7 +60,7 @@ String findGlobal() {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_config_find_global(out);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -81,7 +82,7 @@ String findSystem() {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_config_find_system(out);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -107,7 +108,7 @@ String findXdg() {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_config_find_xdg(out);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -145,7 +146,7 @@ Pointer<git_config_entry> getEntry({
|
|||
required String variable,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_config_entry>>();
|
||||
final nameC = variable.toNativeUtf8().cast<Char>();
|
||||
final nameC = variable.toChar();
|
||||
final error = libgit2.git_config_get_entry(out, configPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -167,7 +168,7 @@ void setBool({
|
|||
required String variable,
|
||||
required bool value,
|
||||
}) {
|
||||
final nameC = variable.toNativeUtf8().cast<Char>();
|
||||
final nameC = variable.toChar();
|
||||
final valueC = value ? 1 : 0;
|
||||
libgit2.git_config_set_bool(configPointer, nameC, valueC);
|
||||
calloc.free(nameC);
|
||||
|
@ -180,7 +181,7 @@ void setInt({
|
|||
required String variable,
|
||||
required int value,
|
||||
}) {
|
||||
final nameC = variable.toNativeUtf8().cast<Char>();
|
||||
final nameC = variable.toChar();
|
||||
libgit2.git_config_set_int64(configPointer, nameC, value);
|
||||
calloc.free(nameC);
|
||||
}
|
||||
|
@ -192,8 +193,8 @@ void setString({
|
|||
required String variable,
|
||||
required String value,
|
||||
}) {
|
||||
final nameC = variable.toNativeUtf8().cast<Char>();
|
||||
final valueC = value.toNativeUtf8().cast<Char>();
|
||||
final nameC = variable.toChar();
|
||||
final valueC = value.toChar();
|
||||
libgit2.git_config_set_string(configPointer, nameC, valueC);
|
||||
calloc.free(nameC);
|
||||
calloc.free(valueC);
|
||||
|
@ -220,7 +221,7 @@ void delete({
|
|||
required Pointer<git_config> configPointer,
|
||||
required String variable,
|
||||
}) {
|
||||
final nameC = variable.toNativeUtf8().cast<Char>();
|
||||
final nameC = variable.toChar();
|
||||
final error = libgit2.git_config_delete_entry(configPointer, nameC);
|
||||
|
||||
calloc.free(nameC);
|
||||
|
@ -243,8 +244,8 @@ List<String> multivarValues({
|
|||
required String variable,
|
||||
String? regexp,
|
||||
}) {
|
||||
final nameC = variable.toNativeUtf8().cast<Char>();
|
||||
final regexpC = regexp?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final nameC = variable.toChar();
|
||||
final regexpC = regexp?.toChar() ?? nullptr;
|
||||
final iterator = calloc<Pointer<git_config_iterator>>();
|
||||
final entry = calloc<Pointer<git_config_entry>>();
|
||||
|
||||
|
@ -261,7 +262,7 @@ List<String> multivarValues({
|
|||
while (error == 0) {
|
||||
error = libgit2.git_config_next(entry, iterator.value);
|
||||
if (error != -31) {
|
||||
entries.add(entry.value.ref.value.cast<Utf8>().toDartString());
|
||||
entries.add(entry.value.ref.value.toDartString());
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -286,9 +287,9 @@ void setMultivar({
|
|||
required String regexp,
|
||||
required String value,
|
||||
}) {
|
||||
final nameC = variable.toNativeUtf8().cast<Char>();
|
||||
final regexpC = regexp.toNativeUtf8().cast<Char>();
|
||||
final valueC = value.toNativeUtf8().cast<Char>();
|
||||
final nameC = variable.toChar();
|
||||
final regexpC = regexp.toChar();
|
||||
final valueC = value.toChar();
|
||||
|
||||
libgit2.git_config_set_multivar(configPointer, nameC, regexpC, valueC);
|
||||
|
||||
|
@ -306,8 +307,8 @@ void deleteMultivar({
|
|||
required String variable,
|
||||
required String regexp,
|
||||
}) {
|
||||
final nameC = variable.toNativeUtf8().cast<Char>();
|
||||
final regexpC = regexp.toNativeUtf8().cast<Char>();
|
||||
final nameC = variable.toChar();
|
||||
final regexpC = regexp.toChar();
|
||||
|
||||
libgit2.git_config_delete_multivar(configPointer, nameC, regexpC);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
|||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Create a new plain-text username and password credential object.
|
||||
|
@ -10,8 +11,8 @@ Pointer<git_credential> userPass({
|
|||
required String password,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_credential>>();
|
||||
final usernameC = username.toNativeUtf8().cast<Char>();
|
||||
final passwordC = password.toNativeUtf8().cast<Char>();
|
||||
final usernameC = username.toChar();
|
||||
final passwordC = password.toChar();
|
||||
|
||||
libgit2.git_credential_userpass_plaintext_new(out, usernameC, passwordC);
|
||||
|
||||
|
@ -32,10 +33,10 @@ Pointer<git_credential> sshKey({
|
|||
required String passPhrase,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_credential>>();
|
||||
final usernameC = username.toNativeUtf8().cast<Char>();
|
||||
final publicKeyC = publicKey.toNativeUtf8().cast<Char>();
|
||||
final privateKeyC = privateKey.toNativeUtf8().cast<Char>();
|
||||
final passPhraseC = passPhrase.toNativeUtf8().cast<Char>();
|
||||
final usernameC = username.toChar();
|
||||
final publicKeyC = publicKey.toChar();
|
||||
final privateKeyC = privateKey.toChar();
|
||||
final passPhraseC = passPhrase.toChar();
|
||||
|
||||
libgit2.git_credential_ssh_key_new(
|
||||
out,
|
||||
|
@ -59,7 +60,7 @@ Pointer<git_credential> sshKey({
|
|||
/// Create a new ssh key credential object used for querying an ssh-agent.
|
||||
Pointer<git_credential> sshKeyFromAgent(String username) {
|
||||
final out = calloc<Pointer<git_credential>>();
|
||||
final usernameC = username.toNativeUtf8().cast<Char>();
|
||||
final usernameC = username.toChar();
|
||||
|
||||
libgit2.git_credential_ssh_key_from_agent(out, usernameC);
|
||||
|
||||
|
@ -79,10 +80,10 @@ Pointer<git_credential> sshKeyFromMemory({
|
|||
required String passPhrase,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_credential>>();
|
||||
final usernameC = username.toNativeUtf8().cast<Char>();
|
||||
final publicKeyC = publicKey.toNativeUtf8().cast<Char>();
|
||||
final privateKeyC = privateKey.toNativeUtf8().cast<Char>();
|
||||
final passPhraseC = passPhrase.toNativeUtf8().cast<Char>();
|
||||
final usernameC = username.toChar();
|
||||
final publicKeyC = publicKey.toChar();
|
||||
final privateKeyC = privateKey.toChar();
|
||||
final passPhraseC = passPhrase.toChar();
|
||||
|
||||
libgit2.git_credential_ssh_key_memory_new(
|
||||
out,
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Describe a commit. The returned describe result must be freed with [free].
|
||||
|
@ -100,12 +101,12 @@ String format({
|
|||
opts.ref.always_use_long_format = alwaysUseLongFormat ? 1 : 0;
|
||||
}
|
||||
if (dirtySuffix != null) {
|
||||
opts.ref.dirty_suffix = dirtySuffix.toNativeUtf8().cast<Char>();
|
||||
opts.ref.dirty_suffix = dirtySuffix.toChar();
|
||||
}
|
||||
|
||||
libgit2.git_describe_format(out, describeResultPointer, opts);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -140,7 +141,7 @@ Pointer<git_describe_options> _initOpts({
|
|||
opts.ref.describe_strategy = describeStrategy;
|
||||
}
|
||||
if (pattern != null) {
|
||||
opts.ref.pattern = pattern.toNativeUtf8().cast<Char>();
|
||||
opts.ref.pattern = pattern.toChar();
|
||||
}
|
||||
if (onlyFollowFirstParent != null) {
|
||||
opts.ref.only_follow_first_parent = onlyFollowFirstParent ? 1 : 0;
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Create a diff with the difference between two index objects. The returned
|
||||
|
@ -253,7 +254,7 @@ void merge({
|
|||
/// other types of patch files.
|
||||
Pointer<git_diff> parse(String content) {
|
||||
final out = calloc<Pointer<git_diff>>();
|
||||
final contentC = content.toNativeUtf8().cast<Char>();
|
||||
final contentC = content.toChar();
|
||||
libgit2.git_diff_from_buffer(out, contentC, content.length);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -383,7 +384,7 @@ String statsPrint({
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_diff_stats_to_buf(out, statsPointer, format, width);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -402,7 +403,7 @@ String addToBuf(Pointer<git_diff> diff) {
|
|||
|
||||
final result = out.ref.ptr == nullptr
|
||||
? ''
|
||||
: out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
: out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Create an in-memory index object.
|
||||
|
@ -45,7 +46,7 @@ void setCapabilities({
|
|||
|
||||
/// Get the full path to the index file on disk.
|
||||
String path(Pointer<git_index> index) {
|
||||
return libgit2.git_index_path(index).cast<Utf8>().toDartString();
|
||||
return libgit2.git_index_path(index).toDartString();
|
||||
}
|
||||
|
||||
/// Update the contents of an existing index object in memory by reading from
|
||||
|
@ -125,7 +126,7 @@ Pointer<git_oid> writeTreeTo({
|
|||
/// Find the first position of any entries which point to given path in the Git
|
||||
/// index.
|
||||
bool find({required Pointer<git_index> indexPointer, required String path}) {
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final result = libgit2.git_index_find(nullptr, indexPointer, pathC);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
@ -164,7 +165,7 @@ Pointer<git_index_entry> getByPath({
|
|||
required String path,
|
||||
required int stage,
|
||||
}) {
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final result = libgit2.git_index_get_bypath(indexPointer, pathC, stage);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
@ -231,7 +232,7 @@ void addByPath({
|
|||
required Pointer<git_index> indexPointer,
|
||||
required String path,
|
||||
}) {
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final error = libgit2.git_index_add_bypath(indexPointer, pathC);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
@ -263,7 +264,7 @@ void addFromBuffer({
|
|||
required Pointer<git_index_entry> entryPointer,
|
||||
required String buffer,
|
||||
}) {
|
||||
final bufferC = buffer.toNativeUtf8().cast<Int8>();
|
||||
final bufferC = buffer.toChar();
|
||||
final error = libgit2.git_index_add_from_buffer(
|
||||
indexPointer,
|
||||
entryPointer,
|
||||
|
@ -293,8 +294,7 @@ void addAll({
|
|||
required List<String> pathspec,
|
||||
}) {
|
||||
final pathspecC = calloc<git_strarray>();
|
||||
final pathPointers =
|
||||
pathspec.map((e) => e.toNativeUtf8().cast<Char>()).toList();
|
||||
final pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||
final strArray = calloc<Pointer<Char>>(pathspec.length);
|
||||
|
||||
for (var i = 0; i < pathspec.length; i++) {
|
||||
|
@ -338,8 +338,7 @@ void updateAll({
|
|||
required List<String> pathspec,
|
||||
}) {
|
||||
final pathspecC = calloc<git_strarray>();
|
||||
final pathPointers =
|
||||
pathspec.map((e) => e.toNativeUtf8().cast<Char>()).toList();
|
||||
final pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||
final strArray = calloc<Pointer<Char>>(pathspec.length);
|
||||
|
||||
for (var i = 0; i < pathspec.length; i++) {
|
||||
|
@ -379,7 +378,7 @@ void remove({
|
|||
required String path,
|
||||
required int stage,
|
||||
}) {
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final error = libgit2.git_index_remove(indexPointer, pathC, stage);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
@ -395,7 +394,7 @@ void removeDirectory({
|
|||
required String dir,
|
||||
required int stage,
|
||||
}) {
|
||||
final dirC = dir.toNativeUtf8().cast<Char>();
|
||||
final dirC = dir.toChar();
|
||||
libgit2.git_index_remove_directory(indexPointer, dirC, stage);
|
||||
calloc.free(dirC);
|
||||
}
|
||||
|
@ -406,8 +405,7 @@ void removeAll({
|
|||
required List<String> pathspec,
|
||||
}) {
|
||||
final pathspecC = calloc<git_strarray>();
|
||||
final pathPointers =
|
||||
pathspec.map((e) => e.toNativeUtf8().cast<Char>()).toList();
|
||||
final pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||
final strArray = calloc<Pointer<Char>>(pathspec.length);
|
||||
|
||||
for (var i = 0; i < pathspec.length; i++) {
|
||||
|
@ -511,7 +509,7 @@ void conflictRemove({
|
|||
required Pointer<git_index> indexPointer,
|
||||
required String path,
|
||||
}) {
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final error = libgit2.git_index_conflict_remove(indexPointer, pathC);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Allocate a new mailmap object. The returned mailmap must be freed with
|
||||
|
@ -25,7 +26,7 @@ Pointer<git_mailmap> init() {
|
|||
/// returned mailmap must be freed with [free].
|
||||
Pointer<git_mailmap> fromBuffer(String buffer) {
|
||||
final out = calloc<Pointer<git_mailmap>>();
|
||||
final bufferC = buffer.toNativeUtf8().cast<Char>();
|
||||
final bufferC = buffer.toChar();
|
||||
|
||||
libgit2.git_mailmap_from_buffer(out, bufferC, buffer.length);
|
||||
|
||||
|
@ -72,8 +73,8 @@ List<String> resolve({
|
|||
}) {
|
||||
final outRealName = calloc<Pointer<Char>>();
|
||||
final outRealEmail = calloc<Pointer<Char>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final emailC = email.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final emailC = email.toChar();
|
||||
libgit2.git_mailmap_resolve(
|
||||
outRealName,
|
||||
outRealEmail,
|
||||
|
@ -82,8 +83,8 @@ List<String> resolve({
|
|||
emailC,
|
||||
);
|
||||
|
||||
final realName = outRealName.value.cast<Utf8>().toDartString();
|
||||
final realEmail = outRealEmail.value.cast<Utf8>().toDartString();
|
||||
final realName = outRealName.value.toDartString();
|
||||
final realEmail = outRealEmail.value.toDartString();
|
||||
calloc.free(outRealName);
|
||||
calloc.free(outRealEmail);
|
||||
calloc.free(nameC);
|
||||
|
@ -119,10 +120,10 @@ void addEntry({
|
|||
String? replaceName,
|
||||
required String replaceEmail,
|
||||
}) {
|
||||
final realNameC = realName?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final realEmailC = realEmail?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final replaceNameC = replaceName?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final replaceEmailC = replaceEmail.toNativeUtf8().cast<Char>();
|
||||
final realNameC = realName?.toChar() ?? nullptr;
|
||||
final realEmailC = realEmail?.toChar() ?? nullptr;
|
||||
final replaceNameC = replaceName?.toChar() ?? nullptr;
|
||||
final replaceEmailC = replaceEmail.toChar();
|
||||
|
||||
libgit2.git_mailmap_add_entry(
|
||||
mailmapPointer,
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Find a merge base between two commits.
|
||||
|
@ -183,11 +184,11 @@ String mergeFile({
|
|||
libgit2.git_merge_file_input_init(ancestorC, GIT_MERGE_FILE_INPUT_VERSION);
|
||||
libgit2.git_merge_file_input_init(oursC, GIT_MERGE_FILE_INPUT_VERSION);
|
||||
libgit2.git_merge_file_input_init(theirsC, GIT_MERGE_FILE_INPUT_VERSION);
|
||||
ancestorC.ref.ptr = ancestor.toNativeUtf8().cast<Char>();
|
||||
ancestorC.ref.ptr = ancestor.toChar();
|
||||
ancestorC.ref.size = ancestor.length;
|
||||
oursC.ref.ptr = ours.toNativeUtf8().cast<Char>();
|
||||
oursC.ref.ptr = ours.toChar();
|
||||
oursC.ref.size = ours.length;
|
||||
theirsC.ref.ptr = theirs.toNativeUtf8().cast<Char>();
|
||||
theirsC.ref.ptr = theirs.toChar();
|
||||
theirsC.ref.size = theirs.length;
|
||||
|
||||
final opts = calloc<git_merge_file_options>();
|
||||
|
@ -195,13 +196,13 @@ String mergeFile({
|
|||
opts.ref.favor = favor;
|
||||
opts.ref.flags = flags;
|
||||
if (ancestorLabel.isNotEmpty) {
|
||||
opts.ref.ancestor_label = ancestorLabel.toNativeUtf8().cast<Char>();
|
||||
opts.ref.ancestor_label = ancestorLabel.toChar();
|
||||
}
|
||||
if (oursLabel.isNotEmpty) {
|
||||
opts.ref.our_label = oursLabel.toNativeUtf8().cast<Char>();
|
||||
opts.ref.our_label = oursLabel.toChar();
|
||||
}
|
||||
if (theirsLabel.isNotEmpty) {
|
||||
opts.ref.their_label = theirsLabel.toNativeUtf8().cast<Char>();
|
||||
opts.ref.their_label = theirsLabel.toChar();
|
||||
}
|
||||
|
||||
libgit2.git_merge_file(out, ancestorC, oursC, theirsC, opts);
|
||||
|
@ -211,7 +212,7 @@ String mergeFile({
|
|||
calloc.free(theirsC);
|
||||
calloc.free(opts);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.len);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.len);
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
|
@ -240,7 +241,7 @@ String mergeFileFromIndex({
|
|||
|
||||
late final String result;
|
||||
if (out.ref.ptr != nullptr) {
|
||||
result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.len);
|
||||
result = out.ref.ptr.toDartString(length: out.ref.len);
|
||||
}
|
||||
|
||||
calloc.free(out);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Returns list of notes for repository. The returned notes must be freed with
|
||||
|
@ -10,7 +11,7 @@ import 'package:libgit2dart/src/util.dart';
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
||||
final notesRef = 'refs/notes/commits'.toNativeUtf8().cast<Char>();
|
||||
final notesRef = 'refs/notes/commits'.toChar();
|
||||
final iterator = calloc<Pointer<git_iterator>>();
|
||||
final iteratorError = libgit2.git_note_iterator_new(iterator, repo, notesRef);
|
||||
|
||||
|
@ -57,7 +58,7 @@ Pointer<git_note> lookup({
|
|||
String notesRef = 'refs/notes/commits',
|
||||
}) {
|
||||
final out = calloc<Pointer<git_note>>();
|
||||
final notesRefC = notesRef.toNativeUtf8().cast<Char>();
|
||||
final notesRefC = notesRef.toChar();
|
||||
final error = libgit2.git_note_read(out, repoPointer, notesRefC, oidPointer);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -85,8 +86,8 @@ Pointer<git_oid> create({
|
|||
bool force = false,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final notesRefC = notesRef.toNativeUtf8().cast<Char>();
|
||||
final noteC = note.toNativeUtf8().cast<Char>();
|
||||
final notesRefC = notesRef.toChar();
|
||||
final noteC = note.toChar();
|
||||
final forceC = force ? 1 : 0;
|
||||
final error = libgit2.git_note_create(
|
||||
out,
|
||||
|
@ -120,7 +121,7 @@ void delete({
|
|||
required Pointer<git_signature> committerPointer,
|
||||
required Pointer<git_oid> oidPointer,
|
||||
}) {
|
||||
final notesRefC = notesRef.toNativeUtf8().cast<Char>();
|
||||
final notesRefC = notesRef.toChar();
|
||||
|
||||
final error = libgit2.git_note_remove(
|
||||
repoPointer,
|
||||
|
@ -142,7 +143,7 @@ Pointer<git_oid> id(Pointer<git_note> note) => libgit2.git_note_id(note);
|
|||
|
||||
/// Get the note message.
|
||||
String message(Pointer<git_note> note) {
|
||||
return libgit2.git_note_message(note).cast<Utf8>().toDartString();
|
||||
return libgit2.git_note_message(note).toDartString();
|
||||
}
|
||||
|
||||
/// Free memory allocated for note object.
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
|||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/bindings/oid.dart' as oid_bindings;
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/oid.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
|
@ -36,7 +37,7 @@ void addDiskAlternate({
|
|||
required Pointer<git_odb> odbPointer,
|
||||
required String path,
|
||||
}) {
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
libgit2.git_odb_add_disk_alternate(odbPointer, pathC);
|
||||
calloc.free(pathC);
|
||||
}
|
||||
|
@ -184,7 +185,7 @@ Pointer<git_oid> write({
|
|||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
||||
final bufferC = data.toNativeUtf8().cast<Char>();
|
||||
final bufferC = data.toChar();
|
||||
libgit2.git_odb_stream_write(stream.value, bufferC, data.length);
|
||||
|
||||
final out = calloc<git_oid>();
|
||||
|
|
|
@ -2,12 +2,13 @@ import 'dart:ffi';
|
|||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Parse N characters of a hex formatted object id into a git_oid.
|
||||
Pointer<git_oid> fromStrN(String hex) {
|
||||
final out = calloc<git_oid>();
|
||||
final hexC = hex.toNativeUtf8().cast<Char>();
|
||||
final hexC = hex.toChar();
|
||||
libgit2.git_oid_fromstrn(out, hexC, hex.length);
|
||||
|
||||
calloc.free(hexC);
|
||||
|
@ -18,7 +19,7 @@ Pointer<git_oid> fromStrN(String hex) {
|
|||
/// Parse a hex formatted object id into a git_oid.
|
||||
Pointer<git_oid> fromSHA(String hex) {
|
||||
final out = calloc<git_oid>();
|
||||
final hexC = hex.toNativeUtf8().cast<Char>();
|
||||
final hexC = hex.toChar();
|
||||
libgit2.git_oid_fromstr(out, hexC);
|
||||
|
||||
calloc.free(hexC);
|
||||
|
@ -47,7 +48,7 @@ String toSHA(Pointer<git_oid> id) {
|
|||
final out = calloc<Char>(40);
|
||||
libgit2.git_oid_fmt(out, id);
|
||||
|
||||
final result = out.cast<Utf8>().toDartString(length: 40);
|
||||
final result = out.toDartString(length: 40);
|
||||
calloc.free(out);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Initialize a new packbuilder. The returned packbuilder must be freed with
|
||||
|
@ -121,7 +122,7 @@ void write({
|
|||
required Pointer<git_packbuilder> packbuilderPointer,
|
||||
String? path,
|
||||
}) {
|
||||
final pathC = path?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final pathC = path?.toChar() ?? nullptr;
|
||||
final error = libgit2.git_packbuilder_write(
|
||||
packbuilderPointer,
|
||||
pathC,
|
||||
|
@ -153,7 +154,7 @@ int writtenCount(Pointer<git_packbuilder> pb) {
|
|||
/// correct after the packfile has been written.
|
||||
String name(Pointer<git_packbuilder> pb) {
|
||||
final result = libgit2.git_packbuilder_name(pb);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Set number of threads to spawn.
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Directly generate a patch from the difference between two buffers. The
|
||||
|
@ -17,11 +18,11 @@ Pointer<git_patch> fromBuffers({
|
|||
required int interhunkLines,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_patch>>();
|
||||
final oldBufferC = oldBuffer?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final oldBufferC = oldBuffer?.toChar() ?? nullptr;
|
||||
final oldAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||
final oldLen = oldBuffer?.length ?? 0;
|
||||
final newBufferC = newBuffer?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final newAsPathC = oldAsPath?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final newBufferC = newBuffer?.toChar() ?? nullptr;
|
||||
final newAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||
final newLen = newBuffer?.length ?? 0;
|
||||
final opts = _diffOptionsInit(
|
||||
flags: flags,
|
||||
|
@ -65,8 +66,8 @@ Pointer<git_patch> fromBlobs({
|
|||
required int interhunkLines,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_patch>>();
|
||||
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final newAsPathC = oldAsPath?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final oldAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||
final newAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||
final opts = _diffOptionsInit(
|
||||
flags: flags,
|
||||
contextLines: contextLines,
|
||||
|
@ -104,9 +105,9 @@ Pointer<git_patch> fromBlobAndBuffer({
|
|||
required int interhunkLines,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_patch>>();
|
||||
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final bufferC = buffer?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final bufferAsPathC = oldAsPath?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final oldAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||
final bufferC = buffer?.toChar() ?? nullptr;
|
||||
final bufferAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||
final bufferLen = buffer?.length ?? 0;
|
||||
final opts = _diffOptionsInit(
|
||||
flags: flags,
|
||||
|
@ -175,8 +176,8 @@ Map<String, Object> hunk({
|
|||
required int hunkIndex,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_diff_hunk>>();
|
||||
final linesInHunk = calloc<Int64>();
|
||||
libgit2.git_patch_get_hunk(out, linesInHunk.cast(), patchPointer, hunkIndex);
|
||||
final linesInHunk = calloc<Size>();
|
||||
libgit2.git_patch_get_hunk(out, linesInHunk, patchPointer, hunkIndex);
|
||||
|
||||
final hunk = out.value;
|
||||
final linesN = linesInHunk.value;
|
||||
|
@ -235,7 +236,7 @@ String text(Pointer<git_patch> patch) {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_patch_to_buf(out, patch);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Initializes a rebase operation to rebase the changes in [branchPointer]
|
||||
|
@ -128,7 +129,7 @@ void commit({
|
|||
required String? message,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final messageC = message?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final messageC = message?.toChar() ?? nullptr;
|
||||
|
||||
final error = libgit2.git_rebase_commit(
|
||||
out,
|
||||
|
@ -163,7 +164,7 @@ Pointer<git_oid> origHeadOid(Pointer<git_rebase> rebase) =>
|
|||
/// Gets the original HEAD ref name for merge rebases.
|
||||
String origHeadName(Pointer<git_rebase> rebase) {
|
||||
final result = libgit2.git_rebase_orig_head_name(rebase);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Gets the onto id for merge rebases.
|
||||
|
@ -172,7 +173,7 @@ Pointer<git_oid> ontoOid(Pointer<git_rebase> rebase) =>
|
|||
|
||||
/// Gets the onto ref name for merge rebases.
|
||||
String ontoName(Pointer<git_rebase> rebase) {
|
||||
return libgit2.git_rebase_onto_name(rebase).cast<Utf8>().toDartString();
|
||||
return libgit2.git_rebase_onto_name(rebase).toDartString();
|
||||
}
|
||||
|
||||
/// Free memory allocated for rebase object.
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Get the type of a reference.
|
||||
|
@ -55,7 +56,7 @@ Pointer<git_reference> lookup({
|
|||
required String name,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final error = libgit2.git_reference_lookup(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -72,7 +73,7 @@ Pointer<git_reference> lookup({
|
|||
|
||||
/// Get the full name of a reference.
|
||||
String name(Pointer<git_reference> ref) {
|
||||
return libgit2.git_reference_name(ref).cast<Utf8>().toDartString();
|
||||
return libgit2.git_reference_name(ref).toDartString();
|
||||
}
|
||||
|
||||
/// Get the reference's short name.
|
||||
|
@ -80,7 +81,7 @@ String name(Pointer<git_reference> ref) {
|
|||
/// This will transform the reference name into a name "human-readable" version.
|
||||
/// If no shortname is appropriate, it will return the full name.
|
||||
String shorthand(Pointer<git_reference> ref) {
|
||||
return libgit2.git_reference_shorthand(ref).cast<Utf8>().toDartString();
|
||||
return libgit2.git_reference_shorthand(ref).toDartString();
|
||||
}
|
||||
|
||||
/// Rename an existing reference. The returned reference must be freed with
|
||||
|
@ -104,9 +105,9 @@ Pointer<git_reference> rename({
|
|||
String? logMessage,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final newNameC = newName.toNativeUtf8().cast<Char>();
|
||||
final newNameC = newName.toChar();
|
||||
final forceC = force == true ? 1 : 0;
|
||||
final logMessageC = logMessage?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||
final error = libgit2.git_reference_rename(
|
||||
out,
|
||||
refPointer,
|
||||
|
@ -140,9 +141,7 @@ List<String> list(Pointer<git_repository> repo) {
|
|||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
for (var i = 0; i < array.ref.count; i++) {
|
||||
result.add(
|
||||
array.ref.strings.elementAt(i).value.cast<Utf8>().toDartString(),
|
||||
);
|
||||
result.add(array.ref.strings.elementAt(i).value.toDartString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,7 +155,7 @@ bool hasLog({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
required String name,
|
||||
}) {
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final result = libgit2.git_reference_has_log(repoPointer, nameC);
|
||||
|
||||
calloc.free(nameC);
|
||||
|
@ -173,7 +172,7 @@ void ensureLog({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
required String refName,
|
||||
}) {
|
||||
final refNameC = refName.toNativeUtf8().cast<Char>();
|
||||
final refNameC = refName.toChar();
|
||||
final error = libgit2.git_reference_ensure_log(repoPointer, refNameC);
|
||||
|
||||
calloc.free(refNameC);
|
||||
|
@ -237,9 +236,9 @@ Pointer<git_reference> createDirect({
|
|||
String? logMessage,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final forceC = force == true ? 1 : 0;
|
||||
final logMessageC = logMessage?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||
final error = libgit2.git_reference_create(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -295,10 +294,10 @@ Pointer<git_reference> createSymbolic({
|
|||
String? logMessage,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final targetC = target.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final targetC = target.toChar();
|
||||
final forceC = force == true ? 1 : 0;
|
||||
final logMessageC = logMessage?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||
final error = libgit2.git_reference_symbolic_create(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -348,7 +347,7 @@ Pointer<git_reference> setTarget({
|
|||
String? logMessage,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final logMessageC = logMessage?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||
final error = libgit2.git_reference_set_target(
|
||||
out,
|
||||
refPointer,
|
||||
|
@ -388,8 +387,8 @@ Pointer<git_reference> setTargetSymbolic({
|
|||
String? logMessage,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reference>>();
|
||||
final targetC = target.toNativeUtf8().cast<Char>();
|
||||
final logMessageC = logMessage?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final targetC = target.toChar();
|
||||
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||
final error = libgit2.git_reference_symbolic_set_target(
|
||||
out,
|
||||
refPointer,
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Read the reflog for the given reference. The returned reflog must be
|
||||
|
@ -15,7 +16,7 @@ Pointer<git_reflog> read({
|
|||
required String name,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_reflog>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
libgit2.git_reflog_read(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -43,7 +44,7 @@ void delete({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
required String name,
|
||||
}) {
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
libgit2.git_reflog_delete(repoPointer, nameC);
|
||||
calloc.free(nameC);
|
||||
}
|
||||
|
@ -60,8 +61,8 @@ void rename({
|
|||
required String oldName,
|
||||
required String newName,
|
||||
}) {
|
||||
final oldNameC = oldName.toNativeUtf8().cast<Char>();
|
||||
final newNameC = newName.toNativeUtf8().cast<Char>();
|
||||
final oldNameC = oldName.toChar();
|
||||
final newNameC = newName.toChar();
|
||||
final error = libgit2.git_reflog_rename(repoPointer, oldNameC, newNameC);
|
||||
|
||||
calloc.free(oldNameC);
|
||||
|
@ -81,8 +82,7 @@ void add({
|
|||
required Pointer<git_signature> committerPointer,
|
||||
required String message,
|
||||
}) {
|
||||
final messageC =
|
||||
message.isEmpty ? nullptr : message.toNativeUtf8().cast<Char>();
|
||||
final messageC = message.isEmpty ? nullptr : message.toChar();
|
||||
|
||||
final error = libgit2.git_reflog_append(
|
||||
reflogPointer,
|
||||
|
@ -130,7 +130,7 @@ Pointer<git_reflog_entry> getByIndex({
|
|||
/// Get the log message.
|
||||
String entryMessage(Pointer<git_reflog_entry> entry) {
|
||||
final result = libgit2.git_reflog_entry_message(entry);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Get the committer of this entry. The returned signature must be freed.
|
||||
|
|
|
@ -3,16 +3,17 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Get the source specifier.
|
||||
String source(Pointer<git_refspec> refspec) {
|
||||
return libgit2.git_refspec_src(refspec).cast<Utf8>().toDartString();
|
||||
return libgit2.git_refspec_src(refspec).toDartString();
|
||||
}
|
||||
|
||||
/// Get the destination specifier.
|
||||
String destination(Pointer<git_refspec> refspec) {
|
||||
return libgit2.git_refspec_dst(refspec).cast<Utf8>().toDartString();
|
||||
return libgit2.git_refspec_dst(refspec).toDartString();
|
||||
}
|
||||
|
||||
/// Get the force update setting.
|
||||
|
@ -22,7 +23,7 @@ bool force(Pointer<git_refspec> refspec) {
|
|||
|
||||
/// Get the refspec's string.
|
||||
String string(Pointer<git_refspec> refspec) {
|
||||
return libgit2.git_refspec_string(refspec).cast<Utf8>().toDartString();
|
||||
return libgit2.git_refspec_string(refspec).toDartString();
|
||||
}
|
||||
|
||||
/// Get the refspec's direction.
|
||||
|
@ -34,7 +35,7 @@ bool matchesSource({
|
|||
required Pointer<git_refspec> refspecPointer,
|
||||
required String refname,
|
||||
}) {
|
||||
final refnameC = refname.toNativeUtf8().cast<Char>();
|
||||
final refnameC = refname.toChar();
|
||||
final result = libgit2.git_refspec_src_matches(refspecPointer, refnameC);
|
||||
|
||||
calloc.free(refnameC);
|
||||
|
@ -47,7 +48,7 @@ bool matchesDestination({
|
|||
required Pointer<git_refspec> refspecPointer,
|
||||
required String refname,
|
||||
}) {
|
||||
final refnameC = refname.toNativeUtf8().cast<Char>();
|
||||
final refnameC = refname.toChar();
|
||||
final result = libgit2.git_refspec_dst_matches(refspecPointer, refnameC);
|
||||
|
||||
calloc.free(refnameC);
|
||||
|
@ -63,10 +64,10 @@ String transform({
|
|||
required String name,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final error = libgit2.git_refspec_transform(out, refspecPointer, nameC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -88,10 +89,10 @@ String rTransform({
|
|||
required String name,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final error = libgit2.git_refspec_rtransform(out, refspecPointer, nameC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
|||
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
||||
import 'package:libgit2dart/src/callbacks.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/oid.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
|
@ -14,8 +15,7 @@ List<String> list(Pointer<git_repository> repo) {
|
|||
libgit2.git_remote_list(out, repo);
|
||||
|
||||
final result = <String>[
|
||||
for (var i = 0; i < out.ref.count; i++)
|
||||
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||
];
|
||||
|
||||
calloc.free(out);
|
||||
|
@ -34,7 +34,7 @@ Pointer<git_remote> lookup({
|
|||
required String name,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_remote>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final error = libgit2.git_remote_lookup(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -59,8 +59,8 @@ Pointer<git_remote> create({
|
|||
required String url,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_remote>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final urlC = url.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final urlC = url.toChar();
|
||||
final error = libgit2.git_remote_create(out, repoPointer, nameC, urlC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -87,9 +87,9 @@ Pointer<git_remote> createWithFetchSpec({
|
|||
required String fetch,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_remote>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final urlC = url.toNativeUtf8().cast<Char>();
|
||||
final fetchC = fetch.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final urlC = url.toChar();
|
||||
final fetchC = fetch.toChar();
|
||||
final error = libgit2.git_remote_create_with_fetchspec(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -122,7 +122,7 @@ void delete({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
required String name,
|
||||
}) {
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final error = libgit2.git_remote_delete(repoPointer, nameC);
|
||||
|
||||
calloc.free(nameC);
|
||||
|
@ -151,8 +151,8 @@ List<String> rename({
|
|||
required String newName,
|
||||
}) {
|
||||
final out = calloc<git_strarray>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final newNameC = newName.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final newNameC = newName.toChar();
|
||||
final error = libgit2.git_remote_rename(out, repoPointer, nameC, newNameC);
|
||||
|
||||
calloc.free(nameC);
|
||||
|
@ -163,8 +163,7 @@ List<String> rename({
|
|||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = <String>[
|
||||
for (var i = 0; i < out.ref.count; i++)
|
||||
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||
];
|
||||
|
||||
calloc.free(out);
|
||||
|
@ -184,8 +183,8 @@ void setUrl({
|
|||
required String remote,
|
||||
required String url,
|
||||
}) {
|
||||
final remoteC = remote.toNativeUtf8().cast<Char>();
|
||||
final urlC = url.toNativeUtf8().cast<Char>();
|
||||
final remoteC = remote.toChar();
|
||||
final urlC = url.toChar();
|
||||
final error = libgit2.git_remote_set_url(repoPointer, remoteC, urlC);
|
||||
|
||||
calloc.free(remoteC);
|
||||
|
@ -207,8 +206,8 @@ void setPushUrl({
|
|||
required String remote,
|
||||
required String url,
|
||||
}) {
|
||||
final remoteC = remote.toNativeUtf8().cast<Char>();
|
||||
final urlC = url.toNativeUtf8().cast<Char>();
|
||||
final remoteC = remote.toChar();
|
||||
final urlC = url.toChar();
|
||||
final error = libgit2.git_remote_set_pushurl(repoPointer, remoteC, urlC);
|
||||
|
||||
calloc.free(remoteC);
|
||||
|
@ -222,12 +221,12 @@ void setPushUrl({
|
|||
/// Get the remote's name.
|
||||
String name(Pointer<git_remote> remote) {
|
||||
final result = libgit2.git_remote_name(remote);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Get the remote's url.
|
||||
String url(Pointer<git_remote> remote) {
|
||||
return libgit2.git_remote_url(remote).cast<Utf8>().toDartString();
|
||||
return libgit2.git_remote_url(remote).toDartString();
|
||||
}
|
||||
|
||||
/// Get the remote's url for pushing.
|
||||
|
@ -235,7 +234,7 @@ String url(Pointer<git_remote> remote) {
|
|||
/// Returns empty string if no special url for pushing is set.
|
||||
String pushUrl(Pointer<git_remote> remote) {
|
||||
final result = libgit2.git_remote_pushurl(remote);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Get the number of refspecs for a remote.
|
||||
|
@ -256,8 +255,7 @@ List<String> fetchRefspecs(Pointer<git_remote> remote) {
|
|||
libgit2.git_remote_get_fetch_refspecs(out, remote);
|
||||
|
||||
final result = <String>[
|
||||
for (var i = 0; i < out.ref.count; i++)
|
||||
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||
];
|
||||
|
||||
calloc.free(out);
|
||||
|
@ -271,8 +269,7 @@ List<String> pushRefspecs(Pointer<git_remote> remote) {
|
|||
libgit2.git_remote_get_push_refspecs(out, remote);
|
||||
|
||||
final result = <String>[
|
||||
for (var i = 0; i < out.ref.count; i++)
|
||||
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||
];
|
||||
|
||||
calloc.free(out);
|
||||
|
@ -291,8 +288,8 @@ void addFetch({
|
|||
required String remote,
|
||||
required String refspec,
|
||||
}) {
|
||||
final remoteC = remote.toNativeUtf8().cast<Char>();
|
||||
final refspecC = refspec.toNativeUtf8().cast<Char>();
|
||||
final remoteC = remote.toChar();
|
||||
final refspecC = refspec.toChar();
|
||||
final error = libgit2.git_remote_add_fetch(repoPointer, remoteC, refspecC);
|
||||
|
||||
calloc.free(remoteC);
|
||||
|
@ -314,8 +311,8 @@ void addPush({
|
|||
required String remote,
|
||||
required String refspec,
|
||||
}) {
|
||||
final remoteC = remote.toNativeUtf8().cast<Char>();
|
||||
final refspecC = refspec.toNativeUtf8().cast<Char>();
|
||||
final remoteC = remote.toChar();
|
||||
final refspecC = refspec.toChar();
|
||||
final error = libgit2.git_remote_add_push(repoPointer, remoteC, refspecC);
|
||||
|
||||
calloc.free(remoteC);
|
||||
|
@ -393,12 +390,11 @@ List<Map<String, Object?>> lsRemotes(Pointer<git_remote> remote) {
|
|||
|
||||
remote['local'] = local;
|
||||
remote['loid'] = local ? Oid.fromRaw(out[0][i].ref.loid) : null;
|
||||
remote['name'] = out[0][i].ref.name == nullptr
|
||||
? ''
|
||||
: out[0][i].ref.name.cast<Utf8>().toDartString();
|
||||
remote['name'] =
|
||||
out[0][i].ref.name == nullptr ? '' : out[0][i].ref.name.toDartString();
|
||||
remote['symref'] = out[0][i].ref.symref_target == nullptr
|
||||
? ''
|
||||
: out[0][i].ref.symref_target.cast<Utf8>().toDartString();
|
||||
: out[0][i].ref.symref_target.toDartString();
|
||||
remote['oid'] = Oid.fromRaw(out[0][i].ref.oid);
|
||||
|
||||
result.add(remote);
|
||||
|
@ -425,8 +421,7 @@ void fetch({
|
|||
String? proxyOption,
|
||||
}) {
|
||||
final refspecsC = calloc<git_strarray>();
|
||||
final refspecsPointers =
|
||||
refspecs.map((e) => e.toNativeUtf8().cast<Char>()).toList();
|
||||
final refspecsPointers = refspecs.map((e) => e.toChar()).toList();
|
||||
final strArray = calloc<Pointer<Char>>(refspecs.length);
|
||||
|
||||
for (var i = 0; i < refspecs.length; i++) {
|
||||
|
@ -435,7 +430,7 @@ void fetch({
|
|||
|
||||
refspecsC.ref.count = refspecs.length;
|
||||
refspecsC.ref.strings = strArray;
|
||||
final reflogMessageC = reflogMessage?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final reflogMessageC = reflogMessage?.toChar() ?? nullptr;
|
||||
|
||||
final proxyOptions = _proxyOptionsInit(proxyOption);
|
||||
|
||||
|
@ -481,8 +476,7 @@ void push({
|
|||
String? proxyOption,
|
||||
}) {
|
||||
final refspecsC = calloc<git_strarray>();
|
||||
final refspecsPointers =
|
||||
refspecs.map((e) => e.toNativeUtf8().cast<Char>()).toList();
|
||||
final refspecsPointers = refspecs.map((e) => e.toChar()).toList();
|
||||
final strArray = calloc<Pointer<Char>>(refspecs.length);
|
||||
|
||||
for (var i = 0; i < refspecs.length; i++) {
|
||||
|
@ -572,7 +566,7 @@ Pointer<git_proxy_options> _proxyOptionsInit(String? proxyOption) {
|
|||
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_AUTO;
|
||||
} else {
|
||||
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_SPECIFIED;
|
||||
proxyOptions.ref.url = proxyOption.toNativeUtf8().cast<Char>();
|
||||
proxyOptions.ref.url = proxyOption.toChar();
|
||||
}
|
||||
|
||||
return proxyOptions;
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
|||
import 'package:libgit2dart/src/bindings/remote.dart' as remote_bindings;
|
||||
import 'package:libgit2dart/src/bindings/repository.dart'
|
||||
as repository_bindings;
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
class RemoteCallbacks {
|
||||
|
@ -33,7 +34,7 @@ class RemoteCallbacks {
|
|||
int length,
|
||||
Pointer<Void> payload,
|
||||
) {
|
||||
sidebandProgress!(progressOutput.cast<Utf8>().toDartString(length: length));
|
||||
sidebandProgress!(progressOutput.toDartString(length: length));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -47,7 +48,7 @@ class RemoteCallbacks {
|
|||
Pointer<git_oid> newOid,
|
||||
Pointer<Void> payload,
|
||||
) {
|
||||
updateTips!(refname.cast<Utf8>().toDartString(), Oid(oldOid), Oid(newOid));
|
||||
updateTips!(refname.toDartString(), Oid(oldOid), Oid(newOid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -62,9 +63,8 @@ class RemoteCallbacks {
|
|||
Pointer<Char> message,
|
||||
Pointer<Void> payload,
|
||||
) {
|
||||
final messageResult =
|
||||
message == nullptr ? '' : message.cast<Utf8>().toDartString();
|
||||
pushUpdateReference!(refname.cast<Utf8>().toDartString(), messageResult);
|
||||
final messageResult = message == nullptr ? '' : message.toDartString();
|
||||
pushUpdateReference!(refname.toDartString(), messageResult);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ class RemoteCallbacks {
|
|||
if (payload.cast<Char>().value == 2) {
|
||||
libgit2.git_error_set_str(
|
||||
git_error_t.GIT_ERROR_INVALID,
|
||||
'Incorrect credentials.'.toNativeUtf8().cast<Char>(),
|
||||
'Incorrect credentials.'.toChar(),
|
||||
);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ class RemoteCallbacks {
|
|||
if (allowedTypes & credentialType.value != credentialType.value) {
|
||||
libgit2.git_error_set_str(
|
||||
git_error_t.GIT_ERROR_INVALID,
|
||||
'Invalid credential type $credentialType'.toNativeUtf8().cast<Char>(),
|
||||
'Invalid credential type $credentialType'.toChar(),
|
||||
);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
|||
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
||||
import 'package:libgit2dart/src/callbacks.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/remote.dart';
|
||||
import 'package:libgit2dart/src/repository.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
@ -17,7 +18,7 @@ import 'package:libgit2dart/src/util.dart';
|
|||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_repository> open(String path) {
|
||||
final out = calloc<Pointer<git_repository>>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final error = libgit2.git_repository_open(out, pathC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -44,15 +45,15 @@ String discover({
|
|||
String? ceilingDirs,
|
||||
}) {
|
||||
final out = calloc<git_buf>();
|
||||
final startPathC = startPath.toNativeUtf8().cast<Char>();
|
||||
final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final startPathC = startPath.toChar();
|
||||
final ceilingDirsC = ceilingDirs?.toChar() ?? nullptr;
|
||||
|
||||
libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC);
|
||||
|
||||
calloc.free(startPathC);
|
||||
calloc.free(ceilingDirsC);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -75,12 +76,12 @@ Pointer<git_repository> init({
|
|||
String? originUrl,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_repository>>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final workdirPathC = workdirPath?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final descriptionC = description?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final templatePathC = templatePath?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final initialHeadC = initialHead?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final originUrlC = originUrl?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final pathC = path.toChar();
|
||||
final workdirPathC = workdirPath?.toChar() ?? nullptr;
|
||||
final descriptionC = description?.toChar() ?? nullptr;
|
||||
final templatePathC = templatePath?.toChar() ?? nullptr;
|
||||
final initialHeadC = initialHead?.toChar() ?? nullptr;
|
||||
final originUrlC = originUrl?.toChar() ?? nullptr;
|
||||
final opts = calloc<git_repository_init_options>();
|
||||
libgit2.git_repository_init_options_init(
|
||||
opts,
|
||||
|
@ -129,10 +130,9 @@ Pointer<git_repository> clone({
|
|||
required Callbacks callbacks,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_repository>>();
|
||||
final urlC = url.toNativeUtf8().cast<Char>();
|
||||
final localPathC = localPath.toNativeUtf8().cast<Char>();
|
||||
final checkoutBranchC =
|
||||
checkoutBranch?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final urlC = url.toChar();
|
||||
final localPathC = localPath.toChar();
|
||||
final checkoutBranchC = checkoutBranch?.toChar() ?? nullptr;
|
||||
|
||||
final cloneOptions = calloc<git_clone_options>();
|
||||
libgit2.git_clone_options_init(cloneOptions, GIT_CLONE_OPTIONS_VERSION);
|
||||
|
@ -187,7 +187,7 @@ Pointer<git_repository> clone({
|
|||
/// Returns the path to the `.git` folder for normal repositories or the
|
||||
/// repository itself for bare repositories.
|
||||
String path(Pointer<git_repository> repo) {
|
||||
return libgit2.git_repository_path(repo).cast<Utf8>().toDartString();
|
||||
return libgit2.git_repository_path(repo).toDartString();
|
||||
}
|
||||
|
||||
/// Get the path of the shared common directory for this repository.
|
||||
|
@ -196,7 +196,7 @@ String path(Pointer<git_repository> repo) {
|
|||
/// If the repository is a worktree, it is the parent repo's `.git` folder.
|
||||
/// Otherwise, it is the `.git` folder.
|
||||
String commonDir(Pointer<git_repository> repo) {
|
||||
return libgit2.git_repository_commondir(repo).cast<Utf8>().toDartString();
|
||||
return libgit2.git_repository_commondir(repo).toDartString();
|
||||
}
|
||||
|
||||
/// Get the currently active namespace for this repository.
|
||||
|
@ -205,11 +205,7 @@ String commonDir(Pointer<git_repository> repo) {
|
|||
/// empty string is returned.
|
||||
String getNamespace(Pointer<git_repository> repo) {
|
||||
final result = libgit2.git_repository_get_namespace(repo);
|
||||
if (result == nullptr) {
|
||||
return '';
|
||||
} else {
|
||||
return result.cast<Utf8>().toDartString();
|
||||
}
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Sets the active namespace for this repository.
|
||||
|
@ -223,7 +219,7 @@ void setNamespace({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
String? namespace,
|
||||
}) {
|
||||
final namespaceC = namespace?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final namespaceC = namespace?.toChar() ?? nullptr;
|
||||
libgit2.git_repository_set_namespace(repoPointer, namespaceC);
|
||||
calloc.free(namespaceC);
|
||||
}
|
||||
|
@ -310,8 +306,8 @@ void setIdentity({
|
|||
String? name,
|
||||
String? email,
|
||||
}) {
|
||||
final nameC = name?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final emailC = email?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final nameC = name?.toChar() ?? nullptr;
|
||||
final emailC = email?.toChar() ?? nullptr;
|
||||
|
||||
libgit2.git_repository_set_ident(repoPointer, nameC, emailC);
|
||||
|
||||
|
@ -331,8 +327,8 @@ List<String> identity(Pointer<git_repository> repo) {
|
|||
if (name.value == nullptr && email.value == nullptr) {
|
||||
return identity;
|
||||
} else {
|
||||
identity.add(name.value.cast<Utf8>().toDartString());
|
||||
identity.add(email.value.cast<Utf8>().toDartString());
|
||||
identity.add(name.value.toDartString());
|
||||
identity.add(email.value.toDartString());
|
||||
}
|
||||
|
||||
calloc.free(name);
|
||||
|
@ -416,7 +412,7 @@ String message(Pointer<git_repository> repo) {
|
|||
final out = calloc<git_buf>();
|
||||
final error = libgit2.git_repository_message(out, repo);
|
||||
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -494,7 +490,7 @@ void setHead({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
required String refname,
|
||||
}) {
|
||||
final refnameC = refname.toNativeUtf8().cast<Char>();
|
||||
final refnameC = refname.toChar();
|
||||
final error = libgit2.git_repository_set_head(repoPointer, refnameC);
|
||||
|
||||
calloc.free(refnameC);
|
||||
|
@ -545,7 +541,7 @@ void setWorkdir({
|
|||
required String path,
|
||||
required bool updateGitlink,
|
||||
}) {
|
||||
final workdirC = path.toNativeUtf8().cast<Char>();
|
||||
final workdirC = path.toChar();
|
||||
final updateGitlinkC = updateGitlink ? 1 : 0;
|
||||
final error = libgit2.git_repository_set_workdir(
|
||||
repoPointer,
|
||||
|
@ -581,12 +577,7 @@ void stateCleanup(Pointer<git_repository> repo) {
|
|||
/// If the repository is bare, this function will always return empty string.
|
||||
String workdir(Pointer<git_repository> repo) {
|
||||
final result = libgit2.git_repository_workdir(repo);
|
||||
|
||||
if (result == nullptr) {
|
||||
return '';
|
||||
} else {
|
||||
return result.cast<Utf8>().toDartString();
|
||||
}
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Free a previously allocated repository.
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Sets the current head to the specified commit oid and optionally resets the
|
||||
|
@ -40,8 +41,7 @@ void resetDefault({
|
|||
required List<String> pathspec,
|
||||
}) {
|
||||
final pathspecC = calloc<git_strarray>();
|
||||
final pathPointers =
|
||||
pathspec.map((e) => e.toNativeUtf8().cast<Char>()).toList();
|
||||
final pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||
final strArray = calloc<Pointer<Char>>(pathspec.length);
|
||||
|
||||
for (var i = 0; i < pathspec.length; i++) {
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Parse a revision string for from, to, and intent.
|
||||
|
@ -16,7 +17,7 @@ Pointer<git_revspec> revParse({
|
|||
required String spec,
|
||||
}) {
|
||||
final out = calloc<git_revspec>();
|
||||
final specC = spec.toNativeUtf8().cast<Char>();
|
||||
final specC = spec.toChar();
|
||||
|
||||
final error = libgit2.git_revparse(out, repoPointer, specC);
|
||||
|
||||
|
@ -42,7 +43,7 @@ Pointer<git_object> revParseSingle({
|
|||
required String spec,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_object>>();
|
||||
final specC = spec.toNativeUtf8().cast<Char>();
|
||||
final specC = spec.toChar();
|
||||
|
||||
final error = libgit2.git_revparse_single(out, repoPointer, specC);
|
||||
|
||||
|
@ -76,7 +77,7 @@ List<Pointer> revParseExt({
|
|||
}) {
|
||||
final objectOut = calloc<Pointer<git_object>>();
|
||||
final referenceOut = calloc<Pointer<git_reference>>();
|
||||
final specC = spec.toNativeUtf8().cast<Char>();
|
||||
final specC = spec.toChar();
|
||||
|
||||
final error = libgit2.git_revparse_ext(
|
||||
objectOut,
|
||||
|
@ -85,8 +86,7 @@ List<Pointer> revParseExt({
|
|||
specC,
|
||||
);
|
||||
|
||||
final result = <Pointer>[];
|
||||
result.add(objectOut.value);
|
||||
final result = <Pointer>[objectOut.value];
|
||||
if (referenceOut.value != nullptr) {
|
||||
result.add(referenceOut.value);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
|||
import 'package:libgit2dart/src/bindings/commit.dart' as commit_bindings;
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Allocate a new revision walker to iterate through a repo. The returned
|
||||
|
@ -81,7 +82,7 @@ void pushGlob({
|
|||
required Pointer<git_revwalk> walkerPointer,
|
||||
required String glob,
|
||||
}) {
|
||||
final globC = glob.toNativeUtf8().cast<Char>();
|
||||
final globC = glob.toChar();
|
||||
libgit2.git_revwalk_push_glob(walkerPointer, globC);
|
||||
calloc.free(globC);
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ void pushRef({
|
|||
required Pointer<git_revwalk> walkerPointer,
|
||||
required String refName,
|
||||
}) {
|
||||
final refNameC = refName.toNativeUtf8().cast<Char>();
|
||||
final refNameC = refName.toChar();
|
||||
final error = libgit2.git_revwalk_push_ref(walkerPointer, refNameC);
|
||||
|
||||
calloc.free(refNameC);
|
||||
|
@ -119,7 +120,7 @@ void pushRange({
|
|||
required Pointer<git_revwalk> walkerPointer,
|
||||
required String range,
|
||||
}) {
|
||||
final rangeC = range.toNativeUtf8().cast<Char>();
|
||||
final rangeC = range.toChar();
|
||||
final error = libgit2.git_revwalk_push_range(walkerPointer, rangeC);
|
||||
|
||||
calloc.free(rangeC);
|
||||
|
@ -199,7 +200,7 @@ void hideGlob({
|
|||
required Pointer<git_revwalk> walkerPointer,
|
||||
required String glob,
|
||||
}) {
|
||||
final globC = glob.toNativeUtf8().cast<Char>();
|
||||
final globC = glob.toChar();
|
||||
libgit2.git_revwalk_hide_glob(walkerPointer, globC);
|
||||
calloc.free(globC);
|
||||
}
|
||||
|
@ -217,7 +218,7 @@ void hideRef({
|
|||
required Pointer<git_revwalk> walkerPointer,
|
||||
required String refName,
|
||||
}) {
|
||||
final refNameC = refName.toNativeUtf8().cast<Char>();
|
||||
final refNameC = refName.toChar();
|
||||
final error = libgit2.git_revwalk_hide_ref(walkerPointer, refNameC);
|
||||
|
||||
calloc.free(refNameC);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Create a new action signature. The returned signature must be freed with
|
||||
|
@ -19,8 +20,8 @@ Pointer<git_signature> create({
|
|||
required int offset,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_signature>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final emailC = email.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final emailC = email.toChar();
|
||||
final error = libgit2.git_signature_new(out, nameC, emailC, time, offset);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -42,8 +43,8 @@ Pointer<git_signature> create({
|
|||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_signature> now({required String name, required String email}) {
|
||||
final out = calloc<Pointer<git_signature>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final emailC = email.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final emailC = email.toChar();
|
||||
final error = libgit2.git_signature_now(out, nameC, emailC);
|
||||
|
||||
final result = out.value;
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
|||
import 'package:libgit2dart/src/bindings/checkout.dart' as checkout_bindings;
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/oid.dart';
|
||||
import 'package:libgit2dart/src/stash.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
@ -18,7 +19,7 @@ Pointer<git_oid> save({
|
|||
required int flags,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final messageC = message?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final messageC = message?.toChar() ?? nullptr;
|
||||
final error = libgit2.git_stash_save(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -148,11 +149,7 @@ int _stashCb(
|
|||
Pointer<Void> payload,
|
||||
) {
|
||||
_stashList.add(
|
||||
Stash(
|
||||
index: index,
|
||||
message: message.cast<Utf8>().toDartString(),
|
||||
oid: Oid(oid),
|
||||
),
|
||||
Stash(index: index, message: message.toDartString(), oid: Oid(oid)),
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
|||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Gather file status information and populate the git_status_list. The
|
||||
|
@ -63,7 +64,7 @@ Pointer<git_status_entry> getByIndex({
|
|||
/// Throws a [LibGit2Error] if error occured.
|
||||
int file({required Pointer<git_repository> repoPointer, required String path}) {
|
||||
final out = calloc<UnsignedInt>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final error = libgit2.git_status_file(out, repoPointer, pathC);
|
||||
|
||||
final result = out.value;
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
|||
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
||||
import 'package:libgit2dart/src/callbacks.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// List of submodule paths.
|
||||
|
@ -50,7 +51,7 @@ Pointer<git_submodule> lookup({
|
|||
required String name,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_submodule>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
|
||||
final error = libgit2.git_submodule_lookup(out, repoPointer, nameC);
|
||||
|
||||
|
@ -159,8 +160,8 @@ Pointer<git_submodule> addSetup({
|
|||
bool useGitlink = true,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_submodule>>();
|
||||
final urlC = url.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final urlC = url.toChar();
|
||||
final pathC = path.toChar();
|
||||
final useGitlinkC = useGitlink ? 1 : 0;
|
||||
final error = libgit2.git_submodule_add_setup(
|
||||
out,
|
||||
|
@ -233,7 +234,7 @@ int status({
|
|||
required int ignore,
|
||||
}) {
|
||||
final out = calloc<UnsignedInt>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
libgit2.git_submodule_status(out, repoPointer, nameC, ignore);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -269,7 +270,7 @@ void reload({
|
|||
|
||||
/// Get the name of submodule.
|
||||
String name(Pointer<git_submodule> submodule) {
|
||||
return libgit2.git_submodule_name(submodule).cast<Utf8>().toDartString();
|
||||
return libgit2.git_submodule_name(submodule).toDartString();
|
||||
}
|
||||
|
||||
/// Get the path to the submodule.
|
||||
|
@ -277,12 +278,12 @@ String name(Pointer<git_submodule> submodule) {
|
|||
/// The path is almost always the same as the submodule name, but the two
|
||||
/// are actually not required to match.
|
||||
String path(Pointer<git_submodule> submodule) {
|
||||
return libgit2.git_submodule_path(submodule).cast<Utf8>().toDartString();
|
||||
return libgit2.git_submodule_path(submodule).toDartString();
|
||||
}
|
||||
|
||||
/// Get the URL for the submodule.
|
||||
String url(Pointer<git_submodule> submodule) {
|
||||
return libgit2.git_submodule_url(submodule).cast<Utf8>().toDartString();
|
||||
return libgit2.git_submodule_url(submodule).toDartString();
|
||||
}
|
||||
|
||||
/// Set the URL for the submodule in the configuration.
|
||||
|
@ -294,8 +295,8 @@ void setUrl({
|
|||
required String name,
|
||||
required String url,
|
||||
}) {
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final urlC = url.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final urlC = url.toChar();
|
||||
|
||||
libgit2.git_submodule_set_url(repoPointer, nameC, urlC);
|
||||
|
||||
|
@ -306,7 +307,7 @@ void setUrl({
|
|||
/// Get the branch for the submodule.
|
||||
String branch(Pointer<git_submodule> submodule) {
|
||||
final result = libgit2.git_submodule_branch(submodule);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Set the branch for the submodule in the configuration.
|
||||
|
@ -318,8 +319,8 @@ void setBranch({
|
|||
required String name,
|
||||
required String branch,
|
||||
}) {
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final branchC = branch.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final branchC = branch.toChar();
|
||||
|
||||
libgit2.git_submodule_set_branch(repoPointer, nameC, branchC);
|
||||
|
||||
|
@ -369,7 +370,7 @@ void setIgnore({
|
|||
required String name,
|
||||
required int ignore,
|
||||
}) {
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
libgit2.git_submodule_set_ignore(repoPointer, nameC, ignore);
|
||||
calloc.free(nameC);
|
||||
}
|
||||
|
@ -389,7 +390,7 @@ void setUpdateRule({
|
|||
required String name,
|
||||
required int update,
|
||||
}) {
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
libgit2.git_submodule_set_update(repoPointer, nameC, update);
|
||||
calloc.free(nameC);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Fill a list with all the tags in the repository.
|
||||
|
@ -12,16 +13,16 @@ List<String> list(Pointer<git_repository> repo) {
|
|||
final out = calloc<git_strarray>();
|
||||
final error = libgit2.git_tag_list(out, 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++) {
|
||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
||||
}
|
||||
final result = <String>[
|
||||
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||
];
|
||||
|
||||
calloc.free(out);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -80,13 +81,12 @@ Pointer<git_oid> targetOid(Pointer<git_tag> tag) =>
|
|||
Pointer<git_oid> id(Pointer<git_tag> tag) => libgit2.git_tag_id(tag);
|
||||
|
||||
/// Get the name of a tag.
|
||||
String name(Pointer<git_tag> tag) =>
|
||||
libgit2.git_tag_name(tag).cast<Utf8>().toDartString();
|
||||
String name(Pointer<git_tag> tag) => libgit2.git_tag_name(tag).toDartString();
|
||||
|
||||
/// Get the message of a tag.
|
||||
String message(Pointer<git_tag> tag) {
|
||||
final result = libgit2.git_tag_message(tag);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
return result == nullptr ? '' : result.toDartString();
|
||||
}
|
||||
|
||||
/// Get the tagger (author) of a tag. The returned signature must be freed.
|
||||
|
@ -115,8 +115,8 @@ Pointer<git_oid> createAnnotated({
|
|||
required bool force,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final tagNameC = tagName.toNativeUtf8().cast<Char>();
|
||||
final messageC = message.toNativeUtf8().cast<Char>();
|
||||
final tagNameC = tagName.toChar();
|
||||
final messageC = message.toChar();
|
||||
final error = libgit2.git_tag_create(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -155,7 +155,7 @@ Pointer<git_oid> createLightweight({
|
|||
required bool force,
|
||||
}) {
|
||||
final out = calloc<git_oid>();
|
||||
final tagNameC = tagName.toNativeUtf8().cast<Char>();
|
||||
final tagNameC = tagName.toChar();
|
||||
final error = libgit2.git_tag_create_lightweight(
|
||||
out,
|
||||
repoPointer,
|
||||
|
@ -183,7 +183,7 @@ void delete({
|
|||
required Pointer<git_repository> repoPointer,
|
||||
required String tagName,
|
||||
}) {
|
||||
final tagNameC = tagName.toNativeUtf8().cast<Char>();
|
||||
final tagNameC = tagName.toChar();
|
||||
final error = libgit2.git_tag_delete(repoPointer, tagNameC);
|
||||
|
||||
calloc.free(tagNameC);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Get the id of a tree.
|
||||
|
@ -59,7 +60,7 @@ Pointer<git_tree_entry> getByName({
|
|||
required Pointer<git_tree> treePointer,
|
||||
required String filename,
|
||||
}) {
|
||||
final filenameC = filename.toNativeUtf8().cast<Char>();
|
||||
final filenameC = filename.toChar();
|
||||
final result = libgit2.git_tree_entry_byname(treePointer, filenameC);
|
||||
|
||||
calloc.free(filenameC);
|
||||
|
@ -83,7 +84,7 @@ Pointer<git_tree_entry> getByPath({
|
|||
required String path,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_tree_entry>>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
final error = libgit2.git_tree_entry_bypath(out, rootPointer, pathC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -107,7 +108,7 @@ Pointer<git_oid> entryId(Pointer<git_tree_entry> entry) =>
|
|||
|
||||
/// Get the filename of a tree entry.
|
||||
String entryName(Pointer<git_tree_entry> entry) =>
|
||||
libgit2.git_tree_entry_name(entry).cast<Utf8>().toDartString();
|
||||
libgit2.git_tree_entry_name(entry).toDartString();
|
||||
|
||||
/// Get the UNIX file attributes of a tree entry.
|
||||
int entryFilemode(Pointer<git_tree_entry> entry) =>
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Create a new tree builder. The returned tree builder must be freed with
|
||||
|
@ -53,7 +54,7 @@ Pointer<git_tree_entry> getByFilename({
|
|||
required Pointer<git_treebuilder> builderPointer,
|
||||
required String filename,
|
||||
}) {
|
||||
final filenameC = filename.toNativeUtf8().cast<Char>();
|
||||
final filenameC = filename.toChar();
|
||||
final result = libgit2.git_treebuilder_get(builderPointer, filenameC);
|
||||
|
||||
calloc.free(filenameC);
|
||||
|
@ -82,7 +83,7 @@ void add({
|
|||
required Pointer<git_oid> oidPointer,
|
||||
required int filemode,
|
||||
}) {
|
||||
final filenameC = filename.toNativeUtf8().cast<Char>();
|
||||
final filenameC = filename.toChar();
|
||||
final error = libgit2.git_treebuilder_insert(
|
||||
nullptr,
|
||||
builderPointer,
|
||||
|
@ -105,7 +106,7 @@ void remove({
|
|||
required Pointer<git_treebuilder> builderPointer,
|
||||
required String filename,
|
||||
}) {
|
||||
final filenameC = filename.toNativeUtf8().cast<Char>();
|
||||
final filenameC = filename.toChar();
|
||||
final error = libgit2.git_treebuilder_remove(builderPointer, filenameC);
|
||||
|
||||
calloc.free(filenameC);
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
|||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/error.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
/// Add a new working tree. The returned worktree must be freed with [free].
|
||||
|
@ -20,8 +21,8 @@ Pointer<git_worktree> create({
|
|||
Pointer<git_reference>? refPointer,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_worktree>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final pathC = path.toChar();
|
||||
|
||||
final opts = calloc<git_worktree_add_options>();
|
||||
libgit2.git_worktree_add_options_init(opts, GIT_WORKTREE_ADD_OPTIONS_VERSION);
|
||||
|
@ -56,7 +57,7 @@ Pointer<git_worktree> lookup({
|
|||
required String name,
|
||||
}) {
|
||||
final out = calloc<Pointer<git_worktree>>();
|
||||
final nameC = name.toNativeUtf8().cast<Char>();
|
||||
final nameC = name.toChar();
|
||||
final error = libgit2.git_worktree_lookup(out, repoPointer, nameC);
|
||||
|
||||
final result = out.value;
|
||||
|
@ -111,8 +112,7 @@ List<String> list(Pointer<git_repository> repo) {
|
|||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
final result = <String>[
|
||||
for (var i = 0; i < out.ref.count; i++)
|
||||
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||
];
|
||||
|
||||
calloc.free(out);
|
||||
|
@ -123,12 +123,12 @@ List<String> list(Pointer<git_repository> repo) {
|
|||
|
||||
/// Retrieve the name of the worktree.
|
||||
String name(Pointer<git_worktree> wt) {
|
||||
return libgit2.git_worktree_name(wt).cast<Utf8>().toDartString();
|
||||
return libgit2.git_worktree_name(wt).toDartString();
|
||||
}
|
||||
|
||||
/// Retrieve the filesystem path for the worktree.
|
||||
String path(Pointer<git_worktree> wt) {
|
||||
return libgit2.git_worktree_path(wt).cast<Utf8>().toDartString();
|
||||
return libgit2.git_worktree_path(wt).toDartString();
|
||||
}
|
||||
|
||||
/// Check if worktree is locked.
|
||||
|
|
|
@ -2,10 +2,10 @@ import 'dart:collection';
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/blame.dart' as bindings;
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class Blame with IterableMixin<BlameHunk> {
|
||||
|
@ -174,8 +174,7 @@ class BlameHunk extends Equatable {
|
|||
|
||||
/// Path to the file where this hunk originated, as of the commit specified by
|
||||
/// [originCommitOid].
|
||||
String get originPath =>
|
||||
_blameHunkPointer.ref.orig_path.cast<Utf8>().toDartString();
|
||||
String get originPath => _blameHunkPointer.ref.orig_path.toDartString();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:ffi/ffi.dart';
|
|||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/config.dart' as bindings;
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
|
@ -98,8 +99,8 @@ class Config with IterableMixin<ConfigEntry> {
|
|||
configPointer: _configPointer,
|
||||
variable: variable,
|
||||
);
|
||||
final name = entryPointer.ref.name.cast<Utf8>().toDartString();
|
||||
final value = entryPointer.ref.value.cast<Utf8>().toDartString();
|
||||
final name = entryPointer.ref.name.toDartString();
|
||||
final value = entryPointer.ref.value.toDartString();
|
||||
final includeDepth = entryPointer.ref.include_depth;
|
||||
final level = GitConfigLevel.values.firstWhere(
|
||||
(e) => entryPointer.ref.level == e.value,
|
||||
|
@ -264,8 +265,8 @@ class _ConfigIterator implements Iterator<ConfigEntry> {
|
|||
} else {
|
||||
error = libgit2.git_config_next(entry, _iteratorPointer);
|
||||
if (error != -31) {
|
||||
final name = entry.value.ref.name.cast<Utf8>().toDartString();
|
||||
final value = entry.value.ref.value.cast<Utf8>().toDartString();
|
||||
final name = entry.value.ref.name.toDartString();
|
||||
final value = entry.value.ref.value.toDartString();
|
||||
final includeDepth = entry.value.ref.include_depth;
|
||||
final level = GitConfigLevel.values.firstWhere(
|
||||
(e) => entry.value.ref.level == e.value,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/diff.dart' as bindings;
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
|
@ -546,7 +546,7 @@ class DiffFile extends Equatable {
|
|||
Oid get oid => Oid.fromRaw(_diffFile.id);
|
||||
|
||||
/// Path to the entry relative to the working directory of the repository.
|
||||
String get path => _diffFile.path.cast<Utf8>().toDartString();
|
||||
String get path => _diffFile.path.toDartString();
|
||||
|
||||
/// Size of the entry in bytes.
|
||||
int get size => _diffFile.size;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// coverage:ignore-file
|
||||
|
||||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
|
||||
/// Details of the last error that occurred.
|
||||
class LibGit2Error {
|
||||
|
@ -11,7 +11,5 @@ class LibGit2Error {
|
|||
final Pointer<git_error> _errorPointer;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return _errorPointer.ref.message.cast<Utf8>().toDartString();
|
||||
}
|
||||
String toString() => _errorPointer.ref.message.toDartString();
|
||||
}
|
||||
|
|
36
lib/src/extensions.dart
Normal file
36
lib/src/extensions.dart
Normal file
|
@ -0,0 +1,36 @@
|
|||
// coverage:ignore-file
|
||||
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
|
||||
extension IsValidSHA on String {
|
||||
bool isValidSHA() {
|
||||
final hexRegExp = RegExp(r'^[0-9a-fA-F]+$');
|
||||
return hexRegExp.hasMatch(this) &&
|
||||
(GIT_OID_MINPREFIXLEN <= length && GIT_OID_HEXSZ >= length);
|
||||
}
|
||||
}
|
||||
|
||||
extension ToChar on String {
|
||||
/// Creates a zero-terminated [Utf8] code-unit array from this String,
|
||||
/// casts it to the C `char` type and returns allocated pointer to result.
|
||||
Pointer<Char> toChar() => toNativeUtf8().cast<Char>();
|
||||
}
|
||||
|
||||
extension ToDartString on Pointer<Char> {
|
||||
/// Converts this UTF-8 encoded string to a Dart string.
|
||||
///
|
||||
/// Decodes the UTF-8 code units of this zero-terminated byte array as
|
||||
/// Unicode code points and creates a Dart string containing those code
|
||||
/// points.
|
||||
///
|
||||
/// If [length] is provided, zero-termination is ignored and the result can
|
||||
/// contain NUL characters.
|
||||
///
|
||||
/// If [length] is not provided, the returned string is the string up til but
|
||||
/// not including the first NUL character.
|
||||
String toDartString({int? length}) =>
|
||||
cast<Utf8>().toDartString(length: length);
|
||||
}
|
|
@ -2,10 +2,10 @@ import 'dart:collection';
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/index.dart' as bindings;
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class Index with IterableMixin<IndexEntry> {
|
||||
|
@ -345,10 +345,9 @@ class IndexEntry extends Equatable {
|
|||
set oid(Oid oid) => _indexEntryPointer.ref.id = oid.pointer.ref;
|
||||
|
||||
/// Path of the index entry.
|
||||
String get path => _indexEntryPointer.ref.path.cast<Utf8>().toDartString();
|
||||
String get path => _indexEntryPointer.ref.path.toDartString();
|
||||
|
||||
set path(String path) =>
|
||||
_indexEntryPointer.ref.path = path.toNativeUtf8().cast<Char>();
|
||||
set path(String path) => _indexEntryPointer.ref.path = path.toChar();
|
||||
|
||||
/// UNIX file attributes of a index entry.
|
||||
GitFilemode get mode {
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
|||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
|
||||
class Libgit2 {
|
||||
|
@ -102,7 +103,7 @@ class Libgit2 {
|
|||
|
||||
final out = calloc<git_buf>();
|
||||
libgit2Opts.git_libgit2_opts_get_search_path(level.value, out);
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -129,7 +130,7 @@ class Libgit2 {
|
|||
}) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
final pathC = path?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final pathC = path?.toChar() ?? nullptr;
|
||||
libgit2Opts.git_libgit2_opts_set_search_path(level.value, pathC);
|
||||
calloc.free(pathC);
|
||||
}
|
||||
|
@ -201,7 +202,7 @@ class Libgit2 {
|
|||
|
||||
final out = calloc<git_buf>();
|
||||
libgit2Opts.git_libgit2_opts_get_template_path(out);
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -212,7 +213,7 @@ class Libgit2 {
|
|||
static set templatePath(String path) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
final pathC = path.toNativeUtf8().cast<Char>();
|
||||
final pathC = path.toChar();
|
||||
libgit2Opts.git_libgit2_opts_set_template_path(pathC);
|
||||
|
||||
calloc.free(pathC);
|
||||
|
@ -234,8 +235,8 @@ class Libgit2 {
|
|||
} else {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
final fileC = file?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final pathC = path?.toNativeUtf8().cast<Char>() ?? nullptr;
|
||||
final fileC = file?.toChar() ?? nullptr;
|
||||
final pathC = path?.toChar() ?? nullptr;
|
||||
|
||||
libgit2Opts.git_libgit2_opts_set_ssl_cert_locations(fileC, pathC);
|
||||
|
||||
|
@ -253,7 +254,7 @@ class Libgit2 {
|
|||
|
||||
final out = calloc<git_buf>();
|
||||
libgit2Opts.git_libgit2_opts_get_user_agent(out);
|
||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
||||
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||
|
||||
libgit2.git_buf_dispose(out);
|
||||
calloc.free(out);
|
||||
|
@ -264,7 +265,7 @@ class Libgit2 {
|
|||
static set userAgent(String userAgent) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
final userAgentC = userAgent.toNativeUtf8().cast<Char>();
|
||||
final userAgentC = userAgent.toChar();
|
||||
libgit2Opts.git_libgit2_opts_set_user_agent(userAgentC);
|
||||
|
||||
calloc.free(userAgentC);
|
||||
|
@ -483,7 +484,7 @@ class Libgit2 {
|
|||
|
||||
final result = <String>[
|
||||
for (var i = 0; i < array.ref.count; i++)
|
||||
array.ref.strings.elementAt(i).value.cast<Utf8>().toDartString()
|
||||
array.ref.strings.elementAt(i).value.toDartString()
|
||||
];
|
||||
|
||||
calloc.free(array);
|
||||
|
@ -496,7 +497,7 @@ class Libgit2 {
|
|||
|
||||
final array = calloc<Pointer<Char>>(extensions.length);
|
||||
for (var i = 0; i < extensions.length; i++) {
|
||||
array[i] = extensions[i].toNativeUtf8().cast<Char>();
|
||||
array[i] = extensions[i].toChar();
|
||||
}
|
||||
|
||||
libgit2Opts.git_libgit2_opts_set_extensions(array, extensions.length);
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'package:libgit2dart/libgit2dart.dart';
|
|||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/bindings/odb.dart' as odb_bindings;
|
||||
import 'package:libgit2dart/src/bindings/oid.dart' as bindings;
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@immutable
|
||||
|
@ -24,7 +24,7 @@ class Oid extends Equatable {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Oid.fromSHA({required Repository repo, required String sha}) {
|
||||
if (isValidShaHex(sha)) {
|
||||
if (sha.isValidSHA()) {
|
||||
if (sha.length == 40) {
|
||||
_oidPointer = bindings.fromSHA(sha);
|
||||
} else {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/bindings/signature.dart' as bindings;
|
||||
import 'package:libgit2dart/src/extensions.dart';
|
||||
import 'package:libgit2dart/src/util.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
|
@ -64,10 +65,10 @@ class Signature extends Equatable {
|
|||
Pointer<git_signature> get pointer => _signaturePointer;
|
||||
|
||||
/// Full name of the author.
|
||||
String get name => _signaturePointer.ref.name.cast<Utf8>().toDartString();
|
||||
String get name => _signaturePointer.ref.name.toDartString();
|
||||
|
||||
/// Email of the author.
|
||||
String get email => _signaturePointer.ref.email.cast<Utf8>().toDartString();
|
||||
String get email => _signaturePointer.ref.email.toDartString();
|
||||
|
||||
/// Time in seconds from epoch.
|
||||
int get time => _signaturePointer.ref.when.time;
|
||||
|
|
|
@ -88,9 +88,3 @@ DynamicLibrary loadLibrary(String name) {
|
|||
|
||||
final libgit2 = Libgit2(loadLibrary(getLibName()));
|
||||
final libgit2Opts = Libgit2Opts(loadLibrary(getLibName()));
|
||||
|
||||
bool isValidShaHex(String str) {
|
||||
final hexRegExp = RegExp(r'^[0-9a-fA-F]+$');
|
||||
return hexRegExp.hasMatch(str) &&
|
||||
(GIT_OID_MINPREFIXLEN <= str.length && GIT_OID_HEXSZ >= str.length);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue