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,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());