refactor: use nullable strings instead of empty in arguments

This commit is contained in:
Aleksey Kulikov 2021-09-27 11:44:16 +03:00
parent 5401717713
commit b5561212e0
7 changed files with 57 additions and 62 deletions

View file

@ -73,21 +73,19 @@ void annotatedFree(Pointer<git_annotated_commit> commit) {
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> create(
Pointer<git_repository> repo,
String updateRef,
String? updateRef,
Pointer<git_signature> author,
Pointer<git_signature> committer,
String messageEncoding,
String? messageEncoding,
String message,
Pointer<git_tree> tree,
int parentCount,
List<String> parents,
) {
final out = calloc<git_oid>();
final updateRefC =
updateRef.isEmpty ? nullptr : updateRef.toNativeUtf8().cast<Int8>();
final messageEncodingC = messageEncoding.isEmpty
? nullptr
: messageEncoding.toNativeUtf8().cast<Int8>();
final updateRefC = updateRef?.toNativeUtf8().cast<Int8>() ?? nullptr;
final messageEncodingC =
messageEncoding?.toNativeUtf8().cast<Int8>() ?? nullptr;
final messageC = message.toNativeUtf8().cast<Int8>();
Pointer<Pointer<git_commit>> parentsC =
calloc.call<Pointer<git_commit>>(parentCount);

View file

@ -296,7 +296,7 @@ void addPush(Pointer<git_repository> repo, String remote, String refspec) {
void connect(
Pointer<git_remote> remote,
int direction,
String proxyOption,
String? proxyOption,
) {
final callbacks = calloc<git_remote_callbacks>();
final callbacksError = libgit2.git_remote_init_callbacks(
@ -380,9 +380,9 @@ List<Map<String, dynamic>> lsRemotes(Pointer<git_remote> remote) {
void fetch(
Pointer<git_remote> remote,
List<String> refspecs,
String reflogMessage,
String? reflogMessage,
int prune,
String proxyOption,
String? proxyOption,
) {
var refspecsC = calloc<git_strarray>();
final refspecsPointers =
@ -411,9 +411,7 @@ void fetch(
opts.ref.prune = prune;
opts.ref.proxy_opts = proxyOptions.ref;
final reflogMessageC = reflogMessage.isEmpty
? nullptr
: reflogMessage.toNativeUtf8().cast<Int8>();
final reflogMessageC = reflogMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_remote_fetch(
remote,
@ -428,6 +426,7 @@ void fetch(
calloc.free(strArray);
calloc.free(refspecsC);
calloc.free(proxyOptions);
calloc.free(reflogMessageC);
calloc.free(opts);
if (error < 0) {
@ -441,7 +440,7 @@ void fetch(
void push(
Pointer<git_remote> remote,
List<String> refspecs,
String proxyOption,
String? proxyOption,
) {
var refspecsC = calloc<git_strarray>();
final refspecsPointers =
@ -527,7 +526,7 @@ void prune(Pointer<git_remote> remote) {
void free(Pointer<git_remote> remote) => libgit2.git_remote_free(remote);
/// Initializes git_proxy_options structure.
Pointer<git_proxy_options> _proxyOptionsInit(String proxyOption) {
Pointer<git_proxy_options> _proxyOptionsInit(String? proxyOption) {
final proxyOptions = calloc<git_proxy_options>();
final proxyOptionsError =
libgit2.git_proxy_options_init(proxyOptions, GIT_PROXY_OPTIONS_VERSION);
@ -536,7 +535,7 @@ Pointer<git_proxy_options> _proxyOptionsInit(String proxyOption) {
throw LibGit2Error(libgit2.git_error_last());
}
if (proxyOption.isEmpty) {
if (proxyOption == null) {
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_NONE;
} else if (proxyOption == 'auto') {
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_AUTO;

View file

@ -51,12 +51,17 @@ 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(String startPath, String? ceilingDirs) {
final out = calloc<git_buf>(sizeOf<git_buf>());
final startPathC = startPath.toNativeUtf8().cast<Int8>();
final ceilingDirsC = ceilingDirs.toNativeUtf8().cast<Int8>();
final error =
libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC);
final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_repository_discover(
out,
startPathC,
0,
ceilingDirsC,
);
calloc.free(startPathC);
calloc.free(ceilingDirsC);
@ -77,24 +82,19 @@ Pointer<git_repository> init(
String path,
int flags,
int mode,
String workdirPath,
String description,
String templatePath,
String initialHead,
String originUrl,
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.isEmpty ? nullptr : workdirPath.toNativeUtf8().cast<Int8>();
final descriptionC =
description.isEmpty ? nullptr : description.toNativeUtf8().cast<Int8>();
final templatePathC =
templatePath.isEmpty ? nullptr : templatePath.toNativeUtf8().cast<Int8>();
final initialHeadC =
initialHead.isEmpty ? nullptr : initialHead.toNativeUtf8().cast<Int8>();
final originUrlC =
originUrl.isEmpty ? nullptr : originUrl.toNativeUtf8().cast<Int8>();
final workdirPathC = workdirPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final descriptionC = description?.toNativeUtf8().cast<Int8>() ?? nullptr;
final templatePathC = templatePath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final initialHeadC = initialHead?.toNativeUtf8().cast<Int8>() ?? nullptr;
final originUrlC = originUrl?.toNativeUtf8().cast<Int8>() ?? nullptr;
final opts = calloc<git_repository_init_options>();
final optsError = libgit2.git_repository_init_options_init(
opts,
@ -139,14 +139,13 @@ Pointer<git_repository> clone(
bool bare,
Remote Function(Repository, String, String)? remote,
Repository Function(String, bool)? repository,
String checkoutBranch,
String? checkoutBranch,
) {
final out = calloc<Pointer<git_repository>>();
final urlC = url.toNativeUtf8().cast<Int8>();
final localPathC = localPath.toNativeUtf8().cast<Int8>();
final checkoutBranchC = checkoutBranch.isEmpty
? nullptr
: checkoutBranch.toNativeUtf8().cast<Int8>();
final checkoutBranchC =
checkoutBranch?.toNativeUtf8().cast<Int8>() ?? nullptr;
final cloneOptions = calloc<git_clone_options>();
final cloneOptionsError =

View file

@ -13,12 +13,11 @@ import '../util.dart';
Pointer<git_oid> stash(
Pointer<git_repository> repo,
Pointer<git_signature> stasher,
String message,
String? message,
int flags,
) {
final out = calloc<git_oid>();
final messageC =
message.isNotEmpty ? message.toNativeUtf8().cast<Int8>() : nullptr;
final messageC = message?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_stash_save(out, repo, stasher, messageC, flags);
if (error < 0) {