refactor!: use named arguments if there is more than one

This commit is contained in:
Aleksey Kulikov 2021-09-30 18:04:36 +03:00
parent ec80ad3dd4
commit 5f7fdf4bd3
66 changed files with 1920 additions and 1136 deletions

View file

@ -7,9 +7,12 @@ import '../util.dart';
/// Lookup a blob object from a repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_blob> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
Pointer<git_blob> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_blob>>();
final error = libgit2.git_blob_lookup(out, repo, id);
final error = libgit2.git_blob_lookup(out, repoPointer, oidPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -47,14 +50,15 @@ int size(Pointer<git_blob> blob) => libgit2.git_blob_rawsize(blob);
/// Write content of a string buffer to the ODB as a blob.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> create(
Pointer<git_repository> repo,
String buffer,
int len,
) {
Pointer<git_oid> create({
required Pointer<git_repository> repoPointer,
required String buffer,
required int len,
}) {
final out = calloc<git_oid>();
final bufferC = buffer.toNativeUtf8().cast<Void>();
final error = libgit2.git_blob_create_from_buffer(out, repo, bufferC, len);
final error =
libgit2.git_blob_create_from_buffer(out, repoPointer, bufferC, len);
calloc.free(bufferC);
@ -69,13 +73,14 @@ Pointer<git_oid> create(
/// Object Database as a loose blob.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> createFromWorkdir(
Pointer<git_repository> repo,
String relativePath,
) {
Pointer<git_oid> createFromWorkdir({
required Pointer<git_repository> repoPointer,
required String relativePath,
}) {
final out = calloc<git_oid>();
final relativePathC = relativePath.toNativeUtf8().cast<Int8>();
final error = libgit2.git_blob_create_from_workdir(out, repo, relativePathC);
final error =
libgit2.git_blob_create_from_workdir(out, repoPointer, relativePathC);
calloc.free(relativePathC);
@ -89,13 +94,13 @@ Pointer<git_oid> createFromWorkdir(
/// Read a file from the filesystem and write its content to the Object Database as a loose blob.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> createFromDisk(
Pointer<git_repository> repo,
String path,
) {
Pointer<git_oid> createFromDisk({
required Pointer<git_repository> repoPointer,
required String path,
}) {
final out = calloc<git_oid>();
final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_blob_create_from_disk(out, repo, pathC);
final error = libgit2.git_blob_create_from_disk(out, repoPointer, pathC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());

View file

@ -9,12 +9,15 @@ import '../util.dart';
/// Return a list of branches.
///
/// Throws a [LibGit2Error] if error occured.
List<String> list(Pointer<git_repository> repo, int listFlags) {
List<String> list({
required Pointer<git_repository> repoPointer,
required int flags,
}) {
final iterator = calloc<Pointer<git_branch_iterator>>();
final iteratorError = libgit2.git_branch_iterator_new(
iterator,
repo,
listFlags,
repoPointer,
flags,
);
if (iteratorError < 0) {
@ -47,14 +50,19 @@ List<String> list(Pointer<git_repository> repo, int listFlags) {
/// The generated reference must be freed by the user. The branch name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> lookup(
Pointer<git_repository> repo,
String branchName,
int branchType,
) {
Pointer<git_reference> lookup({
required Pointer<git_repository> repoPointer,
required String branchName,
required int branchType,
}) {
final out = calloc<Pointer<git_reference>>();
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
final error = libgit2.git_branch_lookup(out, repo, branchNameC, branchType);
final error = libgit2.git_branch_lookup(
out,
repoPointer,
branchNameC,
branchType,
);
calloc.free(branchNameC);
@ -75,20 +83,20 @@ Pointer<git_reference> lookup(
/// The branch name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> create(
Pointer<git_repository> repo,
String branchName,
Pointer<git_commit> target,
bool force,
) {
Pointer<git_reference> create({
required Pointer<git_repository> repoPointer,
required String branchName,
required Pointer<git_commit> targetPointer,
required bool force,
}) {
final out = calloc<Pointer<git_reference>>();
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
final forceC = force ? 1 : 0;
final error = libgit2.git_branch_create(
out,
repo,
repoPointer,
branchNameC,
target,
targetPointer,
forceC,
);
@ -125,22 +133,23 @@ void delete(Pointer<git_reference> branch) {
/// and will be freed immediately.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> rename(
Pointer<git_reference> branch,
String newBranchName,
bool force,
) {
Pointer<git_reference> rename({
required Pointer<git_reference> branchPointer,
required String newBranchName,
required bool force,
}) {
final out = calloc<Pointer<git_reference>>();
final newBranchNameC = newBranchName.toNativeUtf8().cast<Int8>();
final forceC = force ? 1 : 0;
final error = libgit2.git_branch_move(out, branch, newBranchNameC, forceC);
final error =
libgit2.git_branch_move(out, branchPointer, newBranchNameC, forceC);
calloc.free(newBranchNameC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
reference_bindings.free(branch);
reference_bindings.free(branchPointer);
return out.value;
}
}

View file

@ -13,18 +13,19 @@ import '../util.dart';
/// target of the branch and then update HEAD using `setHead` to point to the branch you checked out.
///
/// Throws a [LibGit2Error] if error occured.
void head(
Pointer<git_repository> repo,
int strategy,
void head({
required Pointer<git_repository> repoPointer,
required int strategy,
String? directory,
List<String>? paths,
) {
final initOpts = initOptions(strategy, directory, paths);
}) {
final initOpts =
initOptions(strategy: strategy, directory: directory, paths: paths);
final optsC = initOpts[0];
final pathPointers = initOpts[1];
final strArray = initOpts[2];
final error = libgit2.git_checkout_head(repo, optsC);
final error = libgit2.git_checkout_head(repoPointer, optsC);
for (var p in pathPointers) {
calloc.free(p);
@ -41,18 +42,19 @@ void head(
/// Updates files in the working tree to match the content of the index.
///
/// Throws a [LibGit2Error] if error occured.
void index(
Pointer<git_repository> repo,
int strategy,
void index({
required Pointer<git_repository> repoPointer,
required int strategy,
String? directory,
List<String>? paths,
) {
final initOpts = initOptions(strategy, directory, paths);
}) {
final initOpts =
initOptions(strategy: strategy, directory: directory, paths: paths);
final optsC = initOpts[0];
final pathPointers = initOpts[1];
final strArray = initOpts[2];
final error = libgit2.git_checkout_index(repo, nullptr, optsC);
final error = libgit2.git_checkout_index(repoPointer, nullptr, optsC);
for (var p in pathPointers) {
calloc.free(p);
@ -70,19 +72,23 @@ void index(
/// pointed at by the treeish.
///
/// Throws a [LibGit2Error] if error occured.
void tree(
Pointer<git_repository> repo,
Pointer<git_object> treeish,
int strategy,
void tree({
required Pointer<git_repository> repoPointer,
required Pointer<git_object> treeishPointer,
required int strategy,
String? directory,
List<String>? paths,
) {
final initOpts = initOptions(strategy, directory, paths);
}) {
final initOpts = initOptions(
strategy: strategy,
directory: directory,
paths: paths,
);
final optsC = initOpts[0];
final pathPointers = initOpts[1];
final strArray = initOpts[2];
final error = libgit2.git_checkout_tree(repo, treeish, optsC);
final error = libgit2.git_checkout_tree(repoPointer, treeishPointer, optsC);
for (var p in pathPointers) {
calloc.free(p);
@ -96,17 +102,20 @@ void tree(
}
}
List<dynamic> initOptions(
int strategy,
List<dynamic> initOptions({
required int strategy,
String? directory,
List<String>? paths,
) {
}) {
final optsC = calloc<git_checkout_options>(sizeOf<git_checkout_options>());
libgit2.git_checkout_options_init(optsC, GIT_CHECKOUT_OPTIONS_VERSION);
optsC.ref.checkout_strategy = strategy;
if (directory != null) {
optsC.ref.target_directory = directory.toNativeUtf8().cast<Int8>();
}
List<Pointer<Int8>> pathPointers = [];
Pointer<Pointer<Int8>> strArray = nullptr;
if (paths != null) {

View file

@ -10,9 +10,12 @@ import 'oid.dart' as oid_bindings;
/// The returned object should be released with `free()` when no longer needed.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_commit> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
Pointer<git_commit> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_commit>>();
final error = libgit2.git_commit_lookup(out, repo, id);
final error = libgit2.git_commit_lookup(out, repoPointer, oidPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -24,13 +27,18 @@ Pointer<git_commit> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
/// Lookup a commit object from a repository, given a prefix of its identifier (short id).
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_commit> lookupPrefix(
Pointer<git_repository> repo,
Pointer<git_oid> id,
int len,
) {
Pointer<git_commit> lookupPrefix({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
required int len,
}) {
final out = calloc<Pointer<git_commit>>();
final error = libgit2.git_commit_lookup_prefix(out, repo, id, len);
final error = libgit2.git_commit_lookup_prefix(
out,
repoPointer,
oidPointer,
len,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -49,12 +57,16 @@ Pointer<git_commit> lookupPrefix(
/// this one when that data is known.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<Pointer<git_annotated_commit>> annotatedLookup(
Pointer<git_repository> repo,
Pointer<git_oid> id,
) {
Pointer<Pointer<git_annotated_commit>> annotatedLookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_annotated_commit>>();
final error = libgit2.git_annotated_commit_lookup(out, repo, id);
final error = libgit2.git_annotated_commit_lookup(
out,
repoPointer,
oidPointer,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -71,17 +83,17 @@ void annotatedFree(Pointer<git_annotated_commit> commit) {
/// Create new commit in the repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> create(
Pointer<git_repository> repo,
Pointer<git_oid> create({
required Pointer<git_repository> repoPointer,
String? updateRef,
Pointer<git_signature> author,
Pointer<git_signature> committer,
required Pointer<git_signature> authorPointer,
required Pointer<git_signature> committerPointer,
String? messageEncoding,
String message,
Pointer<git_tree> tree,
int parentCount,
List<String> parents,
) {
required String message,
required Pointer<git_tree> treePointer,
required int parentCount,
required List<String> parents,
}) {
final out = calloc<git_oid>();
final updateRefC = updateRef?.toNativeUtf8().cast<Int8>() ?? nullptr;
final messageEncodingC =
@ -94,7 +106,7 @@ Pointer<git_oid> create(
for (var i = 0; i < parentCount; i++) {
final oid = oid_bindings.fromSHA(parents[i]);
var commit = calloc<IntPtr>();
commit = lookup(repo, oid).cast();
commit = lookup(repoPointer: repoPointer, oidPointer: oid).cast();
parentsC[i] = commit.cast();
}
} else {
@ -104,13 +116,13 @@ Pointer<git_oid> create(
final error = libgit2.git_commit_create(
out,
repo,
repoPointer,
updateRefC,
author,
committer,
authorPointer,
committerPointer,
messageEncodingC,
messageC,
tree,
treePointer,
parentCount,
parentsC,
);
@ -163,8 +175,11 @@ int parentCount(Pointer<git_commit> commit) =>
/// Get the oid of a specified parent for a commit.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> parentId(Pointer<git_commit> commit, int n) {
final parentOid = libgit2.git_commit_parent_id(commit, n);
Pointer<git_oid> parentId({
required Pointer<git_commit> commitPointer,
required int position,
}) {
final parentOid = libgit2.git_commit_parent_id(commitPointer, position);
if (parentOid == nullptr) {
throw LibGit2Error(libgit2.git_error_last());
@ -197,12 +212,12 @@ Pointer<git_oid> tree(Pointer<git_commit> commit) {
/// The returned index must be freed explicitly with `free()`.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_index> revertCommit(
Pointer<git_repository> repo,
Pointer<git_commit> revertCommit,
Pointer<git_commit> ourCommit,
int mainline,
) {
Pointer<git_index> revertCommit({
required Pointer<git_repository> repoPointer,
required Pointer<git_commit> revertCommitPointer,
required Pointer<git_commit> ourCommitPointer,
required int mainline,
}) {
final out = calloc<Pointer<git_index>>();
final opts = calloc<git_merge_options>();
final optsError =
@ -214,9 +229,9 @@ Pointer<git_index> revertCommit(
final error = libgit2.git_revert_commit(
out,
repo,
revertCommit,
ourCommit,
repoPointer,
revertCommitPointer,
ourCommitPointer,
mainline,
opts,
);

View file

@ -134,10 +134,13 @@ Pointer<git_config> snapshot(Pointer<git_config> config) {
/// Get the config entry of a config variable.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_config_entry> getEntry(Pointer<git_config> cfg, String variable) {
Pointer<git_config_entry> getEntry({
required Pointer<git_config> configPointer,
required String variable,
}) {
final out = calloc<Pointer<git_config_entry>>();
final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_get_entry(out, cfg, name);
final error = libgit2.git_config_get_entry(out, configPointer, name);
calloc.free(name);
@ -152,10 +155,14 @@ Pointer<git_config_entry> getEntry(Pointer<git_config> cfg, String variable) {
/// highest level (usually the local one).
///
/// Throws a [LibGit2Error] if error occured.
void setBool(Pointer<git_config> cfg, String variable, bool value) {
void setBool({
required Pointer<git_config> configPointer,
required String variable,
required bool value,
}) {
final name = variable.toNativeUtf8().cast<Int8>();
final valueC = value ? 1 : 0;
final error = libgit2.git_config_set_bool(cfg, name, valueC);
final error = libgit2.git_config_set_bool(configPointer, name, valueC);
calloc.free(name);
@ -168,9 +175,13 @@ void setBool(Pointer<git_config> cfg, String variable, bool value) {
/// highest level (usually the local one).
///
/// Throws a [LibGit2Error] if error occured.
void setInt(Pointer<git_config> cfg, String variable, int value) {
void setInt({
required Pointer<git_config> configPointer,
required String variable,
required int value,
}) {
final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_set_int64(cfg, name, value);
final error = libgit2.git_config_set_int64(configPointer, name, value);
calloc.free(name);
@ -183,10 +194,14 @@ void setInt(Pointer<git_config> cfg, String variable, int value) {
/// highest level (usually the local one).
///
/// Throws a [LibGit2Error] if error occured.
void setString(Pointer<git_config> cfg, String variable, String value) {
void setString({
required Pointer<git_config> configPointer,
required String variable,
required String value,
}) {
final name = variable.toNativeUtf8().cast<Int8>();
final valueC = value.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_set_string(cfg, name, valueC);
final error = libgit2.git_config_set_string(configPointer, name, valueC);
calloc.free(name);
calloc.free(valueC);
@ -207,9 +222,12 @@ Pointer<git_config_iterator> iterator(Pointer<git_config> cfg) {
/// (usually the local one).
///
/// Throws a [LibGit2Error] if error occured.
void delete(Pointer<git_config> cfg, String variable) {
void delete({
required Pointer<git_config> configPointer,
required String variable,
}) {
final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_delete_entry(cfg, name);
final error = libgit2.git_config_delete_entry(configPointer, name);
calloc.free(name);
@ -222,16 +240,23 @@ void delete(Pointer<git_config> cfg, String variable) {
///
/// If regexp is present, then the iterator will only iterate over all
/// values which match the pattern.
List<String> multivarValues(
Pointer<git_config> cfg,
String variable,
List<String> multivarValues({
required Pointer<git_config> configPointer,
required String variable,
String? regexp,
) {
}) {
final name = variable.toNativeUtf8().cast<Int8>();
final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr;
final iterator = calloc<Pointer<git_config_iterator>>();
final entry = calloc<Pointer<git_config_entry>>();
libgit2.git_config_multivar_iterator_new(iterator, cfg, name, regexpC);
libgit2.git_config_multivar_iterator_new(
iterator,
configPointer,
name,
regexpC,
);
var error = 0;
final entries = <String>[];
@ -256,16 +281,17 @@ List<String> multivarValues(
/// highest level (usually the local one).
///
/// The regexp is applied case-sensitively on the value.
void setMultivar(
Pointer<git_config> cfg,
String variable,
String regexp,
String value,
) {
void setMultivar({
required Pointer<git_config> configPointer,
required String variable,
required String regexp,
required String value,
}) {
final name = variable.toNativeUtf8().cast<Int8>();
final regexpC = regexp.toNativeUtf8().cast<Int8>();
final valueC = value.toNativeUtf8().cast<Int8>();
libgit2.git_config_set_multivar(cfg, name, regexpC, valueC);
libgit2.git_config_set_multivar(configPointer, name, regexpC, valueC);
calloc.free(name);
calloc.free(regexpC);
@ -276,10 +302,15 @@ void setMultivar(
/// with the highest level (usually the local one).
///
/// The regexp is applied case-sensitively on the value.
void deleteMultivar(Pointer<git_config> cfg, String variable, String regexp) {
void deleteMultivar({
required Pointer<git_config> configPointer,
required String variable,
required String regexp,
}) {
final name = variable.toNativeUtf8().cast<Int8>();
final regexpC = regexp.toNativeUtf8().cast<Int8>();
libgit2.git_config_delete_multivar(cfg, name, regexpC);
libgit2.git_config_delete_multivar(configPointer, name, regexpC);
calloc.free(name);
calloc.free(regexpC);

View file

@ -28,7 +28,10 @@ Pointer<git_credential> username(String username) {
/// Create a new plain-text username and password credential object.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_credential> userPass(String username, String password) {
Pointer<git_credential> userPass({
required String username,
required String password,
}) {
final out = calloc<Pointer<git_credential>>();
final usernameC = username.toNativeUtf8().cast<Int8>();
final passwordC = password.toNativeUtf8().cast<Int8>();
@ -49,12 +52,12 @@ Pointer<git_credential> userPass(String username, String password) {
/// Create a new passphrase-protected ssh key credential object.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_credential> sshKey(
String username,
String publicKey,
String privateKey,
String passPhrase,
) {
Pointer<git_credential> sshKey({
required String username,
required String publicKey,
required String privateKey,
required String passPhrase,
}) {
final out = calloc<Pointer<git_credential>>();
final usernameC = username.toNativeUtf8().cast<Int8>();
final publicKeyC = publicKey.toNativeUtf8().cast<Int8>();
@ -102,12 +105,12 @@ Pointer<git_credential> sshKeyFromAgent(String username) {
/// Create a new ssh key credential object reading the keys from memory.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_credential> sshKeyFromMemory(
String username,
String publicKey,
String privateKey,
String passPhrase,
) {
Pointer<git_credential> sshKeyFromMemory({
required String username,
required String publicKey,
required String privateKey,
required String passPhrase,
}) {
final out = calloc<Pointer<git_credential>>();
final usernameC = username.toNativeUtf8().cast<Int8>();
final publicKeyC = publicKey.toNativeUtf8().cast<Int8>();

View file

@ -7,17 +7,21 @@ import '../util.dart';
/// Create a diff between the repository index and the workdir directory.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> indexToWorkdir(
Pointer<git_repository> repo,
Pointer<git_index> index,
int flags,
int contextLines,
int interhunkLines,
) {
Pointer<git_diff> indexToWorkdir({
required Pointer<git_repository> repoPointer,
required Pointer<git_index> indexPointer,
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final out = calloc<Pointer<git_diff>>();
final opts = _diffOptionsInit(flags, contextLines, interhunkLines);
final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
libgit2.git_diff_index_to_workdir(out, repo, index, opts);
libgit2.git_diff_index_to_workdir(out, repoPointer, indexPointer, opts);
calloc.free(opts);
@ -27,18 +31,28 @@ Pointer<git_diff> indexToWorkdir(
/// Create a diff between a tree and repository index.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToIndex(
Pointer<git_repository> repo,
Pointer<git_tree> oldTree,
Pointer<git_index> index,
int flags,
int contextLines,
int interhunkLines,
) {
Pointer<git_diff> treeToIndex({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> treePointer,
required Pointer<git_index> indexPointer,
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final out = calloc<Pointer<git_diff>>();
final opts = _diffOptionsInit(flags, contextLines, interhunkLines);
final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
libgit2.git_diff_tree_to_index(out, repo, oldTree, index, opts);
libgit2.git_diff_tree_to_index(
out,
repoPointer,
treePointer,
indexPointer,
opts,
);
calloc.free(opts);
@ -48,17 +62,21 @@ Pointer<git_diff> treeToIndex(
/// Create a diff between a tree and the working directory.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToWorkdir(
Pointer<git_repository> repo,
Pointer<git_tree> oldTree,
int flags,
int contextLines,
int interhunkLines,
) {
Pointer<git_diff> treeToWorkdir({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> treePointer,
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final out = calloc<Pointer<git_diff>>();
final opts = _diffOptionsInit(flags, contextLines, interhunkLines);
final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
libgit2.git_diff_tree_to_workdir(out, repo, oldTree, opts);
libgit2.git_diff_tree_to_workdir(out, repoPointer, treePointer, opts);
calloc.free(opts);
@ -68,18 +86,28 @@ Pointer<git_diff> treeToWorkdir(
/// Create a diff with the difference between two tree objects.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToTree(
Pointer<git_repository> repo,
Pointer<git_tree> oldTree,
Pointer<git_tree> newTree,
int flags,
int contextLines,
int interhunkLines,
) {
Pointer<git_diff> treeToTree({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> oldTreePointer,
required Pointer<git_tree> newTreePointer,
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final out = calloc<Pointer<git_diff>>();
final opts = _diffOptionsInit(flags, contextLines, interhunkLines);
final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
libgit2.git_diff_tree_to_tree(out, repo, oldTree, newTree, opts);
libgit2.git_diff_tree_to_tree(
out,
repoPointer,
oldTreePointer,
newTreePointer,
opts,
);
calloc.free(opts);
@ -96,8 +124,11 @@ int length(Pointer<git_diff> diff) => libgit2.git_diff_num_deltas(diff);
/// then it will be "merged" to appear as if the old version was from the "onto" list
/// and the new version is from the "from" list (with the exception that if the item
/// has a pending DELETE in the middle, then it will show as deleted).
void merge(Pointer<git_diff> onto, Pointer<git_diff> from) {
libgit2.git_diff_merge(onto, from);
void merge({
required Pointer<git_diff> ontoPointer,
required Pointer<git_diff> fromPointer,
}) {
libgit2.git_diff_merge(ontoPointer, fromPointer);
}
/// Read the contents of a git patch file into a git diff object.
@ -132,14 +163,15 @@ Pointer<git_diff> parse(String content) {
/// files into add/remove pairs if the amount of change is above a threshold.
///
/// Throws a [LibGit2Error] if error occured.
void findSimilar(
Pointer<git_diff> diff,
int flags,
int renameThreshold,
int copyThreshold,
int renameFromRewriteThreshold,
int breakRewriteThreshold,
int renameLimit) {
void findSimilar({
required Pointer<git_diff> diffPointer,
required int flags,
required int renameThreshold,
required int copyThreshold,
required int renameFromRewriteThreshold,
required int breakRewriteThreshold,
required int renameLimit,
}) {
final opts = calloc<git_diff_find_options>();
final optsError =
libgit2.git_diff_find_options_init(opts, GIT_DIFF_FIND_OPTIONS_VERSION);
@ -154,7 +186,7 @@ void findSimilar(
throw LibGit2Error(libgit2.git_error_last());
}
final error = libgit2.git_diff_find_similar(diff, opts);
final error = libgit2.git_diff_find_similar(diffPointer, opts);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -187,11 +219,14 @@ Pointer<git_oid> patchId(Pointer<git_diff> diff) {
/// Return the diff delta for an entry in the diff list.
///
/// Throws [RangeError] if index out of range.
Pointer<git_diff_delta> getDeltaByIndex(Pointer<git_diff> diff, int idx) {
final result = libgit2.git_diff_get_delta(diff, idx);
Pointer<git_diff_delta> getDeltaByIndex({
required Pointer<git_diff> diffPointer,
required int index,
}) {
final result = libgit2.git_diff_get_delta(diffPointer, index);
if (result == nullptr) {
throw RangeError('$idx is out of bounds');
throw RangeError('$index is out of bounds');
} else {
return result;
}
@ -237,13 +272,13 @@ int statsFilesChanged(Pointer<git_diff_stats> stats) =>
/// Print diff statistics.
///
/// Throws a [LibGit2Error] if error occured.
String statsPrint(
Pointer<git_diff_stats> stats,
int format,
int width,
) {
String statsPrint({
required Pointer<git_diff_stats> statsPointer,
required int format,
required int width,
}) {
final out = calloc<git_buf>(sizeOf<git_buf>());
final error = libgit2.git_diff_stats_to_buf(out, stats, format, width);
final error = libgit2.git_diff_stats_to_buf(out, statsPointer, format, width);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -257,13 +292,16 @@ String statsPrint(
/// Add patch to buffer.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_buf> addToBuf(Pointer<git_patch> patch, Pointer<git_buf> buffer) {
final error = libgit2.git_patch_to_buf(buffer, patch);
Pointer<git_buf> addToBuf({
required Pointer<git_patch> patchPointer,
required Pointer<git_buf> bufferPointer,
}) {
final error = libgit2.git_patch_to_buf(bufferPointer, patchPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return buffer;
return bufferPointer;
}
}
@ -271,18 +309,18 @@ Pointer<git_buf> addToBuf(Pointer<git_patch> patch, Pointer<git_buf> buffer) {
/// the index, or both.
///
/// Throws a [LibGit2Error] if error occured.
bool apply(
Pointer<git_repository> repo,
Pointer<git_diff> diff,
int location, [
bool apply({
required Pointer<git_repository> repoPointer,
required Pointer<git_diff> diffPointer,
required int location,
bool check = false,
]) {
}) {
final opts = calloc<git_apply_options>();
libgit2.git_apply_options_init(opts, GIT_APPLY_OPTIONS_VERSION);
if (check) {
opts.ref.flags = git_apply_flags_t.GIT_APPLY_CHECK;
}
final error = libgit2.git_apply(repo, diff, location, opts);
final error = libgit2.git_apply(repoPointer, diffPointer, location, opts);
calloc.free(opts);
@ -300,11 +338,11 @@ void statsFree(Pointer<git_diff_stats> stats) =>
/// Free a previously allocated diff.
void free(Pointer<git_diff> diff) => libgit2.git_diff_free(diff);
Pointer<git_diff_options> _diffOptionsInit(
int flags,
int contextLines,
int interhunkLines,
) {
Pointer<git_diff_options> _diffOptionsInit({
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final opts = calloc<git_diff_options>();
final optsError =
libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION);

View file

@ -16,9 +16,9 @@ import '../util.dart';
/// are discarded.
///
/// Throws a [LibGit2Error] if error occured.
void read(Pointer<git_index> index, bool force) {
void read({required Pointer<git_index> indexPointer, required bool force}) {
final forceC = force == true ? 1 : 0;
final error = libgit2.git_index_read(index, forceC);
final error = libgit2.git_index_read(indexPointer, forceC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -30,8 +30,11 @@ void read(Pointer<git_index> index, bool force) {
/// The current index contents will be replaced by the specified tree.
///
/// Throws a [LibGit2Error] if error occured.
void readTree(Pointer<git_index> index, Pointer<git_tree> tree) {
final error = libgit2.git_index_read_tree(index, tree);
void readTree({
required Pointer<git_index> indexPointer,
required Pointer<git_tree> treePointer,
}) {
final error = libgit2.git_index_read_tree(indexPointer, treePointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -68,12 +71,12 @@ Pointer<git_oid> writeTree(Pointer<git_index> index) {
/// The index must not contain any file in conflict.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> writeTreeTo(
Pointer<git_index> index,
Pointer<git_repository> repo,
) {
Pointer<git_oid> writeTreeTo({
required Pointer<git_index> indexPointer,
required Pointer<git_repository> repoPointer,
}) {
final out = calloc<git_oid>();
final error = libgit2.git_index_write_tree_to(out, index, repo);
final error = libgit2.git_index_write_tree_to(out, indexPointer, repoPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -83,9 +86,9 @@ Pointer<git_oid> writeTreeTo(
}
/// Find the first position of any entries which point to given path in the Git index.
bool find(Pointer<git_index> index, String path) {
bool find({required Pointer<git_index> indexPointer, required String path}) {
final pathC = path.toNativeUtf8().cast<Int8>();
final result = libgit2.git_index_find(nullptr, index, pathC);
final result = libgit2.git_index_find(nullptr, indexPointer, pathC);
calloc.free(pathC);
@ -100,8 +103,11 @@ int entryCount(Pointer<git_index> index) => libgit2.git_index_entrycount(index);
/// The entry is not modifiable and should not be freed.
///
/// Throws [RangeError] when provided index is outside of valid range.
Pointer<git_index_entry> getByIndex(Pointer<git_index> index, int n) {
final result = libgit2.git_index_get_byindex(index, n);
Pointer<git_index_entry> getByIndex({
required Pointer<git_index> indexPointer,
required int position,
}) {
final result = libgit2.git_index_get_byindex(indexPointer, position);
if (result == nullptr) {
throw RangeError('Out of bounds');
@ -115,13 +121,13 @@ Pointer<git_index_entry> getByIndex(Pointer<git_index> index, int n) {
///The entry is not modifiable and should not be freed.
///
/// Throws [ArgumentError] if nothing found for provided path.
Pointer<git_index_entry> getByPath(
Pointer<git_index> index,
String path,
int stage,
) {
Pointer<git_index_entry> getByPath({
required Pointer<git_index> indexPointer,
required String path,
required int stage,
}) {
final pathC = path.toNativeUtf8().cast<Int8>();
final result = libgit2.git_index_get_bypath(index, pathC, stage);
final result = libgit2.git_index_get_bypath(indexPointer, pathC, stage);
calloc.free(pathC);
@ -152,8 +158,11 @@ void clear(Pointer<git_index> index) {
/// it will be replaced. Otherwise, the `sourceEntry` will be added.
///
/// Throws a [LibGit2Error] if error occured.
void add(Pointer<git_index> index, Pointer<git_index_entry> sourceEntry) {
final error = libgit2.git_index_add(index, sourceEntry);
void add({
required Pointer<git_index> indexPointer,
required Pointer<git_index_entry> sourceEntryPointer,
}) {
final error = libgit2.git_index_add(indexPointer, sourceEntryPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -173,9 +182,12 @@ void add(Pointer<git_index> index, Pointer<git_index_entry> sourceEntry) {
/// (REUC) section.
///
/// Throws a [LibGit2Error] if error occured.
void addByPath(Pointer<git_index> index, String path) {
void addByPath({
required Pointer<git_index> indexPointer,
required String path,
}) {
final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_index_add_bypath(index, pathC);
final error = libgit2.git_index_add_bypath(indexPointer, pathC);
calloc.free(pathC);
@ -193,7 +205,10 @@ void addByPath(Pointer<git_index> index, String path) {
/// added to the index (either updating an existing entry or adding a new entry).
///
/// Throws a [LibGit2Error] if error occured.
void addAll(Pointer<git_index> index, List<String> pathspec) {
void addAll({
required Pointer<git_index> indexPointer,
required List<String> pathspec,
}) {
var pathspecC = calloc<git_strarray>();
final List<Pointer<Int8>> pathPointers =
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
@ -207,7 +222,7 @@ void addAll(Pointer<git_index> index, List<String> pathspec) {
pathspecC.ref.count = pathspec.length;
final error = libgit2.git_index_add_all(
index,
indexPointer,
pathspecC,
0,
nullptr,
@ -239,9 +254,13 @@ void write(Pointer<git_index> index) {
/// Remove an entry from the index.
///
/// Throws a [LibGit2Error] if error occured.
void remove(Pointer<git_index> index, String path, int stage) {
void remove({
required Pointer<git_index> indexPointer,
required String path,
required int stage,
}) {
final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_index_remove(index, pathC, stage);
final error = libgit2.git_index_remove(indexPointer, pathC, stage);
calloc.free(pathC);
@ -253,7 +272,10 @@ void remove(Pointer<git_index> index, String path, int stage) {
/// Remove all matching index entries.
///
/// Throws a [LibGit2Error] if error occured.
void removeAll(Pointer<git_index> index, List<String> pathspec) {
void removeAll({
required Pointer<git_index> indexPointer,
required List<String> pathspec,
}) {
final pathspecC = calloc<git_strarray>();
final List<Pointer<Int8>> pathPointers =
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
@ -267,7 +289,7 @@ void removeAll(Pointer<git_index> index, List<String> pathspec) {
pathspecC.ref.count = pathspec.length;
final error = libgit2.git_index_remove_all(
index,
indexPointer,
pathspecC,
nullptr,
nullptr,
@ -293,7 +315,8 @@ bool hasConflicts(Pointer<git_index> index) {
///
/// Throws a [LibGit2Error] if error occured.
List<Map<String, Pointer<git_index_entry>>> conflictList(
Pointer<git_index> index) {
Pointer<git_index> index,
) {
final iterator = calloc<Pointer<git_index_conflict_iterator>>();
final iteratorError =
libgit2.git_index_conflict_iterator_new(iterator, index);
@ -336,9 +359,12 @@ List<Map<String, Pointer<git_index_entry>>> conflictList(
/// Removes the index entries that represent a conflict of a single file.
///
/// Throws a [LibGit2Error] if error occured.
void conflictRemove(Pointer<git_index> index, String path) {
void conflictRemove({
required Pointer<git_index> indexPointer,
required String path,
}) {
final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_index_conflict_remove(index, pathC);
final error = libgit2.git_index_conflict_remove(indexPointer, pathC);
calloc.free(pathC);

View file

@ -7,13 +7,13 @@ import '../util.dart';
/// Find a merge base between two commits.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> mergeBase(
Pointer<git_repository> repo,
Pointer<git_oid> one,
Pointer<git_oid> two,
) {
Pointer<git_oid> mergeBase({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> aPointer,
required Pointer<git_oid> bPointer,
}) {
final out = calloc<git_oid>();
final error = libgit2.git_merge_base(out, repo, one, two);
final error = libgit2.git_merge_base(out, repoPointer, aPointer, bPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -26,20 +26,20 @@ Pointer<git_oid> mergeBase(
/// into a reference.
///
/// Throws a [LibGit2Error] if error occured.
List<int> analysis(
Pointer<git_repository> repo,
Pointer<git_reference> ourRef,
Pointer<Pointer<git_annotated_commit>> theirHead,
int theirHeadsLen,
) {
List<int> analysis({
required Pointer<git_repository> repoPointer,
required Pointer<git_reference> ourRefPointer,
required Pointer<Pointer<git_annotated_commit>> theirHeadPointer,
required int theirHeadsLen,
}) {
final analysisOut = calloc<Int32>();
final preferenceOut = calloc<Int32>();
final error = libgit2.git_merge_analysis_for_ref(
analysisOut,
preferenceOut,
repo,
ourRef,
theirHead,
repoPointer,
ourRefPointer,
theirHeadPointer,
theirHeadsLen,
);
var result = <int>[];
@ -61,11 +61,11 @@ List<int> analysis(
/// prepare a commit.
///
/// Throws a [LibGit2Error] if error occured.
void merge(
Pointer<git_repository> repo,
Pointer<Pointer<git_annotated_commit>> theirHeads,
int theirHeadsLen,
) {
void merge({
required Pointer<git_repository> repoPointer,
required Pointer<Pointer<git_annotated_commit>> theirHeadsPointer,
required int theirHeadsLen,
}) {
final mergeOpts = calloc<git_merge_options>(sizeOf<git_merge_options>());
libgit2.git_merge_options_init(mergeOpts, GIT_MERGE_OPTIONS_VERSION);
@ -77,8 +77,8 @@ void merge(
git_checkout_strategy_t.GIT_CHECKOUT_RECREATE_MISSING;
final error = libgit2.git_merge(
repo,
theirHeads,
repoPointer,
theirHeadsPointer,
theirHeadsLen,
mergeOpts,
checkoutOpts,
@ -97,12 +97,12 @@ void merge(
/// The returned index must be freed explicitly.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_index> mergeCommits(
Pointer<git_repository> repo,
Pointer<git_commit> ourCommit,
Pointer<git_commit> theirCommit,
Map<String, int> opts,
) {
Pointer<git_index> mergeCommits({
required Pointer<git_repository> repoPointer,
required Pointer<git_commit> ourCommitPointer,
required Pointer<git_commit> theirCommitPointer,
required Map<String, int> opts,
}) {
final out = calloc<Pointer<git_index>>();
final optsC = calloc<git_merge_options>(sizeOf<git_merge_options>());
optsC.ref.file_favor = opts['favor']!;
@ -112,9 +112,9 @@ Pointer<git_index> mergeCommits(
final error = libgit2.git_merge_commits(
out,
repo,
ourCommit,
theirCommit,
repoPointer,
ourCommitPointer,
theirCommitPointer,
optsC,
);
@ -135,13 +135,13 @@ Pointer<git_index> mergeCommits(
/// The returned index must be freed explicitly.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_index> mergeTrees(
Pointer<git_repository> repo,
Pointer<git_tree> ancestorTree,
Pointer<git_tree> ourTree,
Pointer<git_tree> theirTree,
Map<String, int> opts,
) {
Pointer<git_index> mergeTrees({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> ancestorTreePointer,
required Pointer<git_tree> ourTreePointer,
required Pointer<git_tree> theirTreePointer,
required Map<String, int> opts,
}) {
final out = calloc<Pointer<git_index>>();
final optsC = calloc<git_merge_options>(sizeOf<git_merge_options>());
optsC.ref.file_favor = opts['favor']!;
@ -151,10 +151,10 @@ Pointer<git_index> mergeTrees(
final error = libgit2.git_merge_trees(
out,
repo,
ancestorTree,
ourTree,
theirTree,
repoPointer,
ancestorTreePointer,
ourTreePointer,
theirTreePointer,
optsC,
);
@ -170,13 +170,16 @@ Pointer<git_index> mergeTrees(
/// Cherry-pick the given commit, producing changes in the index and working directory.
///
/// Throws a [LibGit2Error] if error occured.
void cherryPick(Pointer<git_repository> repo, Pointer<git_commit> commit) {
void cherryPick({
required Pointer<git_repository> repoPointer,
required Pointer<git_commit> commitPointer,
}) {
final opts = calloc<git_cherrypick_options>(sizeOf<git_cherrypick_options>());
libgit2.git_cherrypick_options_init(opts, GIT_CHERRYPICK_OPTIONS_VERSION);
opts.ref.checkout_opts.checkout_strategy =
git_checkout_strategy_t.GIT_CHECKOUT_SAFE;
final error = libgit2.git_cherrypick(repo, commit, opts);
final error = libgit2.git_cherrypick(repoPointer, commitPointer, opts);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());

View file

@ -17,13 +17,13 @@ int type(Pointer<git_object> obj) => libgit2.git_object_type(obj);
/// guess the object's type.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_object> lookup(
Pointer<git_repository> repo,
Pointer<git_oid> id,
int type,
) {
Pointer<git_object> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
required int type,
}) {
final out = calloc<Pointer<git_object>>();
final error = libgit2.git_object_lookup(out, repo, id, type);
final error = libgit2.git_object_lookup(out, repoPointer, oidPointer, type);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());

View file

@ -7,13 +7,18 @@ import '../util.dart';
/// Determine if an object can be found in the object database by an abbreviated object ID.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> existsPrefix(
Pointer<git_odb> db,
Pointer<git_oid> shortOid,
int len,
) {
Pointer<git_oid> existsPrefix({
required Pointer<git_odb> odbPointer,
required Pointer<git_oid> shortOidPointer,
required int length,
}) {
final out = calloc<git_oid>();
final error = libgit2.git_odb_exists_prefix(out, db, shortOid, len);
final error = libgit2.git_odb_exists_prefix(
out,
odbPointer,
shortOidPointer,
length,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());

View file

@ -78,6 +78,9 @@ String toSHA(Pointer<git_oid> id) {
/// Compare two oid structures.
///
/// Returns <0 if a < b, 0 if a == b, >0 if a > b.
int compare(Pointer<git_oid> a, Pointer<git_oid> b) {
return libgit2.git_oid_cmp(a, b);
int compare({
required Pointer<git_oid> aPointer,
required Pointer<git_oid> bPointer,
}) {
return libgit2.git_oid_cmp(aPointer, bPointer);
}

View file

@ -10,15 +10,15 @@ import '../util.dart';
/// you must call `free()` on the patch when done.
///
/// Throws a [LibGit2Error] if error occured.
Map<String, dynamic> fromBuffers(
Map<String, dynamic> fromBuffers({
String? oldBuffer,
String? oldAsPath,
String? newBuffer,
String? newAsPath,
int flags,
int contextLines,
int interhunkLines,
) {
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final out = calloc<Pointer<git_patch>>();
final oldBufferC = oldBuffer?.toNativeUtf8().cast<Int8>() ?? nullptr;
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
@ -26,7 +26,11 @@ Map<String, dynamic> fromBuffers(
final newBufferC = newBuffer?.toNativeUtf8().cast<Int8>() ?? nullptr;
final newAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final newLen = newBuffer?.length ?? 0;
final opts = _diffOptionsInit(flags, contextLines, interhunkLines);
final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_buffers(
out,
@ -66,25 +70,29 @@ Map<String, dynamic> fromBuffers(
/// must call `free()` on the patch when done.
///
/// Throws a [LibGit2Error] if error occured.
Map<String, dynamic> fromBlobs(
Pointer<git_blob>? oldBlob,
Map<String, dynamic> fromBlobs({
Pointer<git_blob>? oldBlobPointer,
String? oldAsPath,
Pointer<git_blob>? newBlob,
Pointer<git_blob>? newBlobPointer,
String? newAsPath,
int flags,
int contextLines,
int interhunkLines,
) {
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final out = calloc<Pointer<git_patch>>();
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final newAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final opts = _diffOptionsInit(flags, contextLines, interhunkLines);
final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_blobs(
out,
oldBlob ?? nullptr,
oldBlobPointer ?? nullptr,
oldAsPathC,
newBlob ?? nullptr,
newBlobPointer ?? nullptr,
newAsPathC,
opts,
);
@ -99,11 +107,11 @@ Map<String, dynamic> fromBlobs(
throw LibGit2Error(libgit2.git_error_last());
} else {
// Returning map with pointers to patch and blobs because patch object does not
// have refenrece to underlying blobs. So if the blob is freed/removed the patch
// have reference to underlying blobs. So if the blob is freed/removed the patch
// text becomes corrupted.
result['patch'] = out.value;
result['a'] = oldBlob;
result['b'] = newBlob;
result['a'] = oldBlobPointer;
result['b'] = newBlobPointer;
return result;
}
}
@ -114,25 +122,29 @@ Map<String, dynamic> fromBlobs(
/// call `free()` on the patch when done.
///
/// Throws a [LibGit2Error] if error occured.
Map<String, dynamic> fromBlobAndBuffer(
Pointer<git_blob>? oldBlob,
Map<String, dynamic> fromBlobAndBuffer({
Pointer<git_blob>? oldBlobPointer,
String? oldAsPath,
String? buffer,
String? bufferAsPath,
int flags,
int contextLines,
int interhunkLines,
) {
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final out = calloc<Pointer<git_patch>>();
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final bufferC = buffer?.toNativeUtf8().cast<Int8>() ?? nullptr;
final bufferAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final bufferLen = buffer?.length ?? 0;
final opts = _diffOptionsInit(flags, contextLines, interhunkLines);
final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_blob_and_buffer(
out,
oldBlob ?? nullptr,
oldBlobPointer ?? nullptr,
oldAsPathC,
bufferC.cast(),
bufferLen,
@ -151,10 +163,10 @@ Map<String, dynamic> fromBlobAndBuffer(
throw LibGit2Error(libgit2.git_error_last());
} else {
// Returning map with pointers to patch and buffers because patch object does not
// have refenrece to underlying buffers or blobs. So if the buffer or blob is freed/removed
// have reference to underlying buffers or blobs. So if the buffer or blob is freed/removed
// the patch text becomes corrupted.
result['patch'] = out.value;
result['a'] = oldBlob;
result['a'] = oldBlobPointer;
result['b'] = bufferC;
return result;
}
@ -167,9 +179,12 @@ Map<String, dynamic> fromBlobAndBuffer(
/// hunks and lines in the diff of the one delta.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_patch> fromDiff(Pointer<git_diff> diff, int idx) {
Pointer<git_patch> fromDiff({
required Pointer<git_diff> diffPointer,
required int index,
}) {
final out = calloc<Pointer<git_patch>>();
final error = libgit2.git_patch_from_diff(out, diff, idx);
final error = libgit2.git_patch_from_diff(out, diffPointer, index);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -190,11 +205,18 @@ int numHunks(Pointer<git_patch> patch) => libgit2.git_patch_num_hunks(patch);
/// Given a patch and a hunk index into the patch, this returns detailed information about that hunk.
///
/// Throws a [LibGit2Error] if error occured.
Map<String, dynamic> hunk(Pointer<git_patch> patch, int hunkIdx) {
Map<String, dynamic> hunk({
required Pointer<git_patch> patchPointer,
required int hunkIndex,
}) {
final out = calloc<Pointer<git_diff_hunk>>();
final linesInHunk = calloc<Int32>();
final error =
libgit2.git_patch_get_hunk(out, linesInHunk.cast(), patch, hunkIdx);
final linesInHunk = calloc<Int64>();
final error = libgit2.git_patch_get_hunk(
out,
linesInHunk.cast(),
patchPointer,
hunkIndex,
);
final result = <String, dynamic>{};
if (error < 0) {
@ -209,14 +231,18 @@ Map<String, dynamic> hunk(Pointer<git_patch> patch, int hunkIdx) {
/// Get data about a line in a hunk of a patch.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff_line> lines(
Pointer<git_patch> patch,
int hunkIdx,
int lineOfHunk,
) {
Pointer<git_diff_line> lines({
required Pointer<git_patch> patchPointer,
required int hunkIndex,
required int lineOfHunk,
}) {
final out = calloc<Pointer<git_diff_line>>();
final error =
libgit2.git_patch_get_line_in_hunk(out, patch, hunkIdx, lineOfHunk);
final error = libgit2.git_patch_get_line_in_hunk(
out,
patchPointer,
hunkIndex,
lineOfHunk,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -249,18 +275,18 @@ String text(Pointer<git_patch> patch) {
/// If you pass `includeContext` as true, this will be the size of all of the diff output;
/// if you pass it as false, this will only include the actual changed lines (as if
/// contextLines was 0).
int size(
Pointer<git_patch> patch,
bool includeContext,
bool includeHunkHeaders,
bool includeFileHeaders,
) {
int size({
required Pointer<git_patch> patchPointer,
required bool includeContext,
required bool includeHunkHeaders,
required bool includeFileHeaders,
}) {
final includeContextC = includeContext ? 1 : 0;
final includeHunkHeadersC = includeHunkHeaders ? 1 : 0;
final includeFileHeadersC = includeFileHeaders ? 1 : 0;
return libgit2.git_patch_size(
patch,
patchPointer,
includeContextC,
includeHunkHeadersC,
includeFileHeadersC,
@ -270,11 +296,11 @@ int size(
/// Free a previously allocated patch object.
void free(Pointer<git_patch> patch) => libgit2.git_patch_free(patch);
Pointer<git_diff_options> _diffOptionsInit(
int flags,
int contextLines,
int interhunkLines,
) {
Pointer<git_diff_options> _diffOptionsInit({
required int flags,
required int contextLines,
required int interhunkLines,
}) {
final opts = calloc<git_diff_options>();
final optsError =
libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION);

View file

@ -54,10 +54,13 @@ Pointer<git_reference> resolve(Pointer<git_reference> ref) {
/// The name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> lookup(Pointer<git_repository> repo, String name) {
Pointer<git_reference> lookup({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reference_lookup(out, repo, nameC);
final error = libgit2.git_reference_lookup(out, repoPointer, nameC);
calloc.free(nameC);
@ -74,10 +77,13 @@ Pointer<git_reference> lookup(Pointer<git_repository> repo, String name) {
/// the user is referring to.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> lookupDWIM(Pointer<git_repository> repo, String name) {
Pointer<git_reference> lookupDWIM({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reference_dwim(out, repo, nameC);
final error = libgit2.git_reference_dwim(out, repoPointer, nameC);
calloc.free(nameC);
@ -118,19 +124,19 @@ String shorthand(Pointer<git_reference> ref) {
/// the repository. We only rename the reflog if it exists.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> rename(
Pointer<git_reference> ref,
String newName,
bool force,
Pointer<git_reference> rename({
required Pointer<git_reference> refPointer,
required String newName,
required bool force,
String? logMessage,
) {
}) {
final out = calloc<Pointer<git_reference>>();
final newNameC = newName.toNativeUtf8().cast<Int8>();
final forceC = force == true ? 1 : 0;
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_reference_rename(
out,
ref,
refPointer,
newNameC,
forceC,
logMessageC,
@ -171,9 +177,12 @@ List<String> list(Pointer<git_repository> repo) {
/// Check if a reflog exists for the specified reference.
///
/// Throws a [LibGit2Error] if error occured.
bool hasLog(Pointer<git_repository> repo, String name) {
bool hasLog({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final refname = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reference_has_log(repo, refname);
final error = libgit2.git_reference_has_log(repoPointer, refname);
calloc.free(refname);
@ -230,22 +239,22 @@ bool isTag(Pointer<git_reference> ref) {
///
/// The message for the reflog will be ignored if the reference does not belong in the
/// standard set (HEAD, branches and remote-tracking branches) and it does not have a reflog.
Pointer<git_reference> createDirect(
Pointer<git_repository> repo,
String name,
Pointer<git_oid> oid,
bool force,
Pointer<git_reference> createDirect({
required Pointer<git_repository> repoPointer,
required String name,
required Pointer<git_oid> oidPointer,
required bool force,
String? logMessage,
) {
}) {
final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final forceC = force == true ? 1 : 0;
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_reference_create(
out,
repo,
repoPointer,
nameC,
oid,
oidPointer,
forceC,
logMessageC,
);
@ -282,13 +291,13 @@ Pointer<git_reference> createDirect(
///
/// The message for the reflog will be ignored if the reference does not belong in the standard
/// set (HEAD, branches and remote-tracking branches) and it does not have a reflog.
Pointer<git_reference> createSymbolic(
Pointer<git_repository> repo,
String name,
String target,
bool force,
Pointer<git_reference> createSymbolic({
required Pointer<git_repository> repoPointer,
required String name,
required String target,
required bool force,
String? logMessage,
) {
}) {
final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final targetC = target.toNativeUtf8().cast<Int8>();
@ -296,7 +305,7 @@ Pointer<git_reference> createSymbolic(
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_reference_symbolic_create(
out,
repo,
repoPointer,
nameC,
targetC,
forceC,
@ -339,14 +348,19 @@ Pointer<git_repository> owner(Pointer<git_reference> ref) {
/// The new reference will be written to disk, overwriting the given reference.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> setTarget(
Pointer<git_reference> ref,
Pointer<git_oid> oid,
Pointer<git_reference> setTarget({
required Pointer<git_reference> refPointer,
required Pointer<git_oid> oidPointer,
String? logMessage,
) {
}) {
final out = calloc<Pointer<git_reference>>();
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_reference_set_target(out, ref, oid, logMessageC);
final error = libgit2.git_reference_set_target(
out,
refPointer,
oidPointer,
logMessageC,
);
calloc.free(logMessageC);
@ -368,16 +382,20 @@ Pointer<git_reference> setTarget(
/// standard set (HEAD, branches and remote-tracking branches) and and it does not have a reflog.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> setTargetSymbolic(
Pointer<git_reference> ref,
String target,
Pointer<git_reference> setTargetSymbolic({
required Pointer<git_reference> refPointer,
required String target,
String? logMessage,
) {
}) {
final out = calloc<Pointer<git_reference>>();
final targetC = target.toNativeUtf8().cast<Int8>();
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error =
libgit2.git_reference_symbolic_set_target(out, ref, targetC, logMessageC);
final error = libgit2.git_reference_symbolic_set_target(
out,
refPointer,
targetC,
logMessageC,
);
calloc.free(targetC);
calloc.free(logMessageC);
@ -390,8 +408,11 @@ Pointer<git_reference> setTargetSymbolic(
}
/// Compare two references.
bool compare(Pointer<git_reference> ref1, Pointer<git_reference> ref2) {
final result = libgit2.git_reference_cmp(ref1, ref2);
bool compare({
required Pointer<git_reference> ref1Pointer,
required Pointer<git_reference> ref2Pointer,
}) {
final result = libgit2.git_reference_cmp(ref1Pointer, ref2Pointer);
return result == 0 ? true : false;
}
@ -403,9 +424,12 @@ bool compare(Pointer<git_reference> ref1, Pointer<git_reference> ref2) {
/// non-tag object is met.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_object> peel(Pointer<git_reference> ref, int type) {
Pointer<git_object> peel({
required Pointer<git_reference> refPointer,
required int type,
}) {
final out = calloc<Pointer<git_object>>();
final error = libgit2.git_reference_peel(out, ref, type);
final error = libgit2.git_reference_peel(out, refPointer, type);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());

View file

@ -12,10 +12,13 @@ import '../util.dart';
/// The reflog must be freed manually.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reflog> read(Pointer<git_repository> repo, String name) {
Pointer<git_reflog> read({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_reflog>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reflog_read(out, repo, nameC);
final error = libgit2.git_reflog_read(out, repoPointer, nameC);
calloc.free(nameC);
@ -34,8 +37,11 @@ int entryCount(Pointer<git_reflog> reflog) =>
///
/// Requesting the reflog entry with an index of 0 (zero) will return
/// the most recently created entry.
Pointer<git_reflog_entry> getByIndex(Pointer<git_reflog> reflog, int idx) {
return libgit2.git_reflog_entry_byindex(reflog, idx);
Pointer<git_reflog_entry> getByIndex({
required Pointer<git_reflog> reflogPointer,
required int index,
}) {
return libgit2.git_reflog_entry_byindex(reflogPointer, index);
}
/// Get the log message.

View file

@ -29,9 +29,12 @@ int direction(Pointer<git_refspec> refspec) =>
libgit2.git_refspec_direction(refspec);
/// Check if a refspec's source descriptor matches a reference.
bool matchesSource(Pointer<git_refspec> refspec, String refname) {
bool matchesSource({
required Pointer<git_refspec> refspecPointer,
required String refname,
}) {
final refnameC = refname.toNativeUtf8().cast<Int8>();
final result = libgit2.git_refspec_src_matches(refspec, refnameC);
final result = libgit2.git_refspec_src_matches(refspecPointer, refnameC);
calloc.free(refnameC);
@ -39,9 +42,12 @@ bool matchesSource(Pointer<git_refspec> refspec, String refname) {
}
/// Check if a refspec's destination descriptor matches a reference.
bool matchesDestination(Pointer<git_refspec> refspec, String refname) {
bool matchesDestination({
required Pointer<git_refspec> refspecPointer,
required String refname,
}) {
final refnameC = refname.toNativeUtf8().cast<Int8>();
final result = libgit2.git_refspec_dst_matches(refspec, refnameC);
final result = libgit2.git_refspec_dst_matches(refspecPointer, refnameC);
calloc.free(refnameC);
@ -51,10 +57,13 @@ bool matchesDestination(Pointer<git_refspec> refspec, String refname) {
/// Transform a reference to its target following the refspec's rules.
///
/// Throws a [LibGit2Error] if error occured.
String transform(Pointer<git_refspec> spec, String name) {
String transform({
required Pointer<git_refspec> refspecPointer,
required String name,
}) {
final out = calloc<git_buf>(sizeOf<git_buf>());
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_refspec_transform(out, spec, nameC);
final error = libgit2.git_refspec_transform(out, refspecPointer, nameC);
calloc.free(nameC);
@ -70,10 +79,13 @@ String transform(Pointer<git_refspec> spec, String name) {
/// Transform a target reference to its source reference following the refspec's rules.
///
/// Throws a [LibGit2Error] if error occured.
String rTransform(Pointer<git_refspec> spec, String name) {
String rTransform({
required Pointer<git_refspec> refspecPointer,
required String name,
}) {
final out = calloc<git_buf>(sizeOf<git_buf>());
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_refspec_rtransform(out, spec, nameC);
final error = libgit2.git_refspec_rtransform(out, refspecPointer, nameC);
calloc.free(nameC);

View file

@ -32,10 +32,13 @@ List<String> list(Pointer<git_repository> repo) {
/// The name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_remote> lookup(Pointer<git_repository> repo, String name) {
Pointer<git_remote> lookup({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_remote>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_lookup(out, repo, nameC);
final error = libgit2.git_remote_lookup(out, repoPointer, nameC);
calloc.free(nameC);
@ -49,15 +52,15 @@ Pointer<git_remote> lookup(Pointer<git_repository> repo, String name) {
/// Add a remote with the default fetch refspec to the repository's configuration.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_remote> create(
Pointer<git_repository> repo,
String name,
String url,
) {
Pointer<git_remote> create({
required Pointer<git_repository> repoPointer,
required String name,
required String url,
}) {
final out = calloc<Pointer<git_remote>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_create(out, repo, nameC, urlC);
final error = libgit2.git_remote_create(out, repoPointer, nameC, urlC);
calloc.free(nameC);
calloc.free(urlC);
@ -72,19 +75,19 @@ Pointer<git_remote> create(
/// Add a remote with the provided fetch refspec to the repository's configuration.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_remote> createWithFetchSpec(
Pointer<git_repository> repo,
String name,
String url,
String fetch,
) {
Pointer<git_remote> createWithFetchSpec({
required Pointer<git_repository> repoPointer,
required String name,
required String url,
required String fetch,
}) {
final out = calloc<Pointer<git_remote>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>();
final fetchC = fetch.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_create_with_fetchspec(
out,
repo,
repoPointer,
nameC,
urlC,
fetchC,
@ -106,9 +109,12 @@ Pointer<git_remote> createWithFetchSpec(
/// All remote-tracking branches and configuration settings for the remote will be removed.
///
/// Throws a [LibGit2Error] if error occured.
void delete(Pointer<git_repository> repo, String name) {
void delete({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_delete(repo, nameC);
final error = libgit2.git_remote_delete(repoPointer, nameC);
calloc.free(nameC);
@ -129,11 +135,15 @@ void delete(Pointer<git_repository> repo, String name) {
/// their list of refspecs.
///
/// Throws a [LibGit2Error] if error occured.
List<String> rename(Pointer<git_repository> repo, String name, String newName) {
List<String> rename({
required Pointer<git_repository> repoPointer,
required String name,
required String newName,
}) {
final out = calloc<git_strarray>();
final nameC = name.toNativeUtf8().cast<Int8>();
final newNameC = newName.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_rename(out, repo, nameC, newNameC);
final error = libgit2.git_remote_rename(out, repoPointer, nameC, newNameC);
calloc.free(nameC);
calloc.free(newNameC);
@ -157,10 +167,14 @@ List<String> rename(Pointer<git_repository> repo, String name, String newName) {
/// case of a single-url remote and will otherwise return an error.
///
/// Throws a [LibGit2Error] if error occured.
void setUrl(Pointer<git_repository> repo, String remote, String url) {
void setUrl({
required Pointer<git_repository> repoPointer,
required String remote,
required String url,
}) {
final remoteC = remote.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_set_url(repo, remoteC, urlC);
final error = libgit2.git_remote_set_url(repoPointer, remoteC, urlC);
calloc.free(remoteC);
calloc.free(urlC);
@ -176,10 +190,14 @@ void setUrl(Pointer<git_repository> repo, String remote, String url) {
/// case of a single-url remote and will otherwise return an error.
///
/// Throws a [LibGit2Error] if error occured.
void setPushUrl(Pointer<git_repository> repo, String remote, String url) {
void setPushUrl({
required Pointer<git_repository> repoPointer,
required String remote,
required String url,
}) {
final remoteC = remote.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_set_pushurl(repo, remoteC, urlC);
final error = libgit2.git_remote_set_pushurl(repoPointer, remoteC, urlC);
calloc.free(remoteC);
calloc.free(urlC);
@ -218,8 +236,11 @@ int refspecCount(Pointer<git_remote> remote) =>
libgit2.git_remote_refspec_count(remote);
/// Get a refspec from the remote at provided position.
Pointer<git_refspec> getRefspec(Pointer<git_remote> remote, int n) {
return libgit2.git_remote_get_refspec(remote, n);
Pointer<git_refspec> getRefspec({
required Pointer<git_remote> remotePointer,
required int position,
}) {
return libgit2.git_remote_get_refspec(remotePointer, position);
}
/// Get the remote's list of fetch refspecs.
@ -256,10 +277,14 @@ List<String> pushRefspecs(Pointer<git_remote> remote) {
/// instances will be affected.
///
/// Throws a [LibGit2Error] if error occured.
void addFetch(Pointer<git_repository> repo, String remote, String refspec) {
void addFetch({
required Pointer<git_repository> repoPointer,
required String remote,
required String refspec,
}) {
final remoteC = remote.toNativeUtf8().cast<Int8>();
final refspecC = refspec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_add_fetch(repo, remoteC, refspecC);
final error = libgit2.git_remote_add_fetch(repoPointer, remoteC, refspecC);
calloc.free(remoteC);
calloc.free(refspecC);
@ -275,10 +300,14 @@ void addFetch(Pointer<git_repository> repo, String remote, String refspec) {
/// instances will be affected.
///
/// Throws a [LibGit2Error] if error occured.
void addPush(Pointer<git_repository> repo, String remote, String refspec) {
void addPush({
required Pointer<git_repository> repoPointer,
required String remote,
required String refspec,
}) {
final remoteC = remote.toNativeUtf8().cast<Int8>();
final refspecC = refspec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_add_push(repo, remoteC, refspecC);
final error = libgit2.git_remote_add_push(repoPointer, remoteC, refspecC);
calloc.free(remoteC);
calloc.free(refspecC);
@ -295,12 +324,12 @@ void addPush(Pointer<git_repository> repo, String remote, String refspec) {
/// which can only do the one or the other.
///
/// Throws a [LibGit2Error] if error occured.
void connect(
Pointer<git_remote> remote,
int direction,
void connect({
required Pointer<git_remote> remotePointer,
required int direction,
required Callbacks callbacks,
String? proxyOption,
Callbacks callbacks,
) {
}) {
final callbacksOptions = calloc<git_remote_callbacks>();
final callbacksError = libgit2.git_remote_init_callbacks(
callbacksOptions,
@ -319,7 +348,7 @@ void connect(
final proxyOptions = _proxyOptionsInit(proxyOption);
final error = libgit2.git_remote_connect(
remote,
remotePointer,
direction,
callbacksOptions,
proxyOptions,
@ -386,14 +415,14 @@ List<Map<String, dynamic>> lsRemotes(Pointer<git_remote> remote) {
/// update the remote-tracking branches.
///
/// Throws a [LibGit2Error] if error occured.
void fetch(
Pointer<git_remote> remote,
List<String> refspecs,
void fetch({
required Pointer<git_remote> remotePointer,
required List<String> refspecs,
required int prune,
required Callbacks callbacks,
String? reflogMessage,
int prune,
String? proxyOption,
Callbacks callbacks,
) {
}) {
var refspecsC = calloc<git_strarray>();
final refspecsPointers =
refspecs.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
@ -427,7 +456,7 @@ void fetch(
opts.ref.proxy_opts = proxyOptions.ref;
final error = libgit2.git_remote_fetch(
remote,
remotePointer,
refspecsC,
opts,
reflogMessageC,
@ -451,12 +480,12 @@ void fetch(
/// Perform a push.
///
/// Throws a [LibGit2Error] if error occured.
void push(
Pointer<git_remote> remote,
List<String> refspecs,
void push({
required Pointer<git_remote> remotePointer,
required List<String> refspecs,
required Callbacks callbacks,
String? proxyOption,
Callbacks callbacks,
) {
}) {
var refspecsC = calloc<git_strarray>();
final refspecsPointers =
refspecs.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
@ -485,7 +514,7 @@ void push(
);
opts.ref.proxy_opts = proxyOptions.ref;
final error = libgit2.git_remote_push(remote, refspecsC, opts);
final error = libgit2.git_remote_push(remotePointer, refspecsC, opts);
for (var p in refspecsPointers) {
calloc.free(p);
@ -519,10 +548,10 @@ void disconnect(Pointer<git_remote> remote) {
/// Prune tracking refs that are no longer present on remote.
///
/// Throws a [LibGit2Error] if error occured.
void prune(
Pointer<git_remote> remote,
Callbacks callbacks,
) {
void prune({
required Pointer<git_remote> remotePointer,
required Callbacks callbacks,
}) {
final callbacksOptions = calloc<git_remote_callbacks>();
final callbacksError = libgit2.git_remote_init_callbacks(
callbacksOptions,
@ -538,7 +567,7 @@ void prune(
callbacks: callbacks,
);
final error = libgit2.git_remote_prune(remote, callbacksOptions);
final error = libgit2.git_remote_prune(remotePointer, callbacksOptions);
calloc.free(callbacksOptions);
RemoteCallbacks.reset();

View file

@ -131,16 +131,16 @@ class RemoteCallbacks {
} else if (credentials is UserPass) {
final cred = credentials as UserPass;
credPointer[0] = credentials_bindings.userPass(
cred.username,
cred.password,
username: cred.username,
password: cred.password,
);
} else if (credentials is Keypair) {
final cred = credentials as Keypair;
credPointer[0] = credentials_bindings.sshKey(
cred.username,
cred.pubKey,
cred.privateKey,
cred.passPhrase,
username: cred.username,
publicKey: cred.pubKey,
privateKey: cred.privateKey,
passPhrase: cred.passPhrase,
);
} else if (credentials is KeypairFromAgent) {
final cred = credentials as KeypairFromAgent;
@ -148,10 +148,10 @@ class RemoteCallbacks {
} else if (credentials is KeypairFromMemory) {
final cred = credentials as KeypairFromMemory;
credPointer[0] = credentials_bindings.sshKeyFromMemory(
cred.username,
cred.pubKey,
cred.privateKey,
cred.passPhrase,
username: cred.username,
publicKey: cred.pubKey,
privateKey: cred.privateKey,
passPhrase: cred.passPhrase,
);
}

View file

@ -53,7 +53,10 @@ Pointer<git_repository> openBare(String barePath) {
/// The method will automatically detect if the repository is bare (if there is a repository).
///
/// Throws a [LibGit2Error] if error occured.
String discover(String startPath, String? ceilingDirs) {
String discover({
required String startPath,
String? ceilingDirs,
}) {
final out = calloc<git_buf>(sizeOf<git_buf>());
final startPathC = startPath.toNativeUtf8().cast<Int8>();
final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast<Int8>() ?? nullptr;
@ -80,16 +83,16 @@ String discover(String startPath, String? ceilingDirs) {
/// Creates a new Git repository in the given folder.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_repository> init(
String path,
int flags,
int mode,
Pointer<git_repository> init({
required String path,
required int flags,
required int mode,
String? workdirPath,
String? description,
String? templatePath,
String? initialHead,
String? originUrl,
) {
}) {
final out = calloc<Pointer<git_repository>>();
final pathC = path.toNativeUtf8().cast<Int8>();
final workdirPathC = workdirPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
@ -135,15 +138,15 @@ Pointer<git_repository> init(
/// Clone a remote repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_repository> clone(
String url,
String localPath,
bool bare,
Pointer<git_repository> clone({
required String url,
required String localPath,
required bool bare,
Remote Function(Repository, String, String)? remote,
Repository Function(String, bool)? repository,
String? checkoutBranch,
Callbacks callbacks,
) {
required Callbacks callbacks,
}) {
final out = calloc<Pointer<git_repository>>();
final urlC = url.toNativeUtf8().cast<Int8>();
final localPathC = localPath.toNativeUtf8().cast<Int8>();
@ -245,9 +248,12 @@ String getNamespace(Pointer<git_repository> repo) {
/// under refs/namespaces/foo/, use foo as the namespace.
///
/// Throws a [LibGit2Error] if error occured.
void setNamespace(Pointer<git_repository> repo, String? namespace) {
void setNamespace({
required Pointer<git_repository> repoPointer,
String? namespace,
}) {
final nmspace = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_repository_set_namespace(repo, nmspace);
final error = libgit2.git_repository_set_namespace(repoPointer, nmspace);
calloc.free(nmspace);
@ -330,11 +336,15 @@ bool isBranchUnborn(Pointer<git_repository> repo) {
///
/// If both are set, this name and email will be used to write to the reflog.
/// Pass NULL to unset. When unset, the identity will be taken from the repository's configuration.
void setIdentity(Pointer<git_repository> repo, String? name, String? email) {
void setIdentity({
required Pointer<git_repository> repoPointer,
String? name,
String? email,
}) {
final nameC = name?.toNativeUtf8().cast<Int8>() ?? nullptr;
final emailC = email?.toNativeUtf8().cast<Int8>() ?? nullptr;
libgit2.git_repository_set_ident(repo, nameC, emailC);
libgit2.git_repository_set_ident(repoPointer, nameC, emailC);
calloc.free(nameC);
calloc.free(emailC);
@ -507,11 +517,14 @@ Pointer<git_refdb> refdb(Pointer<git_repository> repo) {
/// Otherwise, the HEAD will be detached and will directly point to the Commit.
///
/// Throws a [LibGit2Error] if error occured.
void setHead(Pointer<git_repository> repo, String ref) {
final refname = ref.toNativeUtf8().cast<Int8>();
final error = libgit2.git_repository_set_head(repo, refname);
void setHead({
required Pointer<git_repository> repoPointer,
required String refname,
}) {
final refnameC = refname.toNativeUtf8().cast<Int8>();
final error = libgit2.git_repository_set_head(repoPointer, refnameC);
calloc.free(refname);
calloc.free(refnameC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -527,8 +540,14 @@ void setHead(Pointer<git_repository> repo, String ref) {
/// Otherwise, the HEAD will eventually be detached and will directly point to the peeled commit.
///
/// Throws a [LibGit2Error] if error occured.
void setHeadDetached(Pointer<git_repository> repo, Pointer<git_oid> commitish) {
final error = libgit2.git_repository_set_head_detached(repo, commitish);
void setHeadDetached({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> commitishPointer,
}) {
final error = libgit2.git_repository_set_head_detached(
repoPointer,
commitishPointer,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -542,12 +561,14 @@ void setHeadDetached(Pointer<git_repository> repo, Pointer<git_oid> commitish) {
/// by a user, allowing for more exact reflog messages.
///
/// See the documentation for [setHeadDetached].
void setHeadDetachedFromAnnotated(
Pointer<git_repository> repo,
Pointer<git_annotated_commit> commitish,
) {
final error =
libgit2.git_repository_set_head_detached_from_annotated(repo, commitish);
void setHeadDetachedFromAnnotated({
required Pointer<git_repository> repoPointer,
required Pointer<git_annotated_commit> commitishPointer,
}) {
final error = libgit2.git_repository_set_head_detached_from_annotated(
repoPointer,
commitishPointer,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -564,15 +585,15 @@ void setHeadDetachedFromAnnotated(
/// (checkout, status, index manipulation, etc).
///
/// Throws a [LibGit2Error] if error occured.
void setWorkdir(
Pointer<git_repository> repo,
String path,
bool updateGitlink,
) {
void setWorkdir({
required Pointer<git_repository> repoPointer,
required String path,
required bool updateGitlink,
}) {
final workdir = path.toNativeUtf8().cast<Int8>();
final updateGitlinkC = updateGitlink ? 1 : 0;
final error = libgit2.git_repository_set_workdir(
repo,
repoPointer,
workdir,
updateGitlinkC,
);

View file

@ -15,13 +15,18 @@ import '../util.dart';
/// with the content of the index. (Untracked and ignored files will be left alone, however.)
///
/// Throws a [LibGit2Error] if error occured.
void reset(
Pointer<git_repository> repo,
Pointer<git_object> target,
int resetType,
Pointer<git_checkout_options> checkoutOpts,
) {
final error = libgit2.git_reset(repo, target, resetType, checkoutOpts);
void reset({
required Pointer<git_repository> repoPointer,
required Pointer<git_object> targetPointer,
required int resetType,
required Pointer<git_checkout_options> checkoutOptsPointer,
}) {
final error = libgit2.git_reset(
repoPointer,
targetPointer,
resetType,
checkoutOptsPointer,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());

View file

@ -10,13 +10,14 @@ import '../util.dart';
/// for information on the syntax accepted.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_revspec> revParse(
Pointer<git_repository> repo,
String spec,
) {
Pointer<git_revspec> revParse({
required Pointer<git_repository> repoPointer,
required String spec,
}) {
final out = calloc<git_revspec>();
final specC = spec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_revparse(out, repo, specC);
final error = libgit2.git_revparse(out, repoPointer, specC);
calloc.free(specC);
@ -34,14 +35,14 @@ Pointer<git_revspec> revParse(
/// The returned object should be released when no longer needed.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_object> revParseSingle(Pointer<git_repository> repo, String spec) {
Pointer<git_object> revParseSingle({
required Pointer<git_repository> repoPointer,
required String spec,
}) {
final out = calloc<Pointer<git_object>>();
final specC = spec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_revparse_single(
out,
repo,
specC,
);
final error = libgit2.git_revparse_single(out, repoPointer, specC);
calloc.free(specC);
@ -64,12 +65,21 @@ Pointer<git_object> revParseSingle(Pointer<git_repository> repo, String spec) {
/// The returned object and reference should be released when no longer needed.
///
/// Throws a [LibGit2Error] if error occured.
List revParseExt(Pointer<git_repository> repo, String spec) {
List revParseExt({
required Pointer<git_repository> repoPointer,
required String spec,
}) {
final objectOut = calloc<Pointer<git_object>>();
final referenceOut = calloc<Pointer<git_reference>>();
final specC = spec.toNativeUtf8().cast<Int8>();
var result = [];
final error = libgit2.git_revparse_ext(objectOut, referenceOut, repo, specC);
final error = libgit2.git_revparse_ext(
objectOut,
referenceOut,
repoPointer,
specC,
);
calloc.free(specC);

View file

@ -33,8 +33,11 @@ Pointer<git_revwalk> create(Pointer<git_repository> repo) {
/// Changing the sorting mode resets the walker.
///
/// Throws a [LibGit2Error] if error occured.
void sorting(Pointer<git_revwalk> walker, int sortMode) {
final error = libgit2.git_revwalk_sorting(walker, sortMode);
void sorting({
required Pointer<git_revwalk> walkerPointer,
required int sortMode,
}) {
final error = libgit2.git_revwalk_sorting(walkerPointer, sortMode);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -51,8 +54,11 @@ void sorting(Pointer<git_revwalk> walker, int sortMode) {
/// The given id must belong to a committish on the walked repository.
///
/// Throws a [LibGit2Error] if error occured.
void push(Pointer<git_revwalk> walker, Pointer<git_oid> id) {
final error = libgit2.git_revwalk_push(walker, id);
void push({
required Pointer<git_revwalk> walkerPointer,
required Pointer<git_oid> oidPointer,
}) {
final error = libgit2.git_revwalk_push(walkerPointer, oidPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -69,18 +75,21 @@ void push(Pointer<git_revwalk> walker, Pointer<git_oid> id) {
/// repositories (topological preprocessing times at 0.3s on the git.git repo).
///
/// The revision walker is reset when the walk is over.
List<Pointer<git_commit>> walk(
Pointer<git_repository> repo,
Pointer<git_revwalk> walker,
) {
List<Pointer<git_commit>> walk({
required Pointer<git_repository> repoPointer,
required Pointer<git_revwalk> walkerPointer,
}) {
var result = <Pointer<git_commit>>[];
var error = 0;
while (error == 0) {
final oid = calloc<git_oid>();
error = libgit2.git_revwalk_next(oid, walker);
error = libgit2.git_revwalk_next(oid, walkerPointer);
if (error == 0) {
final commit = commit_bindings.lookup(repo, oid);
final commit = commit_bindings.lookup(
repoPointer: repoPointer,
oidPointer: oid,
);
result.add(commit);
calloc.free(oid);
} else {
@ -98,8 +107,11 @@ List<Pointer<git_commit>> walk(
/// The resolved commit and all its parents will be hidden from the output on the revision walk.
///
/// Throws a [LibGit2Error] if error occured.
void hide(Pointer<git_revwalk> walk, Pointer<git_oid> oid) {
final error = libgit2.git_revwalk_hide(walk, oid);
void hide({
required Pointer<git_revwalk> walkerPointer,
required Pointer<git_oid> oidPointer,
}) {
final error = libgit2.git_revwalk_hide(walkerPointer, oidPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -119,8 +131,8 @@ void reset(Pointer<git_revwalk> walker) => libgit2.git_revwalk_reset(walker);
/// No parents other than the first for each commit will be enqueued.
///
/// Throws a [LibGit2Error] if error occured.
void simplifyFirstParent(Pointer<git_revwalk> walk) {
final error = libgit2.git_revwalk_simplify_first_parent(walk);
void simplifyFirstParent(Pointer<git_revwalk> walker) {
final error = libgit2.git_revwalk_simplify_first_parent(walker);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());

View file

@ -10,12 +10,12 @@ import '../util.dart';
/// either the name or the email parameter.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_signature> create(
String name,
String email,
int time,
int offset,
) {
Pointer<git_signature> create({
required String name,
required String email,
required int time,
required int offset,
}) {
final out = calloc<Pointer<git_signature>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final emailC = email.toNativeUtf8().cast<Int8>();
@ -34,7 +34,7 @@ Pointer<git_signature> create(
/// Create a new action signature with a timestamp of 'now'.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_signature> now(String name, String email) {
Pointer<git_signature> now({required String name, required String email}) {
final out = calloc<Pointer<git_signature>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final emailC = email.toNativeUtf8().cast<Int8>();

View file

@ -10,15 +10,21 @@ import '../util.dart';
/// Save the local modifications to a new stash.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> stash(
Pointer<git_repository> repo,
Pointer<git_signature> stasher,
Pointer<git_oid> stash({
required Pointer<git_repository> repoPointer,
required Pointer<git_signature> stasherPointer,
String? message,
int flags,
) {
required int flags,
}) {
final out = calloc<git_oid>();
final messageC = message?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_stash_save(out, repo, stasher, messageC, flags);
final error = libgit2.git_stash_save(
out,
repoPointer,
stasherPointer,
messageC,
flags,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -30,14 +36,14 @@ Pointer<git_oid> stash(
/// Apply a single stashed state from the stash list.
///
/// Throws a [LibGit2Error] if error occured.
void apply(
Pointer<git_repository> repo,
int index,
int flags,
int strategy,
void apply({
required Pointer<git_repository> repoPointer,
required int index,
required int flags,
required int strategy,
String? directory,
List<String>? paths,
) {
}) {
final options =
calloc<git_stash_apply_options>(sizeOf<git_stash_apply_options>());
final optionsError = libgit2.git_stash_apply_options_init(
@ -47,8 +53,11 @@ void apply(
throw LibGit2Error(libgit2.git_error_last());
}
final checkoutOptions =
checkout_bindings.initOptions(strategy, directory, paths);
final checkoutOptions = checkout_bindings.initOptions(
strategy: strategy,
directory: directory,
paths: paths,
);
final optsC = checkoutOptions[0];
final pathPointers = checkoutOptions[1];
final strArray = checkoutOptions[2];
@ -56,7 +65,7 @@ void apply(
options.ref.flags = flags;
options.ref.checkout_options = (optsC as Pointer<git_checkout_options>).ref;
final error = libgit2.git_stash_apply(repo, index, options);
final error = libgit2.git_stash_apply(repoPointer, index, options);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -74,21 +83,21 @@ void apply(
/// Remove a single stashed state from the stash list.
///
/// Throws a [LibGit2Error] if error occured.
void drop(Pointer<git_repository> repo, int index) {
libgit2.git_stash_drop(repo, index);
void drop({required Pointer<git_repository> repoPointer, required int index}) {
libgit2.git_stash_drop(repoPointer, index);
}
/// Apply a single stashed state from the stash list and remove it from the list if successful.
///
/// Throws a [LibGit2Error] if error occured.
void pop(
Pointer<git_repository> repo,
int index,
int flags,
int strategy,
void pop({
required Pointer<git_repository> repoPointer,
required int index,
required int flags,
required int strategy,
String? directory,
List<String>? paths,
) {
}) {
final options =
calloc<git_stash_apply_options>(sizeOf<git_stash_apply_options>());
final optionsError = libgit2.git_stash_apply_options_init(
@ -98,8 +107,11 @@ void pop(
throw LibGit2Error(libgit2.git_error_last());
}
final checkoutOptions =
checkout_bindings.initOptions(strategy, directory, paths);
final checkoutOptions = checkout_bindings.initOptions(
strategy: strategy,
directory: directory,
paths: paths,
);
final optsC = checkoutOptions[0];
final pathPointers = checkoutOptions[1];
final strArray = checkoutOptions[2];
@ -107,7 +119,7 @@ void pop(
options.ref.flags = flags;
options.ref.checkout_options = (optsC as Pointer<git_checkout_options>).ref;
final error = libgit2.git_stash_pop(repo, index, options);
final error = libgit2.git_stash_pop(repoPointer, index, options);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -122,6 +134,9 @@ void pop(
calloc.free(options);
}
/// List of stashed states.
///
/// IMPORTANT: make sure to clear that list since it's a global variable.
var _stashList = <Stash>[];
/// Loop over all the stashed states.
@ -136,6 +151,7 @@ List<Stash> list(Pointer<git_repository> repo) {
return result;
}
/// A callback function to iterate over all the stashed states.
int _stashCb(
int index,
Pointer<Int8> message,

View file

@ -32,11 +32,11 @@ int listEntryCount(Pointer<git_status_list> statuslist) {
/// The entry is not modifiable and should not be freed.
///
/// Throws [RangeError] if position is out of bounds
Pointer<git_status_entry> getByIndex(
Pointer<git_status_list> statuslist,
int idx,
) {
final result = libgit2.git_status_byindex(statuslist, idx);
Pointer<git_status_entry> getByIndex({
required Pointer<git_status_list> statuslistPointer,
required int index,
}) {
final result = libgit2.git_status_byindex(statuslistPointer, index);
if (result == nullptr) {
throw RangeError('Out of bounds');
@ -60,10 +60,10 @@ Pointer<git_status_entry> getByIndex(
/// and scan through looking for the path that you are interested in.
///
/// Throws a [LibGit2Error] if error occured.
int file(Pointer<git_repository> repo, String path) {
int file({required Pointer<git_repository> repoPointer, required String path}) {
final out = calloc<Uint32>();
final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_status_file(out, repo, pathC);
final error = libgit2.git_status_file(out, repoPointer, pathC);
calloc.free(pathC);

View file

@ -7,9 +7,12 @@ import '../util.dart';
/// Lookup a tag object from the repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_tag> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
Pointer<git_tag> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_tag>>();
final error = libgit2.git_tag_lookup(out, repo, id);
final error = libgit2.git_tag_lookup(out, repoPointer, oidPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -64,24 +67,24 @@ Pointer<git_signature> tagger(Pointer<git_tag> tag) =>
/// special meaning to revparse.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> create(
Pointer<git_repository> repo,
String tagName,
Pointer<git_object> target,
Pointer<git_signature> tagger,
String message,
bool force,
) {
Pointer<git_oid> create({
required Pointer<git_repository> repoPointer,
required String tagName,
required Pointer<git_object> targetPointer,
required Pointer<git_signature> taggerPointer,
required String message,
required bool force,
}) {
final out = calloc<git_oid>();
final tagNameC = tagName.toNativeUtf8().cast<Int8>();
final messageC = message.toNativeUtf8().cast<Int8>();
final forceC = force ? 1 : 0;
final error = libgit2.git_tag_create(
out,
repo,
repoPointer,
tagNameC,
target,
tagger,
targetPointer,
taggerPointer,
messageC,
forceC,
);

View file

@ -10,9 +10,12 @@ Pointer<git_oid> id(Pointer<git_tree> tree) => libgit2.git_tree_id(tree);
/// Lookup a tree object from the repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_tree> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
Pointer<git_tree> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_tree>>();
final error = libgit2.git_tree_lookup(out, repo, id);
final error = libgit2.git_tree_lookup(out, repoPointer, oidPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -31,8 +34,11 @@ Pointer<git_repository> owner(Pointer<git_tree> tree) =>
/// but you must not use it after the tree is released.
///
/// Throws [RangeError] when provided index is outside of valid range.
Pointer<git_tree_entry> getByIndex(Pointer<git_tree> tree, int index) {
final result = libgit2.git_tree_entry_byindex(tree, index);
Pointer<git_tree_entry> getByIndex({
required Pointer<git_tree> treePointer,
required int index,
}) {
final result = libgit2.git_tree_entry_byindex(treePointer, index);
if (result == nullptr) {
throw RangeError('Out of bounds');
@ -47,9 +53,12 @@ Pointer<git_tree_entry> getByIndex(Pointer<git_tree> tree, int index) {
/// but you must not use it after the tree is released.
///
/// Throws [ArgumentError] if nothing found for provided filename.
Pointer<git_tree_entry> getByName(Pointer<git_tree> tree, String filename) {
Pointer<git_tree_entry> getByName({
required Pointer<git_tree> treePointer,
required String filename,
}) {
final filenameC = filename.toNativeUtf8().cast<Int8>();
final result = libgit2.git_tree_entry_byname(tree, filenameC);
final result = libgit2.git_tree_entry_byname(treePointer, filenameC);
calloc.free(filenameC);
@ -66,10 +75,13 @@ Pointer<git_tree_entry> getByName(Pointer<git_tree> tree, String filename) {
/// freed explicitly with `entryFree()`.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_tree_entry> getByPath(Pointer<git_tree> root, String path) {
Pointer<git_tree_entry> getByPath({
required Pointer<git_tree> rootPointer,
required String path,
}) {
final out = calloc<Pointer<git_tree_entry>>();
final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_tree_entry_bypath(out, root, pathC);
final error = libgit2.git_tree_entry_bypath(out, rootPointer, pathC);
calloc.free(pathC);
@ -98,8 +110,11 @@ int entryFilemode(Pointer<git_tree_entry> entry) =>
/// Compare two tree entries.
///
/// Returns <0 if e1 is before e2, 0 if e1 == e2, >0 if e1 is after e2.
int compare(Pointer<git_tree_entry> e1, Pointer<git_tree_entry> e2) {
return libgit2.git_tree_entry_cmp(e1, e2);
int compare({
required Pointer<git_tree_entry> aPointer,
required Pointer<git_tree_entry> bPointer,
}) {
return libgit2.git_tree_entry_cmp(aPointer, bPointer);
}
/// Free a user-owned tree entry.

View file

@ -16,12 +16,12 @@ import '../util.dart';
/// and will have to be filled manually.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_treebuilder> create(
Pointer<git_repository> repo,
Pointer<git_tree> source,
) {
Pointer<git_treebuilder> create({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> sourcePointer,
}) {
final out = calloc<Pointer<git_treebuilder>>();
final error = libgit2.git_treebuilder_new(out, repo, source);
final error = libgit2.git_treebuilder_new(out, repoPointer, sourcePointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
@ -64,12 +64,12 @@ int entryCount(Pointer<git_treebuilder> bld) =>
/// The returned entry is owned by the builder and should not be freed manually.
///
/// Throws [ArgumentError] if nothing found for provided filename.
Pointer<git_tree_entry> getByFilename(
Pointer<git_treebuilder> bld,
String filename,
) {
Pointer<git_tree_entry> getByFilename({
required Pointer<git_treebuilder> builderPointer,
required String filename,
}) {
final filenameC = filename.toNativeUtf8().cast<Int8>();
final result = libgit2.git_treebuilder_get(bld, filenameC);
final result = libgit2.git_treebuilder_get(builderPointer, filenameC);
calloc.free(filenameC);
@ -91,15 +91,20 @@ Pointer<git_tree_entry> getByFilename(
/// that it exists in the object database and is of the correct type.
///
/// Throws a [LibGit2Error] if error occured.
void add(
Pointer<git_treebuilder> bld,
String filename,
Pointer<git_oid> id,
int filemode,
) {
void add({
required Pointer<git_treebuilder> builderPointer,
required String filename,
required Pointer<git_oid> oidPointer,
required int filemode,
}) {
final filenameC = filename.toNativeUtf8().cast<Int8>();
final error =
libgit2.git_treebuilder_insert(nullptr, bld, filenameC, id, filemode);
final error = libgit2.git_treebuilder_insert(
nullptr,
builderPointer,
filenameC,
oidPointer,
filemode,
);
calloc.free(filenameC);
@ -111,9 +116,12 @@ void add(
/// Remove an entry from the builder by its filename.
///
/// Throws a [LibGit2Error] if error occured.
void remove(Pointer<git_treebuilder> bld, String filename) {
void remove({
required Pointer<git_treebuilder> builderPointer,
required String filename,
}) {
final filenameC = filename.toNativeUtf8().cast<Int8>();
final error = libgit2.git_treebuilder_remove(bld, filenameC);
final error = libgit2.git_treebuilder_remove(builderPointer, filenameC);
calloc.free(filenameC);

View file

@ -11,12 +11,12 @@ import '../util.dart';
/// data structures inside the repository and check out the current HEAD at path.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_worktree> create(
Pointer<git_repository> repo,
String name,
String path,
Pointer<git_reference>? ref,
) {
Pointer<git_worktree> create({
required Pointer<git_repository> repoPointer,
required String name,
required String path,
Pointer<git_reference>? refPointer,
}) {
final out = calloc<Pointer<git_worktree>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final pathC = path.toNativeUtf8().cast<Int8>();
@ -24,10 +24,10 @@ Pointer<git_worktree> create(
calloc<git_worktree_add_options>(sizeOf<git_worktree_add_options>());
opts.ref.version = 1;
opts.ref.lock = 0;
if (ref != null) {
opts.ref.ref = ref;
if (refPointer != null) {
opts.ref.ref = refPointer;
}
final error = libgit2.git_worktree_add(out, repo, nameC, pathC, opts);
final error = libgit2.git_worktree_add(out, repoPointer, nameC, pathC, opts);
calloc.free(nameC);
calloc.free(pathC);
@ -43,10 +43,13 @@ Pointer<git_worktree> create(
/// Lookup a working tree by its name for a given repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_worktree> lookup(Pointer<git_repository> repo, String name) {
Pointer<git_worktree> lookup({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_worktree>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_worktree_lookup(out, repo, nameC);
final error = libgit2.git_worktree_lookup(out, repoPointer, nameC);
calloc.free(nameC);