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

@ -26,7 +26,7 @@ void main() async {
); );
// Rename reference. // Rename reference.
newRef.rename('refs/tags/v1.1'); newRef.rename(newName: 'refs/tags/v1.1');
// Delete reference. // Delete reference.
newRef.delete(); newRef.delete();

View file

@ -7,9 +7,12 @@ import '../util.dart';
/// Lookup a blob object from a repository. /// Lookup a blob object from a repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_blob> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) { Pointer<git_blob> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_blob>>(); final out = calloc<Pointer<git_blob>>();
final error = libgit2.git_blob_lookup(out, repo, id); final error = libgit2.git_blob_lookup(out, repoPointer, oidPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -47,14 +50,15 @@ int size(Pointer<git_blob> blob) => libgit2.git_blob_rawsize(blob);
/// Write content of a string buffer to the ODB as a blob. /// Write content of a string buffer to the ODB as a blob.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> create( Pointer<git_oid> create({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String buffer, required String buffer,
int len, required int len,
) { }) {
final out = calloc<git_oid>(); final out = calloc<git_oid>();
final bufferC = buffer.toNativeUtf8().cast<Void>(); final bufferC = buffer.toNativeUtf8().cast<Void>();
final error = libgit2.git_blob_create_from_buffer(out, repo, bufferC, len); final error =
libgit2.git_blob_create_from_buffer(out, repoPointer, bufferC, len);
calloc.free(bufferC); calloc.free(bufferC);
@ -69,13 +73,14 @@ Pointer<git_oid> create(
/// Object Database as a loose blob. /// Object Database as a loose blob.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> createFromWorkdir( Pointer<git_oid> createFromWorkdir({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String relativePath, required String relativePath,
) { }) {
final out = calloc<git_oid>(); final out = calloc<git_oid>();
final relativePathC = relativePath.toNativeUtf8().cast<Int8>(); final relativePathC = relativePath.toNativeUtf8().cast<Int8>();
final error = libgit2.git_blob_create_from_workdir(out, repo, relativePathC); final error =
libgit2.git_blob_create_from_workdir(out, repoPointer, relativePathC);
calloc.free(relativePathC); calloc.free(relativePathC);
@ -89,13 +94,13 @@ Pointer<git_oid> createFromWorkdir(
/// Read a file from the filesystem and write its content to the Object Database as a loose blob. /// Read a file from the filesystem and write its content to the Object Database as a loose blob.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> createFromDisk( Pointer<git_oid> createFromDisk({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String path, required String path,
) { }) {
final out = calloc<git_oid>(); final out = calloc<git_oid>();
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_blob_create_from_disk(out, repo, pathC); final error = libgit2.git_blob_create_from_disk(out, repoPointer, pathC);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());

View file

@ -9,12 +9,15 @@ import '../util.dart';
/// Return a list of branches. /// Return a list of branches.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<String> list(Pointer<git_repository> repo, int listFlags) { List<String> list({
required Pointer<git_repository> repoPointer,
required int flags,
}) {
final iterator = calloc<Pointer<git_branch_iterator>>(); final iterator = calloc<Pointer<git_branch_iterator>>();
final iteratorError = libgit2.git_branch_iterator_new( final iteratorError = libgit2.git_branch_iterator_new(
iterator, iterator,
repo, repoPointer,
listFlags, flags,
); );
if (iteratorError < 0) { if (iteratorError < 0) {
@ -47,14 +50,19 @@ List<String> list(Pointer<git_repository> repo, int listFlags) {
/// The generated reference must be freed by the user. The branch name will be checked for validity. /// The generated reference must be freed by the user. The branch name will be checked for validity.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> lookup( Pointer<git_reference> lookup({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String branchName, required String branchName,
int branchType, required int branchType,
) { }) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final branchNameC = branchName.toNativeUtf8().cast<Int8>(); final branchNameC = branchName.toNativeUtf8().cast<Int8>();
final error = libgit2.git_branch_lookup(out, repo, branchNameC, branchType); final error = libgit2.git_branch_lookup(
out,
repoPointer,
branchNameC,
branchType,
);
calloc.free(branchNameC); calloc.free(branchNameC);
@ -75,20 +83,20 @@ Pointer<git_reference> lookup(
/// The branch name will be checked for validity. /// The branch name will be checked for validity.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> create( Pointer<git_reference> create({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String branchName, required String branchName,
Pointer<git_commit> target, required Pointer<git_commit> targetPointer,
bool force, required bool force,
) { }) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final branchNameC = branchName.toNativeUtf8().cast<Int8>(); final branchNameC = branchName.toNativeUtf8().cast<Int8>();
final forceC = force ? 1 : 0; final forceC = force ? 1 : 0;
final error = libgit2.git_branch_create( final error = libgit2.git_branch_create(
out, out,
repo, repoPointer,
branchNameC, branchNameC,
target, targetPointer,
forceC, forceC,
); );
@ -125,22 +133,23 @@ void delete(Pointer<git_reference> branch) {
/// and will be freed immediately. /// and will be freed immediately.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> rename( Pointer<git_reference> rename({
Pointer<git_reference> branch, required Pointer<git_reference> branchPointer,
String newBranchName, required String newBranchName,
bool force, required bool force,
) { }) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final newBranchNameC = newBranchName.toNativeUtf8().cast<Int8>(); final newBranchNameC = newBranchName.toNativeUtf8().cast<Int8>();
final forceC = force ? 1 : 0; final forceC = force ? 1 : 0;
final error = libgit2.git_branch_move(out, branch, newBranchNameC, forceC); final error =
libgit2.git_branch_move(out, branchPointer, newBranchNameC, forceC);
calloc.free(newBranchNameC); calloc.free(newBranchNameC);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
} else { } else {
reference_bindings.free(branch); reference_bindings.free(branchPointer);
return out.value; return out.value;
} }
} }

View file

@ -13,18 +13,19 @@ import '../util.dart';
/// target of the branch and then update HEAD using `setHead` to point to the branch you checked out. /// target of the branch and then update HEAD using `setHead` to point to the branch you checked out.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void head( void head({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
int strategy, required int strategy,
String? directory, String? directory,
List<String>? paths, List<String>? paths,
) { }) {
final initOpts = initOptions(strategy, directory, paths); final initOpts =
initOptions(strategy: strategy, directory: directory, paths: paths);
final optsC = initOpts[0]; final optsC = initOpts[0];
final pathPointers = initOpts[1]; final pathPointers = initOpts[1];
final strArray = initOpts[2]; final strArray = initOpts[2];
final error = libgit2.git_checkout_head(repo, optsC); final error = libgit2.git_checkout_head(repoPointer, optsC);
for (var p in pathPointers) { for (var p in pathPointers) {
calloc.free(p); calloc.free(p);
@ -41,18 +42,19 @@ void head(
/// Updates files in the working tree to match the content of the index. /// Updates files in the working tree to match the content of the index.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void index( void index({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
int strategy, required int strategy,
String? directory, String? directory,
List<String>? paths, List<String>? paths,
) { }) {
final initOpts = initOptions(strategy, directory, paths); final initOpts =
initOptions(strategy: strategy, directory: directory, paths: paths);
final optsC = initOpts[0]; final optsC = initOpts[0];
final pathPointers = initOpts[1]; final pathPointers = initOpts[1];
final strArray = initOpts[2]; final strArray = initOpts[2];
final error = libgit2.git_checkout_index(repo, nullptr, optsC); final error = libgit2.git_checkout_index(repoPointer, nullptr, optsC);
for (var p in pathPointers) { for (var p in pathPointers) {
calloc.free(p); calloc.free(p);
@ -70,19 +72,23 @@ void index(
/// pointed at by the treeish. /// pointed at by the treeish.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void tree( void tree({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_object> treeish, required Pointer<git_object> treeishPointer,
int strategy, required int strategy,
String? directory, String? directory,
List<String>? paths, List<String>? paths,
) { }) {
final initOpts = initOptions(strategy, directory, paths); final initOpts = initOptions(
strategy: strategy,
directory: directory,
paths: paths,
);
final optsC = initOpts[0]; final optsC = initOpts[0];
final pathPointers = initOpts[1]; final pathPointers = initOpts[1];
final strArray = initOpts[2]; final strArray = initOpts[2];
final error = libgit2.git_checkout_tree(repo, treeish, optsC); final error = libgit2.git_checkout_tree(repoPointer, treeishPointer, optsC);
for (var p in pathPointers) { for (var p in pathPointers) {
calloc.free(p); calloc.free(p);
@ -96,17 +102,20 @@ void tree(
} }
} }
List<dynamic> initOptions( List<dynamic> initOptions({
int strategy, required int strategy,
String? directory, String? directory,
List<String>? paths, List<String>? paths,
) { }) {
final optsC = calloc<git_checkout_options>(sizeOf<git_checkout_options>()); final optsC = calloc<git_checkout_options>(sizeOf<git_checkout_options>());
libgit2.git_checkout_options_init(optsC, GIT_CHECKOUT_OPTIONS_VERSION); libgit2.git_checkout_options_init(optsC, GIT_CHECKOUT_OPTIONS_VERSION);
optsC.ref.checkout_strategy = strategy; optsC.ref.checkout_strategy = strategy;
if (directory != null) { if (directory != null) {
optsC.ref.target_directory = directory.toNativeUtf8().cast<Int8>(); optsC.ref.target_directory = directory.toNativeUtf8().cast<Int8>();
} }
List<Pointer<Int8>> pathPointers = []; List<Pointer<Int8>> pathPointers = [];
Pointer<Pointer<Int8>> strArray = nullptr; Pointer<Pointer<Int8>> strArray = nullptr;
if (paths != null) { if (paths != null) {

View file

@ -10,9 +10,12 @@ import 'oid.dart' as oid_bindings;
/// The returned object should be released with `free()` when no longer needed. /// The returned object should be released with `free()` when no longer needed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_commit> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) { Pointer<git_commit> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_commit>>(); final out = calloc<Pointer<git_commit>>();
final error = libgit2.git_commit_lookup(out, repo, id); final error = libgit2.git_commit_lookup(out, repoPointer, oidPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -24,13 +27,18 @@ Pointer<git_commit> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) {
/// Lookup a commit object from a repository, given a prefix of its identifier (short id). /// Lookup a commit object from a repository, given a prefix of its identifier (short id).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_commit> lookupPrefix( Pointer<git_commit> lookupPrefix({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_oid> id, required Pointer<git_oid> oidPointer,
int len, required int len,
) { }) {
final out = calloc<Pointer<git_commit>>(); final out = calloc<Pointer<git_commit>>();
final error = libgit2.git_commit_lookup_prefix(out, repo, id, len); final error = libgit2.git_commit_lookup_prefix(
out,
repoPointer,
oidPointer,
len,
);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -49,12 +57,16 @@ Pointer<git_commit> lookupPrefix(
/// this one when that data is known. /// this one when that data is known.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<Pointer<git_annotated_commit>> annotatedLookup( Pointer<Pointer<git_annotated_commit>> annotatedLookup({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_oid> id, required Pointer<git_oid> oidPointer,
) { }) {
final out = calloc<Pointer<git_annotated_commit>>(); final out = calloc<Pointer<git_annotated_commit>>();
final error = libgit2.git_annotated_commit_lookup(out, repo, id); final error = libgit2.git_annotated_commit_lookup(
out,
repoPointer,
oidPointer,
);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -71,17 +83,17 @@ void annotatedFree(Pointer<git_annotated_commit> commit) {
/// Create new commit in the repository. /// Create new commit in the repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> create( Pointer<git_oid> create({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String? updateRef, String? updateRef,
Pointer<git_signature> author, required Pointer<git_signature> authorPointer,
Pointer<git_signature> committer, required Pointer<git_signature> committerPointer,
String? messageEncoding, String? messageEncoding,
String message, required String message,
Pointer<git_tree> tree, required Pointer<git_tree> treePointer,
int parentCount, required int parentCount,
List<String> parents, required List<String> parents,
) { }) {
final out = calloc<git_oid>(); final out = calloc<git_oid>();
final updateRefC = updateRef?.toNativeUtf8().cast<Int8>() ?? nullptr; final updateRefC = updateRef?.toNativeUtf8().cast<Int8>() ?? nullptr;
final messageEncodingC = final messageEncodingC =
@ -94,7 +106,7 @@ Pointer<git_oid> create(
for (var i = 0; i < parentCount; i++) { for (var i = 0; i < parentCount; i++) {
final oid = oid_bindings.fromSHA(parents[i]); final oid = oid_bindings.fromSHA(parents[i]);
var commit = calloc<IntPtr>(); var commit = calloc<IntPtr>();
commit = lookup(repo, oid).cast(); commit = lookup(repoPointer: repoPointer, oidPointer: oid).cast();
parentsC[i] = commit.cast(); parentsC[i] = commit.cast();
} }
} else { } else {
@ -104,13 +116,13 @@ Pointer<git_oid> create(
final error = libgit2.git_commit_create( final error = libgit2.git_commit_create(
out, out,
repo, repoPointer,
updateRefC, updateRefC,
author, authorPointer,
committer, committerPointer,
messageEncodingC, messageEncodingC,
messageC, messageC,
tree, treePointer,
parentCount, parentCount,
parentsC, parentsC,
); );
@ -163,8 +175,11 @@ int parentCount(Pointer<git_commit> commit) =>
/// Get the oid of a specified parent for a commit. /// Get the oid of a specified parent for a commit.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> parentId(Pointer<git_commit> commit, int n) { Pointer<git_oid> parentId({
final parentOid = libgit2.git_commit_parent_id(commit, n); required Pointer<git_commit> commitPointer,
required int position,
}) {
final parentOid = libgit2.git_commit_parent_id(commitPointer, position);
if (parentOid == nullptr) { if (parentOid == nullptr) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -197,12 +212,12 @@ Pointer<git_oid> tree(Pointer<git_commit> commit) {
/// The returned index must be freed explicitly with `free()`. /// The returned index must be freed explicitly with `free()`.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_index> revertCommit( Pointer<git_index> revertCommit({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_commit> revertCommit, required Pointer<git_commit> revertCommitPointer,
Pointer<git_commit> ourCommit, required Pointer<git_commit> ourCommitPointer,
int mainline, required int mainline,
) { }) {
final out = calloc<Pointer<git_index>>(); final out = calloc<Pointer<git_index>>();
final opts = calloc<git_merge_options>(); final opts = calloc<git_merge_options>();
final optsError = final optsError =
@ -214,9 +229,9 @@ Pointer<git_index> revertCommit(
final error = libgit2.git_revert_commit( final error = libgit2.git_revert_commit(
out, out,
repo, repoPointer,
revertCommit, revertCommitPointer,
ourCommit, ourCommitPointer,
mainline, mainline,
opts, opts,
); );

View file

@ -134,10 +134,13 @@ Pointer<git_config> snapshot(Pointer<git_config> config) {
/// Get the config entry of a config variable. /// Get the config entry of a config variable.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_config_entry> getEntry(Pointer<git_config> cfg, String variable) { Pointer<git_config_entry> getEntry({
required Pointer<git_config> configPointer,
required String variable,
}) {
final out = calloc<Pointer<git_config_entry>>(); final out = calloc<Pointer<git_config_entry>>();
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_get_entry(out, cfg, name); final error = libgit2.git_config_get_entry(out, configPointer, name);
calloc.free(name); calloc.free(name);
@ -152,10 +155,14 @@ Pointer<git_config_entry> getEntry(Pointer<git_config> cfg, String variable) {
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setBool(Pointer<git_config> cfg, String variable, bool value) { void setBool({
required Pointer<git_config> configPointer,
required String variable,
required bool value,
}) {
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final valueC = value ? 1 : 0; final valueC = value ? 1 : 0;
final error = libgit2.git_config_set_bool(cfg, name, valueC); final error = libgit2.git_config_set_bool(configPointer, name, valueC);
calloc.free(name); calloc.free(name);
@ -168,9 +175,13 @@ void setBool(Pointer<git_config> cfg, String variable, bool value) {
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setInt(Pointer<git_config> cfg, String variable, int value) { void setInt({
required Pointer<git_config> configPointer,
required String variable,
required int value,
}) {
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_set_int64(cfg, name, value); final error = libgit2.git_config_set_int64(configPointer, name, value);
calloc.free(name); calloc.free(name);
@ -183,10 +194,14 @@ void setInt(Pointer<git_config> cfg, String variable, int value) {
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setString(Pointer<git_config> cfg, String variable, String value) { void setString({
required Pointer<git_config> configPointer,
required String variable,
required String value,
}) {
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final valueC = value.toNativeUtf8().cast<Int8>(); final valueC = value.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_set_string(cfg, name, valueC); final error = libgit2.git_config_set_string(configPointer, name, valueC);
calloc.free(name); calloc.free(name);
calloc.free(valueC); calloc.free(valueC);
@ -207,9 +222,12 @@ Pointer<git_config_iterator> iterator(Pointer<git_config> cfg) {
/// (usually the local one). /// (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void delete(Pointer<git_config> cfg, String variable) { void delete({
required Pointer<git_config> configPointer,
required String variable,
}) {
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_delete_entry(cfg, name); final error = libgit2.git_config_delete_entry(configPointer, name);
calloc.free(name); calloc.free(name);
@ -222,16 +240,23 @@ void delete(Pointer<git_config> cfg, String variable) {
/// ///
/// If regexp is present, then the iterator will only iterate over all /// If regexp is present, then the iterator will only iterate over all
/// values which match the pattern. /// values which match the pattern.
List<String> multivarValues( List<String> multivarValues({
Pointer<git_config> cfg, required Pointer<git_config> configPointer,
String variable, required String variable,
String? regexp, String? regexp,
) { }) {
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr; final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr;
final iterator = calloc<Pointer<git_config_iterator>>(); final iterator = calloc<Pointer<git_config_iterator>>();
final entry = calloc<Pointer<git_config_entry>>(); final entry = calloc<Pointer<git_config_entry>>();
libgit2.git_config_multivar_iterator_new(iterator, cfg, name, regexpC);
libgit2.git_config_multivar_iterator_new(
iterator,
configPointer,
name,
regexpC,
);
var error = 0; var error = 0;
final entries = <String>[]; final entries = <String>[];
@ -256,16 +281,17 @@ List<String> multivarValues(
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// The regexp is applied case-sensitively on the value. /// The regexp is applied case-sensitively on the value.
void setMultivar( void setMultivar({
Pointer<git_config> cfg, required Pointer<git_config> configPointer,
String variable, required String variable,
String regexp, required String regexp,
String value, required String value,
) { }) {
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final regexpC = regexp.toNativeUtf8().cast<Int8>(); final regexpC = regexp.toNativeUtf8().cast<Int8>();
final valueC = value.toNativeUtf8().cast<Int8>(); final valueC = value.toNativeUtf8().cast<Int8>();
libgit2.git_config_set_multivar(cfg, name, regexpC, valueC);
libgit2.git_config_set_multivar(configPointer, name, regexpC, valueC);
calloc.free(name); calloc.free(name);
calloc.free(regexpC); calloc.free(regexpC);
@ -276,10 +302,15 @@ void setMultivar(
/// with the highest level (usually the local one). /// with the highest level (usually the local one).
/// ///
/// The regexp is applied case-sensitively on the value. /// The regexp is applied case-sensitively on the value.
void deleteMultivar(Pointer<git_config> cfg, String variable, String regexp) { void deleteMultivar({
required Pointer<git_config> configPointer,
required String variable,
required String regexp,
}) {
final name = variable.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final regexpC = regexp.toNativeUtf8().cast<Int8>(); final regexpC = regexp.toNativeUtf8().cast<Int8>();
libgit2.git_config_delete_multivar(cfg, name, regexpC);
libgit2.git_config_delete_multivar(configPointer, name, regexpC);
calloc.free(name); calloc.free(name);
calloc.free(regexpC); calloc.free(regexpC);

View file

@ -28,7 +28,10 @@ Pointer<git_credential> username(String username) {
/// Create a new plain-text username and password credential object. /// Create a new plain-text username and password credential object.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_credential> userPass(String username, String password) { Pointer<git_credential> userPass({
required String username,
required String password,
}) {
final out = calloc<Pointer<git_credential>>(); final out = calloc<Pointer<git_credential>>();
final usernameC = username.toNativeUtf8().cast<Int8>(); final usernameC = username.toNativeUtf8().cast<Int8>();
final passwordC = password.toNativeUtf8().cast<Int8>(); final passwordC = password.toNativeUtf8().cast<Int8>();
@ -49,12 +52,12 @@ Pointer<git_credential> userPass(String username, String password) {
/// Create a new passphrase-protected ssh key credential object. /// Create a new passphrase-protected ssh key credential object.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_credential> sshKey( Pointer<git_credential> sshKey({
String username, required String username,
String publicKey, required String publicKey,
String privateKey, required String privateKey,
String passPhrase, required String passPhrase,
) { }) {
final out = calloc<Pointer<git_credential>>(); final out = calloc<Pointer<git_credential>>();
final usernameC = username.toNativeUtf8().cast<Int8>(); final usernameC = username.toNativeUtf8().cast<Int8>();
final publicKeyC = publicKey.toNativeUtf8().cast<Int8>(); final publicKeyC = publicKey.toNativeUtf8().cast<Int8>();
@ -102,12 +105,12 @@ Pointer<git_credential> sshKeyFromAgent(String username) {
/// Create a new ssh key credential object reading the keys from memory. /// Create a new ssh key credential object reading the keys from memory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_credential> sshKeyFromMemory( Pointer<git_credential> sshKeyFromMemory({
String username, required String username,
String publicKey, required String publicKey,
String privateKey, required String privateKey,
String passPhrase, required String passPhrase,
) { }) {
final out = calloc<Pointer<git_credential>>(); final out = calloc<Pointer<git_credential>>();
final usernameC = username.toNativeUtf8().cast<Int8>(); final usernameC = username.toNativeUtf8().cast<Int8>();
final publicKeyC = publicKey.toNativeUtf8().cast<Int8>(); final publicKeyC = publicKey.toNativeUtf8().cast<Int8>();

View file

@ -7,17 +7,21 @@ import '../util.dart';
/// Create a diff between the repository index and the workdir directory. /// Create a diff between the repository index and the workdir directory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> indexToWorkdir( Pointer<git_diff> indexToWorkdir({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_index> index, required Pointer<git_index> indexPointer,
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final out = calloc<Pointer<git_diff>>(); final out = calloc<Pointer<git_diff>>();
final opts = _diffOptionsInit(flags, contextLines, interhunkLines); final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
libgit2.git_diff_index_to_workdir(out, repo, index, opts); libgit2.git_diff_index_to_workdir(out, repoPointer, indexPointer, opts);
calloc.free(opts); calloc.free(opts);
@ -27,18 +31,28 @@ Pointer<git_diff> indexToWorkdir(
/// Create a diff between a tree and repository index. /// Create a diff between a tree and repository index.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToIndex( Pointer<git_diff> treeToIndex({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_tree> oldTree, required Pointer<git_tree> treePointer,
Pointer<git_index> index, required Pointer<git_index> indexPointer,
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final out = calloc<Pointer<git_diff>>(); final out = calloc<Pointer<git_diff>>();
final opts = _diffOptionsInit(flags, contextLines, interhunkLines); final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
libgit2.git_diff_tree_to_index(out, repo, oldTree, index, opts); libgit2.git_diff_tree_to_index(
out,
repoPointer,
treePointer,
indexPointer,
opts,
);
calloc.free(opts); calloc.free(opts);
@ -48,17 +62,21 @@ Pointer<git_diff> treeToIndex(
/// Create a diff between a tree and the working directory. /// Create a diff between a tree and the working directory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToWorkdir( Pointer<git_diff> treeToWorkdir({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_tree> oldTree, required Pointer<git_tree> treePointer,
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final out = calloc<Pointer<git_diff>>(); final out = calloc<Pointer<git_diff>>();
final opts = _diffOptionsInit(flags, contextLines, interhunkLines); final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
libgit2.git_diff_tree_to_workdir(out, repo, oldTree, opts); libgit2.git_diff_tree_to_workdir(out, repoPointer, treePointer, opts);
calloc.free(opts); calloc.free(opts);
@ -68,18 +86,28 @@ Pointer<git_diff> treeToWorkdir(
/// Create a diff with the difference between two tree objects. /// Create a diff with the difference between two tree objects.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToTree( Pointer<git_diff> treeToTree({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_tree> oldTree, required Pointer<git_tree> oldTreePointer,
Pointer<git_tree> newTree, required Pointer<git_tree> newTreePointer,
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final out = calloc<Pointer<git_diff>>(); final out = calloc<Pointer<git_diff>>();
final opts = _diffOptionsInit(flags, contextLines, interhunkLines); final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
libgit2.git_diff_tree_to_tree(out, repo, oldTree, newTree, opts); libgit2.git_diff_tree_to_tree(
out,
repoPointer,
oldTreePointer,
newTreePointer,
opts,
);
calloc.free(opts); calloc.free(opts);
@ -96,8 +124,11 @@ int length(Pointer<git_diff> diff) => libgit2.git_diff_num_deltas(diff);
/// then it will be "merged" to appear as if the old version was from the "onto" list /// then it will be "merged" to appear as if the old version was from the "onto" list
/// and the new version is from the "from" list (with the exception that if the item /// and the new version is from the "from" list (with the exception that if the item
/// has a pending DELETE in the middle, then it will show as deleted). /// has a pending DELETE in the middle, then it will show as deleted).
void merge(Pointer<git_diff> onto, Pointer<git_diff> from) { void merge({
libgit2.git_diff_merge(onto, from); required Pointer<git_diff> ontoPointer,
required Pointer<git_diff> fromPointer,
}) {
libgit2.git_diff_merge(ontoPointer, fromPointer);
} }
/// Read the contents of a git patch file into a git diff object. /// Read the contents of a git patch file into a git diff object.
@ -132,14 +163,15 @@ Pointer<git_diff> parse(String content) {
/// files into add/remove pairs if the amount of change is above a threshold. /// files into add/remove pairs if the amount of change is above a threshold.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void findSimilar( void findSimilar({
Pointer<git_diff> diff, required Pointer<git_diff> diffPointer,
int flags, required int flags,
int renameThreshold, required int renameThreshold,
int copyThreshold, required int copyThreshold,
int renameFromRewriteThreshold, required int renameFromRewriteThreshold,
int breakRewriteThreshold, required int breakRewriteThreshold,
int renameLimit) { required int renameLimit,
}) {
final opts = calloc<git_diff_find_options>(); final opts = calloc<git_diff_find_options>();
final optsError = final optsError =
libgit2.git_diff_find_options_init(opts, GIT_DIFF_FIND_OPTIONS_VERSION); libgit2.git_diff_find_options_init(opts, GIT_DIFF_FIND_OPTIONS_VERSION);
@ -154,7 +186,7 @@ void findSimilar(
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
} }
final error = libgit2.git_diff_find_similar(diff, opts); final error = libgit2.git_diff_find_similar(diffPointer, opts);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -187,11 +219,14 @@ Pointer<git_oid> patchId(Pointer<git_diff> diff) {
/// Return the diff delta for an entry in the diff list. /// Return the diff delta for an entry in the diff list.
/// ///
/// Throws [RangeError] if index out of range. /// Throws [RangeError] if index out of range.
Pointer<git_diff_delta> getDeltaByIndex(Pointer<git_diff> diff, int idx) { Pointer<git_diff_delta> getDeltaByIndex({
final result = libgit2.git_diff_get_delta(diff, idx); required Pointer<git_diff> diffPointer,
required int index,
}) {
final result = libgit2.git_diff_get_delta(diffPointer, index);
if (result == nullptr) { if (result == nullptr) {
throw RangeError('$idx is out of bounds'); throw RangeError('$index is out of bounds');
} else { } else {
return result; return result;
} }
@ -237,13 +272,13 @@ int statsFilesChanged(Pointer<git_diff_stats> stats) =>
/// Print diff statistics. /// Print diff statistics.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
String statsPrint( String statsPrint({
Pointer<git_diff_stats> stats, required Pointer<git_diff_stats> statsPointer,
int format, required int format,
int width, required int width,
) { }) {
final out = calloc<git_buf>(sizeOf<git_buf>()); final out = calloc<git_buf>(sizeOf<git_buf>());
final error = libgit2.git_diff_stats_to_buf(out, stats, format, width); final error = libgit2.git_diff_stats_to_buf(out, statsPointer, format, width);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -257,13 +292,16 @@ String statsPrint(
/// Add patch to buffer. /// Add patch to buffer.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_buf> addToBuf(Pointer<git_patch> patch, Pointer<git_buf> buffer) { Pointer<git_buf> addToBuf({
final error = libgit2.git_patch_to_buf(buffer, patch); required Pointer<git_patch> patchPointer,
required Pointer<git_buf> bufferPointer,
}) {
final error = libgit2.git_patch_to_buf(bufferPointer, patchPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
} else { } else {
return buffer; return bufferPointer;
} }
} }
@ -271,18 +309,18 @@ Pointer<git_buf> addToBuf(Pointer<git_patch> patch, Pointer<git_buf> buffer) {
/// the index, or both. /// the index, or both.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
bool apply( bool apply({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_diff> diff, required Pointer<git_diff> diffPointer,
int location, [ required int location,
bool check = false, bool check = false,
]) { }) {
final opts = calloc<git_apply_options>(); final opts = calloc<git_apply_options>();
libgit2.git_apply_options_init(opts, GIT_APPLY_OPTIONS_VERSION); libgit2.git_apply_options_init(opts, GIT_APPLY_OPTIONS_VERSION);
if (check) { if (check) {
opts.ref.flags = git_apply_flags_t.GIT_APPLY_CHECK; opts.ref.flags = git_apply_flags_t.GIT_APPLY_CHECK;
} }
final error = libgit2.git_apply(repo, diff, location, opts); final error = libgit2.git_apply(repoPointer, diffPointer, location, opts);
calloc.free(opts); calloc.free(opts);
@ -300,11 +338,11 @@ void statsFree(Pointer<git_diff_stats> stats) =>
/// Free a previously allocated diff. /// Free a previously allocated diff.
void free(Pointer<git_diff> diff) => libgit2.git_diff_free(diff); void free(Pointer<git_diff> diff) => libgit2.git_diff_free(diff);
Pointer<git_diff_options> _diffOptionsInit( Pointer<git_diff_options> _diffOptionsInit({
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final opts = calloc<git_diff_options>(); final opts = calloc<git_diff_options>();
final optsError = final optsError =
libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION); libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION);

View file

@ -16,9 +16,9 @@ import '../util.dart';
/// are discarded. /// are discarded.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void read(Pointer<git_index> index, bool force) { void read({required Pointer<git_index> indexPointer, required bool force}) {
final forceC = force == true ? 1 : 0; final forceC = force == true ? 1 : 0;
final error = libgit2.git_index_read(index, forceC); final error = libgit2.git_index_read(indexPointer, forceC);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -30,8 +30,11 @@ void read(Pointer<git_index> index, bool force) {
/// The current index contents will be replaced by the specified tree. /// The current index contents will be replaced by the specified tree.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void readTree(Pointer<git_index> index, Pointer<git_tree> tree) { void readTree({
final error = libgit2.git_index_read_tree(index, tree); required Pointer<git_index> indexPointer,
required Pointer<git_tree> treePointer,
}) {
final error = libgit2.git_index_read_tree(indexPointer, treePointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -68,12 +71,12 @@ Pointer<git_oid> writeTree(Pointer<git_index> index) {
/// The index must not contain any file in conflict. /// The index must not contain any file in conflict.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> writeTreeTo( Pointer<git_oid> writeTreeTo({
Pointer<git_index> index, required Pointer<git_index> indexPointer,
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
) { }) {
final out = calloc<git_oid>(); final out = calloc<git_oid>();
final error = libgit2.git_index_write_tree_to(out, index, repo); final error = libgit2.git_index_write_tree_to(out, indexPointer, repoPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -83,9 +86,9 @@ Pointer<git_oid> writeTreeTo(
} }
/// Find the first position of any entries which point to given path in the Git index. /// Find the first position of any entries which point to given path in the Git index.
bool find(Pointer<git_index> index, String path) { bool find({required Pointer<git_index> indexPointer, required String path}) {
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
final result = libgit2.git_index_find(nullptr, index, pathC); final result = libgit2.git_index_find(nullptr, indexPointer, pathC);
calloc.free(pathC); calloc.free(pathC);
@ -100,8 +103,11 @@ int entryCount(Pointer<git_index> index) => libgit2.git_index_entrycount(index);
/// The entry is not modifiable and should not be freed. /// The entry is not modifiable and should not be freed.
/// ///
/// Throws [RangeError] when provided index is outside of valid range. /// Throws [RangeError] when provided index is outside of valid range.
Pointer<git_index_entry> getByIndex(Pointer<git_index> index, int n) { Pointer<git_index_entry> getByIndex({
final result = libgit2.git_index_get_byindex(index, n); required Pointer<git_index> indexPointer,
required int position,
}) {
final result = libgit2.git_index_get_byindex(indexPointer, position);
if (result == nullptr) { if (result == nullptr) {
throw RangeError('Out of bounds'); throw RangeError('Out of bounds');
@ -115,13 +121,13 @@ Pointer<git_index_entry> getByIndex(Pointer<git_index> index, int n) {
///The entry is not modifiable and should not be freed. ///The entry is not modifiable and should not be freed.
/// ///
/// Throws [ArgumentError] if nothing found for provided path. /// Throws [ArgumentError] if nothing found for provided path.
Pointer<git_index_entry> getByPath( Pointer<git_index_entry> getByPath({
Pointer<git_index> index, required Pointer<git_index> indexPointer,
String path, required String path,
int stage, required int stage,
) { }) {
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
final result = libgit2.git_index_get_bypath(index, pathC, stage); final result = libgit2.git_index_get_bypath(indexPointer, pathC, stage);
calloc.free(pathC); calloc.free(pathC);
@ -152,8 +158,11 @@ void clear(Pointer<git_index> index) {
/// it will be replaced. Otherwise, the `sourceEntry` will be added. /// it will be replaced. Otherwise, the `sourceEntry` will be added.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void add(Pointer<git_index> index, Pointer<git_index_entry> sourceEntry) { void add({
final error = libgit2.git_index_add(index, sourceEntry); required Pointer<git_index> indexPointer,
required Pointer<git_index_entry> sourceEntryPointer,
}) {
final error = libgit2.git_index_add(indexPointer, sourceEntryPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -173,9 +182,12 @@ void add(Pointer<git_index> index, Pointer<git_index_entry> sourceEntry) {
/// (REUC) section. /// (REUC) section.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void addByPath(Pointer<git_index> index, String path) { void addByPath({
required Pointer<git_index> indexPointer,
required String path,
}) {
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_index_add_bypath(index, pathC); final error = libgit2.git_index_add_bypath(indexPointer, pathC);
calloc.free(pathC); calloc.free(pathC);
@ -193,7 +205,10 @@ void addByPath(Pointer<git_index> index, String path) {
/// added to the index (either updating an existing entry or adding a new entry). /// added to the index (either updating an existing entry or adding a new entry).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void addAll(Pointer<git_index> index, List<String> pathspec) { void addAll({
required Pointer<git_index> indexPointer,
required List<String> pathspec,
}) {
var pathspecC = calloc<git_strarray>(); var pathspecC = calloc<git_strarray>();
final List<Pointer<Int8>> pathPointers = final List<Pointer<Int8>> pathPointers =
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList(); pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
@ -207,7 +222,7 @@ void addAll(Pointer<git_index> index, List<String> pathspec) {
pathspecC.ref.count = pathspec.length; pathspecC.ref.count = pathspec.length;
final error = libgit2.git_index_add_all( final error = libgit2.git_index_add_all(
index, indexPointer,
pathspecC, pathspecC,
0, 0,
nullptr, nullptr,
@ -239,9 +254,13 @@ void write(Pointer<git_index> index) {
/// Remove an entry from the index. /// Remove an entry from the index.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void remove(Pointer<git_index> index, String path, int stage) { void remove({
required Pointer<git_index> indexPointer,
required String path,
required int stage,
}) {
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_index_remove(index, pathC, stage); final error = libgit2.git_index_remove(indexPointer, pathC, stage);
calloc.free(pathC); calloc.free(pathC);
@ -253,7 +272,10 @@ void remove(Pointer<git_index> index, String path, int stage) {
/// Remove all matching index entries. /// Remove all matching index entries.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void removeAll(Pointer<git_index> index, List<String> pathspec) { void removeAll({
required Pointer<git_index> indexPointer,
required List<String> pathspec,
}) {
final pathspecC = calloc<git_strarray>(); final pathspecC = calloc<git_strarray>();
final List<Pointer<Int8>> pathPointers = final List<Pointer<Int8>> pathPointers =
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList(); pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
@ -267,7 +289,7 @@ void removeAll(Pointer<git_index> index, List<String> pathspec) {
pathspecC.ref.count = pathspec.length; pathspecC.ref.count = pathspec.length;
final error = libgit2.git_index_remove_all( final error = libgit2.git_index_remove_all(
index, indexPointer,
pathspecC, pathspecC,
nullptr, nullptr,
nullptr, nullptr,
@ -293,7 +315,8 @@ bool hasConflicts(Pointer<git_index> index) {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<Map<String, Pointer<git_index_entry>>> conflictList( List<Map<String, Pointer<git_index_entry>>> conflictList(
Pointer<git_index> index) { Pointer<git_index> index,
) {
final iterator = calloc<Pointer<git_index_conflict_iterator>>(); final iterator = calloc<Pointer<git_index_conflict_iterator>>();
final iteratorError = final iteratorError =
libgit2.git_index_conflict_iterator_new(iterator, index); libgit2.git_index_conflict_iterator_new(iterator, index);
@ -336,9 +359,12 @@ List<Map<String, Pointer<git_index_entry>>> conflictList(
/// Removes the index entries that represent a conflict of a single file. /// Removes the index entries that represent a conflict of a single file.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void conflictRemove(Pointer<git_index> index, String path) { void conflictRemove({
required Pointer<git_index> indexPointer,
required String path,
}) {
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_index_conflict_remove(index, pathC); final error = libgit2.git_index_conflict_remove(indexPointer, pathC);
calloc.free(pathC); calloc.free(pathC);

View file

@ -7,13 +7,13 @@ import '../util.dart';
/// Find a merge base between two commits. /// Find a merge base between two commits.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> mergeBase( Pointer<git_oid> mergeBase({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_oid> one, required Pointer<git_oid> aPointer,
Pointer<git_oid> two, required Pointer<git_oid> bPointer,
) { }) {
final out = calloc<git_oid>(); 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) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -26,20 +26,20 @@ Pointer<git_oid> mergeBase(
/// into a reference. /// into a reference.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<int> analysis( List<int> analysis({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_reference> ourRef, required Pointer<git_reference> ourRefPointer,
Pointer<Pointer<git_annotated_commit>> theirHead, required Pointer<Pointer<git_annotated_commit>> theirHeadPointer,
int theirHeadsLen, required int theirHeadsLen,
) { }) {
final analysisOut = calloc<Int32>(); final analysisOut = calloc<Int32>();
final preferenceOut = calloc<Int32>(); final preferenceOut = calloc<Int32>();
final error = libgit2.git_merge_analysis_for_ref( final error = libgit2.git_merge_analysis_for_ref(
analysisOut, analysisOut,
preferenceOut, preferenceOut,
repo, repoPointer,
ourRef, ourRefPointer,
theirHead, theirHeadPointer,
theirHeadsLen, theirHeadsLen,
); );
var result = <int>[]; var result = <int>[];
@ -61,11 +61,11 @@ List<int> analysis(
/// prepare a commit. /// prepare a commit.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void merge( void merge({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<Pointer<git_annotated_commit>> theirHeads, required Pointer<Pointer<git_annotated_commit>> theirHeadsPointer,
int theirHeadsLen, required int theirHeadsLen,
) { }) {
final mergeOpts = calloc<git_merge_options>(sizeOf<git_merge_options>()); final mergeOpts = calloc<git_merge_options>(sizeOf<git_merge_options>());
libgit2.git_merge_options_init(mergeOpts, GIT_MERGE_OPTIONS_VERSION); libgit2.git_merge_options_init(mergeOpts, GIT_MERGE_OPTIONS_VERSION);
@ -77,8 +77,8 @@ void merge(
git_checkout_strategy_t.GIT_CHECKOUT_RECREATE_MISSING; git_checkout_strategy_t.GIT_CHECKOUT_RECREATE_MISSING;
final error = libgit2.git_merge( final error = libgit2.git_merge(
repo, repoPointer,
theirHeads, theirHeadsPointer,
theirHeadsLen, theirHeadsLen,
mergeOpts, mergeOpts,
checkoutOpts, checkoutOpts,
@ -97,12 +97,12 @@ void merge(
/// The returned index must be freed explicitly. /// The returned index must be freed explicitly.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_index> mergeCommits( Pointer<git_index> mergeCommits({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_commit> ourCommit, required Pointer<git_commit> ourCommitPointer,
Pointer<git_commit> theirCommit, required Pointer<git_commit> theirCommitPointer,
Map<String, int> opts, required Map<String, int> opts,
) { }) {
final out = calloc<Pointer<git_index>>(); final out = calloc<Pointer<git_index>>();
final optsC = calloc<git_merge_options>(sizeOf<git_merge_options>()); final optsC = calloc<git_merge_options>(sizeOf<git_merge_options>());
optsC.ref.file_favor = opts['favor']!; optsC.ref.file_favor = opts['favor']!;
@ -112,9 +112,9 @@ Pointer<git_index> mergeCommits(
final error = libgit2.git_merge_commits( final error = libgit2.git_merge_commits(
out, out,
repo, repoPointer,
ourCommit, ourCommitPointer,
theirCommit, theirCommitPointer,
optsC, optsC,
); );
@ -135,13 +135,13 @@ Pointer<git_index> mergeCommits(
/// The returned index must be freed explicitly. /// The returned index must be freed explicitly.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_index> mergeTrees( Pointer<git_index> mergeTrees({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_tree> ancestorTree, required Pointer<git_tree> ancestorTreePointer,
Pointer<git_tree> ourTree, required Pointer<git_tree> ourTreePointer,
Pointer<git_tree> theirTree, required Pointer<git_tree> theirTreePointer,
Map<String, int> opts, required Map<String, int> opts,
) { }) {
final out = calloc<Pointer<git_index>>(); final out = calloc<Pointer<git_index>>();
final optsC = calloc<git_merge_options>(sizeOf<git_merge_options>()); final optsC = calloc<git_merge_options>(sizeOf<git_merge_options>());
optsC.ref.file_favor = opts['favor']!; optsC.ref.file_favor = opts['favor']!;
@ -151,10 +151,10 @@ Pointer<git_index> mergeTrees(
final error = libgit2.git_merge_trees( final error = libgit2.git_merge_trees(
out, out,
repo, repoPointer,
ancestorTree, ancestorTreePointer,
ourTree, ourTreePointer,
theirTree, theirTreePointer,
optsC, optsC,
); );
@ -170,13 +170,16 @@ Pointer<git_index> mergeTrees(
/// Cherry-pick the given commit, producing changes in the index and working directory. /// Cherry-pick the given commit, producing changes in the index and working directory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// 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>()); final opts = calloc<git_cherrypick_options>(sizeOf<git_cherrypick_options>());
libgit2.git_cherrypick_options_init(opts, GIT_CHERRYPICK_OPTIONS_VERSION); libgit2.git_cherrypick_options_init(opts, GIT_CHERRYPICK_OPTIONS_VERSION);
opts.ref.checkout_opts.checkout_strategy = opts.ref.checkout_opts.checkout_strategy =
git_checkout_strategy_t.GIT_CHECKOUT_SAFE; 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) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());

View file

@ -17,13 +17,13 @@ int type(Pointer<git_object> obj) => libgit2.git_object_type(obj);
/// guess the object's type. /// guess the object's type.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_object> lookup( Pointer<git_object> lookup({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_oid> id, required Pointer<git_oid> oidPointer,
int type, required int type,
) { }) {
final out = calloc<Pointer<git_object>>(); final out = calloc<Pointer<git_object>>();
final error = libgit2.git_object_lookup(out, repo, id, type); final error = libgit2.git_object_lookup(out, repoPointer, oidPointer, type);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());

View file

@ -7,13 +7,18 @@ import '../util.dart';
/// Determine if an object can be found in the object database by an abbreviated object ID. /// Determine if an object can be found in the object database by an abbreviated object ID.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> existsPrefix( Pointer<git_oid> existsPrefix({
Pointer<git_odb> db, required Pointer<git_odb> odbPointer,
Pointer<git_oid> shortOid, required Pointer<git_oid> shortOidPointer,
int len, required int length,
) { }) {
final out = calloc<git_oid>(); final out = calloc<git_oid>();
final error = libgit2.git_odb_exists_prefix(out, db, shortOid, len); final error = libgit2.git_odb_exists_prefix(
out,
odbPointer,
shortOidPointer,
length,
);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());

View file

@ -78,6 +78,9 @@ String toSHA(Pointer<git_oid> id) {
/// Compare two oid structures. /// Compare two oid structures.
/// ///
/// Returns <0 if a < b, 0 if a == b, >0 if a > b. /// Returns <0 if a < b, 0 if a == b, >0 if a > b.
int compare(Pointer<git_oid> a, Pointer<git_oid> b) { int compare({
return libgit2.git_oid_cmp(a, b); required Pointer<git_oid> aPointer,
required Pointer<git_oid> bPointer,
}) {
return libgit2.git_oid_cmp(aPointer, bPointer);
} }

View file

@ -10,15 +10,15 @@ import '../util.dart';
/// you must call `free()` on the patch when done. /// you must call `free()` on the patch when done.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Map<String, dynamic> fromBuffers( Map<String, dynamic> fromBuffers({
String? oldBuffer, String? oldBuffer,
String? oldAsPath, String? oldAsPath,
String? newBuffer, String? newBuffer,
String? newAsPath, String? newAsPath,
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final out = calloc<Pointer<git_patch>>(); final out = calloc<Pointer<git_patch>>();
final oldBufferC = oldBuffer?.toNativeUtf8().cast<Int8>() ?? nullptr; final oldBufferC = oldBuffer?.toNativeUtf8().cast<Int8>() ?? nullptr;
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr; final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
@ -26,7 +26,11 @@ Map<String, dynamic> fromBuffers(
final newBufferC = newBuffer?.toNativeUtf8().cast<Int8>() ?? nullptr; final newBufferC = newBuffer?.toNativeUtf8().cast<Int8>() ?? nullptr;
final newAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr; final newAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final newLen = newBuffer?.length ?? 0; final newLen = newBuffer?.length ?? 0;
final opts = _diffOptionsInit(flags, contextLines, interhunkLines); final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_buffers( final error = libgit2.git_patch_from_buffers(
out, out,
@ -66,25 +70,29 @@ Map<String, dynamic> fromBuffers(
/// must call `free()` on the patch when done. /// must call `free()` on the patch when done.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Map<String, dynamic> fromBlobs( Map<String, dynamic> fromBlobs({
Pointer<git_blob>? oldBlob, Pointer<git_blob>? oldBlobPointer,
String? oldAsPath, String? oldAsPath,
Pointer<git_blob>? newBlob, Pointer<git_blob>? newBlobPointer,
String? newAsPath, String? newAsPath,
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final out = calloc<Pointer<git_patch>>(); final out = calloc<Pointer<git_patch>>();
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr; final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final newAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr; final newAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final opts = _diffOptionsInit(flags, contextLines, interhunkLines); final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_blobs( final error = libgit2.git_patch_from_blobs(
out, out,
oldBlob ?? nullptr, oldBlobPointer ?? nullptr,
oldAsPathC, oldAsPathC,
newBlob ?? nullptr, newBlobPointer ?? nullptr,
newAsPathC, newAsPathC,
opts, opts,
); );
@ -99,11 +107,11 @@ Map<String, dynamic> fromBlobs(
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
} else { } else {
// Returning map with pointers to patch and blobs because patch object does not // Returning map with pointers to patch and blobs because patch object does not
// have refenrece to underlying blobs. So if the blob is freed/removed the patch // have reference to underlying blobs. So if the blob is freed/removed the patch
// text becomes corrupted. // text becomes corrupted.
result['patch'] = out.value; result['patch'] = out.value;
result['a'] = oldBlob; result['a'] = oldBlobPointer;
result['b'] = newBlob; result['b'] = newBlobPointer;
return result; return result;
} }
} }
@ -114,25 +122,29 @@ Map<String, dynamic> fromBlobs(
/// call `free()` on the patch when done. /// call `free()` on the patch when done.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Map<String, dynamic> fromBlobAndBuffer( Map<String, dynamic> fromBlobAndBuffer({
Pointer<git_blob>? oldBlob, Pointer<git_blob>? oldBlobPointer,
String? oldAsPath, String? oldAsPath,
String? buffer, String? buffer,
String? bufferAsPath, String? bufferAsPath,
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final out = calloc<Pointer<git_patch>>(); final out = calloc<Pointer<git_patch>>();
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr; final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final bufferC = buffer?.toNativeUtf8().cast<Int8>() ?? nullptr; final bufferC = buffer?.toNativeUtf8().cast<Int8>() ?? nullptr;
final bufferAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr; final bufferAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
final bufferLen = buffer?.length ?? 0; final bufferLen = buffer?.length ?? 0;
final opts = _diffOptionsInit(flags, contextLines, interhunkLines); final opts = _diffOptionsInit(
flags: flags,
contextLines: contextLines,
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_blob_and_buffer( final error = libgit2.git_patch_from_blob_and_buffer(
out, out,
oldBlob ?? nullptr, oldBlobPointer ?? nullptr,
oldAsPathC, oldAsPathC,
bufferC.cast(), bufferC.cast(),
bufferLen, bufferLen,
@ -151,10 +163,10 @@ Map<String, dynamic> fromBlobAndBuffer(
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
} else { } else {
// Returning map with pointers to patch and buffers because patch object does not // Returning map with pointers to patch and buffers because patch object does not
// have refenrece to underlying buffers or blobs. So if the buffer or blob is freed/removed // have reference to underlying buffers or blobs. So if the buffer or blob is freed/removed
// the patch text becomes corrupted. // the patch text becomes corrupted.
result['patch'] = out.value; result['patch'] = out.value;
result['a'] = oldBlob; result['a'] = oldBlobPointer;
result['b'] = bufferC; result['b'] = bufferC;
return result; return result;
} }
@ -167,9 +179,12 @@ Map<String, dynamic> fromBlobAndBuffer(
/// hunks and lines in the diff of the one delta. /// hunks and lines in the diff of the one delta.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_patch> fromDiff(Pointer<git_diff> diff, int idx) { Pointer<git_patch> fromDiff({
required Pointer<git_diff> diffPointer,
required int index,
}) {
final out = calloc<Pointer<git_patch>>(); final out = calloc<Pointer<git_patch>>();
final error = libgit2.git_patch_from_diff(out, diff, idx); final error = libgit2.git_patch_from_diff(out, diffPointer, index);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -190,11 +205,18 @@ int numHunks(Pointer<git_patch> patch) => libgit2.git_patch_num_hunks(patch);
/// Given a patch and a hunk index into the patch, this returns detailed information about that hunk. /// Given a patch and a hunk index into the patch, this returns detailed information about that hunk.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Map<String, dynamic> hunk(Pointer<git_patch> patch, int hunkIdx) { Map<String, dynamic> hunk({
required Pointer<git_patch> patchPointer,
required int hunkIndex,
}) {
final out = calloc<Pointer<git_diff_hunk>>(); final out = calloc<Pointer<git_diff_hunk>>();
final linesInHunk = calloc<Int32>(); final linesInHunk = calloc<Int64>();
final error = final error = libgit2.git_patch_get_hunk(
libgit2.git_patch_get_hunk(out, linesInHunk.cast(), patch, hunkIdx); out,
linesInHunk.cast(),
patchPointer,
hunkIndex,
);
final result = <String, dynamic>{}; final result = <String, dynamic>{};
if (error < 0) { if (error < 0) {
@ -209,14 +231,18 @@ Map<String, dynamic> hunk(Pointer<git_patch> patch, int hunkIdx) {
/// Get data about a line in a hunk of a patch. /// Get data about a line in a hunk of a patch.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_diff_line> lines( Pointer<git_diff_line> lines({
Pointer<git_patch> patch, required Pointer<git_patch> patchPointer,
int hunkIdx, required int hunkIndex,
int lineOfHunk, required int lineOfHunk,
) { }) {
final out = calloc<Pointer<git_diff_line>>(); final out = calloc<Pointer<git_diff_line>>();
final error = final error = libgit2.git_patch_get_line_in_hunk(
libgit2.git_patch_get_line_in_hunk(out, patch, hunkIdx, lineOfHunk); out,
patchPointer,
hunkIndex,
lineOfHunk,
);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -249,18 +275,18 @@ String text(Pointer<git_patch> patch) {
/// If you pass `includeContext` as true, this will be the size of all of the diff output; /// If you pass `includeContext` as true, this will be the size of all of the diff output;
/// if you pass it as false, this will only include the actual changed lines (as if /// if you pass it as false, this will only include the actual changed lines (as if
/// contextLines was 0). /// contextLines was 0).
int size( int size({
Pointer<git_patch> patch, required Pointer<git_patch> patchPointer,
bool includeContext, required bool includeContext,
bool includeHunkHeaders, required bool includeHunkHeaders,
bool includeFileHeaders, required bool includeFileHeaders,
) { }) {
final includeContextC = includeContext ? 1 : 0; final includeContextC = includeContext ? 1 : 0;
final includeHunkHeadersC = includeHunkHeaders ? 1 : 0; final includeHunkHeadersC = includeHunkHeaders ? 1 : 0;
final includeFileHeadersC = includeFileHeaders ? 1 : 0; final includeFileHeadersC = includeFileHeaders ? 1 : 0;
return libgit2.git_patch_size( return libgit2.git_patch_size(
patch, patchPointer,
includeContextC, includeContextC,
includeHunkHeadersC, includeHunkHeadersC,
includeFileHeadersC, includeFileHeadersC,
@ -270,11 +296,11 @@ int size(
/// Free a previously allocated patch object. /// Free a previously allocated patch object.
void free(Pointer<git_patch> patch) => libgit2.git_patch_free(patch); void free(Pointer<git_patch> patch) => libgit2.git_patch_free(patch);
Pointer<git_diff_options> _diffOptionsInit( Pointer<git_diff_options> _diffOptionsInit({
int flags, required int flags,
int contextLines, required int contextLines,
int interhunkLines, required int interhunkLines,
) { }) {
final opts = calloc<git_diff_options>(); final opts = calloc<git_diff_options>();
final optsError = final optsError =
libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION); libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION);

View file

@ -54,10 +54,13 @@ Pointer<git_reference> resolve(Pointer<git_reference> ref) {
/// The name will be checked for validity. /// The name will be checked for validity.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> lookup(Pointer<git_repository> repo, String name) { Pointer<git_reference> lookup({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reference_lookup(out, repo, nameC); final error = libgit2.git_reference_lookup(out, repoPointer, nameC);
calloc.free(nameC); calloc.free(nameC);
@ -74,10 +77,13 @@ Pointer<git_reference> lookup(Pointer<git_repository> repo, String name) {
/// the user is referring to. /// the user is referring to.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> lookupDWIM(Pointer<git_repository> repo, String name) { Pointer<git_reference> lookupDWIM({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reference_dwim(out, repo, nameC); final error = libgit2.git_reference_dwim(out, repoPointer, nameC);
calloc.free(nameC); calloc.free(nameC);
@ -118,19 +124,19 @@ String shorthand(Pointer<git_reference> ref) {
/// the repository. We only rename the reflog if it exists. /// the repository. We only rename the reflog if it exists.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> rename( Pointer<git_reference> rename({
Pointer<git_reference> ref, required Pointer<git_reference> refPointer,
String newName, required String newName,
bool force, required bool force,
String? logMessage, String? logMessage,
) { }) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final newNameC = newName.toNativeUtf8().cast<Int8>(); final newNameC = newName.toNativeUtf8().cast<Int8>();
final forceC = force == true ? 1 : 0; final forceC = force == true ? 1 : 0;
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr; final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_reference_rename( final error = libgit2.git_reference_rename(
out, out,
ref, refPointer,
newNameC, newNameC,
forceC, forceC,
logMessageC, logMessageC,
@ -171,9 +177,12 @@ List<String> list(Pointer<git_repository> repo) {
/// Check if a reflog exists for the specified reference. /// Check if a reflog exists for the specified reference.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
bool hasLog(Pointer<git_repository> repo, String name) { bool hasLog({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final refname = name.toNativeUtf8().cast<Int8>(); final refname = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reference_has_log(repo, refname); final error = libgit2.git_reference_has_log(repoPointer, refname);
calloc.free(refname); calloc.free(refname);
@ -230,22 +239,22 @@ bool isTag(Pointer<git_reference> ref) {
/// ///
/// The message for the reflog will be ignored if the reference does not belong in the /// The message for the reflog will be ignored if the reference does not belong in the
/// standard set (HEAD, branches and remote-tracking branches) and it does not have a reflog. /// standard set (HEAD, branches and remote-tracking branches) and it does not have a reflog.
Pointer<git_reference> createDirect( Pointer<git_reference> createDirect({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String name, required String name,
Pointer<git_oid> oid, required Pointer<git_oid> oidPointer,
bool force, required bool force,
String? logMessage, String? logMessage,
) { }) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final forceC = force == true ? 1 : 0; final forceC = force == true ? 1 : 0;
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr; final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_reference_create( final error = libgit2.git_reference_create(
out, out,
repo, repoPointer,
nameC, nameC,
oid, oidPointer,
forceC, forceC,
logMessageC, logMessageC,
); );
@ -282,13 +291,13 @@ Pointer<git_reference> createDirect(
/// ///
/// The message for the reflog will be ignored if the reference does not belong in the standard /// The message for the reflog will be ignored if the reference does not belong in the standard
/// set (HEAD, branches and remote-tracking branches) and it does not have a reflog. /// set (HEAD, branches and remote-tracking branches) and it does not have a reflog.
Pointer<git_reference> createSymbolic( Pointer<git_reference> createSymbolic({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String name, required String name,
String target, required String target,
bool force, required bool force,
String? logMessage, String? logMessage,
) { }) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final targetC = target.toNativeUtf8().cast<Int8>(); final targetC = target.toNativeUtf8().cast<Int8>();
@ -296,7 +305,7 @@ Pointer<git_reference> createSymbolic(
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr; final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_reference_symbolic_create( final error = libgit2.git_reference_symbolic_create(
out, out,
repo, repoPointer,
nameC, nameC,
targetC, targetC,
forceC, forceC,
@ -339,14 +348,19 @@ Pointer<git_repository> owner(Pointer<git_reference> ref) {
/// The new reference will be written to disk, overwriting the given reference. /// The new reference will be written to disk, overwriting the given reference.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> setTarget( Pointer<git_reference> setTarget({
Pointer<git_reference> ref, required Pointer<git_reference> refPointer,
Pointer<git_oid> oid, required Pointer<git_oid> oidPointer,
String? logMessage, String? logMessage,
) { }) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr; final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_reference_set_target(out, ref, oid, logMessageC); final error = libgit2.git_reference_set_target(
out,
refPointer,
oidPointer,
logMessageC,
);
calloc.free(logMessageC); calloc.free(logMessageC);
@ -368,16 +382,20 @@ Pointer<git_reference> setTarget(
/// standard set (HEAD, branches and remote-tracking branches) and and it does not have a reflog. /// standard set (HEAD, branches and remote-tracking branches) and and it does not have a reflog.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> setTargetSymbolic( Pointer<git_reference> setTargetSymbolic({
Pointer<git_reference> ref, required Pointer<git_reference> refPointer,
String target, required String target,
String? logMessage, String? logMessage,
) { }) {
final out = calloc<Pointer<git_reference>>(); final out = calloc<Pointer<git_reference>>();
final targetC = target.toNativeUtf8().cast<Int8>(); final targetC = target.toNativeUtf8().cast<Int8>();
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr; final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = final error = libgit2.git_reference_symbolic_set_target(
libgit2.git_reference_symbolic_set_target(out, ref, targetC, logMessageC); out,
refPointer,
targetC,
logMessageC,
);
calloc.free(targetC); calloc.free(targetC);
calloc.free(logMessageC); calloc.free(logMessageC);
@ -390,8 +408,11 @@ Pointer<git_reference> setTargetSymbolic(
} }
/// Compare two references. /// Compare two references.
bool compare(Pointer<git_reference> ref1, Pointer<git_reference> ref2) { bool compare({
final result = libgit2.git_reference_cmp(ref1, ref2); required Pointer<git_reference> ref1Pointer,
required Pointer<git_reference> ref2Pointer,
}) {
final result = libgit2.git_reference_cmp(ref1Pointer, ref2Pointer);
return result == 0 ? true : false; return result == 0 ? true : false;
} }
@ -403,9 +424,12 @@ bool compare(Pointer<git_reference> ref1, Pointer<git_reference> ref2) {
/// non-tag object is met. /// non-tag object is met.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_object> peel(Pointer<git_reference> ref, int type) { Pointer<git_object> peel({
required Pointer<git_reference> refPointer,
required int type,
}) {
final out = calloc<Pointer<git_object>>(); final out = calloc<Pointer<git_object>>();
final error = libgit2.git_reference_peel(out, ref, type); final error = libgit2.git_reference_peel(out, refPointer, type);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());

View file

@ -12,10 +12,13 @@ import '../util.dart';
/// The reflog must be freed manually. /// The reflog must be freed manually.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_reflog> read(Pointer<git_repository> repo, String name) { Pointer<git_reflog> read({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_reflog>>(); final out = calloc<Pointer<git_reflog>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reflog_read(out, repo, nameC); final error = libgit2.git_reflog_read(out, repoPointer, nameC);
calloc.free(nameC); calloc.free(nameC);
@ -34,8 +37,11 @@ int entryCount(Pointer<git_reflog> reflog) =>
/// ///
/// Requesting the reflog entry with an index of 0 (zero) will return /// Requesting the reflog entry with an index of 0 (zero) will return
/// the most recently created entry. /// the most recently created entry.
Pointer<git_reflog_entry> getByIndex(Pointer<git_reflog> reflog, int idx) { Pointer<git_reflog_entry> getByIndex({
return libgit2.git_reflog_entry_byindex(reflog, idx); required Pointer<git_reflog> reflogPointer,
required int index,
}) {
return libgit2.git_reflog_entry_byindex(reflogPointer, index);
} }
/// Get the log message. /// Get the log message.

View file

@ -29,9 +29,12 @@ int direction(Pointer<git_refspec> refspec) =>
libgit2.git_refspec_direction(refspec); libgit2.git_refspec_direction(refspec);
/// Check if a refspec's source descriptor matches a reference. /// Check if a refspec's source descriptor matches a reference.
bool matchesSource(Pointer<git_refspec> refspec, String refname) { bool matchesSource({
required Pointer<git_refspec> refspecPointer,
required String refname,
}) {
final refnameC = refname.toNativeUtf8().cast<Int8>(); final refnameC = refname.toNativeUtf8().cast<Int8>();
final result = libgit2.git_refspec_src_matches(refspec, refnameC); final result = libgit2.git_refspec_src_matches(refspecPointer, refnameC);
calloc.free(refnameC); calloc.free(refnameC);
@ -39,9 +42,12 @@ bool matchesSource(Pointer<git_refspec> refspec, String refname) {
} }
/// Check if a refspec's destination descriptor matches a reference. /// Check if a refspec's destination descriptor matches a reference.
bool matchesDestination(Pointer<git_refspec> refspec, String refname) { bool matchesDestination({
required Pointer<git_refspec> refspecPointer,
required String refname,
}) {
final refnameC = refname.toNativeUtf8().cast<Int8>(); final refnameC = refname.toNativeUtf8().cast<Int8>();
final result = libgit2.git_refspec_dst_matches(refspec, refnameC); final result = libgit2.git_refspec_dst_matches(refspecPointer, refnameC);
calloc.free(refnameC); calloc.free(refnameC);
@ -51,10 +57,13 @@ bool matchesDestination(Pointer<git_refspec> refspec, String refname) {
/// Transform a reference to its target following the refspec's rules. /// Transform a reference to its target following the refspec's rules.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
String transform(Pointer<git_refspec> spec, String name) { String transform({
required Pointer<git_refspec> refspecPointer,
required String name,
}) {
final out = calloc<git_buf>(sizeOf<git_buf>()); final out = calloc<git_buf>(sizeOf<git_buf>());
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_refspec_transform(out, spec, nameC); final error = libgit2.git_refspec_transform(out, refspecPointer, nameC);
calloc.free(nameC); calloc.free(nameC);
@ -70,10 +79,13 @@ String transform(Pointer<git_refspec> spec, String name) {
/// Transform a target reference to its source reference following the refspec's rules. /// Transform a target reference to its source reference following the refspec's rules.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
String rTransform(Pointer<git_refspec> spec, String name) { String rTransform({
required Pointer<git_refspec> refspecPointer,
required String name,
}) {
final out = calloc<git_buf>(sizeOf<git_buf>()); final out = calloc<git_buf>(sizeOf<git_buf>());
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_refspec_rtransform(out, spec, nameC); final error = libgit2.git_refspec_rtransform(out, refspecPointer, nameC);
calloc.free(nameC); calloc.free(nameC);

View file

@ -32,10 +32,13 @@ List<String> list(Pointer<git_repository> repo) {
/// The name will be checked for validity. /// The name will be checked for validity.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_remote> lookup(Pointer<git_repository> repo, String name) { Pointer<git_remote> lookup({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_remote>>(); final out = calloc<Pointer<git_remote>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_lookup(out, repo, nameC); final error = libgit2.git_remote_lookup(out, repoPointer, nameC);
calloc.free(nameC); calloc.free(nameC);
@ -49,15 +52,15 @@ Pointer<git_remote> lookup(Pointer<git_repository> repo, String name) {
/// Add a remote with the default fetch refspec to the repository's configuration. /// Add a remote with the default fetch refspec to the repository's configuration.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_remote> create( Pointer<git_remote> create({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String name, required String name,
String url, required String url,
) { }) {
final out = calloc<Pointer<git_remote>>(); final out = calloc<Pointer<git_remote>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>(); final urlC = url.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_create(out, repo, nameC, urlC); final error = libgit2.git_remote_create(out, repoPointer, nameC, urlC);
calloc.free(nameC); calloc.free(nameC);
calloc.free(urlC); calloc.free(urlC);
@ -72,19 +75,19 @@ Pointer<git_remote> create(
/// Add a remote with the provided fetch refspec to the repository's configuration. /// Add a remote with the provided fetch refspec to the repository's configuration.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_remote> createWithFetchSpec( Pointer<git_remote> createWithFetchSpec({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String name, required String name,
String url, required String url,
String fetch, required String fetch,
) { }) {
final out = calloc<Pointer<git_remote>>(); final out = calloc<Pointer<git_remote>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>(); final urlC = url.toNativeUtf8().cast<Int8>();
final fetchC = fetch.toNativeUtf8().cast<Int8>(); final fetchC = fetch.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_create_with_fetchspec( final error = libgit2.git_remote_create_with_fetchspec(
out, out,
repo, repoPointer,
nameC, nameC,
urlC, urlC,
fetchC, fetchC,
@ -106,9 +109,12 @@ Pointer<git_remote> createWithFetchSpec(
/// All remote-tracking branches and configuration settings for the remote will be removed. /// All remote-tracking branches and configuration settings for the remote will be removed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void delete(Pointer<git_repository> repo, String name) { void delete({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_delete(repo, nameC); final error = libgit2.git_remote_delete(repoPointer, nameC);
calloc.free(nameC); calloc.free(nameC);
@ -129,11 +135,15 @@ void delete(Pointer<git_repository> repo, String name) {
/// their list of refspecs. /// their list of refspecs.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<String> rename(Pointer<git_repository> repo, String name, String newName) { List<String> rename({
required Pointer<git_repository> repoPointer,
required String name,
required String newName,
}) {
final out = calloc<git_strarray>(); final out = calloc<git_strarray>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final newNameC = newName.toNativeUtf8().cast<Int8>(); final newNameC = newName.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_rename(out, repo, nameC, newNameC); final error = libgit2.git_remote_rename(out, repoPointer, nameC, newNameC);
calloc.free(nameC); calloc.free(nameC);
calloc.free(newNameC); calloc.free(newNameC);
@ -157,10 +167,14 @@ List<String> rename(Pointer<git_repository> repo, String name, String newName) {
/// case of a single-url remote and will otherwise return an error. /// case of a single-url remote and will otherwise return an error.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setUrl(Pointer<git_repository> repo, String remote, String url) { void setUrl({
required Pointer<git_repository> repoPointer,
required String remote,
required String url,
}) {
final remoteC = remote.toNativeUtf8().cast<Int8>(); final remoteC = remote.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>(); final urlC = url.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_set_url(repo, remoteC, urlC); final error = libgit2.git_remote_set_url(repoPointer, remoteC, urlC);
calloc.free(remoteC); calloc.free(remoteC);
calloc.free(urlC); calloc.free(urlC);
@ -176,10 +190,14 @@ void setUrl(Pointer<git_repository> repo, String remote, String url) {
/// case of a single-url remote and will otherwise return an error. /// case of a single-url remote and will otherwise return an error.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setPushUrl(Pointer<git_repository> repo, String remote, String url) { void setPushUrl({
required Pointer<git_repository> repoPointer,
required String remote,
required String url,
}) {
final remoteC = remote.toNativeUtf8().cast<Int8>(); final remoteC = remote.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>(); final urlC = url.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_set_pushurl(repo, remoteC, urlC); final error = libgit2.git_remote_set_pushurl(repoPointer, remoteC, urlC);
calloc.free(remoteC); calloc.free(remoteC);
calloc.free(urlC); calloc.free(urlC);
@ -218,8 +236,11 @@ int refspecCount(Pointer<git_remote> remote) =>
libgit2.git_remote_refspec_count(remote); libgit2.git_remote_refspec_count(remote);
/// Get a refspec from the remote at provided position. /// Get a refspec from the remote at provided position.
Pointer<git_refspec> getRefspec(Pointer<git_remote> remote, int n) { Pointer<git_refspec> getRefspec({
return libgit2.git_remote_get_refspec(remote, n); required Pointer<git_remote> remotePointer,
required int position,
}) {
return libgit2.git_remote_get_refspec(remotePointer, position);
} }
/// Get the remote's list of fetch refspecs. /// Get the remote's list of fetch refspecs.
@ -256,10 +277,14 @@ List<String> pushRefspecs(Pointer<git_remote> remote) {
/// instances will be affected. /// instances will be affected.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void addFetch(Pointer<git_repository> repo, String remote, String refspec) { void addFetch({
required Pointer<git_repository> repoPointer,
required String remote,
required String refspec,
}) {
final remoteC = remote.toNativeUtf8().cast<Int8>(); final remoteC = remote.toNativeUtf8().cast<Int8>();
final refspecC = refspec.toNativeUtf8().cast<Int8>(); final refspecC = refspec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_add_fetch(repo, remoteC, refspecC); final error = libgit2.git_remote_add_fetch(repoPointer, remoteC, refspecC);
calloc.free(remoteC); calloc.free(remoteC);
calloc.free(refspecC); calloc.free(refspecC);
@ -275,10 +300,14 @@ void addFetch(Pointer<git_repository> repo, String remote, String refspec) {
/// instances will be affected. /// instances will be affected.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void addPush(Pointer<git_repository> repo, String remote, String refspec) { void addPush({
required Pointer<git_repository> repoPointer,
required String remote,
required String refspec,
}) {
final remoteC = remote.toNativeUtf8().cast<Int8>(); final remoteC = remote.toNativeUtf8().cast<Int8>();
final refspecC = refspec.toNativeUtf8().cast<Int8>(); final refspecC = refspec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_remote_add_push(repo, remoteC, refspecC); final error = libgit2.git_remote_add_push(repoPointer, remoteC, refspecC);
calloc.free(remoteC); calloc.free(remoteC);
calloc.free(refspecC); calloc.free(refspecC);
@ -295,12 +324,12 @@ void addPush(Pointer<git_repository> repo, String remote, String refspec) {
/// which can only do the one or the other. /// which can only do the one or the other.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void connect( void connect({
Pointer<git_remote> remote, required Pointer<git_remote> remotePointer,
int direction, required int direction,
required Callbacks callbacks,
String? proxyOption, String? proxyOption,
Callbacks callbacks, }) {
) {
final callbacksOptions = calloc<git_remote_callbacks>(); final callbacksOptions = calloc<git_remote_callbacks>();
final callbacksError = libgit2.git_remote_init_callbacks( final callbacksError = libgit2.git_remote_init_callbacks(
callbacksOptions, callbacksOptions,
@ -319,7 +348,7 @@ void connect(
final proxyOptions = _proxyOptionsInit(proxyOption); final proxyOptions = _proxyOptionsInit(proxyOption);
final error = libgit2.git_remote_connect( final error = libgit2.git_remote_connect(
remote, remotePointer,
direction, direction,
callbacksOptions, callbacksOptions,
proxyOptions, proxyOptions,
@ -386,14 +415,14 @@ List<Map<String, dynamic>> lsRemotes(Pointer<git_remote> remote) {
/// update the remote-tracking branches. /// update the remote-tracking branches.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void fetch( void fetch({
Pointer<git_remote> remote, required Pointer<git_remote> remotePointer,
List<String> refspecs, required List<String> refspecs,
required int prune,
required Callbacks callbacks,
String? reflogMessage, String? reflogMessage,
int prune,
String? proxyOption, String? proxyOption,
Callbacks callbacks, }) {
) {
var refspecsC = calloc<git_strarray>(); var refspecsC = calloc<git_strarray>();
final refspecsPointers = final refspecsPointers =
refspecs.map((e) => e.toNativeUtf8().cast<Int8>()).toList(); refspecs.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
@ -427,7 +456,7 @@ void fetch(
opts.ref.proxy_opts = proxyOptions.ref; opts.ref.proxy_opts = proxyOptions.ref;
final error = libgit2.git_remote_fetch( final error = libgit2.git_remote_fetch(
remote, remotePointer,
refspecsC, refspecsC,
opts, opts,
reflogMessageC, reflogMessageC,
@ -451,12 +480,12 @@ void fetch(
/// Perform a push. /// Perform a push.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void push( void push({
Pointer<git_remote> remote, required Pointer<git_remote> remotePointer,
List<String> refspecs, required List<String> refspecs,
required Callbacks callbacks,
String? proxyOption, String? proxyOption,
Callbacks callbacks, }) {
) {
var refspecsC = calloc<git_strarray>(); var refspecsC = calloc<git_strarray>();
final refspecsPointers = final refspecsPointers =
refspecs.map((e) => e.toNativeUtf8().cast<Int8>()).toList(); refspecs.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
@ -485,7 +514,7 @@ void push(
); );
opts.ref.proxy_opts = proxyOptions.ref; opts.ref.proxy_opts = proxyOptions.ref;
final error = libgit2.git_remote_push(remote, refspecsC, opts); final error = libgit2.git_remote_push(remotePointer, refspecsC, opts);
for (var p in refspecsPointers) { for (var p in refspecsPointers) {
calloc.free(p); calloc.free(p);
@ -519,10 +548,10 @@ void disconnect(Pointer<git_remote> remote) {
/// Prune tracking refs that are no longer present on remote. /// Prune tracking refs that are no longer present on remote.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void prune( void prune({
Pointer<git_remote> remote, required Pointer<git_remote> remotePointer,
Callbacks callbacks, required Callbacks callbacks,
) { }) {
final callbacksOptions = calloc<git_remote_callbacks>(); final callbacksOptions = calloc<git_remote_callbacks>();
final callbacksError = libgit2.git_remote_init_callbacks( final callbacksError = libgit2.git_remote_init_callbacks(
callbacksOptions, callbacksOptions,
@ -538,7 +567,7 @@ void prune(
callbacks: callbacks, callbacks: callbacks,
); );
final error = libgit2.git_remote_prune(remote, callbacksOptions); final error = libgit2.git_remote_prune(remotePointer, callbacksOptions);
calloc.free(callbacksOptions); calloc.free(callbacksOptions);
RemoteCallbacks.reset(); RemoteCallbacks.reset();

View file

@ -131,16 +131,16 @@ class RemoteCallbacks {
} else if (credentials is UserPass) { } else if (credentials is UserPass) {
final cred = credentials as UserPass; final cred = credentials as UserPass;
credPointer[0] = credentials_bindings.userPass( credPointer[0] = credentials_bindings.userPass(
cred.username, username: cred.username,
cred.password, password: cred.password,
); );
} else if (credentials is Keypair) { } else if (credentials is Keypair) {
final cred = credentials as Keypair; final cred = credentials as Keypair;
credPointer[0] = credentials_bindings.sshKey( credPointer[0] = credentials_bindings.sshKey(
cred.username, username: cred.username,
cred.pubKey, publicKey: cred.pubKey,
cred.privateKey, privateKey: cred.privateKey,
cred.passPhrase, passPhrase: cred.passPhrase,
); );
} else if (credentials is KeypairFromAgent) { } else if (credentials is KeypairFromAgent) {
final cred = credentials as KeypairFromAgent; final cred = credentials as KeypairFromAgent;
@ -148,10 +148,10 @@ class RemoteCallbacks {
} else if (credentials is KeypairFromMemory) { } else if (credentials is KeypairFromMemory) {
final cred = credentials as KeypairFromMemory; final cred = credentials as KeypairFromMemory;
credPointer[0] = credentials_bindings.sshKeyFromMemory( credPointer[0] = credentials_bindings.sshKeyFromMemory(
cred.username, username: cred.username,
cred.pubKey, publicKey: cred.pubKey,
cred.privateKey, privateKey: cred.privateKey,
cred.passPhrase, passPhrase: cred.passPhrase,
); );
} }

View file

@ -53,7 +53,10 @@ 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({
required 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>() ?? nullptr; final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast<Int8>() ?? nullptr;
@ -80,16 +83,16 @@ String discover(String startPath, String? ceilingDirs) {
/// Creates a new Git repository in the given folder. /// Creates a new Git repository in the given folder.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_repository> init( Pointer<git_repository> init({
String path, required String path,
int flags, required int flags,
int mode, required 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 = workdirPath?.toNativeUtf8().cast<Int8>() ?? nullptr; final workdirPathC = workdirPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
@ -135,15 +138,15 @@ Pointer<git_repository> init(
/// Clone a remote repository. /// Clone a remote repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_repository> clone( Pointer<git_repository> clone({
String url, required String url,
String localPath, required String localPath,
bool bare, required 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,
Callbacks callbacks, required Callbacks callbacks,
) { }) {
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>();
@ -245,9 +248,12 @@ String getNamespace(Pointer<git_repository> repo) {
/// under refs/namespaces/foo/, use foo as the namespace. /// under refs/namespaces/foo/, use foo as the namespace.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setNamespace(Pointer<git_repository> repo, String? namespace) { void setNamespace({
required Pointer<git_repository> repoPointer,
String? namespace,
}) {
final nmspace = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr; final nmspace = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_repository_set_namespace(repo, nmspace); final error = libgit2.git_repository_set_namespace(repoPointer, nmspace);
calloc.free(nmspace); calloc.free(nmspace);
@ -330,11 +336,15 @@ bool isBranchUnborn(Pointer<git_repository> repo) {
/// ///
/// If both are set, this name and email will be used to write to the reflog. /// If both are set, this name and email will be used to write to the reflog.
/// Pass NULL to unset. When unset, the identity will be taken from the repository's configuration. /// Pass NULL to unset. When unset, the identity will be taken from the repository's configuration.
void setIdentity(Pointer<git_repository> repo, String? name, String? email) { void setIdentity({
required Pointer<git_repository> repoPointer,
String? name,
String? email,
}) {
final nameC = name?.toNativeUtf8().cast<Int8>() ?? nullptr; final nameC = name?.toNativeUtf8().cast<Int8>() ?? nullptr;
final emailC = email?.toNativeUtf8().cast<Int8>() ?? nullptr; final emailC = email?.toNativeUtf8().cast<Int8>() ?? nullptr;
libgit2.git_repository_set_ident(repo, nameC, emailC); libgit2.git_repository_set_ident(repoPointer, nameC, emailC);
calloc.free(nameC); calloc.free(nameC);
calloc.free(emailC); calloc.free(emailC);
@ -507,11 +517,14 @@ Pointer<git_refdb> refdb(Pointer<git_repository> repo) {
/// Otherwise, the HEAD will be detached and will directly point to the Commit. /// Otherwise, the HEAD will be detached and will directly point to the Commit.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setHead(Pointer<git_repository> repo, String ref) { void setHead({
final refname = ref.toNativeUtf8().cast<Int8>(); required Pointer<git_repository> repoPointer,
final error = libgit2.git_repository_set_head(repo, refname); required String refname,
}) {
final refnameC = refname.toNativeUtf8().cast<Int8>();
final error = libgit2.git_repository_set_head(repoPointer, refnameC);
calloc.free(refname); calloc.free(refnameC);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -527,8 +540,14 @@ void setHead(Pointer<git_repository> repo, String ref) {
/// Otherwise, the HEAD will eventually be detached and will directly point to the peeled commit. /// Otherwise, the HEAD will eventually be detached and will directly point to the peeled commit.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setHeadDetached(Pointer<git_repository> repo, Pointer<git_oid> commitish) { void setHeadDetached({
final error = libgit2.git_repository_set_head_detached(repo, commitish); required Pointer<git_repository> repoPointer,
required Pointer<git_oid> commitishPointer,
}) {
final error = libgit2.git_repository_set_head_detached(
repoPointer,
commitishPointer,
);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -542,12 +561,14 @@ void setHeadDetached(Pointer<git_repository> repo, Pointer<git_oid> commitish) {
/// by a user, allowing for more exact reflog messages. /// by a user, allowing for more exact reflog messages.
/// ///
/// See the documentation for [setHeadDetached]. /// See the documentation for [setHeadDetached].
void setHeadDetachedFromAnnotated( void setHeadDetachedFromAnnotated({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_annotated_commit> commitish, required Pointer<git_annotated_commit> commitishPointer,
) { }) {
final error = final error = libgit2.git_repository_set_head_detached_from_annotated(
libgit2.git_repository_set_head_detached_from_annotated(repo, commitish); repoPointer,
commitishPointer,
);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -564,15 +585,15 @@ void setHeadDetachedFromAnnotated(
/// (checkout, status, index manipulation, etc). /// (checkout, status, index manipulation, etc).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setWorkdir( void setWorkdir({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String path, required String path,
bool updateGitlink, required bool updateGitlink,
) { }) {
final workdir = path.toNativeUtf8().cast<Int8>(); final workdir = path.toNativeUtf8().cast<Int8>();
final updateGitlinkC = updateGitlink ? 1 : 0; final updateGitlinkC = updateGitlink ? 1 : 0;
final error = libgit2.git_repository_set_workdir( final error = libgit2.git_repository_set_workdir(
repo, repoPointer,
workdir, workdir,
updateGitlinkC, updateGitlinkC,
); );

View file

@ -15,13 +15,18 @@ import '../util.dart';
/// with the content of the index. (Untracked and ignored files will be left alone, however.) /// with the content of the index. (Untracked and ignored files will be left alone, however.)
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void reset( void reset({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_object> target, required Pointer<git_object> targetPointer,
int resetType, required int resetType,
Pointer<git_checkout_options> checkoutOpts, required Pointer<git_checkout_options> checkoutOptsPointer,
) { }) {
final error = libgit2.git_reset(repo, target, resetType, checkoutOpts); final error = libgit2.git_reset(
repoPointer,
targetPointer,
resetType,
checkoutOptsPointer,
);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());

View file

@ -10,13 +10,14 @@ import '../util.dart';
/// for information on the syntax accepted. /// for information on the syntax accepted.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_revspec> revParse( Pointer<git_revspec> revParse({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String spec, required String spec,
) { }) {
final out = calloc<git_revspec>(); final out = calloc<git_revspec>();
final specC = spec.toNativeUtf8().cast<Int8>(); final specC = spec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_revparse(out, repo, specC);
final error = libgit2.git_revparse(out, repoPointer, specC);
calloc.free(specC); calloc.free(specC);
@ -34,14 +35,14 @@ Pointer<git_revspec> revParse(
/// The returned object should be released when no longer needed. /// The returned object should be released when no longer needed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_object> revParseSingle(Pointer<git_repository> repo, String spec) { Pointer<git_object> revParseSingle({
required Pointer<git_repository> repoPointer,
required String spec,
}) {
final out = calloc<Pointer<git_object>>(); final out = calloc<Pointer<git_object>>();
final specC = spec.toNativeUtf8().cast<Int8>(); final specC = spec.toNativeUtf8().cast<Int8>();
final error = libgit2.git_revparse_single(
out, final error = libgit2.git_revparse_single(out, repoPointer, specC);
repo,
specC,
);
calloc.free(specC); calloc.free(specC);
@ -64,12 +65,21 @@ Pointer<git_object> revParseSingle(Pointer<git_repository> repo, String spec) {
/// The returned object and reference should be released when no longer needed. /// The returned object and reference should be released when no longer needed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List revParseExt(Pointer<git_repository> repo, String spec) { List revParseExt({
required Pointer<git_repository> repoPointer,
required String spec,
}) {
final objectOut = calloc<Pointer<git_object>>(); final objectOut = calloc<Pointer<git_object>>();
final referenceOut = calloc<Pointer<git_reference>>(); final referenceOut = calloc<Pointer<git_reference>>();
final specC = spec.toNativeUtf8().cast<Int8>(); final specC = spec.toNativeUtf8().cast<Int8>();
var result = []; var result = [];
final error = libgit2.git_revparse_ext(objectOut, referenceOut, repo, specC);
final error = libgit2.git_revparse_ext(
objectOut,
referenceOut,
repoPointer,
specC,
);
calloc.free(specC); calloc.free(specC);

View file

@ -33,8 +33,11 @@ Pointer<git_revwalk> create(Pointer<git_repository> repo) {
/// Changing the sorting mode resets the walker. /// Changing the sorting mode resets the walker.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void sorting(Pointer<git_revwalk> walker, int sortMode) { void sorting({
final error = libgit2.git_revwalk_sorting(walker, sortMode); required Pointer<git_revwalk> walkerPointer,
required int sortMode,
}) {
final error = libgit2.git_revwalk_sorting(walkerPointer, sortMode);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -51,8 +54,11 @@ void sorting(Pointer<git_revwalk> walker, int sortMode) {
/// The given id must belong to a committish on the walked repository. /// The given id must belong to a committish on the walked repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void push(Pointer<git_revwalk> walker, Pointer<git_oid> id) { void push({
final error = libgit2.git_revwalk_push(walker, id); required Pointer<git_revwalk> walkerPointer,
required Pointer<git_oid> oidPointer,
}) {
final error = libgit2.git_revwalk_push(walkerPointer, oidPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -69,18 +75,21 @@ void push(Pointer<git_revwalk> walker, Pointer<git_oid> id) {
/// repositories (topological preprocessing times at 0.3s on the git.git repo). /// repositories (topological preprocessing times at 0.3s on the git.git repo).
/// ///
/// The revision walker is reset when the walk is over. /// The revision walker is reset when the walk is over.
List<Pointer<git_commit>> walk( List<Pointer<git_commit>> walk({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_revwalk> walker, required Pointer<git_revwalk> walkerPointer,
) { }) {
var result = <Pointer<git_commit>>[]; var result = <Pointer<git_commit>>[];
var error = 0; var error = 0;
while (error == 0) { while (error == 0) {
final oid = calloc<git_oid>(); final oid = calloc<git_oid>();
error = libgit2.git_revwalk_next(oid, walker); error = libgit2.git_revwalk_next(oid, walkerPointer);
if (error == 0) { if (error == 0) {
final commit = commit_bindings.lookup(repo, oid); final commit = commit_bindings.lookup(
repoPointer: repoPointer,
oidPointer: oid,
);
result.add(commit); result.add(commit);
calloc.free(oid); calloc.free(oid);
} else { } else {
@ -98,8 +107,11 @@ List<Pointer<git_commit>> walk(
/// The resolved commit and all its parents will be hidden from the output on the revision walk. /// The resolved commit and all its parents will be hidden from the output on the revision walk.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void hide(Pointer<git_revwalk> walk, Pointer<git_oid> oid) { void hide({
final error = libgit2.git_revwalk_hide(walk, oid); required Pointer<git_revwalk> walkerPointer,
required Pointer<git_oid> oidPointer,
}) {
final error = libgit2.git_revwalk_hide(walkerPointer, oidPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -119,8 +131,8 @@ void reset(Pointer<git_revwalk> walker) => libgit2.git_revwalk_reset(walker);
/// No parents other than the first for each commit will be enqueued. /// No parents other than the first for each commit will be enqueued.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void simplifyFirstParent(Pointer<git_revwalk> walk) { void simplifyFirstParent(Pointer<git_revwalk> walker) {
final error = libgit2.git_revwalk_simplify_first_parent(walk); final error = libgit2.git_revwalk_simplify_first_parent(walker);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());

View file

@ -10,12 +10,12 @@ import '../util.dart';
/// either the name or the email parameter. /// either the name or the email parameter.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_signature> create( Pointer<git_signature> create({
String name, required String name,
String email, required String email,
int time, required int time,
int offset, required int offset,
) { }) {
final out = calloc<Pointer<git_signature>>(); final out = calloc<Pointer<git_signature>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final emailC = email.toNativeUtf8().cast<Int8>(); final emailC = email.toNativeUtf8().cast<Int8>();
@ -34,7 +34,7 @@ Pointer<git_signature> create(
/// Create a new action signature with a timestamp of 'now'. /// Create a new action signature with a timestamp of 'now'.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_signature> now(String name, String email) { Pointer<git_signature> now({required String name, required String email}) {
final out = calloc<Pointer<git_signature>>(); final out = calloc<Pointer<git_signature>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final emailC = email.toNativeUtf8().cast<Int8>(); final emailC = email.toNativeUtf8().cast<Int8>();

View file

@ -10,15 +10,21 @@ import '../util.dart';
/// Save the local modifications to a new stash. /// Save the local modifications to a new stash.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> stash( Pointer<git_oid> stash({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_signature> stasher, required Pointer<git_signature> stasherPointer,
String? message, String? message,
int flags, required int flags,
) { }) {
final out = calloc<git_oid>(); final out = calloc<git_oid>();
final messageC = message?.toNativeUtf8().cast<Int8>() ?? nullptr; final messageC = message?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_stash_save(out, repo, stasher, messageC, flags); final error = libgit2.git_stash_save(
out,
repoPointer,
stasherPointer,
messageC,
flags,
);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -30,14 +36,14 @@ Pointer<git_oid> stash(
/// Apply a single stashed state from the stash list. /// Apply a single stashed state from the stash list.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void apply( void apply({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
int index, required int index,
int flags, required int flags,
int strategy, required int strategy,
String? directory, String? directory,
List<String>? paths, List<String>? paths,
) { }) {
final options = final options =
calloc<git_stash_apply_options>(sizeOf<git_stash_apply_options>()); calloc<git_stash_apply_options>(sizeOf<git_stash_apply_options>());
final optionsError = libgit2.git_stash_apply_options_init( final optionsError = libgit2.git_stash_apply_options_init(
@ -47,8 +53,11 @@ void apply(
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
} }
final checkoutOptions = final checkoutOptions = checkout_bindings.initOptions(
checkout_bindings.initOptions(strategy, directory, paths); strategy: strategy,
directory: directory,
paths: paths,
);
final optsC = checkoutOptions[0]; final optsC = checkoutOptions[0];
final pathPointers = checkoutOptions[1]; final pathPointers = checkoutOptions[1];
final strArray = checkoutOptions[2]; final strArray = checkoutOptions[2];
@ -56,7 +65,7 @@ void apply(
options.ref.flags = flags; options.ref.flags = flags;
options.ref.checkout_options = (optsC as Pointer<git_checkout_options>).ref; options.ref.checkout_options = (optsC as Pointer<git_checkout_options>).ref;
final error = libgit2.git_stash_apply(repo, index, options); final error = libgit2.git_stash_apply(repoPointer, index, options);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -74,21 +83,21 @@ void apply(
/// Remove a single stashed state from the stash list. /// Remove a single stashed state from the stash list.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void drop(Pointer<git_repository> repo, int index) { void drop({required Pointer<git_repository> repoPointer, required int index}) {
libgit2.git_stash_drop(repo, index); libgit2.git_stash_drop(repoPointer, index);
} }
/// Apply a single stashed state from the stash list and remove it from the list if successful. /// Apply a single stashed state from the stash list and remove it from the list if successful.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void pop( void pop({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
int index, required int index,
int flags, required int flags,
int strategy, required int strategy,
String? directory, String? directory,
List<String>? paths, List<String>? paths,
) { }) {
final options = final options =
calloc<git_stash_apply_options>(sizeOf<git_stash_apply_options>()); calloc<git_stash_apply_options>(sizeOf<git_stash_apply_options>());
final optionsError = libgit2.git_stash_apply_options_init( final optionsError = libgit2.git_stash_apply_options_init(
@ -98,8 +107,11 @@ void pop(
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
} }
final checkoutOptions = final checkoutOptions = checkout_bindings.initOptions(
checkout_bindings.initOptions(strategy, directory, paths); strategy: strategy,
directory: directory,
paths: paths,
);
final optsC = checkoutOptions[0]; final optsC = checkoutOptions[0];
final pathPointers = checkoutOptions[1]; final pathPointers = checkoutOptions[1];
final strArray = checkoutOptions[2]; final strArray = checkoutOptions[2];
@ -107,7 +119,7 @@ void pop(
options.ref.flags = flags; options.ref.flags = flags;
options.ref.checkout_options = (optsC as Pointer<git_checkout_options>).ref; options.ref.checkout_options = (optsC as Pointer<git_checkout_options>).ref;
final error = libgit2.git_stash_pop(repo, index, options); final error = libgit2.git_stash_pop(repoPointer, index, options);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -122,6 +134,9 @@ void pop(
calloc.free(options); calloc.free(options);
} }
/// List of stashed states.
///
/// IMPORTANT: make sure to clear that list since it's a global variable.
var _stashList = <Stash>[]; var _stashList = <Stash>[];
/// Loop over all the stashed states. /// Loop over all the stashed states.
@ -136,6 +151,7 @@ List<Stash> list(Pointer<git_repository> repo) {
return result; return result;
} }
/// A callback function to iterate over all the stashed states.
int _stashCb( int _stashCb(
int index, int index,
Pointer<Int8> message, Pointer<Int8> message,

View file

@ -32,11 +32,11 @@ int listEntryCount(Pointer<git_status_list> statuslist) {
/// The entry is not modifiable and should not be freed. /// The entry is not modifiable and should not be freed.
/// ///
/// Throws [RangeError] if position is out of bounds /// Throws [RangeError] if position is out of bounds
Pointer<git_status_entry> getByIndex( Pointer<git_status_entry> getByIndex({
Pointer<git_status_list> statuslist, required Pointer<git_status_list> statuslistPointer,
int idx, required int index,
) { }) {
final result = libgit2.git_status_byindex(statuslist, idx); final result = libgit2.git_status_byindex(statuslistPointer, index);
if (result == nullptr) { if (result == nullptr) {
throw RangeError('Out of bounds'); throw RangeError('Out of bounds');
@ -60,10 +60,10 @@ Pointer<git_status_entry> getByIndex(
/// and scan through looking for the path that you are interested in. /// and scan through looking for the path that you are interested in.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
int file(Pointer<git_repository> repo, String path) { int file({required Pointer<git_repository> repoPointer, required String path}) {
final out = calloc<Uint32>(); final out = calloc<Uint32>();
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_status_file(out, repo, pathC); final error = libgit2.git_status_file(out, repoPointer, pathC);
calloc.free(pathC); calloc.free(pathC);

View file

@ -7,9 +7,12 @@ import '../util.dart';
/// Lookup a tag object from the repository. /// Lookup a tag object from the repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_tag> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) { Pointer<git_tag> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_tag>>(); final out = calloc<Pointer<git_tag>>();
final error = libgit2.git_tag_lookup(out, repo, id); final error = libgit2.git_tag_lookup(out, repoPointer, oidPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -64,24 +67,24 @@ Pointer<git_signature> tagger(Pointer<git_tag> tag) =>
/// special meaning to revparse. /// special meaning to revparse.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> create( Pointer<git_oid> create({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String tagName, required String tagName,
Pointer<git_object> target, required Pointer<git_object> targetPointer,
Pointer<git_signature> tagger, required Pointer<git_signature> taggerPointer,
String message, required String message,
bool force, required bool force,
) { }) {
final out = calloc<git_oid>(); final out = calloc<git_oid>();
final tagNameC = tagName.toNativeUtf8().cast<Int8>(); final tagNameC = tagName.toNativeUtf8().cast<Int8>();
final messageC = message.toNativeUtf8().cast<Int8>(); final messageC = message.toNativeUtf8().cast<Int8>();
final forceC = force ? 1 : 0; final forceC = force ? 1 : 0;
final error = libgit2.git_tag_create( final error = libgit2.git_tag_create(
out, out,
repo, repoPointer,
tagNameC, tagNameC,
target, targetPointer,
tagger, taggerPointer,
messageC, messageC,
forceC, forceC,
); );

View file

@ -10,9 +10,12 @@ Pointer<git_oid> id(Pointer<git_tree> tree) => libgit2.git_tree_id(tree);
/// Lookup a tree object from the repository. /// Lookup a tree object from the repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_tree> lookup(Pointer<git_repository> repo, Pointer<git_oid> id) { Pointer<git_tree> lookup({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
}) {
final out = calloc<Pointer<git_tree>>(); final out = calloc<Pointer<git_tree>>();
final error = libgit2.git_tree_lookup(out, repo, id); final error = libgit2.git_tree_lookup(out, repoPointer, oidPointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -31,8 +34,11 @@ Pointer<git_repository> owner(Pointer<git_tree> tree) =>
/// but you must not use it after the tree is released. /// but you must not use it after the tree is released.
/// ///
/// Throws [RangeError] when provided index is outside of valid range. /// Throws [RangeError] when provided index is outside of valid range.
Pointer<git_tree_entry> getByIndex(Pointer<git_tree> tree, int index) { Pointer<git_tree_entry> getByIndex({
final result = libgit2.git_tree_entry_byindex(tree, index); required Pointer<git_tree> treePointer,
required int index,
}) {
final result = libgit2.git_tree_entry_byindex(treePointer, index);
if (result == nullptr) { if (result == nullptr) {
throw RangeError('Out of bounds'); throw RangeError('Out of bounds');
@ -47,9 +53,12 @@ Pointer<git_tree_entry> getByIndex(Pointer<git_tree> tree, int index) {
/// but you must not use it after the tree is released. /// but you must not use it after the tree is released.
/// ///
/// Throws [ArgumentError] if nothing found for provided filename. /// Throws [ArgumentError] if nothing found for provided filename.
Pointer<git_tree_entry> getByName(Pointer<git_tree> tree, String filename) { Pointer<git_tree_entry> getByName({
required Pointer<git_tree> treePointer,
required String filename,
}) {
final filenameC = filename.toNativeUtf8().cast<Int8>(); final filenameC = filename.toNativeUtf8().cast<Int8>();
final result = libgit2.git_tree_entry_byname(tree, filenameC); final result = libgit2.git_tree_entry_byname(treePointer, filenameC);
calloc.free(filenameC); calloc.free(filenameC);
@ -66,10 +75,13 @@ Pointer<git_tree_entry> getByName(Pointer<git_tree> tree, String filename) {
/// freed explicitly with `entryFree()`. /// freed explicitly with `entryFree()`.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_tree_entry> getByPath(Pointer<git_tree> root, String path) { Pointer<git_tree_entry> getByPath({
required Pointer<git_tree> rootPointer,
required String path,
}) {
final out = calloc<Pointer<git_tree_entry>>(); final out = calloc<Pointer<git_tree_entry>>();
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_tree_entry_bypath(out, root, pathC); final error = libgit2.git_tree_entry_bypath(out, rootPointer, pathC);
calloc.free(pathC); calloc.free(pathC);
@ -98,8 +110,11 @@ int entryFilemode(Pointer<git_tree_entry> entry) =>
/// Compare two tree entries. /// Compare two tree entries.
/// ///
/// Returns <0 if e1 is before e2, 0 if e1 == e2, >0 if e1 is after e2. /// Returns <0 if e1 is before e2, 0 if e1 == e2, >0 if e1 is after e2.
int compare(Pointer<git_tree_entry> e1, Pointer<git_tree_entry> e2) { int compare({
return libgit2.git_tree_entry_cmp(e1, e2); required Pointer<git_tree_entry> aPointer,
required Pointer<git_tree_entry> bPointer,
}) {
return libgit2.git_tree_entry_cmp(aPointer, bPointer);
} }
/// Free a user-owned tree entry. /// Free a user-owned tree entry.

View file

@ -16,12 +16,12 @@ import '../util.dart';
/// and will have to be filled manually. /// and will have to be filled manually.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_treebuilder> create( Pointer<git_treebuilder> create({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
Pointer<git_tree> source, required Pointer<git_tree> sourcePointer,
) { }) {
final out = calloc<Pointer<git_treebuilder>>(); final out = calloc<Pointer<git_treebuilder>>();
final error = libgit2.git_treebuilder_new(out, repo, source); final error = libgit2.git_treebuilder_new(out, repoPointer, sourcePointer);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -64,12 +64,12 @@ int entryCount(Pointer<git_treebuilder> bld) =>
/// The returned entry is owned by the builder and should not be freed manually. /// The returned entry is owned by the builder and should not be freed manually.
/// ///
/// Throws [ArgumentError] if nothing found for provided filename. /// Throws [ArgumentError] if nothing found for provided filename.
Pointer<git_tree_entry> getByFilename( Pointer<git_tree_entry> getByFilename({
Pointer<git_treebuilder> bld, required Pointer<git_treebuilder> builderPointer,
String filename, required String filename,
) { }) {
final filenameC = filename.toNativeUtf8().cast<Int8>(); final filenameC = filename.toNativeUtf8().cast<Int8>();
final result = libgit2.git_treebuilder_get(bld, filenameC); final result = libgit2.git_treebuilder_get(builderPointer, filenameC);
calloc.free(filenameC); calloc.free(filenameC);
@ -91,15 +91,20 @@ Pointer<git_tree_entry> getByFilename(
/// that it exists in the object database and is of the correct type. /// that it exists in the object database and is of the correct type.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void add( void add({
Pointer<git_treebuilder> bld, required Pointer<git_treebuilder> builderPointer,
String filename, required String filename,
Pointer<git_oid> id, required Pointer<git_oid> oidPointer,
int filemode, required int filemode,
) { }) {
final filenameC = filename.toNativeUtf8().cast<Int8>(); final filenameC = filename.toNativeUtf8().cast<Int8>();
final error = final error = libgit2.git_treebuilder_insert(
libgit2.git_treebuilder_insert(nullptr, bld, filenameC, id, filemode); nullptr,
builderPointer,
filenameC,
oidPointer,
filemode,
);
calloc.free(filenameC); calloc.free(filenameC);
@ -111,9 +116,12 @@ void add(
/// Remove an entry from the builder by its filename. /// Remove an entry from the builder by its filename.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void remove(Pointer<git_treebuilder> bld, String filename) { void remove({
required Pointer<git_treebuilder> builderPointer,
required String filename,
}) {
final filenameC = filename.toNativeUtf8().cast<Int8>(); final filenameC = filename.toNativeUtf8().cast<Int8>();
final error = libgit2.git_treebuilder_remove(bld, filenameC); final error = libgit2.git_treebuilder_remove(builderPointer, filenameC);
calloc.free(filenameC); calloc.free(filenameC);

View file

@ -11,12 +11,12 @@ import '../util.dart';
/// data structures inside the repository and check out the current HEAD at path. /// data structures inside the repository and check out the current HEAD at path.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_worktree> create( Pointer<git_worktree> create({
Pointer<git_repository> repo, required Pointer<git_repository> repoPointer,
String name, required String name,
String path, required String path,
Pointer<git_reference>? ref, Pointer<git_reference>? refPointer,
) { }) {
final out = calloc<Pointer<git_worktree>>(); final out = calloc<Pointer<git_worktree>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final pathC = path.toNativeUtf8().cast<Int8>(); final pathC = path.toNativeUtf8().cast<Int8>();
@ -24,10 +24,10 @@ Pointer<git_worktree> create(
calloc<git_worktree_add_options>(sizeOf<git_worktree_add_options>()); calloc<git_worktree_add_options>(sizeOf<git_worktree_add_options>());
opts.ref.version = 1; opts.ref.version = 1;
opts.ref.lock = 0; opts.ref.lock = 0;
if (ref != null) { if (refPointer != null) {
opts.ref.ref = ref; opts.ref.ref = refPointer;
} }
final error = libgit2.git_worktree_add(out, repo, nameC, pathC, opts); final error = libgit2.git_worktree_add(out, repoPointer, nameC, pathC, opts);
calloc.free(nameC); calloc.free(nameC);
calloc.free(pathC); calloc.free(pathC);
@ -43,10 +43,13 @@ Pointer<git_worktree> create(
/// Lookup a working tree by its name for a given repository. /// Lookup a working tree by its name for a given repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_worktree> lookup(Pointer<git_repository> repo, String name) { Pointer<git_worktree> lookup({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_worktree>>(); final out = calloc<Pointer<git_worktree>>();
final nameC = name.toNativeUtf8().cast<Int8>(); final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_worktree_lookup(out, repo, nameC); final error = libgit2.git_worktree_lookup(out, repoPointer, nameC);
calloc.free(nameC); calloc.free(nameC);

View file

@ -18,9 +18,12 @@ class Blob {
/// [Repository] object and [sha] hex string. /// [Repository] object and [sha] hex string.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Blob.lookup(Repository repo, String sha) { Blob.lookup({required Repository repo, required String sha}) {
final oid = Oid.fromSHA(repo, sha); final oid = Oid.fromSHA(repo: repo, sha: sha);
_blobPointer = bindings.lookup(repo.pointer, oid.pointer); _blobPointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
);
} }
late final Pointer<git_blob> _blobPointer; late final Pointer<git_blob> _blobPointer;
@ -31,23 +34,33 @@ class Blob {
/// Creates a new blob from a [content] string and writes it to ODB. /// Creates a new blob from a [content] string and writes it to ODB.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
static Oid create(Repository repo, String content) { static Oid create({required Repository repo, required String content}) {
return Oid(bindings.create(repo.pointer, content, content.length)); return Oid(bindings.create(
repoPointer: repo.pointer,
buffer: content,
len: content.length,
));
} }
/// Creates a new blob from the file in working directory of a repository and writes /// Creates a new blob from the file in working directory of a repository and writes
/// it to the ODB. Provided [relativePath] should be relative to the working directory. /// it to the ODB. Provided [relativePath] should be relative to the working directory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
static Oid createFromWorkdir(Repository repo, String relativePath) { static Oid createFromWorkdir({
return Oid(bindings.createFromWorkdir(repo.pointer, relativePath)); required Repository repo,
required String relativePath,
}) {
return Oid(bindings.createFromWorkdir(
repoPointer: repo.pointer,
relativePath: relativePath,
));
} }
/// Creates a new blob from the file in filesystem and writes it to the ODB. /// Creates a new blob from the file in filesystem and writes it to the ODB.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
static Oid createFromDisk(Repository repo, String path) { static Oid createFromDisk({required Repository repo, required String path}) {
return Oid(bindings.createFromDisk(repo.pointer, path)); return Oid(bindings.createFromDisk(repoPointer: repo.pointer, path: path));
} }
/// Returns the Oid of the blob. /// Returns the Oid of the blob.
@ -83,13 +96,13 @@ class Blob {
flags.fold(0, (previousValue, e) => previousValue | e.value); flags.fold(0, (previousValue, e) => previousValue | e.value);
final result = patch_bindings.fromBlobs( final result = patch_bindings.fromBlobs(
_blobPointer, oldBlobPointer: _blobPointer,
oldAsPath, oldAsPath: oldAsPath,
newBlob?.pointer, newBlobPointer: newBlob?.pointer,
newAsPath, newAsPath: newAsPath,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
); );
return Patch(result['patch'], result['a'], result['b']); return Patch(result['patch'], result['a'], result['b']);
@ -112,13 +125,13 @@ class Blob {
flags.fold(0, (previousValue, e) => previousValue | e.value); flags.fold(0, (previousValue, e) => previousValue | e.value);
final result = patch_bindings.fromBlobAndBuffer( final result = patch_bindings.fromBlobAndBuffer(
_blobPointer, oldBlobPointer: _blobPointer,
oldAsPath, oldAsPath: oldAsPath,
buffer, buffer: buffer,
bufferAsPath, bufferAsPath: bufferAsPath,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
); );
return Patch(result['patch'], result['a'], result['b']); return Patch(result['patch'], result['a'], result['b']);

View file

@ -21,18 +21,32 @@ class Branches {
/// Returns a list of all branches that can be found in a repository. /// Returns a list of all branches that can be found in a repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<String> list() => bindings.list(_repoPointer, GitBranch.all.value); List<String> list() {
return bindings.list(
repoPointer: _repoPointer,
flags: GitBranch.all.value,
);
}
/// Returns a list of local branches that can be found in a repository. /// Returns a list of local branches that can be found in a repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<String> get local => bindings.list(_repoPointer, GitBranch.local.value); List<String> get local {
return bindings.list(
repoPointer: _repoPointer,
flags: GitBranch.local.value,
);
}
/// Returns a list of remote branches that can be found in a repository. /// Returns a list of remote branches that can be found in a repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<String> get remote => List<String> get remote {
bindings.list(_repoPointer, GitBranch.remote.value); return bindings.list(
repoPointer: _repoPointer,
flags: GitBranch.remote.value,
);
}
/// Lookups a branch by its name in a repository. /// Lookups a branch by its name in a repository.
/// ///
@ -41,13 +55,20 @@ class Branches {
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Branch operator [](String branchName) { Branch operator [](String branchName) {
final ref = Reference( final ref = Reference(
reference_bindings.lookupDWIM(_repoPointer, branchName), reference_bindings.lookupDWIM(
repoPointer: _repoPointer,
name: branchName,
),
); );
late final GitBranch type; late final GitBranch type;
ref.isBranch ? type = GitBranch.local : GitBranch.remote; ref.isBranch ? type = GitBranch.local : GitBranch.remote;
ref.free(); ref.free();
return Branch(bindings.lookup(_repoPointer, branchName, type.value)); return Branch(bindings.lookup(
repoPointer: _repoPointer,
branchName: branchName,
branchType: type.value,
));
} }
/// Creates a new branch pointing at a [target] commit. /// Creates a new branch pointing at a [target] commit.
@ -66,10 +87,10 @@ class Branches {
bool force = false, bool force = false,
}) { }) {
return Reference(bindings.create( return Reference(bindings.create(
_repoPointer, repoPointer: _repoPointer,
name, branchName: name,
target.pointer, targetPointer: target.pointer,
force, force: force,
)); ));
} }
} }
@ -108,7 +129,11 @@ class Branch {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Branch rename({required String newName, bool force = false}) { Branch rename({required String newName, bool force = false}) {
return Branch(bindings.rename(_branchPointer, newName, force)); return Branch(bindings.rename(
branchPointer: _branchPointer,
newBranchName: newName,
force: force,
));
} }
/// Checks if HEAD points to the given branch. /// Checks if HEAD points to the given branch.

View file

@ -18,9 +18,12 @@ class Commit {
/// and [sha] hex string. /// and [sha] hex string.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Commit.lookup(Repository repo, String sha) { Commit.lookup({required Repository repo, required String sha}) {
final oid = Oid.fromSHA(repo, sha); final oid = Oid.fromSHA(repo: repo, sha: sha);
_commitPointer = bindings.lookup(repo.pointer, oid.pointer); _commitPointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
);
} }
late final Pointer<git_commit> _commitPointer; late final Pointer<git_commit> _commitPointer;
@ -47,18 +50,18 @@ class Commit {
String? updateRef, String? updateRef,
String? messageEncoding, String? messageEncoding,
}) { }) {
final tree = Tree.lookup(repo, treeSHA); final tree = Tree.lookup(repo: repo, sha: treeSHA);
final result = Oid(bindings.create( final result = Oid(bindings.create(
repo.pointer, repoPointer: repo.pointer,
updateRef, updateRef: updateRef,
author.pointer, authorPointer: author.pointer,
commiter.pointer, committerPointer: commiter.pointer,
messageEncoding, messageEncoding: messageEncoding,
message, message: message,
tree.pointer, treePointer: tree.pointer,
parents.length, parentCount: parents.length,
parents, parents: parents,
)); ));
tree.free(); tree.free();
@ -95,7 +98,10 @@ class Commit {
final parentCount = bindings.parentCount(_commitPointer); final parentCount = bindings.parentCount(_commitPointer);
for (var i = 0; i < parentCount; i++) { for (var i = 0; i < parentCount; i++) {
final parentOid = bindings.parentId(_commitPointer, i); final parentOid = bindings.parentId(
commitPointer: _commitPointer,
position: i,
);
parents.add(Oid(parentOid)); parents.add(Oid(parentOid));
} }
@ -106,7 +112,7 @@ class Commit {
Tree get tree { Tree get tree {
final repo = bindings.owner(_commitPointer); final repo = bindings.owner(_commitPointer);
final oid = bindings.tree(_commitPointer); final oid = bindings.tree(_commitPointer);
return Tree(tree_bindings.lookup(repo, oid)); return Tree(tree_bindings.lookup(repoPointer: repo, oidPointer: oid));
} }
/// Releases memory allocated for commit object. /// Releases memory allocated for commit object.

View file

@ -91,17 +91,33 @@ class Config with IterableMixin<ConfigEntry> {
Config get snapshot => Config(bindings.snapshot(_configPointer)); Config get snapshot => Config(bindings.snapshot(_configPointer));
/// Returns the [ConfigEntry] of a [variable]. /// Returns the [ConfigEntry] of a [variable].
ConfigEntry operator [](String variable) => ConfigEntry operator [](String variable) {
ConfigEntry(bindings.getEntry(_configPointer, variable)); return ConfigEntry(bindings.getEntry(
configPointer: _configPointer,
variable: variable,
));
}
/// Sets the [value] of config [variable]. /// Sets the [value] of config [variable].
void operator []=(String variable, dynamic value) { void operator []=(String variable, dynamic value) {
if (value is bool) { if (value is bool) {
bindings.setBool(_configPointer, variable, value); bindings.setBool(
configPointer: _configPointer,
variable: variable,
value: value,
);
} else if (value is int) { } else if (value is int) {
bindings.setInt(_configPointer, variable, value); bindings.setInt(
configPointer: _configPointer,
variable: variable,
value: value,
);
} else { } else {
bindings.setString(_configPointer, variable, value); bindings.setString(
configPointer: _configPointer,
variable: variable,
value: value,
);
} }
} }
@ -109,14 +125,19 @@ class Config with IterableMixin<ConfigEntry> {
/// (usually the local one). /// (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void delete(String variable) => bindings.delete(_configPointer, variable); void delete(String variable) =>
bindings.delete(configPointer: _configPointer, variable: variable);
/// Returns list of values for multivar [variable] /// Returns list of values for multivar [variable]
/// ///
/// If [regexp] is present, then the iterator will only iterate over all /// If [regexp] is present, then the iterator will only iterate over all
/// values which match the pattern. /// values which match the pattern.
List<String> multivar(String variable, {String? regexp}) { List<String> multivar({required String variable, String? regexp}) {
return bindings.multivarValues(_configPointer, variable, regexp); return bindings.multivarValues(
configPointer: _configPointer,
variable: variable,
regexp: regexp,
);
} }
/// Sets the [value] of a multivar [variable] in the config file with the /// Sets the [value] of a multivar [variable] in the config file with the
@ -124,8 +145,17 @@ class Config with IterableMixin<ConfigEntry> {
/// ///
/// The [regexp] is applied case-sensitively on the value. /// The [regexp] is applied case-sensitively on the value.
/// Empty [regexp] sets [value] for all values of a multivar [variable]. /// Empty [regexp] sets [value] for all values of a multivar [variable].
void setMultivar(String variable, String regexp, String value) { void setMultivar({
bindings.setMultivar(_configPointer, variable, regexp, value); required String variable,
required String regexp,
required String value,
}) {
bindings.setMultivar(
configPointer: _configPointer,
variable: variable,
regexp: regexp,
value: value,
);
} }
/// Deletes one or several values from a multivar [variable] in the config file /// Deletes one or several values from a multivar [variable] in the config file
@ -133,8 +163,12 @@ class Config with IterableMixin<ConfigEntry> {
/// ///
/// The [regexp] is applied case-sensitively on the value. /// The [regexp] is applied case-sensitively on the value.
/// Empty [regexp] deletes all values of a multivar [variable]. /// Empty [regexp] deletes all values of a multivar [variable].
void deleteMultivar(String variable, String regexp) { void deleteMultivar({required String variable, required String regexp}) {
bindings.deleteMultivar(_configPointer, variable, regexp); bindings.deleteMultivar(
configPointer: _configPointer,
variable: variable,
regexp: regexp,
);
} }
/// Releases memory allocated for config object. /// Releases memory allocated for config object.

View file

@ -33,7 +33,10 @@ class Diff {
final length = bindings.length(_diffPointer); final length = bindings.length(_diffPointer);
var deltas = <DiffDelta>[]; var deltas = <DiffDelta>[];
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
deltas.add(DiffDelta(bindings.getDeltaByIndex(_diffPointer, i))); deltas.add(DiffDelta(bindings.getDeltaByIndex(
diffPointer: _diffPointer,
index: i,
)));
} }
return deltas; return deltas;
} }
@ -43,7 +46,7 @@ class Diff {
final length = bindings.length(_diffPointer); final length = bindings.length(_diffPointer);
var patches = <Patch>[]; var patches = <Patch>[];
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
patches.add(Patch.fromDiff(this, i)); patches.add(Patch.fromDiff(diff: this, index: i));
} }
return patches; return patches;
} }
@ -54,8 +57,11 @@ class Diff {
var buffer = calloc<git_buf>(sizeOf<git_buf>()); var buffer = calloc<git_buf>(sizeOf<git_buf>());
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
final patch = Patch.fromDiff(this, i); final patch = Patch.fromDiff(diff: this, index: i);
buffer = bindings.addToBuf(patch.pointer, buffer); buffer = bindings.addToBuf(
patchPointer: patch.pointer,
bufferPointer: buffer,
);
patch.free(); patch.free();
} }
@ -70,7 +76,12 @@ class Diff {
DiffStats get stats => DiffStats(bindings.stats(_diffPointer)); DiffStats get stats => DiffStats(bindings.stats(_diffPointer));
/// Merges one diff into another. /// Merges one diff into another.
void merge(Diff diff) => bindings.merge(_diffPointer, diff.pointer); void merge(Diff diff) {
bindings.merge(
ontoPointer: _diffPointer,
fromPointer: diff.pointer,
);
}
/// Transforms a diff marking file renames, copies, etc. /// Transforms a diff marking file renames, copies, etc.
/// ///
@ -91,13 +102,13 @@ class Diff {
flags.fold(0, (previousValue, e) => previousValue | e.value); flags.fold(0, (previousValue, e) => previousValue | e.value);
bindings.findSimilar( bindings.findSimilar(
_diffPointer, diffPointer: _diffPointer,
flagsInt, flags: flagsInt,
renameThreshold, renameThreshold: renameThreshold,
copyThreshold, copyThreshold: copyThreshold,
renameFromRewriteThreshold, renameFromRewriteThreshold: renameFromRewriteThreshold,
breakRewriteThreshold, breakRewriteThreshold: breakRewriteThreshold,
renameLimit, renameLimit: renameLimit,
); );
} }
@ -240,10 +251,15 @@ class DiffStats {
/// Width for output only affects formatting of [GitDiffStats.full]. /// Width for output only affects formatting of [GitDiffStats.full].
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
String print(Set<GitDiffStats> format, int width) { String print({required Set<GitDiffStats> format, required int width}) {
final int formatInt = final int formatInt =
format.fold(0, (previousValue, e) => previousValue | e.value); format.fold(0, (previousValue, e) => previousValue | e.value);
return bindings.statsPrint(_diffStatsPointer, formatInt, width);
return bindings.statsPrint(
statsPointer: _diffStatsPointer,
format: formatInt,
width: width,
);
} }
/// Releases memory allocated for diff stats object. /// Releases memory allocated for diff stats object.
@ -299,7 +315,11 @@ class DiffHunk {
List<DiffLine> get lines { List<DiffLine> get lines {
var lines = <DiffLine>[]; var lines = <DiffLine>[];
for (var i = 0; i < linesCount; i++) { for (var i = 0; i < linesCount; i++) {
lines.add(DiffLine(patch_bindings.lines(_patchPointer, index, i))); lines.add(DiffLine(patch_bindings.lines(
patchPointer: _patchPointer,
hunkIndex: index,
lineOfHunk: i,
)));
} }
return lines; return lines;
} }

View file

@ -27,14 +27,26 @@ class Index with IterableMixin<IndexEntry> {
/// Throws error if position is out of bounds or entry isn't found at path. /// Throws error if position is out of bounds or entry isn't found at path.
IndexEntry operator [](Object value) { IndexEntry operator [](Object value) {
if (value is int) { if (value is int) {
return IndexEntry(bindings.getByIndex(_indexPointer, value)); return IndexEntry(bindings.getByIndex(
indexPointer: _indexPointer,
position: value,
));
} else { } else {
return IndexEntry(bindings.getByPath(_indexPointer, value as String, 0)); return IndexEntry(bindings.getByPath(
indexPointer: _indexPointer,
path: value as String,
stage: 0,
));
} }
} }
/// Checks whether entry at provided [path] is in the git index or not. /// Checks whether entry at provided [path] is in the git index or not.
bool find(String path) => bindings.find(_indexPointer, path); bool find(String path) {
return bindings.find(
indexPointer: _indexPointer,
path: path,
);
}
/// Checks if the index contains entries representing file conflicts. /// Checks if the index contains entries representing file conflicts.
bool get hasConflicts => bindings.hasConflicts(_indexPointer); bool get hasConflicts => bindings.hasConflicts(_indexPointer);
@ -93,9 +105,12 @@ class Index with IterableMixin<IndexEntry> {
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void add(Object entry) { void add(Object entry) {
if (entry is IndexEntry) { if (entry is IndexEntry) {
bindings.add(_indexPointer, entry._indexEntryPointer); bindings.add(
indexPointer: _indexPointer,
sourceEntryPointer: entry._indexEntryPointer,
);
} else { } else {
bindings.addByPath(_indexPointer, entry as String); bindings.addByPath(indexPointer: _indexPointer, path: entry as String);
} }
} }
@ -109,7 +124,7 @@ class Index with IterableMixin<IndexEntry> {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void addAll(List<String> pathspec) { void addAll(List<String> pathspec) {
bindings.addAll(_indexPointer, pathspec); bindings.addAll(indexPointer: _indexPointer, pathspec: pathspec);
} }
/// Updates the contents of an existing index object in memory by reading from the hard disk. /// Updates the contents of an existing index object in memory by reading from the hard disk.
@ -124,7 +139,8 @@ class Index with IterableMixin<IndexEntry> {
/// are discarded. /// are discarded.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void read({bool force = true}) => bindings.read(_indexPointer, force); void read({bool force = true}) =>
bindings.read(indexPointer: _indexPointer, force: force);
/// Updates the contents of an existing index object in memory by reading from the /// Updates the contents of an existing index object in memory by reading from the
/// specified tree. /// specified tree.
@ -133,18 +149,18 @@ class Index with IterableMixin<IndexEntry> {
if (target is Oid) { if (target is Oid) {
final repo = Repository(bindings.owner(_indexPointer)); final repo = Repository(bindings.owner(_indexPointer));
tree = Tree.lookup(repo, target.sha); tree = Tree.lookup(repo: repo, sha: target.sha);
} else if (target is Tree) { } else if (target is Tree) {
tree = target; tree = target;
} else if (target is String) { } else if (target is String) {
final repo = Repository(bindings.owner(_indexPointer)); final repo = Repository(bindings.owner(_indexPointer));
tree = Tree.lookup(repo, target); tree = Tree.lookup(repo: repo, sha: target);
} else { } else {
throw ArgumentError.value( throw ArgumentError.value(
'$target should be either Oid object, SHA hex string or Tree object'); '$target should be either Oid object, SHA hex string or Tree object');
} }
bindings.readTree(_indexPointer, tree.pointer); bindings.readTree(indexPointer: _indexPointer, treePointer: tree.pointer);
tree.free(); tree.free();
} }
@ -166,7 +182,10 @@ class Index with IterableMixin<IndexEntry> {
if (repo == null) { if (repo == null) {
return Oid(bindings.writeTree(_indexPointer)); return Oid(bindings.writeTree(_indexPointer));
} else { } else {
return Oid(bindings.writeTreeTo(_indexPointer, repo.pointer)); return Oid(bindings.writeTreeTo(
indexPointer: _indexPointer,
repoPointer: repo.pointer,
));
} }
} }
@ -174,12 +193,13 @@ class Index with IterableMixin<IndexEntry> {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void remove(String path, [int stage = 0]) => void remove(String path, [int stage = 0]) =>
bindings.remove(_indexPointer, path, stage); bindings.remove(indexPointer: _indexPointer, path: path, stage: stage);
/// Removes all matching index entries. /// Removes all matching index entries.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void removeAll(List<String> path) => bindings.removeAll(_indexPointer, path); void removeAll(List<String> path) =>
bindings.removeAll(indexPointer: _indexPointer, pathspec: path);
/// Creates a diff between the repository index and the workdir directory. /// Creates a diff between the repository index and the workdir directory.
/// ///
@ -194,11 +214,11 @@ class Index with IterableMixin<IndexEntry> {
flags.fold(0, (previousValue, e) => previousValue | e.value); flags.fold(0, (previousValue, e) => previousValue | e.value);
return Diff(diff_bindings.indexToWorkdir( return Diff(diff_bindings.indexToWorkdir(
repo, repoPointer: repo,
_indexPointer, indexPointer: _indexPointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} }
@ -216,12 +236,12 @@ class Index with IterableMixin<IndexEntry> {
flags.fold(0, (previousValue, e) => previousValue | e.value); flags.fold(0, (previousValue, e) => previousValue | e.value);
return Diff(diff_bindings.treeToIndex( return Diff(diff_bindings.treeToIndex(
repo, repoPointer: repo,
tree.pointer, treePointer: tree.pointer,
_indexPointer, indexPointer: _indexPointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} }
@ -299,7 +319,8 @@ class ConflictEntry {
/// Removes the index entry that represent a conflict of a single file. /// Removes the index entry that represent a conflict of a single file.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void remove() => bindings.conflictRemove(_indexPointer, _path); void remove() =>
bindings.conflictRemove(indexPointer: _indexPointer, path: _path);
@override @override
String toString() => String toString() =>
@ -324,7 +345,10 @@ class _IndexIterator implements Iterator<IndexEntry> {
if (_index == count) { if (_index == count) {
return false; return false;
} else { } else {
_currentEntry = IndexEntry(bindings.getByIndex(_indexPointer, _index)); _currentEntry = IndexEntry(bindings.getByIndex(
indexPointer: _indexPointer,
position: _index,
));
_index++; _index++;
return true; return true;
} }

View file

@ -15,11 +15,15 @@ class Odb {
/// Determine if an object can be found in the object database by an abbreviated object ID. /// Determine if an object can be found in the object database by an abbreviated object ID.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> existsPrefix( Pointer<git_oid> existsPrefix({
Pointer<git_oid> shortOid, required Pointer<git_oid> shortOidPointer,
int len, required int length,
) { }) {
return bindings.existsPrefix(_odbPointer, shortOid, len); return bindings.existsPrefix(
odbPointer: _odbPointer,
shortOidPointer: shortOidPointer,
length: length,
);
} }
/// Releases memory allocated for odb object. /// Releases memory allocated for odb object.

View file

@ -10,19 +10,22 @@ class Oid {
Oid(this._oidPointer); Oid(this._oidPointer);
/// Initializes a new instance of [Oid] class by determining if an object can be found /// Initializes a new instance of [Oid] class by determining if an object can be found
/// in the ODB of [repository] with provided hexadecimal [sha] string that is 40 characters /// in the ODB of [repo]sitory with provided hexadecimal [sha] string that is 40 characters
/// long or shorter. /// long or shorter.
/// ///
/// Throws [ArgumentError] if provided [sha] hex string is not valid. /// Throws [ArgumentError] if provided [sha] hex string is not valid.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Oid.fromSHA(Repository repository, String sha) { Oid.fromSHA({required Repository repo, required String sha}) {
if (isValidShaHex(sha)) { if (isValidShaHex(sha)) {
if (sha.length == 40) { if (sha.length == 40) {
_oidPointer = bindings.fromSHA(sha); _oidPointer = bindings.fromSHA(sha);
} else { } else {
final odb = repository.odb; final odb = repo.odb;
_oidPointer = odb.existsPrefix(bindings.fromStrN(sha), sha.length); _oidPointer = odb.existsPrefix(
shortOidPointer: bindings.fromStrN(sha),
length: sha.length,
);
odb.free(); odb.free();
} }
} else { } else {
@ -46,27 +49,32 @@ class Oid {
@override @override
bool operator ==(other) { bool operator ==(other) {
return (other is Oid) && return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == 0); (bindings.compare(aPointer: _oidPointer, bPointer: other._oidPointer) ==
0);
} }
bool operator <(other) { bool operator <(other) {
return (other is Oid) && return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == -1); (bindings.compare(aPointer: _oidPointer, bPointer: other._oidPointer) ==
-1);
} }
bool operator <=(other) { bool operator <=(other) {
return (other is Oid) && return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == -1); (bindings.compare(aPointer: _oidPointer, bPointer: other._oidPointer) ==
-1);
} }
bool operator >(other) { bool operator >(other) {
return (other is Oid) && return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == 1); (bindings.compare(aPointer: _oidPointer, bPointer: other._oidPointer) ==
1);
} }
bool operator >=(other) { bool operator >=(other) {
return (other is Oid) && return (other is Oid) &&
(bindings.compare(_oidPointer, other._oidPointer) == 1); (bindings.compare(aPointer: _oidPointer, bPointer: other._oidPointer) ==
1);
} }
@override @override

View file

@ -40,36 +40,36 @@ class Patch {
if (a is Blob || a == null) { if (a is Blob || a == null) {
if (b is Blob) { if (b is Blob) {
result = bindings.fromBlobs( result = bindings.fromBlobs(
a?.pointer, oldBlobPointer: a?.pointer,
aPath, oldAsPath: aPath,
b.pointer, newBlobPointer: b.pointer,
bPath, newAsPath: bPath,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
); );
} else if (b is String || b == null) { } else if (b is String || b == null) {
result = bindings.fromBlobAndBuffer( result = bindings.fromBlobAndBuffer(
a?.pointer, oldBlobPointer: a?.pointer,
aPath, oldAsPath: aPath,
b, buffer: b,
bPath, bufferAsPath: bPath,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
); );
} else { } else {
throw ArgumentError('Provided argument(s) is not Blob or String'); throw ArgumentError('Provided argument(s) is not Blob or String');
} }
} else if ((a is String || a == null) && (b is String || b == null)) { } else if ((a is String || a == null) && (b is String || b == null)) {
result = bindings.fromBuffers( result = bindings.fromBuffers(
a, oldBuffer: a,
aPath, oldAsPath: aPath,
b, newBuffer: b,
bPath, newAsPath: bPath,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
); );
} else { } else {
throw ArgumentError('Provided argument(s) is not Blob or String'); throw ArgumentError('Provided argument(s) is not Blob or String');
@ -85,10 +85,10 @@ class Patch {
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Patch.fromDiff(Diff diff, int index) { Patch.fromDiff({required Diff diff, required int index}) {
libgit2.git_libgit2_init(); libgit2.git_libgit2_init();
_patchPointer = bindings.fromDiff(diff.pointer, index); _patchPointer = bindings.fromDiff(diffPointer: diff.pointer, index: index);
} }
late final Pointer<git_patch> _patchPointer; late final Pointer<git_patch> _patchPointer;
@ -118,10 +118,10 @@ class Patch {
bool includeFileHeaders = false, bool includeFileHeaders = false,
}) { }) {
return bindings.size( return bindings.size(
_patchPointer, patchPointer: _patchPointer,
includeContext, includeContext: includeContext,
includeHunkHeaders, includeHunkHeaders: includeHunkHeaders,
includeFileHeaders, includeFileHeaders: includeFileHeaders,
); );
} }
@ -136,7 +136,7 @@ class Patch {
final hunks = <DiffHunk>[]; final hunks = <DiffHunk>[];
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
final hunk = bindings.hunk(_patchPointer, i); final hunk = bindings.hunk(patchPointer: _patchPointer, hunkIndex: i);
hunks.add(DiffHunk(_patchPointer, hunk['hunk'], hunk['linesN'], i)); hunks.add(DiffHunk(_patchPointer, hunk['hunk'], hunk['linesN'], i));
} }

View file

@ -40,7 +40,7 @@ class References {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Reference operator [](String name) { Reference operator [](String name) {
return Reference(bindings.lookup(_repoPointer, name)); return Reference(bindings.lookup(repoPointer: _repoPointer, name: name));
} }
/// Creates a new reference. /// Creates a new reference.
@ -74,7 +74,7 @@ class References {
isDirect = true; isDirect = true;
} else if (isValidShaHex(target as String)) { } else if (isValidShaHex(target as String)) {
final repo = Repository(_repoPointer); final repo = Repository(_repoPointer);
oid = Oid.fromSHA(repo, target); oid = Oid.fromSHA(repo: repo, sha: target);
isDirect = true; isDirect = true;
} else { } else {
isDirect = false; isDirect = false;
@ -82,19 +82,19 @@ class References {
if (isDirect) { if (isDirect) {
return Reference(bindings.createDirect( return Reference(bindings.createDirect(
_repoPointer, repoPointer: _repoPointer,
name, name: name,
oid.pointer, oidPointer: oid.pointer,
force, force: force,
logMessage, logMessage: logMessage,
)); ));
} else { } else {
return Reference(bindings.createSymbolic( return Reference(bindings.createSymbolic(
_repoPointer, repoPointer: _repoPointer,
name, name: name,
target as String, target: target as String,
force, force: force,
logMessage, logMessage: logMessage,
)); ));
} }
} }
@ -148,23 +148,31 @@ class Reference {
/// The new reference will be written to disk, overwriting the given reference. /// The new reference will be written to disk, overwriting the given reference.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setTarget(String target, [String? logMessage]) { void setTarget({required String target, String? logMessage}) {
late final Oid oid; late final Oid oid;
final owner = bindings.owner(_refPointer); final owner = bindings.owner(_refPointer);
if (isValidShaHex(target)) { if (isValidShaHex(target)) {
final repo = Repository(owner); final repo = Repository(owner);
oid = Oid.fromSHA(repo, target); oid = Oid.fromSHA(repo: repo, sha: target);
} else { } else {
final ref = Reference(bindings.lookup(owner, target)); final ref = Reference(bindings.lookup(repoPointer: owner, name: target));
oid = ref.target; oid = ref.target;
ref.free(); ref.free();
} }
if (type == ReferenceType.direct) { if (type == ReferenceType.direct) {
_refPointer = bindings.setTarget(_refPointer, oid.pointer, logMessage); _refPointer = bindings.setTarget(
refPointer: _refPointer,
oidPointer: oid.pointer,
logMessage: logMessage,
);
} else { } else {
_refPointer = bindings.setTargetSymbolic(_refPointer, target, logMessage); _refPointer = bindings.setTargetSymbolic(
refPointer: _refPointer,
target: target,
logMessage: logMessage,
);
} }
} }
@ -183,7 +191,7 @@ class Reference {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Object peel([GitObject type = GitObject.any]) { Object peel([GitObject type = GitObject.any]) {
final object = bindings.peel(_refPointer, type.value); final object = bindings.peel(refPointer: _refPointer, type: type.value);
final objectType = object_bindings.type(object); final objectType = object_bindings.type(object);
if (objectType == GitObject.commit.value) { if (objectType == GitObject.commit.value) {
@ -219,8 +227,17 @@ class Reference {
/// the repository. We only rename the reflog if it exists. /// the repository. We only rename the reflog if it exists.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void rename(String newName, {bool force = false, String? logMessage}) { void rename({
_refPointer = bindings.rename(_refPointer, newName, force, logMessage); required String newName,
bool force = false,
String? logMessage,
}) {
_refPointer = bindings.rename(
refPointer: _refPointer,
newName: newName,
force: force,
logMessage: logMessage,
);
} }
/// Checks if a reflog exists for the specified reference [name]. /// Checks if a reflog exists for the specified reference [name].
@ -228,7 +245,7 @@ class Reference {
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
bool get hasLog { bool get hasLog {
final owner = bindings.owner(_refPointer); final owner = bindings.owner(_refPointer);
return bindings.hasLog(owner, name); return bindings.hasLog(repoPointer: owner, name: name);
} }
/// Returns a [RefLog] object. /// Returns a [RefLog] object.
@ -262,7 +279,10 @@ class Reference {
@override @override
bool operator ==(other) { bool operator ==(other) {
return (other is Reference) && return (other is Reference) &&
bindings.compare(_refPointer, other._refPointer); bindings.compare(
ref1Pointer: _refPointer,
ref2Pointer: other._refPointer,
);
} }
@override @override

View file

@ -12,7 +12,7 @@ class RefLog with IterableMixin<RefLogEntry> {
RefLog(Reference ref) { RefLog(Reference ref) {
final repo = ref.owner; final repo = ref.owner;
final name = ref.name; final name = ref.name;
_reflogPointer = bindings.read(repo.pointer, name); _reflogPointer = bindings.read(repoPointer: repo.pointer, name: name);
} }
/// Pointer to memory address for allocated reflog object. /// Pointer to memory address for allocated reflog object.
@ -23,7 +23,10 @@ class RefLog with IterableMixin<RefLogEntry> {
/// Requesting the reflog entry with an index of 0 (zero) will return /// Requesting the reflog entry with an index of 0 (zero) will return
/// the most recently created entry. /// the most recently created entry.
RefLogEntry operator [](int index) { RefLogEntry operator [](int index) {
return RefLogEntry(bindings.getByIndex(_reflogPointer, index)); return RefLogEntry(bindings.getByIndex(
reflogPointer: _reflogPointer,
index: index,
));
} }
/// Releases memory allocated for reflog object. /// Releases memory allocated for reflog object.
@ -70,7 +73,10 @@ class _RefLogIterator implements Iterator<RefLogEntry> {
if (_index == _count) { if (_index == _count) {
return false; return false;
} else { } else {
_currentEntry = RefLogEntry(bindings.getByIndex(_reflogPointer, _index)); _currentEntry = RefLogEntry(bindings.getByIndex(
reflogPointer: _reflogPointer,
index: _index,
));
_index++; _index++;
return true; return true;
} }

View file

@ -33,20 +33,38 @@ class Refspec {
} }
/// Checks if a refspec's source descriptor matches a reference. /// Checks if a refspec's source descriptor matches a reference.
bool matchesSource(String refname) => bool matchesSource(String refname) {
bindings.matchesSource(_refspecPointer, refname); return bindings.matchesSource(
refspecPointer: _refspecPointer,
refname: refname,
);
}
/// Checks if a refspec's destination descriptor matches a reference. /// Checks if a refspec's destination descriptor matches a reference.
bool matchesDestination(String refname) => bool matchesDestination(String refname) {
bindings.matchesDestination(_refspecPointer, refname); return bindings.matchesDestination(
refspecPointer: _refspecPointer,
refname: refname,
);
}
/// Transforms a reference to its target following the refspec's rules. /// Transforms a reference to its target following the refspec's rules.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
String transform(String name) => bindings.transform(_refspecPointer, name); String transform(String name) {
return bindings.transform(
refspecPointer: _refspecPointer,
name: name,
);
}
/// Transforms a target reference to its source reference following the refspec's rules. /// Transforms a target reference to its source reference following the refspec's rules.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
String rTransform(String name) => bindings.rTransform(_refspecPointer, name); String rTransform(String name) {
return bindings.rTransform(
refspecPointer: _refspecPointer,
name: name,
);
}
} }

View file

@ -33,7 +33,7 @@ class Remotes {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Remote operator [](String name) { Remote operator [](String name) {
return Remote(bindings.lookup(_repoPointer, name)); return Remote(bindings.lookup(repoPointer: _repoPointer, name: name));
} }
/// Adds a remote to the repository's configuration with the default [fetch] /// Adds a remote to the repository's configuration with the default [fetch]
@ -46,13 +46,17 @@ class Remotes {
String? fetch, String? fetch,
}) { }) {
if (fetch == null) { if (fetch == null) {
return Remote(bindings.create(_repoPointer, name, url)); return Remote(bindings.create(
repoPointer: _repoPointer,
name: name,
url: url,
));
} else { } else {
return Remote(bindings.createWithFetchSpec( return Remote(bindings.createWithFetchSpec(
_repoPointer, repoPointer: _repoPointer,
name, name: name,
url, url: url,
fetch, fetch: fetch,
)); ));
} }
} }
@ -62,7 +66,9 @@ class Remotes {
/// All remote-tracking branches and configuration settings for the remote will be removed. /// All remote-tracking branches and configuration settings for the remote will be removed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void delete(String name) => bindings.delete(_repoPointer, name); void delete(String name) {
bindings.delete(repoPointer: _repoPointer, name: name);
}
/// Give the remote a new name. /// Give the remote a new name.
/// ///
@ -76,8 +82,13 @@ class Remotes {
/// their list of refspecs. /// their list of refspecs.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<String> rename(String name, String newName) => List<String> rename({required String remote, required String newName}) {
bindings.rename(_repoPointer, name, newName); return bindings.rename(
repoPointer: _repoPointer,
name: remote,
newName: newName,
);
}
/// Sets the remote's url in the configuration. /// Sets the remote's url in the configuration.
/// ///
@ -85,8 +96,13 @@ class Remotes {
/// case of a single-url remote and will otherwise return an error. /// case of a single-url remote and will otherwise return an error.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setUrl(String remote, String url) => void setUrl({required String remote, required String url}) {
bindings.setUrl(_repoPointer, remote, url); bindings.setUrl(
repoPointer: _repoPointer,
remote: remote,
url: url,
);
}
/// Sets the remote's url for pushing in the configuration. /// Sets the remote's url for pushing in the configuration.
/// ///
@ -94,24 +110,39 @@ class Remotes {
/// case of a single-url remote and will otherwise return an error. /// case of a single-url remote and will otherwise return an error.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setPushUrl(String remote, String url) => void setPushUrl({required String remote, required String url}) {
bindings.setPushUrl(_repoPointer, remote, url); bindings.setPushUrl(
repoPointer: _repoPointer,
remote: remote,
url: url,
);
}
/// Adds a fetch refspec to the remote's configuration. /// Adds a fetch refspec to the remote's configuration.
/// ///
/// No loaded remote instances will be affected. /// No loaded remote instances will be affected.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void addFetch(String remote, String refspec) => void addFetch({required String remote, required String refspec}) {
bindings.addFetch(_repoPointer, remote, refspec); bindings.addFetch(
repoPointer: _repoPointer,
remote: remote,
refspec: refspec,
);
}
/// Adds a push refspec to the remote's configuration. /// Adds a push refspec to the remote's configuration.
/// ///
/// No loaded remote instances will be affected. /// No loaded remote instances will be affected.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void addPush(String remote, String refspec) => void addPush({required String remote, required String refspec}) {
bindings.addPush(_repoPointer, remote, refspec); bindings.addPush(
repoPointer: _repoPointer,
remote: remote,
refspec: refspec,
);
}
} }
class Remote { class Remote {
@ -139,8 +170,12 @@ class Remote {
int get refspecCount => bindings.refspecCount(_remotePointer); int get refspecCount => bindings.refspecCount(_remotePointer);
/// Returns a [Refspec] object from the remote at provided position. /// Returns a [Refspec] object from the remote at provided position.
Refspec getRefspec(int index) => Refspec getRefspec(int index) {
Refspec(bindings.getRefspec(_remotePointer, index)); return Refspec(bindings.getRefspec(
remotePointer: _remotePointer,
position: index,
));
}
/// Returns the remote's list of fetch refspecs. /// Returns the remote's list of fetch refspecs.
List<String> get fetchRefspecs => bindings.fetchRefspecs(_remotePointer); List<String> get fetchRefspecs => bindings.fetchRefspecs(_remotePointer);
@ -159,10 +194,10 @@ class Remote {
Callbacks callbacks = const Callbacks(), Callbacks callbacks = const Callbacks(),
}) { }) {
bindings.connect( bindings.connect(
_remotePointer, remotePointer: _remotePointer,
GitDirection.fetch.value, direction: GitDirection.fetch.value,
proxy, callbacks: callbacks,
callbacks, proxyOption: proxy,
); );
final result = bindings.lsRemotes(_remotePointer); final result = bindings.lsRemotes(_remotePointer);
bindings.disconnect(_remotePointer); bindings.disconnect(_remotePointer);
@ -185,12 +220,12 @@ class Remote {
Callbacks callbacks = const Callbacks(), Callbacks callbacks = const Callbacks(),
}) { }) {
bindings.fetch( bindings.fetch(
_remotePointer, remotePointer: _remotePointer,
refspecs, refspecs: refspecs,
reflogMessage, prune: prune.value,
prune.value, callbacks: callbacks,
proxy, reflogMessage: reflogMessage,
callbacks, proxyOption: proxy,
); );
return TransferProgress(bindings.stats(_remotePointer)); return TransferProgress(bindings.stats(_remotePointer));
} }
@ -204,18 +239,22 @@ class Remote {
Callbacks callbacks = const Callbacks(), Callbacks callbacks = const Callbacks(),
}) { }) {
bindings.push( bindings.push(
_remotePointer, remotePointer: _remotePointer,
refspecs, refspecs: refspecs,
proxy, callbacks: callbacks,
callbacks, proxyOption: proxy,
); );
} }
/// Prunes tracking refs that are no longer present on remote. /// Prunes tracking refs that are no longer present on remote.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void prune([Callbacks callbacks = const Callbacks()]) => void prune([Callbacks callbacks = const Callbacks()]) {
bindings.prune(_remotePointer, callbacks); bindings.prune(
remotePointer: _remotePointer,
callbacks: callbacks,
);
}
/// Releases memory allocated for remote object. /// Releases memory allocated for remote object.
void free() => bindings.free(_remotePointer); void free() => bindings.free(_remotePointer);

View file

@ -61,14 +61,14 @@ class Repository {
} }
_repoPointer = bindings.init( _repoPointer = bindings.init(
path, path: path,
flagsInt, flags: flagsInt,
mode, mode: mode,
workdirPath, workdirPath: workdirPath,
description, description: description,
templatePath, templatePath: templatePath,
initialHead, initialHead: initialHead,
originUrl, originUrl: originUrl,
); );
} }
@ -113,13 +113,13 @@ class Repository {
libgit2.git_libgit2_init(); libgit2.git_libgit2_init();
_repoPointer = bindings.clone( _repoPointer = bindings.clone(
url, url: url,
localPath, localPath: localPath,
bare, bare: bare,
remote, remote: remote,
repository, repository: repository,
checkoutBranch, checkoutBranch: checkoutBranch,
callbacks, callbacks: callbacks,
); );
} }
@ -135,8 +135,11 @@ 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({required String startPath, String? ceilingDirs}) {
return bindings.discover(startPath, ceilingDirs); return bindings.discover(
startPath: startPath,
ceilingDirs: ceilingDirs,
);
} }
/// Returns path to the `.git` folder for normal repositories /// Returns path to the `.git` folder for normal repositories
@ -167,7 +170,10 @@ class Repository {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setNamespace(String? namespace) { void setNamespace(String? namespace) {
bindings.setNamespace(_repoPointer, namespace); bindings.setNamespace(
repoPointer: _repoPointer,
namespace: namespace,
);
} }
/// Checks whether this repository is a bare repository or not. /// Checks whether this repository is a bare repository or not.
@ -206,10 +212,13 @@ class Repository {
late final Oid oid; late final Oid oid;
if (isValidShaHex(target)) { if (isValidShaHex(target)) {
oid = Oid.fromSHA(this, target); oid = Oid.fromSHA(repo: this, sha: target);
bindings.setHeadDetached(_repoPointer, oid.pointer); bindings.setHeadDetached(
repoPointer: _repoPointer,
commitishPointer: oid.pointer,
);
} else { } else {
bindings.setHead(_repoPointer, target); bindings.setHead(repoPointer: _repoPointer, refname: target);
} }
} }
@ -228,7 +237,11 @@ class Repository {
/// If both are set, this name and email will be used to write to the reflog. /// If both are set, this name and email will be used to write to the reflog.
/// Pass null to unset. When unset, the identity will be taken from the repository's configuration. /// Pass null to unset. When unset, the identity will be taken from the repository's configuration.
void setIdentity({required String? name, required String? email}) { void setIdentity({required String? name, required String? email}) {
bindings.setIdentity(_repoPointer, name, email); bindings.setIdentity(
repoPointer: _repoPointer,
name: name,
email: email,
);
} }
/// Returns the configured identity to use for reflogs. /// Returns the configured identity to use for reflogs.
@ -285,8 +298,12 @@ class Repository {
/// (checkout, status, index manipulation, etc). /// (checkout, status, index manipulation, etc).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setWorkdir(String path, [bool updateGitlink = false]) { void setWorkdir({required String path, bool updateGitlink = false}) {
bindings.setWorkdir(_repoPointer, path, updateGitlink); bindings.setWorkdir(
repoPointer: _repoPointer,
path: path,
updateGitlink: updateGitlink,
);
} }
/// Releases memory allocated for repository object. /// Releases memory allocated for repository object.
@ -345,11 +362,11 @@ class Repository {
/// ///
/// Throws [ArgumentError] if provided [sha] is not pointing to commit, tree, blob or tag. /// Throws [ArgumentError] if provided [sha] is not pointing to commit, tree, blob or tag.
Object operator [](String sha) { Object operator [](String sha) {
final oid = Oid.fromSHA(this, sha); final oid = Oid.fromSHA(repo: this, sha: sha);
final object = object_bindings.lookup( final object = object_bindings.lookup(
_repoPointer, repoPointer: _repoPointer,
oid.pointer, oidPointer: oid.pointer,
GitObject.any.value, type: GitObject.any.value,
); );
final type = object_bindings.type(object); final type = object_bindings.type(object);
@ -378,8 +395,11 @@ class Repository {
/// Returns the list of commits starting from provided [sha] hex string. /// Returns the list of commits starting from provided [sha] hex string.
/// ///
/// If [sorting] isn't provided default will be used (reverse chronological order, like in git). /// If [sorting] isn't provided default will be used (reverse chronological order, like in git).
List<Commit> log(String sha, [Set<GitSort> sorting = const {GitSort.none}]) { List<Commit> log({
final oid = Oid.fromSHA(this, sha); required String sha,
Set<GitSort> sorting = const {GitSort.none},
}) {
final oid = Oid.fromSHA(repo: this, sha: sha);
final walker = RevWalk(this); final walker = RevWalk(this);
walker.sorting(sorting); walker.sorting(sorting);
@ -398,7 +418,9 @@ class Repository {
/// The returned object should be released when no longer needed. /// The returned object should be released when no longer needed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Commit revParseSingle(String spec) => RevParse.single(this, spec); Commit revParseSingle(String spec) {
return RevParse.single(repo: this, spec: spec);
}
/// Creates new commit in the repository. /// Creates new commit in the repository.
/// ///
@ -440,7 +462,9 @@ class Repository {
/// The returned object and reference should be released when no longer needed. /// The returned object and reference should be released when no longer needed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
RevParse revParseExt(String spec) => RevParse.ext(this, spec); RevParse revParseExt(String spec) {
return RevParse.ext(repo: this, spec: spec);
}
/// Parses a revision string for from, to, and intent. /// Parses a revision string for from, to, and intent.
/// ///
@ -448,24 +472,32 @@ class Repository {
/// for information on the syntax accepted. /// for information on the syntax accepted.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
RevSpec revParse(String spec) => RevParse.range(this, spec); RevSpec revParse(String spec) {
return RevParse.range(repo: this, spec: spec);
}
/// Creates a new blob from a [content] string and writes it to ODB. /// Creates a new blob from a [content] string and writes it to ODB.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Oid createBlob(String content) => Blob.create(this, content); Oid createBlob(String content) => Blob.create(repo: this, content: content);
/// Creates a new blob from the file in working directory of a repository and writes /// Creates a new blob from the file in working directory of a repository and writes
/// it to the ODB. Provided [path] should be relative to the working directory. /// it to the ODB. Provided [path] should be relative to the working directory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Oid createBlobFromWorkdir(String relativePath) => Oid createBlobFromWorkdir(String relativePath) {
Blob.createFromWorkdir(this, relativePath); return Blob.createFromWorkdir(
repo: this,
relativePath: relativePath,
);
}
/// Creates a new blob from the file in filesystem and writes it to the ODB. /// Creates a new blob from the file in filesystem and writes it to the ODB.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Oid createBlobFromDisk(String path) => Blob.createFromDisk(this, path); Oid createBlobFromDisk(String path) {
return Blob.createFromDisk(repo: this, path: path);
}
/// Creates a new tag in the repository from provided Oid object. /// Creates a new tag in the repository from provided Oid object.
/// ///
@ -488,7 +520,7 @@ class Repository {
bool force = false, bool force = false,
}) { }) {
return Tag.create( return Tag.create(
repository: this, repo: this,
tagName: tagName, tagName: tagName,
target: target, target: target,
targetType: targetType, targetType: targetType,
@ -510,7 +542,11 @@ class Repository {
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
late String path; late String path;
final entry = status_bindings.getByIndex(list, i); final entry = status_bindings.getByIndex(
statuslistPointer: list,
index: i,
);
if (entry.ref.head_to_index != nullptr) { if (entry.ref.head_to_index != nullptr) {
path = entry.ref.head_to_index.ref.old_file.path path = entry.ref.head_to_index.ref.old_file.path
.cast<Utf8>() .cast<Utf8>()
@ -520,6 +556,7 @@ class Repository {
.cast<Utf8>() .cast<Utf8>()
.toDartString(); .toDartString();
} }
var statuses = <GitStatus>{}; var statuses = <GitStatus>{};
// Skipping GitStatus.current because entry that is in the list can't be without changes // Skipping GitStatus.current because entry that is in the list can't be without changes
// but `&` on `0` value falsly adds it to the set of flags // but `&` on `0` value falsly adds it to the set of flags
@ -545,9 +582,12 @@ class Repository {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Set<GitStatus> statusFile(String path) { Set<GitStatus> statusFile(String path) {
final statusInt = status_bindings.file(_repoPointer, path); final statusInt = status_bindings.file(
var statuses = <GitStatus>{}; repoPointer: _repoPointer,
path: path,
);
var statuses = <GitStatus>{};
if (statusInt == GitStatus.current.value) { if (statusInt == GitStatus.current.value) {
statuses.add(GitStatus.current); statuses.add(GitStatus.current);
} else { } else {
@ -565,13 +605,13 @@ class Repository {
/// Finds a merge base between two commits. /// Finds a merge base between two commits.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Oid mergeBase(String one, String two) { Oid mergeBase({required String a, required String b}) {
final oidOne = Oid.fromSHA(this, one); final oidA = Oid.fromSHA(repo: this, sha: a);
final oidTwo = Oid.fromSHA(this, two); final oidB = Oid.fromSHA(repo: this, sha: b);
return Oid(merge_bindings.mergeBase( return Oid(merge_bindings.mergeBase(
_repoPointer, repoPointer: _repoPointer,
oidOne.pointer, aPointer: oidA.pointer,
oidTwo.pointer, bPointer: oidB.pointer,
)); ));
} }
@ -582,20 +622,23 @@ class Repository {
/// respectively. /// respectively.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
List<Set<dynamic>> mergeAnalysis(Oid theirHead, [String ourRef = 'HEAD']) { List<Set<dynamic>> mergeAnalysis({
required Oid theirHead,
String ourRef = 'HEAD',
}) {
final ref = references[ourRef]; final ref = references[ourRef];
final head = commit_bindings.annotatedLookup( final head = commit_bindings.annotatedLookup(
_repoPointer, repoPointer: _repoPointer,
theirHead.pointer, oidPointer: theirHead.pointer,
); );
var result = <Set<dynamic>>[]; var result = <Set<dynamic>>[];
var analysisSet = <GitMergeAnalysis>{}; var analysisSet = <GitMergeAnalysis>{};
final analysisInt = merge_bindings.analysis( final analysisInt = merge_bindings.analysis(
_repoPointer, repoPointer: _repoPointer,
ref.pointer, ourRefPointer: ref.pointer,
head, theirHeadPointer: head,
1, theirHeadsLen: 1,
); );
for (var analysis in GitMergeAnalysis.values) { for (var analysis in GitMergeAnalysis.values) {
if (analysisInt[0] & analysis.value == analysis.value) { if (analysisInt[0] & analysis.value == analysis.value) {
@ -621,11 +664,15 @@ class Repository {
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void merge(Oid oid) { void merge(Oid oid) {
final theirHead = commit_bindings.annotatedLookup( final theirHead = commit_bindings.annotatedLookup(
_repoPointer, repoPointer: _repoPointer,
oid.pointer, oidPointer: oid.pointer,
); );
merge_bindings.merge(_repoPointer, theirHead, 1); merge_bindings.merge(
repoPointer: _repoPointer,
theirHeadsPointer: theirHead,
theirHeadsLen: 1,
);
commit_bindings.annotatedFree(theirHead.value); commit_bindings.annotatedFree(theirHead.value);
} }
@ -653,10 +700,10 @@ class Repository {
fileFlags.fold(0, (previousValue, e) => previousValue | e.value); fileFlags.fold(0, (previousValue, e) => previousValue | e.value);
final result = merge_bindings.mergeCommits( final result = merge_bindings.mergeCommits(
_repoPointer, repoPointer: _repoPointer,
ourCommit.pointer, ourCommitPointer: ourCommit.pointer,
theirCommit.pointer, theirCommitPointer: theirCommit.pointer,
opts, opts: opts,
); );
return Index(result); return Index(result);
@ -670,13 +717,16 @@ class Repository {
/// The returned index must be freed explicitly with `free()`. /// The returned index must be freed explicitly with `free()`.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Index revertCommit( Index revertCommit({
{required Commit revertCommit, required Commit ourCommit, mainline = 0}) { required Commit revertCommit,
required Commit ourCommit,
mainline = 0,
}) {
return Index(commit_bindings.revertCommit( return Index(commit_bindings.revertCommit(
_repoPointer, repoPointer: _repoPointer,
revertCommit.pointer, revertCommitPointer: revertCommit.pointer,
ourCommit.pointer, ourCommitPointer: ourCommit.pointer,
mainline, mainline: mainline,
)); ));
} }
@ -708,11 +758,11 @@ class Repository {
); );
final result = merge_bindings.mergeTrees( final result = merge_bindings.mergeTrees(
_repoPointer, repoPointer: _repoPointer,
ancestorTree.pointer, ancestorTreePointer: ancestorTree.pointer,
ourTree.pointer, ourTreePointer: ourTree.pointer,
theirTree.pointer, theirTreePointer: theirTree.pointer,
opts, opts: opts,
); );
return Index(result); return Index(result);
@ -725,8 +775,12 @@ class Repository {
/// prepare a commit. /// prepare a commit.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void cherryPick(Commit commit) => void cherryPick(Commit commit) {
merge_bindings.cherryPick(_repoPointer, commit.pointer); merge_bindings.cherryPick(
repoPointer: _repoPointer,
commitPointer: commit.pointer,
);
}
/// Checkouts the provided reference [refName] using the given strategy, and update the HEAD. /// Checkouts the provided reference [refName] using the given strategy, and update the HEAD.
/// ///
@ -752,14 +806,33 @@ class Repository {
strategy.fold(0, (previousValue, e) => previousValue | e.value); strategy.fold(0, (previousValue, e) => previousValue | e.value);
if (refName == null) { if (refName == null) {
checkout_bindings.index(_repoPointer, strat, directory, paths); checkout_bindings.index(
repoPointer: _repoPointer,
strategy: strat,
directory: directory,
paths: paths,
);
} else if (refName == 'HEAD') { } else if (refName == 'HEAD') {
checkout_bindings.head(_repoPointer, strat, directory, paths); checkout_bindings.head(
repoPointer: _repoPointer,
strategy: strat,
directory: directory,
paths: paths,
);
} else { } else {
final ref = references[refName]; final ref = references[refName];
final treeish = object_bindings.lookup( final treeish = object_bindings.lookup(
_repoPointer, ref.target.pointer, GitObject.any.value); repoPointer: _repoPointer,
checkout_bindings.tree(_repoPointer, treeish, strat, directory, paths); oidPointer: ref.target.pointer,
type: GitObject.any.value,
);
checkout_bindings.tree(
repoPointer: _repoPointer,
treeishPointer: treeish,
strategy: strat,
directory: directory,
paths: paths,
);
if (paths == null) { if (paths == null) {
setHead(refName); setHead(refName);
} }
@ -773,15 +846,20 @@ class Repository {
/// and working tree to match. /// and working tree to match.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void reset(String target, GitReset resetType) { void reset({required String target, required GitReset resetType}) {
final oid = Oid.fromSHA(this, target); final oid = Oid.fromSHA(repo: this, sha: target);
final object = object_bindings.lookup( final object = object_bindings.lookup(
_repoPointer, repoPointer: _repoPointer,
oid.pointer, oidPointer: oid.pointer,
GitObject.any.value, type: GitObject.any.value,
); );
reset_bindings.reset(_repoPointer, object, resetType.value, nullptr); reset_bindings.reset(
repoPointer: _repoPointer,
targetPointer: object,
resetType: resetType.value,
checkoutOptsPointer: nullptr,
);
object_bindings.free(object); object_bindings.free(object);
} }
@ -806,39 +884,39 @@ class Repository {
if (a is Tree && b is Tree) { if (a is Tree && b is Tree) {
return Diff(diff_bindings.treeToTree( return Diff(diff_bindings.treeToTree(
_repoPointer, repoPointer: _repoPointer,
a.pointer, oldTreePointer: a.pointer,
b.pointer, newTreePointer: b.pointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} else if (a is Tree && b == null) { } else if (a is Tree && b == null) {
if (cached) { if (cached) {
return Diff(diff_bindings.treeToIndex( return Diff(diff_bindings.treeToIndex(
_repoPointer, repoPointer: _repoPointer,
a.pointer, treePointer: a.pointer,
index.pointer, indexPointer: index.pointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} else { } else {
return Diff(diff_bindings.treeToWorkdir( return Diff(diff_bindings.treeToWorkdir(
_repoPointer, repoPointer: _repoPointer,
a.pointer, treePointer: a.pointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} }
} else if (a == null && b == null) { } else if (a == null && b == null) {
return Diff(diff_bindings.indexToWorkdir( return Diff(diff_bindings.indexToWorkdir(
_repoPointer, repoPointer: _repoPointer,
index.pointer, indexPointer: index.pointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} else { } else {
throw ArgumentError.notNull('a'); throw ArgumentError.notNull('a');
@ -865,19 +943,19 @@ class Repository {
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void apply(Diff diff) { void apply(Diff diff) {
diff_bindings.apply( diff_bindings.apply(
_repoPointer, repoPointer: _repoPointer,
diff.pointer, diffPointer: diff.pointer,
GitApplyLocation.workdir.value, location: GitApplyLocation.workdir.value,
); );
} }
/// Checks if the [diff] will apply to HEAD. /// Checks if the [diff] will apply to HEAD.
bool applies(Diff diff) { bool applies(Diff diff) {
return diff_bindings.apply( return diff_bindings.apply(
_repoPointer, repoPointer: _repoPointer,
diff.pointer, diffPointer: diff.pointer,
GitApplyLocation.index.value, location: GitApplyLocation.index.value,
true, check: true,
); );
} }
@ -897,10 +975,10 @@ class Repository {
if (includeIgnored) flags |= GitStash.includeIgnored.value; if (includeIgnored) flags |= GitStash.includeIgnored.value;
return Oid(stash_bindings.stash( return Oid(stash_bindings.stash(
_repoPointer, repoPointer: _repoPointer,
stasher.pointer, stasherPointer: stasher.pointer,
message, message: message,
flags, flags: flags,
)); ));
} }
@ -921,13 +999,25 @@ class Repository {
final int strat = final int strat =
strategy.fold(0, (previousValue, e) => previousValue | e.value); strategy.fold(0, (previousValue, e) => previousValue | e.value);
stash_bindings.apply(_repoPointer, index, flags, strat, directory, paths); stash_bindings.apply(
repoPointer: _repoPointer,
index: index,
flags: flags,
strategy: strat,
directory: directory,
paths: paths,
);
} }
/// Removes a single stashed state from the stash list. /// Removes a single stashed state from the stash list.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void stashDrop([int index = 0]) => stash_bindings.drop(_repoPointer, index); void stashDrop([int index = 0]) {
stash_bindings.drop(
repoPointer: _repoPointer,
index: index,
);
}
/// Applies a single stashed state from the stash list and remove it from the list if successful. /// Applies a single stashed state from the stash list and remove it from the list if successful.
/// ///
@ -946,7 +1036,14 @@ class Repository {
final int strat = final int strat =
strategy.fold(0, (previousValue, e) => previousValue | e.value); strategy.fold(0, (previousValue, e) => previousValue | e.value);
stash_bindings.pop(_repoPointer, index, flags, strat, directory, paths); stash_bindings.pop(
repoPointer: _repoPointer,
index: index,
flags: flags,
strategy: strat,
directory: directory,
paths: paths,
);
} }
/// Returns list of all the stashed states, first being the most recent. /// Returns list of all the stashed states, first being the most recent.

View file

@ -19,8 +19,11 @@ class RevParse {
/// The returned object and reference should be released when no longer needed. /// The returned object and reference should be released when no longer needed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
RevParse.ext(Repository repo, String spec) { RevParse.ext({required Repository repo, required String spec}) {
final pointers = bindings.revParseExt(repo.pointer, spec); final pointers = bindings.revParseExt(
repoPointer: repo.pointer,
spec: spec,
);
object = Commit(pointers[0].cast<git_commit>()); object = Commit(pointers[0].cast<git_commit>());
if (pointers.length == 2) { if (pointers.length == 2) {
reference = Reference(pointers[1].cast<git_reference>()); reference = Reference(pointers[1].cast<git_reference>());
@ -42,8 +45,13 @@ class RevParse {
/// The returned object should be released when no longer needed. /// The returned object should be released when no longer needed.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
static Commit single(Repository repo, String spec) { static Commit single({required Repository repo, required String spec}) {
return Commit(bindings.revParseSingle(repo.pointer, spec).cast()); return Commit(bindings
.revParseSingle(
repoPointer: repo.pointer,
spec: spec,
)
.cast());
} }
/// Parses a revision string for from, to, and intent. /// Parses a revision string for from, to, and intent.
@ -52,8 +60,11 @@ class RevParse {
/// for information on the syntax accepted. /// for information on the syntax accepted.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
static RevSpec range(Repository repo, String spec) { static RevSpec range({required Repository repo, required String spec}) {
return RevSpec(bindings.revParse(repo.pointer, spec)); return RevSpec(bindings.revParse(
repoPointer: repo.pointer,
spec: spec,
));
} }
} }

View file

@ -23,7 +23,10 @@ class RevWalk {
final repoPointer = bindings.repository(_revWalkPointer); final repoPointer = bindings.repository(_revWalkPointer);
var result = <Commit>[]; var result = <Commit>[];
final commits = bindings.walk(repoPointer, _revWalkPointer); final commits = bindings.walk(
repoPointer: repoPointer,
walkerPointer: _revWalkPointer,
);
for (var commit in commits) { for (var commit in commits) {
result.add(Commit(commit)); result.add(Commit(commit));
} }
@ -41,7 +44,7 @@ class RevWalk {
0, 0,
(previousValue, e) => previousValue | e.value, (previousValue, e) => previousValue | e.value,
); );
bindings.sorting(_revWalkPointer, sort); bindings.sorting(walkerPointer: _revWalkPointer, sortMode: sort);
} }
/// Adds a new root for the traversal. /// Adds a new root for the traversal.
@ -54,7 +57,12 @@ class RevWalk {
/// The given id must belong to a committish on the walked repository. /// The given id must belong to a committish on the walked repository.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void push(Oid oid) => bindings.push(_revWalkPointer, oid.pointer); void push(Oid oid) {
bindings.push(
walkerPointer: _revWalkPointer,
oidPointer: oid.pointer,
);
}
/// Marks a commit (and its ancestors) uninteresting for the output. /// Marks a commit (and its ancestors) uninteresting for the output.
/// ///
@ -63,7 +71,12 @@ class RevWalk {
/// The resolved commit and all its parents will be hidden from the output on the revision walk. /// The resolved commit and all its parents will be hidden from the output on the revision walk.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void hide(Oid oid) => bindings.hide(_revWalkPointer, oid.pointer); void hide(Oid oid) {
bindings.hide(
walkerPointer: _revWalkPointer,
oidPointer: oid.pointer,
);
}
/// Resets the revision walker for reuse. /// Resets the revision walker for reuse.
/// ///

View file

@ -27,9 +27,14 @@ class Signature {
libgit2.git_libgit2_init(); libgit2.git_libgit2_init();
if (time == null) { if (time == null) {
_signaturePointer = bindings.now(name, email); _signaturePointer = bindings.now(name: name, email: email);
} else { } else {
_signaturePointer = bindings.create(name, email, time, offset); _signaturePointer = bindings.create(
name: name,
email: email,
time: time,
offset: offset,
);
} }
} }

View file

@ -21,9 +21,12 @@ class Tag {
/// [Repository] object and [sha] hex string. /// [Repository] object and [sha] hex string.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Tag.lookup(Repository repo, String sha) { Tag.lookup({required Repository repo, required String sha}) {
final oid = Oid.fromSHA(repo, sha); final oid = Oid.fromSHA(repo: repo, sha: sha);
_tagPointer = bindings.lookup(repo.pointer, oid.pointer); _tagPointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
);
} }
late final Pointer<git_tag> _tagPointer; late final Pointer<git_tag> _tagPointer;
@ -44,7 +47,7 @@ class Tag {
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
static Oid create({ static Oid create({
required Repository repository, required Repository repo,
required String tagName, required String tagName,
required String target, required String target,
required GitObject targetType, required GitObject targetType,
@ -52,19 +55,19 @@ class Tag {
required String message, required String message,
bool force = false, bool force = false,
}) { }) {
final targetOid = Oid.fromSHA(repository, target); final targetOid = Oid.fromSHA(repo: repo, sha: target);
final object = object_bindings.lookup( final object = object_bindings.lookup(
repository.pointer, repoPointer: repo.pointer,
targetOid.pointer, oidPointer: targetOid.pointer,
targetType.value, type: targetType.value,
); );
final result = bindings.create( final result = bindings.create(
repository.pointer, repoPointer: repo.pointer,
tagName, tagName: tagName,
object, targetPointer: object,
tagger.pointer, taggerPointer: tagger.pointer,
message, message: message,
force, force: force,
); );
object_bindings.free(object); object_bindings.free(object);

View file

@ -19,9 +19,12 @@ class Tree {
/// [Repository] object and [sha] hex string. /// [Repository] object and [sha] hex string.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Tree.lookup(Repository repo, String sha) { Tree.lookup({required Repository repo, required String sha}) {
final oid = Oid.fromSHA(repo, sha); final oid = Oid.fromSHA(repo: repo, sha: sha);
_treePointer = bindings.lookup(repo.pointer, oid.pointer); _treePointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
);
} }
late final Pointer<git_tree> _treePointer; late final Pointer<git_tree> _treePointer;
@ -34,7 +37,10 @@ class Tree {
final entryCount = bindings.entryCount(_treePointer); final entryCount = bindings.entryCount(_treePointer);
var result = <TreeEntry>[]; var result = <TreeEntry>[];
for (var i = 0; i < entryCount; i++) { for (var i = 0; i < entryCount; i++) {
result.add(TreeEntry(bindings.getByIndex(_treePointer, i))); result.add(TreeEntry(bindings.getByIndex(
treePointer: _treePointer,
index: i,
)));
} }
return result; return result;
@ -49,11 +55,20 @@ class Tree {
/// If provided string [value] is a path to file, lookup is done by path. /// If provided string [value] is a path to file, lookup is done by path.
TreeEntry operator [](Object value) { TreeEntry operator [](Object value) {
if (value is int) { if (value is int) {
return TreeEntry(bindings.getByIndex(_treePointer, value)); return TreeEntry(bindings.getByIndex(
treePointer: _treePointer,
index: value,
));
} else if (value is String && value.contains('/')) { } else if (value is String && value.contains('/')) {
return TreeEntry(bindings.getByPath(_treePointer, value)); return TreeEntry(bindings.getByPath(
rootPointer: _treePointer,
path: value,
));
} else if (value is String) { } else if (value is String) {
return TreeEntry(bindings.getByName(_treePointer, value)); return TreeEntry(bindings.getByName(
treePointer: _treePointer,
filename: value,
));
} else { } else {
throw ArgumentError.value( throw ArgumentError.value(
'$value should be either index position, filename or path'); '$value should be either index position, filename or path');
@ -79,11 +94,11 @@ class Tree {
flags.fold(0, (previousValue, e) => previousValue | e.value); flags.fold(0, (previousValue, e) => previousValue | e.value);
return Diff(diff_bindings.treeToWorkdir( return Diff(diff_bindings.treeToWorkdir(
repo, repoPointer: repo,
_treePointer, treePointer: _treePointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} }
@ -101,12 +116,12 @@ class Tree {
flags.fold(0, (previousValue, e) => previousValue | e.value); flags.fold(0, (previousValue, e) => previousValue | e.value);
return Diff(diff_bindings.treeToIndex( return Diff(diff_bindings.treeToIndex(
repo, repoPointer: repo,
_treePointer, treePointer: _treePointer,
index.pointer, indexPointer: index.pointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} }
@ -124,12 +139,12 @@ class Tree {
flags.fold(0, (previousValue, e) => previousValue | e.value); flags.fold(0, (previousValue, e) => previousValue | e.value);
return Diff(diff_bindings.treeToTree( return Diff(diff_bindings.treeToTree(
repo, repoPointer: repo,
_treePointer, oldTreePointer: _treePointer,
tree.pointer, newTreePointer: tree.pointer,
flagsInt, flags: flagsInt,
contextLines, contextLines: contextLines,
interhunkLines, interhunkLines: interhunkLines,
)); ));
} }
@ -159,27 +174,42 @@ class TreeEntry {
@override @override
bool operator ==(other) { bool operator ==(other) {
return (other is TreeEntry) && return (other is TreeEntry) &&
(bindings.compare(_treeEntryPointer, other._treeEntryPointer) == 0); (bindings.compare(
aPointer: _treeEntryPointer,
bPointer: other._treeEntryPointer) ==
0);
} }
bool operator <(other) { bool operator <(other) {
return (other is TreeEntry) && return (other is TreeEntry) &&
(bindings.compare(_treeEntryPointer, other._treeEntryPointer) == -1); (bindings.compare(
aPointer: _treeEntryPointer,
bPointer: other._treeEntryPointer) ==
-1);
} }
bool operator <=(other) { bool operator <=(other) {
return (other is TreeEntry) && return (other is TreeEntry) &&
(bindings.compare(_treeEntryPointer, other._treeEntryPointer) == -1); (bindings.compare(
aPointer: _treeEntryPointer,
bPointer: other._treeEntryPointer) ==
-1);
} }
bool operator >(other) { bool operator >(other) {
return (other is TreeEntry) && return (other is TreeEntry) &&
(bindings.compare(_treeEntryPointer, other._treeEntryPointer) == 1); (bindings.compare(
aPointer: _treeEntryPointer,
bPointer: other._treeEntryPointer) ==
1);
} }
bool operator >=(other) { bool operator >=(other) {
return (other is TreeEntry) && return (other is TreeEntry) &&
(bindings.compare(_treeEntryPointer, other._treeEntryPointer) == 1); (bindings.compare(
aPointer: _treeEntryPointer,
bPointer: other._treeEntryPointer) ==
1);
} }
@override @override

View file

@ -13,10 +13,10 @@ class TreeBuilder {
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
TreeBuilder(Repository repo, [Tree? tree]) { TreeBuilder({required Repository repo, Tree? tree}) {
_treeBuilderPointer = bindings.create( _treeBuilderPointer = bindings.create(
repo.pointer, repoPointer: repo.pointer,
tree?.pointer ?? nullptr, sourcePointer: tree?.pointer ?? nullptr,
); );
} }
@ -44,7 +44,10 @@ class TreeBuilder {
/// ///
/// Throws [ArgumentError] if nothing found for provided filename. /// Throws [ArgumentError] if nothing found for provided filename.
TreeEntry operator [](String filename) { TreeEntry operator [](String filename) {
return TreeEntry(bindings.getByFilename(_treeBuilderPointer, filename)); return TreeEntry(bindings.getByFilename(
builderPointer: _treeBuilderPointer,
filename: filename,
));
} }
/// Adds or updates an entry to the tree builder with the given attributes. /// Adds or updates an entry to the tree builder with the given attributes.
@ -56,20 +59,28 @@ class TreeBuilder {
/// that it exists in the object database and is of the correct type. /// that it exists in the object database and is of the correct type.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void add(String filename, Oid id, GitFilemode filemode) { void add({
required String filename,
required Oid oid,
required GitFilemode filemode,
}) {
bindings.add( bindings.add(
_treeBuilderPointer, builderPointer: _treeBuilderPointer,
filename, filename: filename,
id.pointer, oidPointer: oid.pointer,
filemode.value, filemode: filemode.value,
); );
} }
/// Removes an entry from the tree builder by its filename. /// Removes an entry from the tree builder by its filename.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void remove(String filename) => void remove(String filename) {
bindings.remove(_treeBuilderPointer, filename); bindings.remove(
builderPointer: _treeBuilderPointer,
filename: filename,
);
}
/// Releases memory allocated for tree builder object. /// Releases memory allocated for tree builder object.
void free() => bindings.free(_treeBuilderPointer); void free() => bindings.free(_treeBuilderPointer);

View file

@ -21,7 +21,12 @@ class Worktree {
required String path, required String path,
Reference? ref, Reference? ref,
}) { }) {
_worktreePointer = bindings.create(repo.pointer, name, path, ref?.pointer); _worktreePointer = bindings.create(
repoPointer: repo.pointer,
name: name,
path: path,
refPointer: ref?.pointer,
);
} }
/// Initializes a new instance of [Worktree] class by looking up existing worktree /// Initializes a new instance of [Worktree] class by looking up existing worktree
@ -30,8 +35,8 @@ class Worktree {
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
Worktree.lookup(Repository repo, String name) { Worktree.lookup({required Repository repo, required String name}) {
_worktreePointer = bindings.lookup(repo.pointer, name); _worktreePointer = bindings.lookup(repoPointer: repo.pointer, name: name);
} }
/// Pointer to memory address for allocated branch object. /// Pointer to memory address for allocated branch object.

View file

@ -15,7 +15,7 @@ void main() {
setUp(() async { setUp(() async {
tmpDir = await setupRepo(Directory('test/assets/testrepo/')); tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
repo = Repository.open(tmpDir.path); repo = Repository.open(tmpDir.path);
blob = Blob.lookup(repo, blobSHA); blob = Blob.lookup(repo: repo, sha: blobSHA);
}); });
tearDown(() async { tearDown(() async {
@ -37,8 +37,8 @@ void main() {
}); });
test('successfully creates new blob', () { test('successfully creates new blob', () {
final oid = Blob.create(repo, newBlobContent); final oid = Blob.create(repo: repo, content: newBlobContent);
final newBlob = Blob.lookup(repo, oid.sha); final newBlob = Blob.lookup(repo: repo, sha: oid.sha);
expect(newBlob.id.sha, '18fdaeef018e57a92bcad2d4a35b577f34089af6'); expect(newBlob.id.sha, '18fdaeef018e57a92bcad2d4a35b577f34089af6');
expect(newBlob.isBinary, false); expect(newBlob.isBinary, false);
@ -50,8 +50,11 @@ void main() {
test('successfully creates new blob from file at provided relative path', test('successfully creates new blob from file at provided relative path',
() { () {
final oid = Blob.createFromWorkdir(repo, 'feature_file'); final oid = Blob.createFromWorkdir(
final newBlob = Blob.lookup(repo, oid.sha); repo: repo,
relativePath: 'feature_file',
);
final newBlob = Blob.lookup(repo: repo, sha: oid.sha);
expect(newBlob.id.sha, blobSHA); expect(newBlob.id.sha, blobSHA);
expect(newBlob.isBinary, false); expect(newBlob.isBinary, false);
@ -63,7 +66,10 @@ void main() {
test('throws when creating new blob from invalid path', () { test('throws when creating new blob from invalid path', () {
expect( expect(
() => Blob.createFromWorkdir(repo, 'invalid/path.txt'), () => Blob.createFromWorkdir(
repo: repo,
relativePath: 'invalid/path.txt',
),
throwsA(isA<LibGit2Error>()), throwsA(isA<LibGit2Error>()),
); );
}); });
@ -74,7 +80,10 @@ void main() {
final outsideFile = final outsideFile =
File('${Directory.current.absolute.path}/test/blob_test.dart'); File('${Directory.current.absolute.path}/test/blob_test.dart');
expect( expect(
() => Blob.createFromWorkdir(repo, outsideFile.path), () => Blob.createFromWorkdir(
repo: repo,
relativePath: outsideFile.path,
),
throwsA(isA<LibGit2Error>()), throwsA(isA<LibGit2Error>()),
); );
}); });
@ -82,8 +91,8 @@ void main() {
test('successfully creates new blob from file at provided path', () { test('successfully creates new blob from file at provided path', () {
final outsideFile = final outsideFile =
File('${Directory.current.absolute.path}/test/blob_test.dart'); File('${Directory.current.absolute.path}/test/blob_test.dart');
final oid = Blob.createFromDisk(repo, outsideFile.path); final oid = Blob.createFromDisk(repo: repo, path: outsideFile.path);
final newBlob = Blob.lookup(repo, oid.sha); final newBlob = Blob.lookup(repo: repo, sha: oid.sha);
expect(newBlob, isA<Blob>()); expect(newBlob, isA<Blob>());
expect(newBlob.isBinary, false); expect(newBlob.isBinary, false);

View file

@ -89,7 +89,7 @@ void main() {
group('get multivar values', () { group('get multivar values', () {
test('returns list of values', () { test('returns list of values', () {
expect( expect(
config.multivar('core.gitproxy'), config.multivar(variable: 'core.gitproxy'),
[ [
'proxy-command for kernel.org', 'proxy-command for kernel.org',
'default-proxy', 'default-proxy',
@ -99,27 +99,38 @@ void main() {
test('returns list of values for provided regexp', () { test('returns list of values for provided regexp', () {
expect( expect(
config.multivar('core.gitproxy', regexp: 'for kernel.org\$'), config.multivar(
variable: 'core.gitproxy',
regexp: 'for kernel.org\$',
),
['proxy-command for kernel.org'], ['proxy-command for kernel.org'],
); );
}); });
test('returns empty list if multivar not found', () { test('returns empty list if multivar not found', () {
expect(config.multivar('not.there'), []); expect(config.multivar(variable: 'not.there'), []);
}); });
}); });
group('setMultivarValue()', () { group('setMultivarValue()', () {
test('sets value of multivar', () { test('sets value of multivar', () {
config.setMultivar('core.gitproxy', 'default', 'updated'); config.setMultivar(
final multivarValues = config.multivar('core.gitproxy'); variable: 'core.gitproxy',
regexp: 'default',
value: 'updated',
);
final multivarValues = config.multivar(variable: 'core.gitproxy');
expect(multivarValues, isNot(contains('default-proxy'))); expect(multivarValues, isNot(contains('default-proxy')));
expect(multivarValues, contains('updated')); expect(multivarValues, contains('updated'));
}); });
test('sets value for all multivar values when regexp is empty', () { test('sets value for all multivar values when regexp is empty', () {
config.setMultivar('core.gitproxy', '', 'updated'); config.setMultivar(
final multivarValues = config.multivar('core.gitproxy'); variable: 'core.gitproxy',
regexp: '',
value: 'updated',
);
final multivarValues = config.multivar(variable: 'core.gitproxy');
expect(multivarValues, isNot(contains('default-proxy'))); expect(multivarValues, isNot(contains('default-proxy')));
expect(multivarValues, isNot(contains('proxy-command for kernel.org'))); expect(multivarValues, isNot(contains('proxy-command for kernel.org')));
expect(multivarValues, contains('updated')); expect(multivarValues, contains('updated'));
@ -130,14 +141,23 @@ void main() {
group('deleteMultivar()', () { group('deleteMultivar()', () {
test('successfully deletes value of a multivar', () { test('successfully deletes value of a multivar', () {
expect( expect(
config.multivar('core.gitproxy', regexp: 'for kernel.org\$'), config.multivar(
variable: 'core.gitproxy',
regexp: 'for kernel.org\$',
),
['proxy-command for kernel.org'], ['proxy-command for kernel.org'],
); );
config.deleteMultivar('core.gitproxy', 'for kernel.org\$'); config.deleteMultivar(
variable: 'core.gitproxy',
regexp: 'for kernel.org\$',
);
expect( expect(
config.multivar('core.gitproxy', regexp: 'for kernel.org\$'), config.multivar(
variable: 'core.gitproxy',
regexp: 'for kernel.org\$',
),
[], [],
); );
}); });
@ -145,16 +165,16 @@ void main() {
test('successfully deletes all values of a multivar when regexp is empty', test('successfully deletes all values of a multivar when regexp is empty',
() { () {
expect( expect(
config.multivar('core.gitproxy'), config.multivar(variable: 'core.gitproxy'),
[ [
'proxy-command for kernel.org', 'proxy-command for kernel.org',
'default-proxy', 'default-proxy',
], ],
); );
config.deleteMultivar('core.gitproxy', ''); config.deleteMultivar(variable: 'core.gitproxy', regexp: '');
expect(config.multivar('core.gitproxy'), []); expect(config.multivar(variable: 'core.gitproxy'), []);
}); });
}); });
}); });

View file

@ -194,7 +194,10 @@ index e69de29..c217c63 100644
final diff = Diff.parse(patchText); final diff = Diff.parse(patchText);
final file = File('${tmpDir.path}/subdir/modified_file'); final file = File('${tmpDir.path}/subdir/modified_file');
repo.reset('a763aa560953e7cfb87ccbc2f536d665aa4dff22', GitReset.hard); repo.reset(
target: 'a763aa560953e7cfb87ccbc2f536d665aa4dff22',
resetType: GitReset.hard,
);
expect(file.readAsStringSync(), ''); expect(file.readAsStringSync(), '');
expect(repo.applies(diff), true); expect(repo.applies(diff), true);
@ -206,7 +209,7 @@ index e69de29..c217c63 100644
test('successfully creates patch from entry index in diff', () { test('successfully creates patch from entry index in diff', () {
final diff = Diff.parse(patchText); final diff = Diff.parse(patchText);
final patch = Patch.fromDiff(diff, 0); final patch = Patch.fromDiff(diff: diff, index: 0);
expect(diff.length, 1); expect(diff.length, 1);
expect(patch.text, patchText); expect(patch.text, patchText);
@ -298,7 +301,7 @@ index e69de29..c217c63 100644
expect(stats.insertions, 4); expect(stats.insertions, 4);
expect(stats.deletions, 2); expect(stats.deletions, 2);
expect(stats.filesChanged, 8); expect(stats.filesChanged, 8);
expect(stats.print({GitDiffStats.full}, 80), statsPrint); expect(stats.print(format: {GitDiffStats.full}, width: 80), statsPrint);
stats.free(); stats.free();
diff.free(); diff.free();
@ -315,7 +318,7 @@ index e69de29..c217c63 100644
test('returns hunks in a patch', () { test('returns hunks in a patch', () {
final diff = Diff.parse(patchText); final diff = Diff.parse(patchText);
final patch = Patch.fromDiff(diff, 0); final patch = Patch.fromDiff(diff: diff, index: 0);
final hunk = patch.hunks[0]; final hunk = patch.hunks[0];
expect(patch.hunks.length, 1); expect(patch.hunks.length, 1);
@ -332,7 +335,7 @@ index e69de29..c217c63 100644
test('returns lines in a hunk', () { test('returns lines in a hunk', () {
final diff = Diff.parse(patchText); final diff = Diff.parse(patchText);
final patch = Patch.fromDiff(diff, 0); final patch = Patch.fromDiff(diff: diff, index: 0);
final hunk = patch.hunks[0]; final hunk = patch.hunks[0];
final line = hunk.lines[0]; final line = hunk.lines[0];

View file

@ -24,7 +24,7 @@ void main() {
final commit = final commit =
repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'] as Commit; repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'] as Commit;
final result = repo.mergeAnalysis(commit.id); final result = repo.mergeAnalysis(theirHead: commit.id);
expect(result[0], {GitMergeAnalysis.upToDate}); expect(result[0], {GitMergeAnalysis.upToDate});
expect(result[1], {GitMergePreference.none}); expect(result[1], {GitMergePreference.none});
expect(repo.status, isEmpty); expect(repo.status, isEmpty);
@ -36,7 +36,10 @@ void main() {
final commit = final commit =
repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'] as Commit; repo['c68ff54aabf660fcdd9a2838d401583fe31249e3'] as Commit;
final result = repo.mergeAnalysis(commit.id, 'refs/tags/v0.1'); final result = repo.mergeAnalysis(
theirHead: commit.id,
ourRef: 'refs/tags/v0.1',
);
expect(result[0], {GitMergeAnalysis.upToDate}); expect(result[0], {GitMergeAnalysis.upToDate});
expect(repo.status, isEmpty); expect(repo.status, isEmpty);
@ -53,7 +56,10 @@ void main() {
target: ffCommit, target: ffCommit,
); );
final result = repo.mergeAnalysis(theirHead.id, ffBranch.name); final result = repo.mergeAnalysis(
theirHead: theirHead.id,
ourRef: ffBranch.name,
);
expect( expect(
result[0], result[0],
{GitMergeAnalysis.fastForward, GitMergeAnalysis.normal}, {GitMergeAnalysis.fastForward, GitMergeAnalysis.normal},
@ -69,7 +75,7 @@ void main() {
final commit = final commit =
repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'] as Commit; repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'] as Commit;
final result = repo.mergeAnalysis(commit.id); final result = repo.mergeAnalysis(theirHead: commit.id);
expect(result[0], {GitMergeAnalysis.normal}); expect(result[0], {GitMergeAnalysis.normal});
expect(repo.status, isEmpty); expect(repo.status, isEmpty);
@ -81,7 +87,7 @@ void main() {
final conflictBranch = repo.branches['conflict-branch']; final conflictBranch = repo.branches['conflict-branch'];
final index = repo.index; final index = repo.index;
final result = repo.mergeAnalysis(conflictBranch.target); final result = repo.mergeAnalysis(theirHead: conflictBranch.target);
expect(result[0], {GitMergeAnalysis.normal}); expect(result[0], {GitMergeAnalysis.normal});
repo.merge(conflictBranch.target); repo.merge(conflictBranch.target);
@ -212,7 +218,7 @@ void main() {
final ourCommit = final ourCommit =
repo['14905459d775f3f56a39ebc2ff081163f7da3529'] as Commit; repo['14905459d775f3f56a39ebc2ff081163f7da3529'] as Commit;
final baseCommit = final baseCommit =
repo[repo.mergeBase(ourCommit.id.sha, theirCommit.id.sha).sha] repo[repo.mergeBase(a: ourCommit.id.sha, b: theirCommit.id.sha).sha]
as Commit; as Commit;
final theirTree = theirCommit.tree; final theirTree = theirCommit.tree;
final ourTree = ourCommit.tree; final ourTree = ourCommit.tree;
@ -250,7 +256,7 @@ void main() {
final ourCommit = final ourCommit =
repo['14905459d775f3f56a39ebc2ff081163f7da3529'] as Commit; repo['14905459d775f3f56a39ebc2ff081163f7da3529'] as Commit;
final baseCommit = final baseCommit =
repo[repo.mergeBase(ourCommit.id.sha, theirCommit.id.sha).sha] repo[repo.mergeBase(a: ourCommit.id.sha, b: theirCommit.id.sha).sha]
as Commit; as Commit;
final theirTree = theirCommit.tree; final theirTree = theirCommit.tree;
final ourTree = ourCommit.tree; final ourTree = ourCommit.tree;

View file

@ -27,7 +27,10 @@ void main() {
}); });
test('finds object by short oid', () { test('finds object by short oid', () {
final oid = Oid.fromSHA(repo, lastCommit.substring(0, 5)); final oid = Oid.fromSHA(
repo: repo,
sha: lastCommit.substring(0, 5),
);
expect(oid.sha, lastCommit); expect(oid.sha, lastCommit);
}); });
}); });

View file

@ -24,13 +24,13 @@ void main() {
group('Oid', () { group('Oid', () {
group('fromSHA()', () { group('fromSHA()', () {
test('initializes successfully', () { test('initializes successfully', () {
final oid = Oid.fromSHA(repo, sha); final oid = Oid.fromSHA(repo: repo, sha: sha);
expect(oid, isA<Oid>()); expect(oid, isA<Oid>());
expect(oid.sha, sha); expect(oid.sha, sha);
}); });
test('initializes successfully from short hex string', () { test('initializes successfully from short hex string', () {
final oid = Oid.fromSHA(repo, sha.substring(0, 5)); final oid = Oid.fromSHA(repo: repo, sha: sha.substring(0, 5));
expect(oid, isA<Oid>()); expect(oid, isA<Oid>());
expect(oid.sha, sha); expect(oid.sha, sha);
@ -39,7 +39,7 @@ void main() {
group('fromRaw()', () { group('fromRaw()', () {
test('initializes successfully', () { test('initializes successfully', () {
final sourceOid = Oid.fromSHA(repo, sha); final sourceOid = Oid.fromSHA(repo: repo, sha: sha);
final oid = Oid.fromRaw(sourceOid.pointer.ref); final oid = Oid.fromRaw(sourceOid.pointer.ref);
expect(oid, isA<Oid>()); expect(oid, isA<Oid>());
expect(oid.sha, sha); expect(oid.sha, sha);
@ -47,27 +47,27 @@ void main() {
}); });
test('returns sha hex string', () { test('returns sha hex string', () {
final oid = Oid.fromSHA(repo, sha); final oid = Oid.fromSHA(repo: repo, sha: sha);
expect(oid.sha, equals(sha)); expect(oid.sha, equals(sha));
}); });
group('compare', () { group('compare', () {
test('< and <=', () { test('< and <=', () {
final oid1 = Oid.fromSHA(repo, sha); final oid1 = Oid.fromSHA(repo: repo, sha: sha);
final oid2 = Oid.fromSHA(repo, biggerSha); final oid2 = Oid.fromSHA(repo: repo, sha: biggerSha);
expect(oid1 < oid2, true); expect(oid1 < oid2, true);
expect(oid1 <= oid2, true); expect(oid1 <= oid2, true);
}); });
test('==', () { test('==', () {
final oid1 = Oid.fromSHA(repo, sha); final oid1 = Oid.fromSHA(repo: repo, sha: sha);
final oid2 = Oid.fromSHA(repo, sha); final oid2 = Oid.fromSHA(repo: repo, sha: sha);
expect(oid1 == oid2, true); expect(oid1 == oid2, true);
}); });
test('> and >=', () { test('> and >=', () {
final oid1 = Oid.fromSHA(repo, sha); final oid1 = Oid.fromSHA(repo: repo, sha: sha);
final oid2 = Oid.fromSHA(repo, lesserSha); final oid2 = Oid.fromSHA(repo: repo, sha: lesserSha);
expect(oid1 > oid2, true); expect(oid1 > oid2, true);
expect(oid1 >= oid2, true); expect(oid1 >= oid2, true);
}); });

View file

@ -346,7 +346,7 @@ void main() {
group('set target', () { group('set target', () {
test('successfully sets with SHA hex', () { test('successfully sets with SHA hex', () {
final ref = repo.references['refs/heads/master']; final ref = repo.references['refs/heads/master'];
ref.setTarget(newCommit); ref.setTarget(target: newCommit);
expect(ref.target.sha, newCommit); expect(ref.target.sha, newCommit);
ref.free(); ref.free();
@ -354,7 +354,7 @@ void main() {
test('successfully sets target with short SHA hex', () { test('successfully sets target with short SHA hex', () {
final ref = repo.references['refs/heads/master']; final ref = repo.references['refs/heads/master'];
ref.setTarget(newCommit.substring(0, 5)); ref.setTarget(target: newCommit.substring(0, 5));
expect(ref.target.sha, newCommit); expect(ref.target.sha, newCommit);
ref.free(); ref.free();
@ -364,7 +364,7 @@ void main() {
final ref = repo.references['HEAD']; final ref = repo.references['HEAD'];
expect(ref.target.sha, lastCommit); expect(ref.target.sha, lastCommit);
ref.setTarget('refs/heads/feature'); ref.setTarget(target: 'refs/heads/feature');
expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
ref.free(); ref.free();
@ -375,7 +375,7 @@ void main() {
expect(ref.target.sha, lastCommit); expect(ref.target.sha, lastCommit);
repo.setIdentity(name: 'name', email: 'email'); repo.setIdentity(name: 'name', email: 'email');
ref.setTarget('refs/heads/feature', 'log message'); ref.setTarget(target: 'refs/heads/feature', logMessage: 'log message');
expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); expect(ref.target.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
final reflog = ref.log; final reflog = ref.log;
expect(reflog.first.message, 'log message'); expect(reflog.first.message, 'log message');
@ -389,7 +389,7 @@ void main() {
test('throws on invalid target', () { test('throws on invalid target', () {
final ref = repo.references['HEAD']; final ref = repo.references['HEAD'];
expect( expect(
() => ref.setTarget('refs/heads/invalid~'), () => ref.setTarget(target: 'refs/heads/invalid~'),
throwsA(isA<LibGit2Error>()), throwsA(isA<LibGit2Error>()),
); );
@ -405,7 +405,7 @@ void main() {
); );
expect(ref.name, 'refs/tags/v1'); expect(ref.name, 'refs/tags/v1');
ref.rename('refs/tags/v2'); ref.rename(newName: 'refs/tags/v2');
expect(ref.name, 'refs/tags/v2'); expect(ref.name, 'refs/tags/v2');
ref.free(); ref.free();
@ -418,7 +418,7 @@ void main() {
); );
expect( expect(
() => ref.rename('refs/tags/invalid~'), () => ref.rename(newName: 'refs/tags/invalid~'),
throwsA(isA<LibGit2Error>()), throwsA(isA<LibGit2Error>()),
); );
@ -437,7 +437,7 @@ void main() {
); );
expect( expect(
() => ref1.rename('refs/tags/v2'), () => ref1.rename(newName: 'refs/tags/v2'),
throwsA(isA<LibGit2Error>()), throwsA(isA<LibGit2Error>()),
); );
@ -458,7 +458,7 @@ void main() {
expect(ref2.target.sha, newCommit); expect(ref2.target.sha, newCommit);
ref1.rename('refs/tags/v2', force: true); ref1.rename(newName: 'refs/tags/v2', force: true);
expect(ref1.name, 'refs/tags/v2'); expect(ref1.name, 'refs/tags/v2');
ref1.free(); ref1.free();

View file

@ -79,7 +79,7 @@ void main() {
test('successfully renames', () { test('successfully renames', () {
final remote = repo.remotes[remoteName]; final remote = repo.remotes[remoteName];
final problems = repo.remotes.rename(remoteName, 'new'); final problems = repo.remotes.rename(remote: remoteName, newName: 'new');
expect(problems, isEmpty); expect(problems, isEmpty);
expect(remote.name, isNot('new')); expect(remote.name, isNot('new'));
@ -91,7 +91,10 @@ void main() {
}); });
test('throws when renaming with invalid names', () { test('throws when renaming with invalid names', () {
expect(() => repo.remotes.rename('', ''), throwsA(isA<LibGit2Error>())); expect(
() => repo.remotes.rename(remote: '', newName: ''),
throwsA(isA<LibGit2Error>()),
);
}); });
test('successfully sets url', () { test('successfully sets url', () {
@ -99,7 +102,7 @@ void main() {
expect(remote.url, remoteUrl); expect(remote.url, remoteUrl);
const newUrl = 'git://new/url.git'; const newUrl = 'git://new/url.git';
repo.remotes.setUrl(remoteName, newUrl); repo.remotes.setUrl(remote: remoteName, url: newUrl);
final newRemote = repo.remotes[remoteName]; final newRemote = repo.remotes[remoteName];
expect(newRemote.url, newUrl); expect(newRemote.url, newUrl);
@ -110,14 +113,14 @@ void main() {
test('throws when trying to set invalid url name', () { test('throws when trying to set invalid url name', () {
expect( expect(
() => repo.remotes.setUrl('origin', ''), () => repo.remotes.setUrl(remote: 'origin', url: ''),
throwsA(isA<LibGit2Error>()), throwsA(isA<LibGit2Error>()),
); );
}); });
test('successfully sets url for pushing', () { test('successfully sets url for pushing', () {
const newUrl = 'git://new/url.git'; const newUrl = 'git://new/url.git';
repo.remotes.setPushUrl(remoteName, newUrl); repo.remotes.setPushUrl(remote: remoteName, url: newUrl);
final remote = repo.remotes[remoteName]; final remote = repo.remotes[remoteName];
expect(remote.pushUrl, newUrl); expect(remote.pushUrl, newUrl);
@ -127,7 +130,7 @@ void main() {
test('throws when trying to set invalid push url name', () { test('throws when trying to set invalid push url name', () {
expect( expect(
() => repo.remotes.setPushUrl('origin', ''), () => repo.remotes.setPushUrl(remote: 'origin', url: ''),
throwsA(isA<LibGit2Error>()), throwsA(isA<LibGit2Error>()),
); );
}); });
@ -159,7 +162,10 @@ void main() {
}); });
test('successfully adds fetch refspec', () { test('successfully adds fetch refspec', () {
repo.remotes.addFetch('origin', '+refs/test/*:refs/test/remotes/*'); repo.remotes.addFetch(
remote: 'origin',
refspec: '+refs/test/*:refs/test/remotes/*',
);
final remote = repo.remotes['origin']; final remote = repo.remotes['origin'];
expect(remote.fetchRefspecs.length, 2); expect(remote.fetchRefspecs.length, 2);
expect( expect(
@ -174,7 +180,10 @@ void main() {
}); });
test('successfully adds push refspec', () { test('successfully adds push refspec', () {
repo.remotes.addPush('origin', '+refs/test/*:refs/test/remotes/*'); repo.remotes.addPush(
remote: 'origin',
refspec: '+refs/test/*:refs/test/remotes/*',
);
final remote = repo.remotes['origin']; final remote = repo.remotes['origin'];
expect(remote.pushRefspecs.length, 1); expect(remote.pushRefspecs.length, 1);
expect(remote.pushRefspecs, ['+refs/test/*:refs/test/remotes/*']); expect(remote.pushRefspecs, ['+refs/test/*:refs/test/remotes/*']);
@ -184,8 +193,8 @@ void main() {
test('successfully returns remote repo\'s reference list', () { test('successfully returns remote repo\'s reference list', () {
repo.remotes.setUrl( repo.remotes.setUrl(
'libgit2', remote: 'libgit2',
'https://github.com/libgit2/TestGitRepository', url: 'https://github.com/libgit2/TestGitRepository',
); );
final remote = repo.remotes['libgit2']; final remote = repo.remotes['libgit2'];
@ -204,8 +213,8 @@ void main() {
test('successfully fetches data', () { test('successfully fetches data', () {
repo.remotes.setUrl( repo.remotes.setUrl(
'libgit2', remote: 'libgit2',
'https://github.com/libgit2/TestGitRepository', url: 'https://github.com/libgit2/TestGitRepository',
); );
final remote = repo.remotes['libgit2']; final remote = repo.remotes['libgit2'];
@ -225,8 +234,8 @@ void main() {
test('successfully fetches data with provided transfer progress callback', test('successfully fetches data with provided transfer progress callback',
() { () {
repo.remotes.setUrl( repo.remotes.setUrl(
'libgit2', remote: 'libgit2',
'https://github.com/libgit2/TestGitRepository', url: 'https://github.com/libgit2/TestGitRepository',
); );
final remote = repo.remotes['libgit2']; final remote = repo.remotes['libgit2'];
@ -255,8 +264,8 @@ Counting objects: 100% (1/1)\rCounting objects: 100% (1/1), done.
Total 69 (delta 0), reused 1 (delta 0), pack-reused 68 Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
"""; """;
repo.remotes.setUrl( repo.remotes.setUrl(
'libgit2', remote: 'libgit2',
'https://github.com/libgit2/TestGitRepository', url: 'https://github.com/libgit2/TestGitRepository',
); );
final remote = repo.remotes['libgit2']; final remote = repo.remotes['libgit2'];
@ -275,8 +284,8 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
test('successfully fetches data with provided update tips callback', () { test('successfully fetches data with provided update tips callback', () {
repo.remotes.setUrl( repo.remotes.setUrl(
'libgit2', remote: 'libgit2',
'https://github.com/libgit2/TestGitRepository', url: 'https://github.com/libgit2/TestGitRepository',
); );
final remote = repo.remotes['libgit2']; final remote = repo.remotes['libgit2'];
const tipsExpected = [ const tipsExpected = [

View file

@ -40,7 +40,7 @@ void main() {
'6cbc22e509d72758ab4c8d9f287ea846b90c448b', '6cbc22e509d72758ab4c8d9f287ea846b90c448b',
'f17d0d48eae3aa08cecf29128a35e310c97b3521', 'f17d0d48eae3aa08cecf29128a35e310c97b3521',
]; ];
final commits = repo.log(lastCommit); final commits = repo.log(sha: lastCommit);
for (var i = 0; i < commits.length; i++) { for (var i = 0; i < commits.length; i++) {
expect(commits[i].id.sha, log[i]); expect(commits[i].id.sha, log[i]);
@ -55,11 +55,11 @@ void main() {
test('discovers repository', () async { test('discovers repository', () async {
final subDir = '${tmpDir.path}/subdir1/subdir2/'; final subDir = '${tmpDir.path}/subdir1/subdir2/';
await Directory(subDir).create(recursive: true); await Directory(subDir).create(recursive: true);
expect(Repository.discover(subDir), repo.path); expect(Repository.discover(startPath: subDir), repo.path);
}); });
test('returns empty string when repository not found', () { test('returns empty string when repository not found', () {
expect(Repository.discover(Directory.systemTemp.path), ''); expect(Repository.discover(startPath: Directory.systemTemp.path), '');
}); });
}); });
@ -79,7 +79,7 @@ void main() {
final tmpWorkDir = Directory('${Directory.systemTemp.path}/tmp_work_dir'); final tmpWorkDir = Directory('${Directory.systemTemp.path}/tmp_work_dir');
tmpWorkDir.createSync(); tmpWorkDir.createSync();
repo.setWorkdir(tmpWorkDir.path); repo.setWorkdir(path: tmpWorkDir.path);
expect(repo.workdir, '${tmpWorkDir.path}/'); expect(repo.workdir, '${tmpWorkDir.path}/');
tmpWorkDir.deleteSync(); tmpWorkDir.deleteSync();
@ -166,7 +166,7 @@ void main() {
const message = 'init tag\n'; const message = 'init tag\n';
final oid = Tag.create( final oid = Tag.create(
repository: repo, repo: repo,
tagName: tagName, tagName: tagName,
target: target, target: target,
targetType: GitObject.commit, targetType: GitObject.commit,

View file

@ -26,7 +26,7 @@ void main() {
var contents = file.readAsStringSync(); var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n'); expect(contents, 'Feature edit\n');
repo.reset(sha, GitReset.hard); repo.reset(target: sha, resetType: GitReset.hard);
contents = file.readAsStringSync(); contents = file.readAsStringSync();
expect(contents, isEmpty); expect(contents, isEmpty);
}); });
@ -35,7 +35,7 @@ void main() {
var contents = file.readAsStringSync(); var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n'); expect(contents, 'Feature edit\n');
repo.reset(sha, GitReset.soft); repo.reset(target: sha, resetType: GitReset.soft);
contents = file.readAsStringSync(); contents = file.readAsStringSync();
expect(contents, 'Feature edit\n'); expect(contents, 'Feature edit\n');
@ -50,7 +50,7 @@ void main() {
var contents = file.readAsStringSync(); var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n'); expect(contents, 'Feature edit\n');
repo.reset(sha, GitReset.mixed); repo.reset(target: sha, resetType: GitReset.mixed);
contents = file.readAsStringSync(); contents = file.readAsStringSync();
expect(contents, 'Feature edit\n'); expect(contents, 'Feature edit\n');

View file

@ -94,7 +94,7 @@ void main() {
expect(revspec.to?.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'); expect(revspec.to?.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
expect(revspec.flags, {GitRevSpec.range, GitRevSpec.mergeBase}); expect(revspec.flags, {GitRevSpec.range, GitRevSpec.mergeBase});
expect( expect(
repo.mergeBase(revspec.from.id.sha, revspec.to!.id.sha), repo.mergeBase(a: revspec.from.id.sha, b: revspec.to!.id.sha),
isA<Oid>(), isA<Oid>(),
); );

View file

@ -28,7 +28,7 @@ void main() {
group('RevWalk', () { group('RevWalk', () {
test('returns list of commits with default sorting', () { test('returns list of commits with default sorting', () {
final walker = RevWalk(repo); final walker = RevWalk(repo);
final start = Oid.fromSHA(repo, log.first); final start = Oid.fromSHA(repo: repo, sha: log.first);
walker.push(start); walker.push(start);
final commits = walker.walk(); final commits = walker.walk();
@ -45,7 +45,7 @@ void main() {
test('returns list of commits with reverse sorting', () { test('returns list of commits with reverse sorting', () {
final walker = RevWalk(repo); final walker = RevWalk(repo);
final start = Oid.fromSHA(repo, log.first); final start = Oid.fromSHA(repo: repo, sha: log.first);
walker.push(start); walker.push(start);
walker.sorting({GitSort.reverse}); walker.sorting({GitSort.reverse});
@ -63,7 +63,7 @@ void main() {
test('successfully changes sorting', () { test('successfully changes sorting', () {
final walker = RevWalk(repo); final walker = RevWalk(repo);
final start = Oid.fromSHA(repo, log.first); final start = Oid.fromSHA(repo: repo, sha: log.first);
walker.push(start); walker.push(start);
final timeSortedCommits = walker.walk(); final timeSortedCommits = walker.walk();
@ -89,8 +89,8 @@ void main() {
test('successfully hides commit and its ancestors', () { test('successfully hides commit and its ancestors', () {
final walker = RevWalk(repo); final walker = RevWalk(repo);
final start = Oid.fromSHA(repo, log.first); final start = Oid.fromSHA(repo: repo, sha: log.first);
final oidToHide = Oid.fromSHA(repo, log[2]); final oidToHide = Oid.fromSHA(repo: repo, sha: log[2]);
walker.push(start); walker.push(start);
walker.hide(oidToHide); walker.hide(oidToHide);
@ -106,7 +106,7 @@ void main() {
test('successfully resets walker', () { test('successfully resets walker', () {
final walker = RevWalk(repo); final walker = RevWalk(repo);
final start = Oid.fromSHA(repo, log.first); final start = Oid.fromSHA(repo: repo, sha: log.first);
walker.push(start); walker.push(start);
walker.reset(); walker.reset();
@ -120,7 +120,7 @@ void main() {
test('simplifies walker by enqueuing only first parent for each commit', test('simplifies walker by enqueuing only first parent for each commit',
() { () {
final walker = RevWalk(repo); final walker = RevWalk(repo);
final start = Oid.fromSHA(repo, log.first); final start = Oid.fromSHA(repo: repo, sha: log.first);
walker.push(start); walker.push(start);
walker.simplifyFirstParent(); walker.simplifyFirstParent();

View file

@ -13,7 +13,7 @@ void main() {
setUp(() async { setUp(() async {
tmpDir = await setupRepo(Directory('test/assets/testrepo/')); tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
repo = Repository.open(tmpDir.path); repo = Repository.open(tmpDir.path);
tag = Tag.lookup(repo, tagSHA); tag = Tag.lookup(repo: repo, sha: tagSHA);
}); });
tearDown(() async { tearDown(() async {
@ -58,7 +58,7 @@ void main() {
const message = 'init tag\n'; const message = 'init tag\n';
final oid = Tag.create( final oid = Tag.create(
repository: repo, repo: repo,
tagName: tagName, tagName: tagName,
target: target, target: target,
targetType: GitObject.commit, targetType: GitObject.commit,
@ -66,7 +66,7 @@ void main() {
message: message, message: message,
); );
final newTag = Tag.lookup(repo, oid.sha); final newTag = Tag.lookup(repo: repo, sha: oid.sha);
final tagger = newTag.tagger; final tagger = newTag.tagger;
final newTagTarget = newTag.target as Commit; final newTagTarget = newTag.target as Commit;

View file

@ -14,7 +14,7 @@ void main() {
setUp(() async { setUp(() async {
tmpDir = await setupRepo(Directory('test/assets/testrepo/')); tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
repo = Repository.open(tmpDir.path); repo = Repository.open(tmpDir.path);
tree = Tree.lookup(repo, treeSHA); tree = Tree.lookup(repo: repo, sha: treeSHA);
}); });
tearDown(() async { tearDown(() async {
@ -64,10 +64,14 @@ void main() {
test('successfully creates tree', () { test('successfully creates tree', () {
final fileOid = repo.createBlob('blob content'); final fileOid = repo.createBlob('blob content');
final builder = TreeBuilder(repo); final builder = TreeBuilder(repo: repo);
builder.add('filename', fileOid, GitFilemode.blob); builder.add(
final newTree = Tree.lookup(repo, builder.write().sha); filename: 'filename',
oid: fileOid,
filemode: GitFilemode.blob,
);
final newTree = Tree.lookup(repo: repo, sha: builder.write().sha);
final entry = newTree['filename']; final entry = newTree['filename'];
expect(newTree.length, 1); expect(newTree.length, 1);

View file

@ -13,7 +13,7 @@ void main() {
setUp(() async { setUp(() async {
tmpDir = await setupRepo(Directory('test/assets/testrepo/')); tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
repo = Repository.open(tmpDir.path); repo = Repository.open(tmpDir.path);
tree = Tree.lookup(repo, treeSHA); tree = Tree.lookup(repo: repo, sha: treeSHA);
}); });
tearDown(() async { tearDown(() async {
@ -24,13 +24,13 @@ void main() {
group('TreeBuilder', () { group('TreeBuilder', () {
test('successfully initializes tree builder when no tree is provided', () { test('successfully initializes tree builder when no tree is provided', () {
final builder = TreeBuilder(repo); final builder = TreeBuilder(repo: repo);
expect(builder, isA<TreeBuilder>()); expect(builder, isA<TreeBuilder>());
builder.free(); builder.free();
}); });
test('successfully initializes tree builder with provided tree', () { test('successfully initializes tree builder with provided tree', () {
final builder = TreeBuilder(repo, tree); final builder = TreeBuilder(repo: repo, tree: tree);
final oid = builder.write(); final oid = builder.write();
expect(builder, isA<TreeBuilder>()); expect(builder, isA<TreeBuilder>());
@ -41,7 +41,7 @@ void main() {
}); });
test('clears all the entries in the builder', () { test('clears all the entries in the builder', () {
final builder = TreeBuilder(repo, tree); final builder = TreeBuilder(repo: repo, tree: tree);
expect(builder.length, 4); expect(builder.length, 4);
builder.clear(); builder.clear();
@ -51,12 +51,13 @@ void main() {
}); });
test('successfully builds the tree builder from entry of tree', () { test('successfully builds the tree builder from entry of tree', () {
final builder = TreeBuilder(repo); final builder = TreeBuilder(repo: repo);
final entry = tree.entries[0]; final entry = tree.entries[0];
expect(() => builder[entry.name], throwsA(isA<ArgumentError>())); expect(() => builder[entry.name], throwsA(isA<ArgumentError>()));
builder.add(entry.name, entry.id, entry.filemode); builder.add(
filename: entry.name, oid: entry.id, filemode: entry.filemode);
expect(builder[entry.name].name, entry.name); expect(builder[entry.name].name, entry.name);
builder.free(); builder.free();
@ -64,7 +65,7 @@ void main() {
}); });
test('successfully removes an entry', () { test('successfully removes an entry', () {
final builder = TreeBuilder(repo, tree); final builder = TreeBuilder(repo: repo, tree: tree);
expect(builder.length, tree.length); expect(builder.length, tree.length);