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

@ -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,