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.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_oid> create(
|
Pointer<git_oid> create(
|
||||||
Pointer<git_repository> repo,
|
Pointer<git_repository> repo,
|
||||||
String updateRef,
|
String? updateRef,
|
||||||
Pointer<git_signature> author,
|
Pointer<git_signature> author,
|
||||||
Pointer<git_signature> committer,
|
Pointer<git_signature> committer,
|
||||||
String messageEncoding,
|
String? messageEncoding,
|
||||||
String message,
|
String message,
|
||||||
Pointer<git_tree> tree,
|
Pointer<git_tree> tree,
|
||||||
int parentCount,
|
int parentCount,
|
||||||
List<String> parents,
|
List<String> parents,
|
||||||
) {
|
) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final updateRefC =
|
final updateRefC = updateRef?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
updateRef.isEmpty ? nullptr : updateRef.toNativeUtf8().cast<Int8>();
|
final messageEncodingC =
|
||||||
final messageEncodingC = messageEncoding.isEmpty
|
messageEncoding?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
? nullptr
|
|
||||||
: messageEncoding.toNativeUtf8().cast<Int8>();
|
|
||||||
final messageC = message.toNativeUtf8().cast<Int8>();
|
final messageC = message.toNativeUtf8().cast<Int8>();
|
||||||
Pointer<Pointer<git_commit>> parentsC =
|
Pointer<Pointer<git_commit>> parentsC =
|
||||||
calloc.call<Pointer<git_commit>>(parentCount);
|
calloc.call<Pointer<git_commit>>(parentCount);
|
||||||
|
|
|
@ -296,7 +296,7 @@ void addPush(Pointer<git_repository> repo, String remote, String refspec) {
|
||||||
void connect(
|
void connect(
|
||||||
Pointer<git_remote> remote,
|
Pointer<git_remote> remote,
|
||||||
int direction,
|
int direction,
|
||||||
String proxyOption,
|
String? proxyOption,
|
||||||
) {
|
) {
|
||||||
final callbacks = calloc<git_remote_callbacks>();
|
final callbacks = calloc<git_remote_callbacks>();
|
||||||
final callbacksError = libgit2.git_remote_init_callbacks(
|
final callbacksError = libgit2.git_remote_init_callbacks(
|
||||||
|
@ -380,9 +380,9 @@ List<Map<String, dynamic>> lsRemotes(Pointer<git_remote> remote) {
|
||||||
void fetch(
|
void fetch(
|
||||||
Pointer<git_remote> remote,
|
Pointer<git_remote> remote,
|
||||||
List<String> refspecs,
|
List<String> refspecs,
|
||||||
String reflogMessage,
|
String? reflogMessage,
|
||||||
int prune,
|
int prune,
|
||||||
String proxyOption,
|
String? proxyOption,
|
||||||
) {
|
) {
|
||||||
var refspecsC = calloc<git_strarray>();
|
var refspecsC = calloc<git_strarray>();
|
||||||
final refspecsPointers =
|
final refspecsPointers =
|
||||||
|
@ -411,9 +411,7 @@ void fetch(
|
||||||
opts.ref.prune = prune;
|
opts.ref.prune = prune;
|
||||||
opts.ref.proxy_opts = proxyOptions.ref;
|
opts.ref.proxy_opts = proxyOptions.ref;
|
||||||
|
|
||||||
final reflogMessageC = reflogMessage.isEmpty
|
final reflogMessageC = reflogMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
? nullptr
|
|
||||||
: reflogMessage.toNativeUtf8().cast<Int8>();
|
|
||||||
|
|
||||||
final error = libgit2.git_remote_fetch(
|
final error = libgit2.git_remote_fetch(
|
||||||
remote,
|
remote,
|
||||||
|
@ -428,6 +426,7 @@ void fetch(
|
||||||
calloc.free(strArray);
|
calloc.free(strArray);
|
||||||
calloc.free(refspecsC);
|
calloc.free(refspecsC);
|
||||||
calloc.free(proxyOptions);
|
calloc.free(proxyOptions);
|
||||||
|
calloc.free(reflogMessageC);
|
||||||
calloc.free(opts);
|
calloc.free(opts);
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
|
@ -441,7 +440,7 @@ void fetch(
|
||||||
void push(
|
void push(
|
||||||
Pointer<git_remote> remote,
|
Pointer<git_remote> remote,
|
||||||
List<String> refspecs,
|
List<String> refspecs,
|
||||||
String proxyOption,
|
String? proxyOption,
|
||||||
) {
|
) {
|
||||||
var refspecsC = calloc<git_strarray>();
|
var refspecsC = calloc<git_strarray>();
|
||||||
final refspecsPointers =
|
final refspecsPointers =
|
||||||
|
@ -527,7 +526,7 @@ void prune(Pointer<git_remote> remote) {
|
||||||
void free(Pointer<git_remote> remote) => libgit2.git_remote_free(remote);
|
void free(Pointer<git_remote> remote) => libgit2.git_remote_free(remote);
|
||||||
|
|
||||||
/// Initializes git_proxy_options structure.
|
/// 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 proxyOptions = calloc<git_proxy_options>();
|
||||||
final proxyOptionsError =
|
final proxyOptionsError =
|
||||||
libgit2.git_proxy_options_init(proxyOptions, GIT_PROXY_OPTIONS_VERSION);
|
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());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxyOption.isEmpty) {
|
if (proxyOption == null) {
|
||||||
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_NONE;
|
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_NONE;
|
||||||
} else if (proxyOption == 'auto') {
|
} else if (proxyOption == 'auto') {
|
||||||
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_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).
|
/// The method will automatically detect if the repository is bare (if there is a repository).
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// 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 out = calloc<git_buf>(sizeOf<git_buf>());
|
||||||
final startPathC = startPath.toNativeUtf8().cast<Int8>();
|
final startPathC = startPath.toNativeUtf8().cast<Int8>();
|
||||||
final ceilingDirsC = ceilingDirs.toNativeUtf8().cast<Int8>();
|
final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final error =
|
|
||||||
libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC);
|
final error = libgit2.git_repository_discover(
|
||||||
|
out,
|
||||||
|
startPathC,
|
||||||
|
0,
|
||||||
|
ceilingDirsC,
|
||||||
|
);
|
||||||
|
|
||||||
calloc.free(startPathC);
|
calloc.free(startPathC);
|
||||||
calloc.free(ceilingDirsC);
|
calloc.free(ceilingDirsC);
|
||||||
|
@ -77,24 +82,19 @@ Pointer<git_repository> init(
|
||||||
String path,
|
String path,
|
||||||
int flags,
|
int flags,
|
||||||
int mode,
|
int mode,
|
||||||
String workdirPath,
|
String? workdirPath,
|
||||||
String description,
|
String? description,
|
||||||
String templatePath,
|
String? templatePath,
|
||||||
String initialHead,
|
String? initialHead,
|
||||||
String originUrl,
|
String? originUrl,
|
||||||
) {
|
) {
|
||||||
final out = calloc<Pointer<git_repository>>();
|
final out = calloc<Pointer<git_repository>>();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
final workdirPathC =
|
final workdirPathC = workdirPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
workdirPath.isEmpty ? nullptr : workdirPath.toNativeUtf8().cast<Int8>();
|
final descriptionC = description?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final descriptionC =
|
final templatePathC = templatePath?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
description.isEmpty ? nullptr : description.toNativeUtf8().cast<Int8>();
|
final initialHeadC = initialHead?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
final templatePathC =
|
final originUrlC = originUrl?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
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 opts = calloc<git_repository_init_options>();
|
final opts = calloc<git_repository_init_options>();
|
||||||
final optsError = libgit2.git_repository_init_options_init(
|
final optsError = libgit2.git_repository_init_options_init(
|
||||||
opts,
|
opts,
|
||||||
|
@ -139,14 +139,13 @@ Pointer<git_repository> clone(
|
||||||
bool bare,
|
bool bare,
|
||||||
Remote Function(Repository, String, String)? remote,
|
Remote Function(Repository, String, String)? remote,
|
||||||
Repository Function(String, bool)? repository,
|
Repository Function(String, bool)? repository,
|
||||||
String checkoutBranch,
|
String? checkoutBranch,
|
||||||
) {
|
) {
|
||||||
final out = calloc<Pointer<git_repository>>();
|
final out = calloc<Pointer<git_repository>>();
|
||||||
final urlC = url.toNativeUtf8().cast<Int8>();
|
final urlC = url.toNativeUtf8().cast<Int8>();
|
||||||
final localPathC = localPath.toNativeUtf8().cast<Int8>();
|
final localPathC = localPath.toNativeUtf8().cast<Int8>();
|
||||||
final checkoutBranchC = checkoutBranch.isEmpty
|
final checkoutBranchC =
|
||||||
? nullptr
|
checkoutBranch?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
: checkoutBranch.toNativeUtf8().cast<Int8>();
|
|
||||||
|
|
||||||
final cloneOptions = calloc<git_clone_options>();
|
final cloneOptions = calloc<git_clone_options>();
|
||||||
final cloneOptionsError =
|
final cloneOptionsError =
|
||||||
|
|
|
@ -13,12 +13,11 @@ import '../util.dart';
|
||||||
Pointer<git_oid> stash(
|
Pointer<git_oid> stash(
|
||||||
Pointer<git_repository> repo,
|
Pointer<git_repository> repo,
|
||||||
Pointer<git_signature> stasher,
|
Pointer<git_signature> stasher,
|
||||||
String message,
|
String? message,
|
||||||
int flags,
|
int flags,
|
||||||
) {
|
) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final messageC =
|
final messageC = message?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
||||||
message.isNotEmpty ? message.toNativeUtf8().cast<Int8>() : nullptr;
|
|
||||||
final error = libgit2.git_stash_save(out, repo, stasher, messageC, flags);
|
final error = libgit2.git_stash_save(out, repo, stasher, messageC, flags);
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
|
|
|
@ -47,8 +47,8 @@ class Commit {
|
||||||
required Signature commiter,
|
required Signature commiter,
|
||||||
required String treeSHA,
|
required String treeSHA,
|
||||||
required List<String> parents,
|
required List<String> parents,
|
||||||
String updateRef = '',
|
String? updateRef,
|
||||||
String messageEncoding = '',
|
String? messageEncoding,
|
||||||
}) {
|
}) {
|
||||||
final tree = Tree.lookup(repo, treeSHA);
|
final tree = Tree.lookup(repo, treeSHA);
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,9 @@ class Remotes {
|
||||||
Remote create({
|
Remote create({
|
||||||
required String name,
|
required String name,
|
||||||
required String url,
|
required String url,
|
||||||
String fetch = '',
|
String? fetch,
|
||||||
}) {
|
}) {
|
||||||
if (fetch.isEmpty) {
|
if (fetch == null) {
|
||||||
return Remote(bindings.create(_repoPointer, name, url));
|
return Remote(bindings.create(_repoPointer, name, url));
|
||||||
} else {
|
} else {
|
||||||
return Remote(bindings.createWithFetchSpec(
|
return Remote(bindings.createWithFetchSpec(
|
||||||
|
@ -154,7 +154,7 @@ class Remote {
|
||||||
/// specified url. By default connection isn't done through proxy.
|
/// specified url. By default connection isn't done through proxy.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// 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);
|
bindings.connect(_remotePointer, GitDirection.fetch.value, proxy);
|
||||||
final result = bindings.lsRemotes(_remotePointer);
|
final result = bindings.lsRemotes(_remotePointer);
|
||||||
bindings.disconnect(_remotePointer);
|
bindings.disconnect(_remotePointer);
|
||||||
|
@ -171,9 +171,9 @@ class Remote {
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
TransferProgress fetch({
|
TransferProgress fetch({
|
||||||
List<String> refspecs = const [],
|
List<String> refspecs = const [],
|
||||||
String reflogMessage = '',
|
String? reflogMessage,
|
||||||
GitFetchPrune prune = GitFetchPrune.unspecified,
|
GitFetchPrune prune = GitFetchPrune.unspecified,
|
||||||
String proxy = '',
|
String? proxy,
|
||||||
}) {
|
}) {
|
||||||
bindings.fetch(_remotePointer, refspecs, reflogMessage, prune.value, proxy);
|
bindings.fetch(_remotePointer, refspecs, reflogMessage, prune.value, proxy);
|
||||||
return TransferProgress(bindings.stats(_remotePointer));
|
return TransferProgress(bindings.stats(_remotePointer));
|
||||||
|
@ -182,7 +182,7 @@ class Remote {
|
||||||
/// Performs a push.
|
/// Performs a push.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// 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);
|
bindings.push(_remotePointer, refspecs, proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,11 @@ class Repository {
|
||||||
bool bare = false,
|
bool bare = false,
|
||||||
Set<GitRepositoryInit> flags = const {GitRepositoryInit.mkpath},
|
Set<GitRepositoryInit> flags = const {GitRepositoryInit.mkpath},
|
||||||
int mode = 0,
|
int mode = 0,
|
||||||
String workdirPath = '',
|
String? workdirPath,
|
||||||
String description = '',
|
String? description,
|
||||||
String templatePath = '',
|
String? templatePath,
|
||||||
String initialHead = '',
|
String? initialHead,
|
||||||
String originUrl = '',
|
String? originUrl,
|
||||||
}) {
|
}) {
|
||||||
libgit2.git_libgit2_init();
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class Repository {
|
||||||
bool bare = false,
|
bool bare = false,
|
||||||
Remote Function(Repository, String, String)? remote,
|
Remote Function(Repository, String, String)? remote,
|
||||||
Repository Function(String, bool)? repository,
|
Repository Function(String, bool)? repository,
|
||||||
String checkoutBranch = '',
|
String? checkoutBranch,
|
||||||
}) {
|
}) {
|
||||||
libgit2.git_libgit2_init();
|
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).
|
/// The method will automatically detect if the repository is bare (if there is a repository).
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// 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);
|
return bindings.discover(startPath, ceilingDirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,8 +412,8 @@ class Repository {
|
||||||
required Signature commiter,
|
required Signature commiter,
|
||||||
required String treeSHA,
|
required String treeSHA,
|
||||||
required List<String> parents,
|
required List<String> parents,
|
||||||
String updateRef = '',
|
String? updateRef,
|
||||||
String messageEncoding = '',
|
String? messageEncoding,
|
||||||
}) {
|
}) {
|
||||||
return Commit.create(
|
return Commit.create(
|
||||||
repo: this,
|
repo: this,
|
||||||
|
@ -737,7 +737,7 @@ class Repository {
|
||||||
/// [paths] is list of files to checkout from provided reference [refName]. If paths are provided
|
/// [paths] is list of files to checkout from provided reference [refName]. If paths are provided
|
||||||
/// HEAD will not be set to the reference [refName].
|
/// HEAD will not be set to the reference [refName].
|
||||||
void checkout({
|
void checkout({
|
||||||
String refName = '',
|
String? refName,
|
||||||
Set<GitCheckout> strategy = const {
|
Set<GitCheckout> strategy = const {
|
||||||
GitCheckout.safe,
|
GitCheckout.safe,
|
||||||
GitCheckout.recreateMissing
|
GitCheckout.recreateMissing
|
||||||
|
@ -748,7 +748,7 @@ class Repository {
|
||||||
final int strat =
|
final int strat =
|
||||||
strategy.fold(0, (previousValue, e) => previousValue | e.value);
|
strategy.fold(0, (previousValue, e) => previousValue | e.value);
|
||||||
|
|
||||||
if (refName.isEmpty) {
|
if (refName == null) {
|
||||||
checkout_bindings.index(_repoPointer, strat, directory, paths);
|
checkout_bindings.index(_repoPointer, strat, directory, paths);
|
||||||
} else if (refName == 'HEAD') {
|
} else if (refName == 'HEAD') {
|
||||||
checkout_bindings.head(_repoPointer, strat, directory, paths);
|
checkout_bindings.head(_repoPointer, strat, directory, paths);
|
||||||
|
@ -883,7 +883,7 @@ class Repository {
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Oid stash({
|
Oid stash({
|
||||||
required Signature stasher,
|
required Signature stasher,
|
||||||
String message = '',
|
String? message,
|
||||||
bool keepIndex = false,
|
bool keepIndex = false,
|
||||||
bool includeUntracked = false,
|
bool includeUntracked = false,
|
||||||
bool includeIgnored = false,
|
bool includeIgnored = false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue