mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
refactor: use nullable strings instead of empty in arguments
This commit is contained in:
parent
5401717713
commit
b5561212e0
7 changed files with 57 additions and 62 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -47,8 +47,8 @@ class Commit {
|
|||
required Signature commiter,
|
||||
required String treeSHA,
|
||||
required List<String> parents,
|
||||
String updateRef = '',
|
||||
String messageEncoding = '',
|
||||
String? updateRef,
|
||||
String? messageEncoding,
|
||||
}) {
|
||||
final tree = Tree.lookup(repo, treeSHA);
|
||||
|
||||
|
|
|
@ -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<Map<String, dynamic>> ls([String proxy = '']) {
|
||||
List<Map<String, dynamic>> 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<String> 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<String> refspecs, [String proxy = '']) {
|
||||
void push(List<String> refspecs, [String? proxy]) {
|
||||
bindings.push(_remotePointer, refspecs, proxy);
|
||||
}
|
||||
|
||||
|
|
|
@ -45,11 +45,11 @@ class Repository {
|
|||
bool bare = false,
|
||||
Set<GitRepositoryInit> 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<String> 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<GitCheckout> 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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue