diff --git a/lib/src/bindings/commit.dart b/lib/src/bindings/commit.dart index 0e320fe..c43344b 100644 --- a/lib/src/bindings/commit.dart +++ b/lib/src/bindings/commit.dart @@ -73,21 +73,19 @@ void annotatedFree(Pointer commit) { /// Throws a [LibGit2Error] if error occured. Pointer create( Pointer repo, - String updateRef, + String? updateRef, Pointer author, Pointer committer, - String messageEncoding, + String? messageEncoding, String message, Pointer tree, int parentCount, List parents, ) { final out = calloc(); - final updateRefC = - updateRef.isEmpty ? nullptr : updateRef.toNativeUtf8().cast(); - final messageEncodingC = messageEncoding.isEmpty - ? nullptr - : messageEncoding.toNativeUtf8().cast(); + final updateRefC = updateRef?.toNativeUtf8().cast() ?? nullptr; + final messageEncodingC = + messageEncoding?.toNativeUtf8().cast() ?? nullptr; final messageC = message.toNativeUtf8().cast(); Pointer> parentsC = calloc.call>(parentCount); diff --git a/lib/src/bindings/remote.dart b/lib/src/bindings/remote.dart index 49ce350..aeb1623 100644 --- a/lib/src/bindings/remote.dart +++ b/lib/src/bindings/remote.dart @@ -296,7 +296,7 @@ void addPush(Pointer repo, String remote, String refspec) { void connect( Pointer remote, int direction, - String proxyOption, + String? proxyOption, ) { final callbacks = calloc(); final callbacksError = libgit2.git_remote_init_callbacks( @@ -380,9 +380,9 @@ List> lsRemotes(Pointer remote) { void fetch( Pointer remote, List refspecs, - String reflogMessage, + String? reflogMessage, int prune, - String proxyOption, + String? proxyOption, ) { var refspecsC = calloc(); 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(); + final reflogMessageC = reflogMessage?.toNativeUtf8().cast() ?? 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 remote, List refspecs, - String proxyOption, + String? proxyOption, ) { var refspecsC = calloc(); final refspecsPointers = @@ -527,7 +526,7 @@ void prune(Pointer remote) { void free(Pointer remote) => libgit2.git_remote_free(remote); /// Initializes git_proxy_options structure. -Pointer _proxyOptionsInit(String proxyOption) { +Pointer _proxyOptionsInit(String? proxyOption) { final proxyOptions = calloc(); final proxyOptionsError = libgit2.git_proxy_options_init(proxyOptions, GIT_PROXY_OPTIONS_VERSION); @@ -536,7 +535,7 @@ Pointer _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; diff --git a/lib/src/bindings/repository.dart b/lib/src/bindings/repository.dart index 23cf210..72caf75 100644 --- a/lib/src/bindings/repository.dart +++ b/lib/src/bindings/repository.dart @@ -51,12 +51,17 @@ Pointer 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(sizeOf()); final startPathC = startPath.toNativeUtf8().cast(); - final ceilingDirsC = ceilingDirs.toNativeUtf8().cast(); - final error = - libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC); + final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast() ?? nullptr; + + final error = libgit2.git_repository_discover( + out, + startPathC, + 0, + ceilingDirsC, + ); calloc.free(startPathC); calloc.free(ceilingDirsC); @@ -77,24 +82,19 @@ Pointer 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>(); final pathC = path.toNativeUtf8().cast(); - final workdirPathC = - workdirPath.isEmpty ? nullptr : workdirPath.toNativeUtf8().cast(); - final descriptionC = - description.isEmpty ? nullptr : description.toNativeUtf8().cast(); - final templatePathC = - templatePath.isEmpty ? nullptr : templatePath.toNativeUtf8().cast(); - final initialHeadC = - initialHead.isEmpty ? nullptr : initialHead.toNativeUtf8().cast(); - final originUrlC = - originUrl.isEmpty ? nullptr : originUrl.toNativeUtf8().cast(); + final workdirPathC = workdirPath?.toNativeUtf8().cast() ?? nullptr; + final descriptionC = description?.toNativeUtf8().cast() ?? nullptr; + final templatePathC = templatePath?.toNativeUtf8().cast() ?? nullptr; + final initialHeadC = initialHead?.toNativeUtf8().cast() ?? nullptr; + final originUrlC = originUrl?.toNativeUtf8().cast() ?? nullptr; final opts = calloc(); final optsError = libgit2.git_repository_init_options_init( opts, @@ -139,14 +139,13 @@ Pointer clone( bool bare, Remote Function(Repository, String, String)? remote, Repository Function(String, bool)? repository, - String checkoutBranch, + String? checkoutBranch, ) { final out = calloc>(); final urlC = url.toNativeUtf8().cast(); final localPathC = localPath.toNativeUtf8().cast(); - final checkoutBranchC = checkoutBranch.isEmpty - ? nullptr - : checkoutBranch.toNativeUtf8().cast(); + final checkoutBranchC = + checkoutBranch?.toNativeUtf8().cast() ?? nullptr; final cloneOptions = calloc(); final cloneOptionsError = diff --git a/lib/src/bindings/stash.dart b/lib/src/bindings/stash.dart index e98b534..fb9f782 100644 --- a/lib/src/bindings/stash.dart +++ b/lib/src/bindings/stash.dart @@ -13,12 +13,11 @@ import '../util.dart'; Pointer stash( Pointer repo, Pointer stasher, - String message, + String? message, int flags, ) { final out = calloc(); - final messageC = - message.isNotEmpty ? message.toNativeUtf8().cast() : nullptr; + final messageC = message?.toNativeUtf8().cast() ?? nullptr; final error = libgit2.git_stash_save(out, repo, stasher, messageC, flags); if (error < 0) { diff --git a/lib/src/commit.dart b/lib/src/commit.dart index 5a00997..d2e4cdc 100644 --- a/lib/src/commit.dart +++ b/lib/src/commit.dart @@ -47,8 +47,8 @@ class Commit { required Signature commiter, required String treeSHA, required List parents, - String updateRef = '', - String messageEncoding = '', + String? updateRef, + String? messageEncoding, }) { final tree = Tree.lookup(repo, treeSHA); diff --git a/lib/src/remote.dart b/lib/src/remote.dart index 080e1a2..ae3196a 100644 --- a/lib/src/remote.dart +++ b/lib/src/remote.dart @@ -43,9 +43,9 @@ class Remotes { Remote create({ required String name, required String url, - String fetch = '', + String? fetch, }) { - if (fetch.isEmpty) { + if (fetch == null) { return Remote(bindings.create(_repoPointer, name, url)); } else { return Remote(bindings.createWithFetchSpec( @@ -154,7 +154,7 @@ class Remote { /// specified url. By default connection isn't done through proxy. /// /// Throws a [LibGit2Error] if error occured. - List> ls([String proxy = '']) { + List> ls([String? proxy]) { bindings.connect(_remotePointer, GitDirection.fetch.value, proxy); final result = bindings.lsRemotes(_remotePointer); bindings.disconnect(_remotePointer); @@ -171,9 +171,9 @@ class Remote { /// Throws a [LibGit2Error] if error occured. TransferProgress fetch({ List refspecs = const [], - String reflogMessage = '', + String? reflogMessage, GitFetchPrune prune = GitFetchPrune.unspecified, - String proxy = '', + String? proxy, }) { bindings.fetch(_remotePointer, refspecs, reflogMessage, prune.value, proxy); return TransferProgress(bindings.stats(_remotePointer)); @@ -182,7 +182,7 @@ class Remote { /// Performs a push. /// /// Throws a [LibGit2Error] if error occured. - void push(List refspecs, [String proxy = '']) { + void push(List refspecs, [String? proxy]) { bindings.push(_remotePointer, refspecs, proxy); } diff --git a/lib/src/repository.dart b/lib/src/repository.dart index d444aa6..fa61fcb 100644 --- a/lib/src/repository.dart +++ b/lib/src/repository.dart @@ -45,11 +45,11 @@ class Repository { bool bare = false, Set flags = const {GitRepositoryInit.mkpath}, int mode = 0, - String workdirPath = '', - String description = '', - String templatePath = '', - String initialHead = '', - String originUrl = '', + String? workdirPath, + String? description, + String? templatePath, + String? initialHead, + String? originUrl, }) { libgit2.git_libgit2_init(); @@ -106,7 +106,7 @@ class Repository { bool bare = false, Remote Function(Repository, String, String)? remote, Repository Function(String, bool)? repository, - String checkoutBranch = '', + String? checkoutBranch, }) { libgit2.git_libgit2_init(); @@ -132,7 +132,7 @@ class Repository { /// The method will automatically detect if the repository is bare (if there is a repository). /// /// Throws a [LibGit2Error] if error occured. - static String discover(String startPath, [String ceilingDirs = '']) { + static String discover(String startPath, [String? ceilingDirs]) { return bindings.discover(startPath, ceilingDirs); } @@ -412,8 +412,8 @@ class Repository { required Signature commiter, required String treeSHA, required List parents, - String updateRef = '', - String messageEncoding = '', + String? updateRef, + String? messageEncoding, }) { return Commit.create( repo: this, @@ -737,7 +737,7 @@ class Repository { /// [paths] is list of files to checkout from provided reference [refName]. If paths are provided /// HEAD will not be set to the reference [refName]. void checkout({ - String refName = '', + String? refName, Set strategy = const { GitCheckout.safe, GitCheckout.recreateMissing @@ -748,7 +748,7 @@ class Repository { final int strat = strategy.fold(0, (previousValue, e) => previousValue | e.value); - if (refName.isEmpty) { + if (refName == null) { checkout_bindings.index(_repoPointer, strat, directory, paths); } else if (refName == 'HEAD') { checkout_bindings.head(_repoPointer, strat, directory, paths); @@ -883,7 +883,7 @@ class Repository { /// Throws a [LibGit2Error] if error occured. Oid stash({ required Signature stasher, - String message = '', + String? message, bool keepIndex = false, bool includeUntracked = false, bool includeIgnored = false,