mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat: generate bindings with ffigen
This commit is contained in:
parent
9d81c715ff
commit
1414d5f6d7
95 changed files with 38582 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
.vscode/
|
||||||
.packages
|
.packages
|
||||||
.dart_tool
|
.dart_tool
|
||||||
.pub
|
.pub
|
||||||
|
|
|
@ -4,3 +4,6 @@ linter:
|
||||||
- file_names
|
- file_names
|
||||||
- prefer_const_constructors
|
- prefer_const_constructors
|
||||||
- sort_constructors_first
|
- sort_constructors_first
|
||||||
|
analyzer:
|
||||||
|
exclude:
|
||||||
|
- lib/src/bindings/libgit2_bindings.dart
|
||||||
|
|
2
lib/libgit2dart.dart
Normal file
2
lib/libgit2dart.dart
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export 'src/repository.dart';
|
||||||
|
export 'src/error.dart';
|
38479
lib/src/bindings/libgit2_bindings.dart
Normal file
38479
lib/src/bindings/libgit2_bindings.dart
Normal file
File diff suppressed because it is too large
Load diff
89
lib/src/bindings/repository.dart
Normal file
89
lib/src/bindings/repository.dart
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
import 'dart:ffi';
|
||||||
|
import 'package:ffi/ffi.dart';
|
||||||
|
import '../error.dart';
|
||||||
|
import 'libgit2_bindings.dart';
|
||||||
|
import '../util.dart';
|
||||||
|
|
||||||
|
/// Attempt to open an already-existing repository at [path].
|
||||||
|
///
|
||||||
|
/// The [path] can point to either a normal or bare repository.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
Pointer<Pointer<git_repository>> open(String path) {
|
||||||
|
final out = calloc<Pointer<git_repository>>();
|
||||||
|
final pathC = path.toNativeUtf8().cast<Int8>();
|
||||||
|
final error = libgit2.git_repository_open(out, pathC);
|
||||||
|
calloc.free(pathC);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(error, libgit2.git_error_last());
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Attempt to open an already-existing bare repository at [bare_path].
|
||||||
|
///
|
||||||
|
/// The [bare_path] can point to only a bare repository.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
Pointer<Pointer<git_repository>> openBare(String bare_path) {
|
||||||
|
final out = calloc<Pointer<git_repository>>();
|
||||||
|
final error = libgit2.git_repository_open_bare(
|
||||||
|
out, bare_path.toNativeUtf8().cast<Int8>());
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(error, libgit2.git_error_last());
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the path to the `.git` folder for normal repositories or the
|
||||||
|
/// repository itself for bare repositories.
|
||||||
|
String path(Pointer<git_repository> repo) {
|
||||||
|
final path = libgit2.git_repository_path(repo);
|
||||||
|
return path.cast<Utf8>().toDartString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the currently active namespace for this repository.
|
||||||
|
///
|
||||||
|
/// If there is no namespace, or the namespace is not a valid utf8 string,
|
||||||
|
/// empty string is returned.
|
||||||
|
String getNamespace(Pointer<git_repository> repo) {
|
||||||
|
final namespace = libgit2.git_repository_get_namespace(repo);
|
||||||
|
if (namespace == nullptr) {
|
||||||
|
return '';
|
||||||
|
} else {
|
||||||
|
return namespace.cast<Utf8>().toDartString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tests whether this repository is a bare repository or not.
|
||||||
|
bool isBare(Pointer<git_repository> repo) {
|
||||||
|
final result = libgit2.git_repository_is_bare(repo);
|
||||||
|
return result == 1 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Find a single object, as specified by a [spec] string.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
///
|
||||||
|
/// The returned object should be released when no longer needed.
|
||||||
|
Pointer<Pointer<git_object>> revParseSingle(
|
||||||
|
Pointer<git_repository> repo,
|
||||||
|
String spec,
|
||||||
|
) {
|
||||||
|
final out = calloc<Pointer<git_object>>();
|
||||||
|
final error = libgit2.git_revparse_single(
|
||||||
|
out,
|
||||||
|
repo,
|
||||||
|
spec.toNativeUtf8().cast<Int8>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(error, libgit2.git_error_last());
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
BIN
libgit2-1.1.0/libgit2.so
Executable file
BIN
libgit2-1.1.0/libgit2.so
Executable file
Binary file not shown.
14
pubspec.yaml
14
pubspec.yaml
|
@ -1,6 +1,6 @@
|
||||||
name: libgit2_dart
|
name: libgit2dart
|
||||||
|
description: Dart bindings to libgit2
|
||||||
description: Dart bindings for libgit2
|
version: 0.0.1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.12.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
@ -9,15 +9,17 @@ dependencies:
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
pedantic: ^1.11.0
|
pedantic: ^1.11.0
|
||||||
ffigen: ^3.0.0
|
ffigen: ^3.1.0-dev.1
|
||||||
|
|
||||||
ffigen:
|
ffigen:
|
||||||
output: "./lib/src/libgit2_bindings.dart"
|
output: "lib/src/libgit2_bindings.dart"
|
||||||
headers:
|
headers:
|
||||||
entry-points:
|
entry-points:
|
||||||
- "./src/headers/"
|
- "libgit2-1.1.0/headers/*.h"
|
||||||
name: "Libgit2"
|
name: "Libgit2"
|
||||||
description: "Bindings to libgit2"
|
description: "Bindings to libgit2"
|
||||||
comments:
|
comments:
|
||||||
style: any
|
style: any
|
||||||
length: full
|
length: full
|
||||||
|
llvm-path:
|
||||||
|
- "/usr/lib64/libclang.so"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue