mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
Compare commits
34 commits
Author | SHA1 | Date | |
---|---|---|---|
|
b66662f33c | ||
|
e1ca7e81a2 | ||
|
7c6060b02c | ||
|
ed67a4e307 | ||
|
675872c3ef | ||
|
fa946c5ce3 | ||
|
34d492a9b6 | ||
|
ef9390d08b | ||
|
d55742d6d7 | ||
|
07e83a1f41 | ||
|
a41fc55099 | ||
|
016370625b | ||
|
4a36922129 | ||
|
5f829dd1ca | ||
|
2daadaa9a4 | ||
|
d71e00947e | ||
|
aa073c531e | ||
|
d113af44b5 | ||
|
75687c469c | ||
|
aa74c46a12 | ||
|
6be34fe9a0 | ||
|
48e2240c73 | ||
|
a708d54b0a | ||
|
b0b8067203 | ||
|
5739de545b | ||
|
3d235f5ce4 | ||
|
4aea9a306a | ||
|
ae2aef5e2e | ||
|
c35d336a56 | ||
|
3900ec92cc | ||
|
faddaa52e2 | ||
|
16c42b9b2d | ||
|
d231164775 | ||
|
bad40bdb61 |
118 changed files with 5889 additions and 3748 deletions
4
.github/workflows/master.yml
vendored
4
.github/workflows/master.yml
vendored
|
@ -19,7 +19,7 @@ jobs:
|
||||||
- uses: actions/checkout@v3.0.1
|
- uses: actions/checkout@v3.0.1
|
||||||
- uses: subosito/flutter-action@v2
|
- uses: subosito/flutter-action@v2
|
||||||
with:
|
with:
|
||||||
channel: master
|
channel: stable
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: flutter pub get
|
run: flutter pub get
|
||||||
|
@ -47,7 +47,7 @@ jobs:
|
||||||
- uses: actions/checkout@v3.0.1
|
- uses: actions/checkout@v3.0.1
|
||||||
- uses: subosito/flutter-action@v2
|
- uses: subosito/flutter-action@v2
|
||||||
with:
|
with:
|
||||||
channel: master
|
channel: stable
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: flutter pub get
|
run: flutter pub get
|
||||||
|
|
58
CHANGELOG.md
58
CHANGELOG.md
|
@ -1,3 +1,61 @@
|
||||||
|
## 1.2.2
|
||||||
|
|
||||||
|
- fix: lookup package in correct location of Dart/Flutter cached packages
|
||||||
|
|
||||||
|
## 1.2.1
|
||||||
|
|
||||||
|
- fix: use default location of Flutter's '.pub_cache' folder
|
||||||
|
|
||||||
|
- docs: update README with troubleshooting instructions for Windows
|
||||||
|
|
||||||
|
- chore: bump minimum dart and flutter versions
|
||||||
|
|
||||||
|
- chore: Lookup library in system path (thanks @dnys1)
|
||||||
|
|
||||||
|
## 1.2.0
|
||||||
|
|
||||||
|
- feat: upgrade libgit2 to 1.5.0
|
||||||
|
|
||||||
|
- feat: add ability to pass checkout options to `reset(...)` API method
|
||||||
|
|
||||||
|
- feat: add ability to pass options to `prune(...)` Worktree API method
|
||||||
|
|
||||||
|
- feat: add ability to pass options to `Merge.fileFromIndex(...)` API method
|
||||||
|
|
||||||
|
- feat: add ability to pass options to `addAll(...)` Index API method
|
||||||
|
|
||||||
|
- feat: add ability to pass options to `revert(...)` and `revertTo(...)` Commit API methods:
|
||||||
|
|
||||||
|
- select parent to revert to for merge commits
|
||||||
|
- merge options
|
||||||
|
- checkout options
|
||||||
|
|
||||||
|
- chore: upgrade dependencies
|
||||||
|
|
||||||
|
## 1.1.2
|
||||||
|
|
||||||
|
- fix: lookup library in Flutter's .pub_cache folder
|
||||||
|
|
||||||
|
- feat: add ability to limit number of commits to walk in revision walk
|
||||||
|
|
||||||
|
## 1.1.1
|
||||||
|
|
||||||
|
- fix: lookup library in correct locations
|
||||||
|
|
||||||
|
- feat: add ability to pass optional notes location to `Note.list(...)` method
|
||||||
|
|
||||||
|
## 1.1.0
|
||||||
|
|
||||||
|
- feat: add ability to get and set libgit2 global options
|
||||||
|
|
||||||
|
- feat: upgrade Flutter version constraints to `>=3.0.0`
|
||||||
|
|
||||||
|
- feat: add ability to remove entries in index with `resetDefault(...)` method
|
||||||
|
|
||||||
|
- feat: add ability to compare objects (value based equality)
|
||||||
|
|
||||||
|
Note: comparison of Repository objects have naive implementation. Comparison is based on repository path, and previously loaded into memory index, odb, etc. might be different. Use with caution.
|
||||||
|
|
||||||
## 1.0.0
|
## 1.0.0
|
||||||
|
|
||||||
- Initial release.
|
- Initial release.
|
||||||
|
|
19
README.md
19
README.md
|
@ -1,7 +1,5 @@
|
||||||
# libgit2dart
|
# libgit2dart
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
**Dart bindings to libgit2**
|
**Dart bindings to libgit2**
|
||||||
|
|
||||||
libgit2dart package provides ability to use [libgit2](https://github.com/libgit2/libgit2) in Dart/Flutter.
|
libgit2dart package provides ability to use [libgit2](https://github.com/libgit2/libgit2) in Dart/Flutter.
|
||||||
|
@ -49,13 +47,13 @@ print(Libgit2.version);
|
||||||
|
|
||||||
**Note**: The following steps only required if you are using package in Dart application (Flutter application will have libgit2 library bundled automatically when you build for release).
|
**Note**: The following steps only required if you are using package in Dart application (Flutter application will have libgit2 library bundled automatically when you build for release).
|
||||||
|
|
||||||
After compiling the application you should run:
|
After adding the package as dependency you should run:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
dart run libgit2dart:setup
|
dart run libgit2dart:setup
|
||||||
```
|
```
|
||||||
|
|
||||||
That'll copy the prebuilt libgit2 library for your platform into `.dart_tool/libgit2/<platform>/` which you'll need to add to the same folder as your executable.
|
That'll copy the prebuilt libgit2 library for your platform into `.dart_tool/libgit2/<platform>/` which you'll need to add to the same folder as your executable after compilation.
|
||||||
|
|
||||||
If you upgrade the version of libgit2dart package in your dependencies you should run the following commands to have the latest libgit2 library for your platform to provide with your application:
|
If you upgrade the version of libgit2dart package in your dependencies you should run the following commands to have the latest libgit2 library for your platform to provide with your application:
|
||||||
|
|
||||||
|
@ -665,6 +663,8 @@ Fork libgit2dart, improve libgit2dart, send a pull request.
|
||||||
|
|
||||||
### Troubleshooting
|
### Troubleshooting
|
||||||
|
|
||||||
|
#### Linux:
|
||||||
|
|
||||||
If you are developing on Linux using non-Debian based distrib you might encounter these errors:
|
If you are developing on Linux using non-Debian based distrib you might encounter these errors:
|
||||||
|
|
||||||
- Failed to load dynamic library: libpcre.so.3: cannot open shared object file: No such file or directory
|
- Failed to load dynamic library: libpcre.so.3: cannot open shared object file: No such file or directory
|
||||||
|
@ -679,6 +679,16 @@ sudo ln -s /usr/lib64/libpcre.so /usr/lib64/libpcre.so.3
|
||||||
sudo ln -s /usr/lib64/libpcreposix.so /usr/lib64/libpcreposix.so.3
|
sudo ln -s /usr/lib64/libpcreposix.so /usr/lib64/libpcreposix.so.3
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Windows:
|
||||||
|
|
||||||
|
If you are developing on Windows you might encounter:
|
||||||
|
|
||||||
|
- Failed to load dynamic library: error code 126
|
||||||
|
|
||||||
|
That happens because libgit2 dynamic library bundled with libgit2dart package is precompiled with ssh support, and it fails to find the `libssh2.dll`.
|
||||||
|
|
||||||
|
To fix that error you should [build](https://github.com/libssh2/libssh2/blob/master/docs/INSTALL_CMAKE.md) libssh2, and place resulting `libssh2.dll` somewhere in system path (e.g. "Windows\System32").
|
||||||
|
|
||||||
### Ffigen
|
### Ffigen
|
||||||
|
|
||||||
To generate bindings with ffigen use (adjust paths to yours):
|
To generate bindings with ffigen use (adjust paths to yours):
|
||||||
|
@ -693,7 +703,6 @@ To run all tests and generate coverage report make sure to have activated packag
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ dart pub global activate coverage
|
$ dart pub global activate coverage
|
||||||
$ dart pub global activate flutter_coverage_badge
|
|
||||||
```
|
```
|
||||||
|
|
||||||
And run:
|
And run:
|
||||||
|
|
|
@ -4,9 +4,11 @@ analyzer:
|
||||||
language:
|
language:
|
||||||
strict-casts: true
|
strict-casts: true
|
||||||
strict-raw-types: true
|
strict-raw-types: true
|
||||||
|
strict-inference: true
|
||||||
|
|
||||||
exclude:
|
exclude:
|
||||||
- lib/src/bindings/libgit2_bindings.dart
|
- lib/src/bindings/libgit2_bindings.dart
|
||||||
|
- lib/src/bindings/libgit2_opts_bindings.dart
|
||||||
|
|
||||||
linter:
|
linter:
|
||||||
rules:
|
rules:
|
||||||
|
|
|
@ -1,48 +1,45 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:args/command_runner.dart';
|
import 'package:args/command_runner.dart';
|
||||||
import 'package:cli_util/cli_logging.dart' show Ansi, Logger;
|
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/libgit2.dart';
|
import 'package:libgit2dart/src/libgit2.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:pub_cache/pub_cache.dart';
|
|
||||||
|
|
||||||
/// Copies prebuilt libgit2 library from package in '.pub_cache' into correct
|
/// Copies prebuilt libgit2 library from package in '.pub_cache' into correct
|
||||||
/// directory for [platform].
|
/// directory for [platform].
|
||||||
Future<void> copyLibrary(String platform) async {
|
Future<void> copyLibrary(String platform) async {
|
||||||
final logger = Logger.standard();
|
|
||||||
final ansi = Ansi(Ansi.terminalSupportsAnsi);
|
|
||||||
|
|
||||||
if (File(path.join(Directory.current.path, libDir, platform, getLibName()))
|
if (File(path.join(Directory.current.path, libDir, platform, getLibName()))
|
||||||
.existsSync()) {
|
.existsSync()) {
|
||||||
if (libgit2Version == Libgit2.version) {
|
if (libgit2Version == Libgit2.version) {
|
||||||
logger.stdout('${ansi.green}libgit2 for $platform is already available.');
|
stdout.writeln('libgit2 for $platform is already available.');
|
||||||
} else {
|
} else {
|
||||||
logger.stdout(
|
stdout.writeln(
|
||||||
'${ansi.red}libgit2 for $platform is outdated.\n'
|
'libgit2 for $platform is outdated.\n'
|
||||||
'Please run following commands: \n'
|
'Please run following commands: \n'
|
||||||
'dart run libgit2dart:setup clean\n'
|
'dart run libgit2dart:setup clean\n'
|
||||||
'dart run libgit2dart:setup\n\n',
|
'dart run libgit2dart:setup\n\n',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final pubCache = PubCache();
|
final libPath = checkCache();
|
||||||
final pubCacheDir =
|
|
||||||
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
|
|
||||||
final libName = getLibName();
|
final libName = getLibName();
|
||||||
|
|
||||||
logger.stdout('Copying libgit2 for $platform');
|
stdout.writeln('Copying libgit2 for $platform');
|
||||||
|
if (libPath == null) {
|
||||||
|
stdout.writeln(
|
||||||
|
"Couldn't find libgit2dart package.\n"
|
||||||
|
"Make sure to run 'dart pub get' to resolve dependencies.",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
final destination = path.join(libDir, platform);
|
final destination = path.join(libDir, platform);
|
||||||
Directory(destination).createSync(recursive: true);
|
Directory(destination).createSync(recursive: true);
|
||||||
File(path.join(pubCacheDir.path, platform, libName)).copySync(
|
File(path.join(libPath, platform, libName)).copySync(
|
||||||
path.join(destination, libName),
|
path.join(destination, libName),
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.stdout(
|
stdout.writeln('Done! libgit2 for $platform is now available!');
|
||||||
'${ansi.green}Done! libgit2 for $platform is now available!'
|
}
|
||||||
'${ansi.none}',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,10 +52,11 @@ class CleanCommand extends Command<void> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final logger = Logger.standard();
|
stdout.writeln('Cleaning...');
|
||||||
logger.stdout('Cleaning...');
|
if (Directory(libDir).existsSync()) {
|
||||||
Directory(libDir).deleteSync(recursive: true);
|
Directory(libDir).deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(List<String> args) {
|
void main(List<String> args) {
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
dart test --coverage="coverage" --test-randomize-ordering-seed random && format_coverage --lcov --check-ignore --in=coverage --out=coverage/lcov.info --packages=.packages --report-on=lib && genhtml coverage/lcov.info -o coverage/ && dart pub global run flutter_coverage_badge
|
dart test --coverage=coverage --test-randomize-ordering-seed random && dart pub global run coverage:format_coverage --lcov --check-ignore --in=coverage --out=coverage/lcov.info --report-on=lib && genhtml coverage/lcov.info -o coverage/
|
|
@ -1,20 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="102" height="20">
|
|
||||||
<linearGradient id="b" x2="0" y2="100%">
|
|
||||||
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
|
||||||
<stop offset="1" stop-opacity=".1"/>
|
|
||||||
</linearGradient>
|
|
||||||
<clipPath id="a">
|
|
||||||
<rect width="102" height="20" rx="3" fill="#fff"/>
|
|
||||||
</clipPath>
|
|
||||||
<g clip-path="url(#a)">
|
|
||||||
<path fill="#555" d="M0 0h59v20H0z"/>
|
|
||||||
<path fill="#44cc11" d="M59 0h43v20H59z"/>
|
|
||||||
<path fill="url(#b)" d="M0 0h102v20H0z"/>
|
|
||||||
</g>
|
|
||||||
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110">
|
|
||||||
<text x="305" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="490">coverage</text>
|
|
||||||
<text x="305" y="140" transform="scale(.1)" textLength="490">coverage</text>
|
|
||||||
<text x="795" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="330">100%</text>
|
|
||||||
<text x="795" y="140" transform="scale(.1)" textLength="330">100%</text>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 1 KiB |
|
@ -1,10 +1,13 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/annotated.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/annotated.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class AnnotatedCommit {
|
@immutable
|
||||||
|
class AnnotatedCommit extends Equatable {
|
||||||
/// Lookups an annotated commit from the given commit [oid].
|
/// Lookups an annotated commit from the given commit [oid].
|
||||||
///
|
///
|
||||||
/// It is preferable to use [AnnotatedCommit.fromReference] instead of this
|
/// It is preferable to use [AnnotatedCommit.fromReference] instead of this
|
||||||
|
@ -81,6 +84,7 @@ class AnnotatedCommit {
|
||||||
/// Pointer to pointer to memory address for allocated commit object.
|
/// Pointer to pointer to memory address for allocated commit object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_annotated_commit> get pointer => _annotatedCommitPointer;
|
Pointer<git_annotated_commit> get pointer => _annotatedCommitPointer;
|
||||||
|
|
||||||
/// Commit oid that the given annotated commit refers to.
|
/// Commit oid that the given annotated commit refers to.
|
||||||
|
@ -96,6 +100,9 @@ class AnnotatedCommit {
|
||||||
bindings.free(_annotatedCommitPointer);
|
bindings.free(_annotatedCommitPointer);
|
||||||
_finalizer.detach(this);
|
_finalizer.detach(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Creates an annotated commit from the given commit id. The returned
|
/// Creates an annotated commit from the given commit id. The returned
|
||||||
|
@ -76,7 +77,7 @@ Pointer<git_annotated_commit> fromRevSpec({
|
||||||
required String revspec,
|
required String revspec,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_annotated_commit>>();
|
final out = calloc<Pointer<git_annotated_commit>>();
|
||||||
final revspecC = revspec.toNativeUtf8().cast<Int8>();
|
final revspecC = revspec.toChar();
|
||||||
final error = libgit2.git_annotated_commit_from_revspec(
|
final error = libgit2.git_annotated_commit_from_revspec(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -106,8 +107,8 @@ Pointer<git_annotated_commit> fromFetchHead({
|
||||||
required Pointer<git_oid> oid,
|
required Pointer<git_oid> oid,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_annotated_commit>>();
|
final out = calloc<Pointer<git_annotated_commit>>();
|
||||||
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
|
final branchNameC = branchName.toChar();
|
||||||
final remoteUrlC = remoteUrl.toNativeUtf8().cast<Int8>();
|
final remoteUrlC = remoteUrl.toChar();
|
||||||
final error = libgit2.git_annotated_commit_from_fetchhead(
|
final error = libgit2.git_annotated_commit_from_fetchhead(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -136,7 +137,7 @@ Pointer<git_oid> oid(Pointer<git_annotated_commit> commit) =>
|
||||||
/// Get the refname that the given annotated commit refers to.
|
/// Get the refname that the given annotated commit refers to.
|
||||||
String refName(Pointer<git_annotated_commit> commit) {
|
String refName(Pointer<git_annotated_commit> commit) {
|
||||||
final result = libgit2.git_annotated_commit_ref(commit);
|
final result = libgit2.git_annotated_commit_ref(commit);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frees an annotated commit.
|
/// Frees an annotated commit.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Look up the value of one git attribute for path.
|
/// Look up the value of one git attribute for path.
|
||||||
|
@ -14,9 +15,9 @@ Object? getAttribute({
|
||||||
required String path,
|
required String path,
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<Int8>>();
|
final out = calloc<Pointer<Char>>();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
libgit2.git_attr_get(out, repoPointer, flags, pathC, nameC);
|
libgit2.git_attr_get(out, repoPointer, flags, pathC, nameC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -37,7 +38,7 @@ Object? getAttribute({
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_STRING) {
|
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_STRING) {
|
||||||
return result.cast<Utf8>().toDartString();
|
return result.toDartString();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/oid.dart';
|
import 'package:libgit2dart/src/oid.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ Pointer<git_blame> file({
|
||||||
int? maxLine,
|
int? maxLine,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_blame>>();
|
final out = calloc<Pointer<git_blame>>();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final options = calloc<git_blame_options>();
|
final options = calloc<git_blame_options>();
|
||||||
libgit2.git_blame_options_init(options, GIT_BLAME_OPTIONS_VERSION);
|
libgit2.git_blame_options_init(options, GIT_BLAME_OPTIONS_VERSION);
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ Pointer<git_blame> buffer({
|
||||||
required String buffer,
|
required String buffer,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_blame>>();
|
final out = calloc<Pointer<git_blame>>();
|
||||||
final bufferC = buffer.toNativeUtf8().cast<Int8>();
|
final bufferC = buffer.toChar();
|
||||||
final error = libgit2.git_blame_buffer(
|
final error = libgit2.git_blame_buffer(
|
||||||
out,
|
out,
|
||||||
reference,
|
reference,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
||||||
|
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Lookup a blob object from a repository. The returned blob must be freed
|
/// Lookup a blob object from a repository. The returned blob must be freed
|
||||||
|
@ -84,7 +85,7 @@ Pointer<git_oid> createFromWorkdir({
|
||||||
required String relativePath,
|
required String relativePath,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final relativePathC = relativePath.toNativeUtf8().cast<Int8>();
|
final relativePathC = relativePath.toChar();
|
||||||
final error = libgit2.git_blob_create_from_workdir(
|
final error = libgit2.git_blob_create_from_workdir(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -110,7 +111,7 @@ Pointer<git_oid> createFromDisk({
|
||||||
required String path,
|
required String path,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final error = libgit2.git_blob_create_from_disk(out, repoPointer, pathC);
|
final error = libgit2.git_blob_create_from_disk(out, repoPointer, pathC);
|
||||||
|
|
||||||
calloc.free(pathC);
|
calloc.free(pathC);
|
||||||
|
@ -150,7 +151,7 @@ String filterContent({
|
||||||
git_oid? attributesCommit,
|
git_oid? attributesCommit,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final asPathC = asPath.toNativeUtf8().cast<Int8>();
|
final asPathC = asPath.toChar();
|
||||||
final opts = calloc<git_blob_filter_options>();
|
final opts = calloc<git_blob_filter_options>();
|
||||||
libgit2.git_blob_filter_options_init(opts, GIT_BLOB_FILTER_OPTIONS_VERSION);
|
libgit2.git_blob_filter_options_init(opts, GIT_BLOB_FILTER_OPTIONS_VERSION);
|
||||||
opts.ref.flags = flags;
|
opts.ref.flags = flags;
|
||||||
|
@ -162,7 +163,7 @@ String filterContent({
|
||||||
|
|
||||||
late final String result;
|
late final String result;
|
||||||
if (out.ref.ptr != nullptr) {
|
if (out.ref.ptr != nullptr) {
|
||||||
result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/reference.dart' as reference_bindings;
|
import 'package:libgit2dart/src/bindings/reference.dart' as reference_bindings;
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Return a list of branches. The returned references must be freed with
|
/// Return a list of branches. The returned references must be freed with
|
||||||
|
@ -60,7 +61,7 @@ Pointer<git_reference> lookup({
|
||||||
required 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.toChar();
|
||||||
final error = libgit2.git_branch_lookup(
|
final error = libgit2.git_branch_lookup(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -97,7 +98,7 @@ Pointer<git_reference> create({
|
||||||
required 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.toChar();
|
||||||
final forceC = force ? 1 : 0;
|
final forceC = force ? 1 : 0;
|
||||||
final error = libgit2.git_branch_create(
|
final error = libgit2.git_branch_create(
|
||||||
out,
|
out,
|
||||||
|
@ -147,7 +148,7 @@ void rename({
|
||||||
required 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.toChar();
|
||||||
final forceC = force ? 1 : 0;
|
final forceC = force ? 1 : 0;
|
||||||
final error = libgit2.git_branch_move(
|
final error = libgit2.git_branch_move(
|
||||||
out,
|
out,
|
||||||
|
@ -202,7 +203,7 @@ bool isCheckedOut(Pointer<git_reference> branch) {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
String name(Pointer<git_reference> ref) {
|
String name(Pointer<git_reference> ref) {
|
||||||
final out = calloc<Pointer<Int8>>();
|
final out = calloc<Pointer<Char>>();
|
||||||
final error = libgit2.git_branch_name(out, ref);
|
final error = libgit2.git_branch_name(out, ref);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -212,7 +213,7 @@ String name(Pointer<git_reference> ref) {
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return result.cast<Utf8>().toDartString();
|
return result.toDartString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,10 +230,10 @@ String remoteName({
|
||||||
required String branchName,
|
required String branchName,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
|
final branchNameC = branchName.toChar();
|
||||||
final error = libgit2.git_branch_remote_name(out, repoPointer, branchNameC);
|
final error = libgit2.git_branch_remote_name(out, repoPointer, branchNameC);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -281,7 +282,7 @@ void setUpstream({
|
||||||
required Pointer<git_reference> branchPointer,
|
required Pointer<git_reference> branchPointer,
|
||||||
required String? branchName,
|
required String? branchName,
|
||||||
}) {
|
}) {
|
||||||
final branchNameC = branchName?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final branchNameC = branchName?.toChar() ?? nullptr;
|
||||||
final error = libgit2.git_branch_set_upstream(branchPointer, branchNameC);
|
final error = libgit2.git_branch_set_upstream(branchPointer, branchNameC);
|
||||||
|
|
||||||
calloc.free(branchNameC);
|
calloc.free(branchNameC);
|
||||||
|
@ -303,10 +304,10 @@ String upstreamName({
|
||||||
required String branchName,
|
required String branchName,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
|
final branchNameC = branchName.toChar();
|
||||||
final error = libgit2.git_branch_upstream_name(out, repoPointer, branchNameC);
|
final error = libgit2.git_branch_upstream_name(out, repoPointer, branchNameC);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -330,14 +331,14 @@ String upstreamRemote({
|
||||||
required String branchName,
|
required String branchName,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
|
final branchNameC = branchName.toChar();
|
||||||
final error = libgit2.git_branch_upstream_remote(
|
final error = libgit2.git_branch_upstream_remote(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
branchNameC,
|
branchNameC,
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -361,14 +362,14 @@ String upstreamMerge({
|
||||||
required String branchName,
|
required String branchName,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final branchNameC = branchName.toNativeUtf8().cast<Int8>();
|
final branchNameC = branchName.toChar();
|
||||||
final error = libgit2.git_branch_upstream_merge(
|
final error = libgit2.git_branch_upstream_merge(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
branchNameC,
|
branchNameC,
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Updates files in the index and the working tree to match the content of the
|
/// Updates files in the index and the working tree to match the content of the
|
||||||
|
@ -127,13 +128,13 @@ List<Object> initOptions({
|
||||||
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.toChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
var pathPointers = <Pointer<Int8>>[];
|
var pathPointers = <Pointer<Char>>[];
|
||||||
Pointer<Pointer<Int8>> strArray = nullptr;
|
Pointer<Pointer<Char>> strArray = nullptr;
|
||||||
if (paths != null) {
|
if (paths != null) {
|
||||||
pathPointers = paths.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
pathPointers = paths.map((e) => e.toChar()).toList();
|
||||||
strArray = calloc(paths.length);
|
strArray = calloc(paths.length);
|
||||||
for (var i = 0; i < paths.length; i++) {
|
for (var i = 0; i < paths.length; i++) {
|
||||||
strArray[i] = pathPointers[i];
|
strArray[i] = pathPointers[i];
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Lookup a commit object from a repository. The returned commit must be
|
/// Lookup a commit object from a repository. The returned commit must be
|
||||||
|
@ -45,10 +46,9 @@ Pointer<git_oid> create({
|
||||||
required List<Pointer<git_commit>> parents,
|
required List<Pointer<git_commit>> parents,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final updateRefC = updateRef.toNativeUtf8().cast<Int8>();
|
final updateRefC = updateRef.toChar();
|
||||||
final messageEncodingC =
|
final messageEncodingC = messageEncoding?.toChar() ?? nullptr;
|
||||||
messageEncoding?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final messageC = message.toChar();
|
||||||
final messageC = message.toNativeUtf8().cast<Int8>();
|
|
||||||
final parentsC = calloc<Pointer<git_commit>>(parentCount);
|
final parentsC = calloc<Pointer<git_commit>>(parentCount);
|
||||||
|
|
||||||
if (parents.isNotEmpty) {
|
if (parents.isNotEmpty) {
|
||||||
|
@ -103,10 +103,9 @@ String createBuffer({
|
||||||
required List<Pointer<git_commit>> parents,
|
required List<Pointer<git_commit>> parents,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final updateRefC = updateRef.toNativeUtf8().cast<Int8>();
|
final updateRefC = updateRef.toChar();
|
||||||
final messageEncodingC =
|
final messageEncodingC = messageEncoding?.toChar() ?? nullptr;
|
||||||
messageEncoding?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final messageC = message.toChar();
|
||||||
final messageC = message.toNativeUtf8().cast<Int8>();
|
|
||||||
final parentsC = calloc<Pointer<git_commit>>(parentCount);
|
final parentsC = calloc<Pointer<git_commit>>(parentCount);
|
||||||
|
|
||||||
if (parents.isNotEmpty) {
|
if (parents.isNotEmpty) {
|
||||||
|
@ -129,7 +128,7 @@ String createBuffer({
|
||||||
parentsC,
|
parentsC,
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -169,10 +168,9 @@ Pointer<git_oid> amend({
|
||||||
required Pointer<git_tree>? treePointer,
|
required Pointer<git_tree>? treePointer,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final updateRefC = updateRef?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final updateRefC = updateRef?.toChar() ?? nullptr;
|
||||||
final messageEncodingC =
|
final messageEncodingC = messageEncoding?.toChar() ?? nullptr;
|
||||||
messageEncoding?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final messageC = message?.toChar() ?? nullptr;
|
||||||
final messageC = message?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
|
||||||
|
|
||||||
final error = libgit2.git_commit_amend(
|
final error = libgit2.git_commit_amend(
|
||||||
out,
|
out,
|
||||||
|
@ -216,7 +214,7 @@ Pointer<git_commit> duplicate(Pointer<git_commit> source) {
|
||||||
/// If the encoding header in the commit is missing UTF-8 is assumed.
|
/// If the encoding header in the commit is missing UTF-8 is assumed.
|
||||||
String messageEncoding(Pointer<git_commit> commit) {
|
String messageEncoding(Pointer<git_commit> commit) {
|
||||||
final result = libgit2.git_commit_message_encoding(commit);
|
final result = libgit2.git_commit_message_encoding(commit);
|
||||||
return result == nullptr ? 'utf-8' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? 'utf-8' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the full message of a commit.
|
/// Get the full message of a commit.
|
||||||
|
@ -224,7 +222,7 @@ String messageEncoding(Pointer<git_commit> commit) {
|
||||||
/// The returned message will be slightly prettified by removing any potential
|
/// The returned message will be slightly prettified by removing any potential
|
||||||
/// leading newlines.
|
/// leading newlines.
|
||||||
String message(Pointer<git_commit> commit) {
|
String message(Pointer<git_commit> commit) {
|
||||||
return libgit2.git_commit_message(commit).cast<Utf8>().toDartString();
|
return libgit2.git_commit_message(commit).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the short "summary" of the git commit message.
|
/// Get the short "summary" of the git commit message.
|
||||||
|
@ -239,7 +237,7 @@ String summary(Pointer<git_commit> commit) {
|
||||||
if (result == nullptr) {
|
if (result == nullptr) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
return result.cast<Utf8>().toDartString();
|
return result.toDartString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +248,7 @@ String summary(Pointer<git_commit> commit) {
|
||||||
/// trimmed.
|
/// trimmed.
|
||||||
String body(Pointer<git_commit> commit) {
|
String body(Pointer<git_commit> commit) {
|
||||||
final result = libgit2.git_commit_body(commit);
|
final result = libgit2.git_commit_body(commit);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an arbitrary header field.
|
/// Get an arbitrary header field.
|
||||||
|
@ -261,10 +259,10 @@ String headerField({
|
||||||
required String field,
|
required String field,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final fieldC = field.toNativeUtf8().cast<Int8>();
|
final fieldC = field.toChar();
|
||||||
final error = libgit2.git_commit_header_field(out, commitPointer, fieldC);
|
final error = libgit2.git_commit_header_field(out, commitPointer, fieldC);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -386,8 +384,48 @@ Pointer<git_tree> tree(Pointer<git_commit> commit) {
|
||||||
void revert({
|
void revert({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required Pointer<git_commit> commitPointer,
|
required Pointer<git_commit> commitPointer,
|
||||||
|
required int mainline,
|
||||||
|
int? mergeFavor,
|
||||||
|
int? mergeFlags,
|
||||||
|
int? mergeFileFlags,
|
||||||
|
int? checkoutStrategy,
|
||||||
|
String? checkoutDirectory,
|
||||||
|
List<String>? checkoutPaths,
|
||||||
}) {
|
}) {
|
||||||
final error = libgit2.git_revert(repoPointer, commitPointer, nullptr);
|
final opts = calloc<git_revert_options>();
|
||||||
|
libgit2.git_revert_options_init(opts, GIT_REVERT_OPTIONS_VERSION);
|
||||||
|
|
||||||
|
opts.ref.mainline = mainline;
|
||||||
|
|
||||||
|
if (mergeFavor != null) opts.ref.merge_opts.file_favor = mergeFavor;
|
||||||
|
if (mergeFlags != null) opts.ref.merge_opts.flags = mergeFlags;
|
||||||
|
if (mergeFileFlags != null) opts.ref.merge_opts.file_flags = mergeFileFlags;
|
||||||
|
|
||||||
|
if (checkoutStrategy != null) {
|
||||||
|
opts.ref.checkout_opts.checkout_strategy = checkoutStrategy;
|
||||||
|
}
|
||||||
|
if (checkoutDirectory != null) {
|
||||||
|
opts.ref.checkout_opts.target_directory = checkoutDirectory.toChar();
|
||||||
|
}
|
||||||
|
var pathPointers = <Pointer<Char>>[];
|
||||||
|
Pointer<Pointer<Char>> strArray = nullptr;
|
||||||
|
if (checkoutPaths != null) {
|
||||||
|
pathPointers = checkoutPaths.map((e) => e.toChar()).toList();
|
||||||
|
strArray = calloc(checkoutPaths.length);
|
||||||
|
for (var i = 0; i < checkoutPaths.length; i++) {
|
||||||
|
strArray[i] = pathPointers[i];
|
||||||
|
}
|
||||||
|
opts.ref.checkout_opts.paths.strings = strArray;
|
||||||
|
opts.ref.checkout_opts.paths.count = checkoutPaths.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
final error = libgit2.git_revert(repoPointer, commitPointer, opts);
|
||||||
|
|
||||||
|
for (final p in pathPointers) {
|
||||||
|
calloc.free(p);
|
||||||
|
}
|
||||||
|
calloc.free(strArray);
|
||||||
|
calloc.free(opts);
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
@ -405,11 +443,18 @@ Pointer<git_index> revertCommit({
|
||||||
required Pointer<git_commit> revertCommitPointer,
|
required Pointer<git_commit> revertCommitPointer,
|
||||||
required Pointer<git_commit> ourCommitPointer,
|
required Pointer<git_commit> ourCommitPointer,
|
||||||
required int mainline,
|
required int mainline,
|
||||||
|
int? mergeFavor,
|
||||||
|
int? mergeFlags,
|
||||||
|
int? mergeFileFlags,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_index>>();
|
final out = calloc<Pointer<git_index>>();
|
||||||
final opts = calloc<git_merge_options>();
|
final opts = calloc<git_merge_options>();
|
||||||
libgit2.git_merge_options_init(opts, GIT_MERGE_OPTIONS_VERSION);
|
libgit2.git_merge_options_init(opts, GIT_MERGE_OPTIONS_VERSION);
|
||||||
|
|
||||||
|
if (mergeFavor != null) opts.ref.file_favor = mergeFavor;
|
||||||
|
if (mergeFlags != null) opts.ref.flags = mergeFlags;
|
||||||
|
if (mergeFileFlags != null) opts.ref.file_flags = mergeFileFlags;
|
||||||
|
|
||||||
final error = libgit2.git_revert_commit(
|
final error = libgit2.git_revert_commit(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
|
|
@ -5,13 +5,14 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Create a new config instance containing a single on-disk file. The returned
|
/// Create a new config instance containing a single on-disk file. The returned
|
||||||
/// config must be freed with [free].
|
/// config must be freed with [free].
|
||||||
Pointer<git_config> open(String path) {
|
Pointer<git_config> open(String path) {
|
||||||
final out = calloc<Pointer<git_config>>();
|
final out = calloc<Pointer<git_config>>();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
libgit2.git_config_open_ondisk(out, pathC);
|
libgit2.git_config_open_ondisk(out, pathC);
|
||||||
|
|
||||||
calloc.free(pathC);
|
calloc.free(pathC);
|
||||||
|
@ -59,7 +60,7 @@ String findGlobal() {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final error = libgit2.git_config_find_global(out);
|
final error = libgit2.git_config_find_global(out);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -81,7 +82,7 @@ String findSystem() {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final error = libgit2.git_config_find_system(out);
|
final error = libgit2.git_config_find_system(out);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -107,7 +108,7 @@ String findXdg() {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final error = libgit2.git_config_find_xdg(out);
|
final error = libgit2.git_config_find_xdg(out);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -145,7 +146,7 @@ Pointer<git_config_entry> getEntry({
|
||||||
required String variable,
|
required String variable,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_config_entry>>();
|
final out = calloc<Pointer<git_config_entry>>();
|
||||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
final nameC = variable.toChar();
|
||||||
final error = libgit2.git_config_get_entry(out, configPointer, nameC);
|
final error = libgit2.git_config_get_entry(out, configPointer, nameC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -167,7 +168,7 @@ void setBool({
|
||||||
required String variable,
|
required String variable,
|
||||||
required bool value,
|
required bool value,
|
||||||
}) {
|
}) {
|
||||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
final nameC = variable.toChar();
|
||||||
final valueC = value ? 1 : 0;
|
final valueC = value ? 1 : 0;
|
||||||
libgit2.git_config_set_bool(configPointer, nameC, valueC);
|
libgit2.git_config_set_bool(configPointer, nameC, valueC);
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
|
@ -180,7 +181,7 @@ void setInt({
|
||||||
required String variable,
|
required String variable,
|
||||||
required int value,
|
required int value,
|
||||||
}) {
|
}) {
|
||||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
final nameC = variable.toChar();
|
||||||
libgit2.git_config_set_int64(configPointer, nameC, value);
|
libgit2.git_config_set_int64(configPointer, nameC, value);
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
}
|
}
|
||||||
|
@ -192,8 +193,8 @@ void setString({
|
||||||
required String variable,
|
required String variable,
|
||||||
required String value,
|
required String value,
|
||||||
}) {
|
}) {
|
||||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
final nameC = variable.toChar();
|
||||||
final valueC = value.toNativeUtf8().cast<Int8>();
|
final valueC = value.toChar();
|
||||||
libgit2.git_config_set_string(configPointer, nameC, valueC);
|
libgit2.git_config_set_string(configPointer, nameC, valueC);
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
calloc.free(valueC);
|
calloc.free(valueC);
|
||||||
|
@ -220,7 +221,7 @@ void delete({
|
||||||
required Pointer<git_config> configPointer,
|
required Pointer<git_config> configPointer,
|
||||||
required String variable,
|
required String variable,
|
||||||
}) {
|
}) {
|
||||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
final nameC = variable.toChar();
|
||||||
final error = libgit2.git_config_delete_entry(configPointer, nameC);
|
final error = libgit2.git_config_delete_entry(configPointer, nameC);
|
||||||
|
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
|
@ -243,8 +244,8 @@ List<String> multivarValues({
|
||||||
required String variable,
|
required String variable,
|
||||||
String? regexp,
|
String? regexp,
|
||||||
}) {
|
}) {
|
||||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
final nameC = variable.toChar();
|
||||||
final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final regexpC = regexp?.toChar() ?? 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>>();
|
||||||
|
|
||||||
|
@ -261,7 +262,7 @@ List<String> multivarValues({
|
||||||
while (error == 0) {
|
while (error == 0) {
|
||||||
error = libgit2.git_config_next(entry, iterator.value);
|
error = libgit2.git_config_next(entry, iterator.value);
|
||||||
if (error != -31) {
|
if (error != -31) {
|
||||||
entries.add(entry.value.ref.value.cast<Utf8>().toDartString());
|
entries.add(entry.value.ref.value.toDartString());
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -286,9 +287,9 @@ void setMultivar({
|
||||||
required String regexp,
|
required String regexp,
|
||||||
required String value,
|
required String value,
|
||||||
}) {
|
}) {
|
||||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
final nameC = variable.toChar();
|
||||||
final regexpC = regexp.toNativeUtf8().cast<Int8>();
|
final regexpC = regexp.toChar();
|
||||||
final valueC = value.toNativeUtf8().cast<Int8>();
|
final valueC = value.toChar();
|
||||||
|
|
||||||
libgit2.git_config_set_multivar(configPointer, nameC, regexpC, valueC);
|
libgit2.git_config_set_multivar(configPointer, nameC, regexpC, valueC);
|
||||||
|
|
||||||
|
@ -306,8 +307,8 @@ void deleteMultivar({
|
||||||
required String variable,
|
required String variable,
|
||||||
required String regexp,
|
required String regexp,
|
||||||
}) {
|
}) {
|
||||||
final nameC = variable.toNativeUtf8().cast<Int8>();
|
final nameC = variable.toChar();
|
||||||
final regexpC = regexp.toNativeUtf8().cast<Int8>();
|
final regexpC = regexp.toChar();
|
||||||
|
|
||||||
libgit2.git_config_delete_multivar(configPointer, nameC, regexpC);
|
libgit2.git_config_delete_multivar(configPointer, nameC, regexpC);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Create a new plain-text username and password credential object.
|
/// Create a new plain-text username and password credential object.
|
||||||
|
@ -10,8 +11,8 @@ Pointer<git_credential> userPass({
|
||||||
required String password,
|
required String password,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_credential>>();
|
final out = calloc<Pointer<git_credential>>();
|
||||||
final usernameC = username.toNativeUtf8().cast<Int8>();
|
final usernameC = username.toChar();
|
||||||
final passwordC = password.toNativeUtf8().cast<Int8>();
|
final passwordC = password.toChar();
|
||||||
|
|
||||||
libgit2.git_credential_userpass_plaintext_new(out, usernameC, passwordC);
|
libgit2.git_credential_userpass_plaintext_new(out, usernameC, passwordC);
|
||||||
|
|
||||||
|
@ -32,10 +33,10 @@ Pointer<git_credential> sshKey({
|
||||||
required 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.toChar();
|
||||||
final publicKeyC = publicKey.toNativeUtf8().cast<Int8>();
|
final publicKeyC = publicKey.toChar();
|
||||||
final privateKeyC = privateKey.toNativeUtf8().cast<Int8>();
|
final privateKeyC = privateKey.toChar();
|
||||||
final passPhraseC = passPhrase.toNativeUtf8().cast<Int8>();
|
final passPhraseC = passPhrase.toChar();
|
||||||
|
|
||||||
libgit2.git_credential_ssh_key_new(
|
libgit2.git_credential_ssh_key_new(
|
||||||
out,
|
out,
|
||||||
|
@ -59,7 +60,7 @@ Pointer<git_credential> sshKey({
|
||||||
/// Create a new ssh key credential object used for querying an ssh-agent.
|
/// Create a new ssh key credential object used for querying an ssh-agent.
|
||||||
Pointer<git_credential> sshKeyFromAgent(String username) {
|
Pointer<git_credential> sshKeyFromAgent(String username) {
|
||||||
final out = calloc<Pointer<git_credential>>();
|
final out = calloc<Pointer<git_credential>>();
|
||||||
final usernameC = username.toNativeUtf8().cast<Int8>();
|
final usernameC = username.toChar();
|
||||||
|
|
||||||
libgit2.git_credential_ssh_key_from_agent(out, usernameC);
|
libgit2.git_credential_ssh_key_from_agent(out, usernameC);
|
||||||
|
|
||||||
|
@ -79,10 +80,10 @@ Pointer<git_credential> sshKeyFromMemory({
|
||||||
required 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.toChar();
|
||||||
final publicKeyC = publicKey.toNativeUtf8().cast<Int8>();
|
final publicKeyC = publicKey.toChar();
|
||||||
final privateKeyC = privateKey.toNativeUtf8().cast<Int8>();
|
final privateKeyC = privateKey.toChar();
|
||||||
final passPhraseC = passPhrase.toNativeUtf8().cast<Int8>();
|
final passPhraseC = passPhrase.toChar();
|
||||||
|
|
||||||
libgit2.git_credential_ssh_key_memory_new(
|
libgit2.git_credential_ssh_key_memory_new(
|
||||||
out,
|
out,
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Describe a commit. The returned describe result must be freed with [free].
|
/// Describe a commit. The returned describe result must be freed with [free].
|
||||||
|
@ -100,12 +101,12 @@ String format({
|
||||||
opts.ref.always_use_long_format = alwaysUseLongFormat ? 1 : 0;
|
opts.ref.always_use_long_format = alwaysUseLongFormat ? 1 : 0;
|
||||||
}
|
}
|
||||||
if (dirtySuffix != null) {
|
if (dirtySuffix != null) {
|
||||||
opts.ref.dirty_suffix = dirtySuffix.toNativeUtf8().cast<Int8>();
|
opts.ref.dirty_suffix = dirtySuffix.toChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
libgit2.git_describe_format(out, describeResultPointer, opts);
|
libgit2.git_describe_format(out, describeResultPointer, opts);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -140,7 +141,7 @@ Pointer<git_describe_options> _initOpts({
|
||||||
opts.ref.describe_strategy = describeStrategy;
|
opts.ref.describe_strategy = describeStrategy;
|
||||||
}
|
}
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
opts.ref.pattern = pattern.toNativeUtf8().cast<Int8>();
|
opts.ref.pattern = pattern.toChar();
|
||||||
}
|
}
|
||||||
if (onlyFollowFirstParent != null) {
|
if (onlyFollowFirstParent != null) {
|
||||||
opts.ref.only_follow_first_parent = onlyFollowFirstParent ? 1 : 0;
|
opts.ref.only_follow_first_parent = onlyFollowFirstParent ? 1 : 0;
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Create a diff with the difference between two index objects. The returned
|
/// Create a diff with the difference between two index objects. The returned
|
||||||
|
@ -253,7 +254,7 @@ void merge({
|
||||||
/// other types of patch files.
|
/// other types of patch files.
|
||||||
Pointer<git_diff> parse(String content) {
|
Pointer<git_diff> parse(String content) {
|
||||||
final out = calloc<Pointer<git_diff>>();
|
final out = calloc<Pointer<git_diff>>();
|
||||||
final contentC = content.toNativeUtf8().cast<Int8>();
|
final contentC = content.toChar();
|
||||||
libgit2.git_diff_from_buffer(out, contentC, content.length);
|
libgit2.git_diff_from_buffer(out, contentC, content.length);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -383,7 +384,7 @@ String statsPrint({
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final error = libgit2.git_diff_stats_to_buf(out, statsPointer, format, width);
|
final error = libgit2.git_diff_stats_to_buf(out, statsPointer, format, width);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -402,7 +403,7 @@ String addToBuf(Pointer<git_diff> diff) {
|
||||||
|
|
||||||
final result = out.ref.ptr == nullptr
|
final result = out.ref.ptr == nullptr
|
||||||
? ''
|
? ''
|
||||||
: out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
: out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
|
@ -33,8 +33,8 @@ List<int> aheadBehind({
|
||||||
required Pointer<git_oid> localPointer,
|
required Pointer<git_oid> localPointer,
|
||||||
required Pointer<git_oid> upstreamPointer,
|
required Pointer<git_oid> upstreamPointer,
|
||||||
}) {
|
}) {
|
||||||
final ahead = calloc<Uint64>();
|
final ahead = calloc<Size>();
|
||||||
final behind = calloc<Uint64>();
|
final behind = calloc<Size>();
|
||||||
|
|
||||||
libgit2.git_graph_ahead_behind(
|
libgit2.git_graph_ahead_behind(
|
||||||
ahead,
|
ahead,
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Create an in-memory index object.
|
/// Create an in-memory index object.
|
||||||
|
@ -45,7 +46,7 @@ void setCapabilities({
|
||||||
|
|
||||||
/// Get the full path to the index file on disk.
|
/// Get the full path to the index file on disk.
|
||||||
String path(Pointer<git_index> index) {
|
String path(Pointer<git_index> index) {
|
||||||
return libgit2.git_index_path(index).cast<Utf8>().toDartString();
|
return libgit2.git_index_path(index).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the contents of an existing index object in memory by reading from
|
/// Update the contents of an existing index object in memory by reading from
|
||||||
|
@ -125,7 +126,7 @@ Pointer<git_oid> writeTreeTo({
|
||||||
/// Find the first position of any entries which point to given path in the Git
|
/// Find the first position of any entries which point to given path in the Git
|
||||||
/// index.
|
/// index.
|
||||||
bool find({required Pointer<git_index> indexPointer, required String path}) {
|
bool find({required Pointer<git_index> indexPointer, required String path}) {
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final result = libgit2.git_index_find(nullptr, indexPointer, pathC);
|
final result = libgit2.git_index_find(nullptr, indexPointer, pathC);
|
||||||
|
|
||||||
calloc.free(pathC);
|
calloc.free(pathC);
|
||||||
|
@ -164,7 +165,7 @@ Pointer<git_index_entry> getByPath({
|
||||||
required String path,
|
required String path,
|
||||||
required int stage,
|
required int stage,
|
||||||
}) {
|
}) {
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final result = libgit2.git_index_get_bypath(indexPointer, pathC, stage);
|
final result = libgit2.git_index_get_bypath(indexPointer, pathC, stage);
|
||||||
|
|
||||||
calloc.free(pathC);
|
calloc.free(pathC);
|
||||||
|
@ -231,7 +232,7 @@ void addByPath({
|
||||||
required Pointer<git_index> indexPointer,
|
required Pointer<git_index> indexPointer,
|
||||||
required String path,
|
required String path,
|
||||||
}) {
|
}) {
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final error = libgit2.git_index_add_bypath(indexPointer, pathC);
|
final error = libgit2.git_index_add_bypath(indexPointer, pathC);
|
||||||
|
|
||||||
calloc.free(pathC);
|
calloc.free(pathC);
|
||||||
|
@ -263,7 +264,7 @@ void addFromBuffer({
|
||||||
required Pointer<git_index_entry> entryPointer,
|
required Pointer<git_index_entry> entryPointer,
|
||||||
required String buffer,
|
required String buffer,
|
||||||
}) {
|
}) {
|
||||||
final bufferC = buffer.toNativeUtf8().cast<Int8>();
|
final bufferC = buffer.toChar();
|
||||||
final error = libgit2.git_index_add_from_buffer(
|
final error = libgit2.git_index_add_from_buffer(
|
||||||
indexPointer,
|
indexPointer,
|
||||||
entryPointer,
|
entryPointer,
|
||||||
|
@ -291,11 +292,11 @@ void addFromBuffer({
|
||||||
void addAll({
|
void addAll({
|
||||||
required Pointer<git_index> indexPointer,
|
required Pointer<git_index> indexPointer,
|
||||||
required List<String> pathspec,
|
required List<String> pathspec,
|
||||||
|
required int flags,
|
||||||
}) {
|
}) {
|
||||||
final pathspecC = calloc<git_strarray>();
|
final pathspecC = calloc<git_strarray>();
|
||||||
final pathPointers =
|
final pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||||
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
final strArray = calloc<Pointer<Char>>(pathspec.length);
|
||||||
final strArray = calloc<Pointer<Int8>>(pathspec.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < pathspec.length; i++) {
|
for (var i = 0; i < pathspec.length; i++) {
|
||||||
strArray[i] = pathPointers[i];
|
strArray[i] = pathPointers[i];
|
||||||
|
@ -307,7 +308,7 @@ void addAll({
|
||||||
final error = libgit2.git_index_add_all(
|
final error = libgit2.git_index_add_all(
|
||||||
indexPointer,
|
indexPointer,
|
||||||
pathspecC,
|
pathspecC,
|
||||||
0,
|
flags,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
);
|
);
|
||||||
|
@ -338,9 +339,8 @@ void updateAll({
|
||||||
required List<String> pathspec,
|
required List<String> pathspec,
|
||||||
}) {
|
}) {
|
||||||
final pathspecC = calloc<git_strarray>();
|
final pathspecC = calloc<git_strarray>();
|
||||||
final pathPointers =
|
final pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||||
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
final strArray = calloc<Pointer<Char>>(pathspec.length);
|
||||||
final strArray = calloc<Pointer<Int8>>(pathspec.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < pathspec.length; i++) {
|
for (var i = 0; i < pathspec.length; i++) {
|
||||||
strArray[i] = pathPointers[i];
|
strArray[i] = pathPointers[i];
|
||||||
|
@ -379,7 +379,7 @@ void remove({
|
||||||
required String path,
|
required String path,
|
||||||
required int stage,
|
required int stage,
|
||||||
}) {
|
}) {
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final error = libgit2.git_index_remove(indexPointer, pathC, stage);
|
final error = libgit2.git_index_remove(indexPointer, pathC, stage);
|
||||||
|
|
||||||
calloc.free(pathC);
|
calloc.free(pathC);
|
||||||
|
@ -395,7 +395,7 @@ void removeDirectory({
|
||||||
required String dir,
|
required String dir,
|
||||||
required int stage,
|
required int stage,
|
||||||
}) {
|
}) {
|
||||||
final dirC = dir.toNativeUtf8().cast<Int8>();
|
final dirC = dir.toChar();
|
||||||
libgit2.git_index_remove_directory(indexPointer, dirC, stage);
|
libgit2.git_index_remove_directory(indexPointer, dirC, stage);
|
||||||
calloc.free(dirC);
|
calloc.free(dirC);
|
||||||
}
|
}
|
||||||
|
@ -406,9 +406,8 @@ void removeAll({
|
||||||
required List<String> pathspec,
|
required List<String> pathspec,
|
||||||
}) {
|
}) {
|
||||||
final pathspecC = calloc<git_strarray>();
|
final pathspecC = calloc<git_strarray>();
|
||||||
final pathPointers =
|
final pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||||
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
final strArray = calloc<Pointer<Char>>(pathspec.length);
|
||||||
final strArray = calloc<Pointer<Int8>>(pathspec.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < pathspec.length; i++) {
|
for (var i = 0; i < pathspec.length; i++) {
|
||||||
strArray[i] = pathPointers[i];
|
strArray[i] = pathPointers[i];
|
||||||
|
@ -511,7 +510,7 @@ void conflictRemove({
|
||||||
required Pointer<git_index> indexPointer,
|
required Pointer<git_index> indexPointer,
|
||||||
required String path,
|
required String path,
|
||||||
}) {
|
}) {
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final error = libgit2.git_index_conflict_remove(indexPointer, pathC);
|
final error = libgit2.git_index_conflict_remove(indexPointer, pathC);
|
||||||
|
|
||||||
calloc.free(pathC);
|
calloc.free(pathC);
|
||||||
|
|
File diff suppressed because it is too large
Load diff
468
lib/src/bindings/libgit2_opts_bindings.dart
Normal file
468
lib/src/bindings/libgit2_opts_bindings.dart
Normal file
|
@ -0,0 +1,468 @@
|
||||||
|
// coverage:ignore-file
|
||||||
|
|
||||||
|
import 'dart:ffi' as ffi;
|
||||||
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
|
||||||
|
/// Bindings to libgit2 global options
|
||||||
|
class Libgit2Opts {
|
||||||
|
/// Holds the symbol lookup function.
|
||||||
|
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||||
|
_lookup;
|
||||||
|
|
||||||
|
/// The symbols are looked up in [dynamicLibrary].
|
||||||
|
Libgit2Opts(ffi.DynamicLibrary dynamicLibrary)
|
||||||
|
: _lookup = dynamicLibrary.lookup;
|
||||||
|
|
||||||
|
/// Get the maximum mmap window size.
|
||||||
|
int git_libgit2_opts_get_mwindow_size(ffi.Pointer<ffi.Int> out) {
|
||||||
|
return _git_libgit2_opts_get_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_MWINDOW_SIZE,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the maximum mmap window size.
|
||||||
|
int git_libgit2_opts_set_mwindow_size(int value) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_MWINDOW_SIZE,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the maximum memory that will be mapped in total by the library.
|
||||||
|
///
|
||||||
|
/// The default (0) is unlimited.
|
||||||
|
int git_libgit2_opts_get_mwindow_mapped_limit(ffi.Pointer<ffi.Int> out) {
|
||||||
|
return _git_libgit2_opts_get_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_MWINDOW_MAPPED_LIMIT,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the maximum amount of memory that can be mapped at any time by the
|
||||||
|
/// library.
|
||||||
|
int git_libgit2_opts_set_mwindow_mapped_limit(int value) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_MWINDOW_MAPPED_LIMIT,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the maximum number of files that will be mapped at any time by the
|
||||||
|
/// library.
|
||||||
|
///
|
||||||
|
/// The default (0) is unlimited.
|
||||||
|
int git_libgit2_opts_get_mwindow_file_limit(ffi.Pointer<ffi.Int> out) {
|
||||||
|
return _git_libgit2_opts_get_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_MWINDOW_FILE_LIMIT,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the maximum number of files that can be mapped at any time by the
|
||||||
|
/// library.
|
||||||
|
int git_libgit2_opts_set_mwindow_file_limit(int value) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_MWINDOW_FILE_LIMIT,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the search path for a given level of config data.
|
||||||
|
///
|
||||||
|
/// [level] must be one of `GIT_CONFIG_LEVEL_SYSTEM`,
|
||||||
|
/// `GIT_CONFIG_LEVEL_GLOBAL`, `GIT_CONFIG_LEVEL_XDG`, or
|
||||||
|
/// `GIT_CONFIG_LEVEL_PROGRAMDATA`.
|
||||||
|
///
|
||||||
|
/// The search path is written to the [out] buffer.
|
||||||
|
int git_libgit2_opts_get_search_path(int level, ffi.Pointer<git_buf> out) {
|
||||||
|
return _git_libgit2_opts_get_search_path(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_SEARCH_PATH,
|
||||||
|
level,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the search path for a level of config data. The search path applied
|
||||||
|
/// to shared attributes and ignore files, too.
|
||||||
|
///
|
||||||
|
/// [path] lists directories delimited by GIT_PATH_LIST_SEPARATOR.
|
||||||
|
/// Pass NULL to reset to the default (generally based on environment
|
||||||
|
/// variables). Use magic path `$PATH` to include the old value of the path
|
||||||
|
/// (if you want to prepend or append, for instance).
|
||||||
|
///
|
||||||
|
/// [level] must be one of `GIT_CONFIG_LEVEL_SYSTEM`,
|
||||||
|
/// `GIT_CONFIG_LEVEL_GLOBAL`, `GIT_CONFIG_LEVEL_XDG`, or
|
||||||
|
/// `GIT_CONFIG_LEVEL_PROGRAMDATA`.
|
||||||
|
int git_libgit2_opts_set_search_path(int level, ffi.Pointer<ffi.Char> path) {
|
||||||
|
return _git_libgit2_opts_set_search_path(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_SEARCH_PATH,
|
||||||
|
level,
|
||||||
|
path,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the maximum data size for the given [type] of object to be
|
||||||
|
/// considered eligible for caching in memory. Setting the [value] to
|
||||||
|
/// zero means that that type of object will not be cached.
|
||||||
|
///
|
||||||
|
/// Defaults to 0 for GIT_OBJECT_BLOB (i.e. won't cache blobs) and 4k
|
||||||
|
/// for GIT_OBJECT_COMMIT, GIT_OBJECT_TREE, and GIT_OBJECT_TAG.
|
||||||
|
int git_libgit2_opts_set_cache_object_limit(int type, int value) {
|
||||||
|
return _git_libgit2_opts_set_cache_object_limit(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_CACHE_OBJECT_LIMIT,
|
||||||
|
type,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the maximum total data size that will be cached in memory
|
||||||
|
/// across all repositories before libgit2 starts evicting objects
|
||||||
|
/// from the cache. This is a soft limit, in that the library might
|
||||||
|
/// briefly exceed it, but will start aggressively evicting objects
|
||||||
|
/// from cache when that happens.
|
||||||
|
///
|
||||||
|
/// The default cache size is 256MB.
|
||||||
|
int git_libgit2_opts_set_cache_max_size(int bytes) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_CACHE_MAX_SIZE,
|
||||||
|
bytes,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the current bytes in cache and the maximum that would be
|
||||||
|
/// allowed in the cache.
|
||||||
|
int git_libgit2_opts_get_cached_memory(
|
||||||
|
ffi.Pointer<ffi.Int> current,
|
||||||
|
ffi.Pointer<ffi.Int> allowed,
|
||||||
|
) {
|
||||||
|
return _git_libgit2_opts_get_cached_memory(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_CACHED_MEMORY,
|
||||||
|
current,
|
||||||
|
allowed,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enable or disable caching completely.
|
||||||
|
///
|
||||||
|
/// Because caches are repository-specific, disabling the cache
|
||||||
|
/// cannot immediately clear all cached objects, but each cache will
|
||||||
|
/// be cleared on the next attempt to update anything in it.
|
||||||
|
int git_libgit2_opts_enable_caching(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_ENABLE_CACHING,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the default template path.
|
||||||
|
/// The path is written to the `out` buffer.
|
||||||
|
int git_libgit2_opts_get_template_path(ffi.Pointer<git_buf> out) {
|
||||||
|
return _git_libgit2_opts_get_buf(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_TEMPLATE_PATH,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the default template [path].
|
||||||
|
int git_libgit2_opts_set_template_path(ffi.Pointer<ffi.Char> path) {
|
||||||
|
return _git_libgit2_opts_set_char(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_TEMPLATE_PATH,
|
||||||
|
path,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the SSL certificate-authority locations.
|
||||||
|
///
|
||||||
|
/// - [file] is the location of a file containing several
|
||||||
|
/// certificates concatenated together.
|
||||||
|
/// - [path] is the location of a directory holding several
|
||||||
|
/// certificates, one per file.
|
||||||
|
///
|
||||||
|
/// Either parameter may be `NULL`, but not both.
|
||||||
|
int git_libgit2_opts_set_ssl_cert_locations(
|
||||||
|
ffi.Pointer<ffi.Char> file,
|
||||||
|
ffi.Pointer<ffi.Char> path,
|
||||||
|
) {
|
||||||
|
return _git_libgit2_opts_set_ssl_cert_locations(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_SSL_CERT_LOCATIONS,
|
||||||
|
file,
|
||||||
|
path,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the value of the User-Agent header.
|
||||||
|
///
|
||||||
|
/// The User-Agent is written to the `out` buffer.
|
||||||
|
int git_libgit2_opts_get_user_agent(ffi.Pointer<git_buf> out) {
|
||||||
|
return _git_libgit2_opts_get_buf(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_USER_AGENT,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the value of the User-Agent header. This value will be
|
||||||
|
/// appended to "git/1.0", for compatibility with other git clients.
|
||||||
|
///
|
||||||
|
/// - [user_agent] is the value that will be delivered as the
|
||||||
|
/// User-Agent header on HTTP requests.
|
||||||
|
int git_libgit2_opts_set_user_agent(ffi.Pointer<ffi.Char> user_agent) {
|
||||||
|
return _git_libgit2_opts_set_char(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_USER_AGENT,
|
||||||
|
user_agent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enable strict input validation when creating new objects
|
||||||
|
/// to ensure that all inputs to the new objects are valid.
|
||||||
|
///
|
||||||
|
/// For example, when this is enabled, the parent(s) and tree inputs
|
||||||
|
/// will be validated when creating a new commit.
|
||||||
|
///
|
||||||
|
/// This defaults to enabled.
|
||||||
|
int git_libgit2_opts_enable_strict_object_creation(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Validate the target of a symbolic ref when creating it.
|
||||||
|
///
|
||||||
|
/// For example, `foobar` is not a valid ref, therefore `foobar` is
|
||||||
|
/// not a valid target for a symbolic ref by default, whereas
|
||||||
|
/// `refs/heads/foobar` is.
|
||||||
|
///
|
||||||
|
/// Disabling this bypasses validation so that an arbitrary strings
|
||||||
|
/// such as `foobar` can be used for a symbolic ref target.
|
||||||
|
///
|
||||||
|
/// This defaults to enabled.
|
||||||
|
int git_libgit2_opts_enable_strict_symbolic_ref_creation(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enable or disable the use of "offset deltas" when creating packfiles,
|
||||||
|
/// and the negotiation of them when talking to a remote server.
|
||||||
|
///
|
||||||
|
/// Offset deltas store a delta base location as an offset into the
|
||||||
|
/// packfile from the current location, which provides a shorter encoding
|
||||||
|
/// and thus smaller resultant packfiles.
|
||||||
|
///
|
||||||
|
/// Packfiles containing offset deltas can still be read.
|
||||||
|
///
|
||||||
|
/// This defaults to enabled.
|
||||||
|
int git_libgit2_opts_enable_offset_delta(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_ENABLE_OFS_DELTA,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enable synchronized writes of files in the gitdir using `fsync`
|
||||||
|
/// (or the platform equivalent) to ensure that new object data
|
||||||
|
/// is written to permanent storage, not simply cached.
|
||||||
|
///
|
||||||
|
/// This defaults to disabled.
|
||||||
|
int git_libgit2_opts_enable_fsync_gitdir(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_ENABLE_FSYNC_GITDIR,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enable strict verification of object hashsums when reading
|
||||||
|
/// objects from disk.
|
||||||
|
///
|
||||||
|
/// This may impact performance due to an additional checksum calculation
|
||||||
|
/// on each object.
|
||||||
|
///
|
||||||
|
/// This defaults to enabled.
|
||||||
|
int git_libgit2_opts_enable_strict_hash_verification(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ensure that there are no unsaved changes in the index before
|
||||||
|
/// beginning any operation that reloads the index from disk (e.g.,
|
||||||
|
/// checkout).
|
||||||
|
///
|
||||||
|
/// If there are unsaved changes, the instruction will fail (using
|
||||||
|
/// the FORCE flag to checkout will still overwrite these changes).
|
||||||
|
int git_libgit2_opts_enable_unsaved_index_safety(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the maximum number of objects libgit2 will allow in a pack
|
||||||
|
/// file when downloading a pack file from a remote. This can be
|
||||||
|
/// used to limit maximum memory usage when fetching from an untrusted
|
||||||
|
/// remote.
|
||||||
|
int git_libgit2_opts_get_pack_max_objects(ffi.Pointer<ffi.Int> out) {
|
||||||
|
return _git_libgit2_opts_get_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_PACK_MAX_OBJECTS,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the maximum number of objects libgit2 will allow in a pack
|
||||||
|
/// file when downloading a pack file from a remote.
|
||||||
|
int git_libgit2_opts_set_pack_max_objects(int value) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_PACK_MAX_OBJECTS,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This will cause .keep file existence checks to be skipped when
|
||||||
|
/// accessing packfiles, which can help performance with remote filesystems.
|
||||||
|
int git_libgit2_opts_disable_pack_keep_file_checks(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When connecting to a server using NTLM or Negotiate
|
||||||
|
/// authentication, use expect/continue when POSTing data.
|
||||||
|
///
|
||||||
|
/// This option is not available on Windows.
|
||||||
|
int git_libgit2_opts_enable_http_expect_continue(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the owner validation setting for repository directories.
|
||||||
|
int git_libgit2_opts_get_owner_validation(ffi.Pointer<ffi.Int> out) {
|
||||||
|
return _git_libgit2_opts_get_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_OWNER_VALIDATION,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set that repository directories should be owned by the current
|
||||||
|
/// user. The default is to validate ownership.
|
||||||
|
int git_libgit2_opts_set_owner_validation(int enabled) {
|
||||||
|
return _git_libgit2_opts_set_int(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_OWNER_VALIDATION,
|
||||||
|
enabled,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the list of git extensions that are supported.
|
||||||
|
/// This is the list of built-in extensions supported by libgit2 and
|
||||||
|
/// custom extensions that have been added with [git_libgit2_opts_set_extensions].
|
||||||
|
///
|
||||||
|
/// Extensions that have been negated will not be returned.
|
||||||
|
int git_libgit2_opts_get_extensions(ffi.Pointer<git_strarray> out) {
|
||||||
|
return _git_libgit2_opts_get_extensions(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_GET_EXTENSIONS,
|
||||||
|
out,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set that the given git extensions are supported by the caller.
|
||||||
|
///
|
||||||
|
/// Extensions supported by libgit2 may be negated by prefixing
|
||||||
|
/// them with a `!`. For example: setting extensions to
|
||||||
|
/// { "!noop", "newext" } indicates that the caller does not want
|
||||||
|
/// to support repositories with the `noop` extension but does want
|
||||||
|
/// to support repositories with the `newext` extension.
|
||||||
|
int git_libgit2_opts_set_extensions(
|
||||||
|
ffi.Pointer<ffi.Pointer<ffi.Char>> extensions,
|
||||||
|
int len,
|
||||||
|
) {
|
||||||
|
return _git_libgit2_opts_set_extensions(
|
||||||
|
git_libgit2_opt_t.GIT_OPT_SET_EXTENSIONS,
|
||||||
|
extensions,
|
||||||
|
len,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_get_intPtr = _lookup<
|
||||||
|
ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Pointer<ffi.Int>)>>(
|
||||||
|
'git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_get_int = _git_libgit2_opts_get_intPtr
|
||||||
|
.asFunction<int Function(int, ffi.Pointer<ffi.Int>)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_set_intPtr =
|
||||||
|
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int)>>(
|
||||||
|
'git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_set_int =
|
||||||
|
_git_libgit2_opts_set_intPtr.asFunction<int Function(int, int)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_get_bufPtr = _lookup<
|
||||||
|
ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Pointer<git_buf>)>>(
|
||||||
|
'git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_get_buf = _git_libgit2_opts_get_bufPtr
|
||||||
|
.asFunction<int Function(int, ffi.Pointer<git_buf>)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_set_charPtr = _lookup<
|
||||||
|
ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Pointer<ffi.Char>)>>(
|
||||||
|
'git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_set_char = _git_libgit2_opts_set_charPtr
|
||||||
|
.asFunction<int Function(int, ffi.Pointer<ffi.Char>)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_get_search_pathPtr = _lookup<
|
||||||
|
ffi.NativeFunction<
|
||||||
|
ffi.Int Function(
|
||||||
|
ffi.Int, ffi.Int, ffi.Pointer<git_buf>)>>('git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_get_search_path =
|
||||||
|
_git_libgit2_opts_get_search_pathPtr
|
||||||
|
.asFunction<int Function(int, int, ffi.Pointer<git_buf>)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_set_search_pathPtr = _lookup<
|
||||||
|
ffi.NativeFunction<
|
||||||
|
ffi.Int Function(
|
||||||
|
ffi.Int, ffi.Int, ffi.Pointer<ffi.Char>)>>('git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_set_search_path =
|
||||||
|
_git_libgit2_opts_set_search_pathPtr
|
||||||
|
.asFunction<int Function(int, int, ffi.Pointer<ffi.Char>)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_set_cache_object_limitPtr =
|
||||||
|
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int, ffi.Int)>>(
|
||||||
|
'git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_set_cache_object_limit =
|
||||||
|
_git_libgit2_opts_set_cache_object_limitPtr
|
||||||
|
.asFunction<int Function(int, int, int)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_get_cached_memoryPtr = _lookup<
|
||||||
|
ffi.NativeFunction<
|
||||||
|
ffi.Int Function(ffi.Int, ffi.Pointer<ffi.Int>,
|
||||||
|
ffi.Pointer<ffi.Int>)>>('git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_get_cached_memory =
|
||||||
|
_git_libgit2_opts_get_cached_memoryPtr.asFunction<
|
||||||
|
int Function(int, ffi.Pointer<ffi.Int>, ffi.Pointer<ffi.Int>)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_set_ssl_cert_locationsPtr = _lookup<
|
||||||
|
ffi.NativeFunction<
|
||||||
|
ffi.Int Function(ffi.Int, ffi.Pointer<ffi.Char>,
|
||||||
|
ffi.Pointer<ffi.Char>)>>('git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_set_ssl_cert_locations =
|
||||||
|
_git_libgit2_opts_set_ssl_cert_locationsPtr.asFunction<
|
||||||
|
int Function(int, ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_get_extensionsPtr = _lookup<
|
||||||
|
ffi.NativeFunction<
|
||||||
|
ffi.Int Function(
|
||||||
|
ffi.Int, ffi.Pointer<git_strarray>)>>('git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_get_extensions =
|
||||||
|
_git_libgit2_opts_get_extensionsPtr
|
||||||
|
.asFunction<int Function(int, ffi.Pointer<git_strarray>)>();
|
||||||
|
|
||||||
|
late final _git_libgit2_opts_set_extensionsPtr = _lookup<
|
||||||
|
ffi.NativeFunction<
|
||||||
|
ffi.Int Function(ffi.Int, ffi.Pointer<ffi.Pointer<ffi.Char>>,
|
||||||
|
ffi.Int)>>('git_libgit2_opts');
|
||||||
|
late final _git_libgit2_opts_set_extensions =
|
||||||
|
_git_libgit2_opts_set_extensionsPtr.asFunction<
|
||||||
|
int Function(int, ffi.Pointer<ffi.Pointer<ffi.Char>>, int)>();
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Allocate a new mailmap object. The returned mailmap must be freed with
|
/// Allocate a new mailmap object. The returned mailmap must be freed with
|
||||||
|
@ -25,7 +26,7 @@ Pointer<git_mailmap> init() {
|
||||||
/// returned mailmap must be freed with [free].
|
/// returned mailmap must be freed with [free].
|
||||||
Pointer<git_mailmap> fromBuffer(String buffer) {
|
Pointer<git_mailmap> fromBuffer(String buffer) {
|
||||||
final out = calloc<Pointer<git_mailmap>>();
|
final out = calloc<Pointer<git_mailmap>>();
|
||||||
final bufferC = buffer.toNativeUtf8().cast<Int8>();
|
final bufferC = buffer.toChar();
|
||||||
|
|
||||||
libgit2.git_mailmap_from_buffer(out, bufferC, buffer.length);
|
libgit2.git_mailmap_from_buffer(out, bufferC, buffer.length);
|
||||||
|
|
||||||
|
@ -70,10 +71,10 @@ List<String> resolve({
|
||||||
required String name,
|
required String name,
|
||||||
required String email,
|
required String email,
|
||||||
}) {
|
}) {
|
||||||
final outRealName = calloc<Pointer<Int8>>();
|
final outRealName = calloc<Pointer<Char>>();
|
||||||
final outRealEmail = calloc<Pointer<Int8>>();
|
final outRealEmail = calloc<Pointer<Char>>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final emailC = email.toNativeUtf8().cast<Int8>();
|
final emailC = email.toChar();
|
||||||
libgit2.git_mailmap_resolve(
|
libgit2.git_mailmap_resolve(
|
||||||
outRealName,
|
outRealName,
|
||||||
outRealEmail,
|
outRealEmail,
|
||||||
|
@ -82,8 +83,8 @@ List<String> resolve({
|
||||||
emailC,
|
emailC,
|
||||||
);
|
);
|
||||||
|
|
||||||
final realName = outRealName.value.cast<Utf8>().toDartString();
|
final realName = outRealName.value.toDartString();
|
||||||
final realEmail = outRealEmail.value.cast<Utf8>().toDartString();
|
final realEmail = outRealEmail.value.toDartString();
|
||||||
calloc.free(outRealName);
|
calloc.free(outRealName);
|
||||||
calloc.free(outRealEmail);
|
calloc.free(outRealEmail);
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
|
@ -119,10 +120,10 @@ void addEntry({
|
||||||
String? replaceName,
|
String? replaceName,
|
||||||
required String replaceEmail,
|
required String replaceEmail,
|
||||||
}) {
|
}) {
|
||||||
final realNameC = realName?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final realNameC = realName?.toChar() ?? nullptr;
|
||||||
final realEmailC = realEmail?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final realEmailC = realEmail?.toChar() ?? nullptr;
|
||||||
final replaceNameC = replaceName?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final replaceNameC = replaceName?.toChar() ?? nullptr;
|
||||||
final replaceEmailC = replaceEmail.toNativeUtf8().cast<Int8>();
|
final replaceEmailC = replaceEmail.toChar();
|
||||||
|
|
||||||
libgit2.git_mailmap_add_entry(
|
libgit2.git_mailmap_add_entry(
|
||||||
mailmapPointer,
|
mailmapPointer,
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Find a merge base between two commits.
|
/// Find a merge base between two commits.
|
||||||
|
@ -183,35 +184,44 @@ String mergeFile({
|
||||||
libgit2.git_merge_file_input_init(ancestorC, GIT_MERGE_FILE_INPUT_VERSION);
|
libgit2.git_merge_file_input_init(ancestorC, GIT_MERGE_FILE_INPUT_VERSION);
|
||||||
libgit2.git_merge_file_input_init(oursC, GIT_MERGE_FILE_INPUT_VERSION);
|
libgit2.git_merge_file_input_init(oursC, GIT_MERGE_FILE_INPUT_VERSION);
|
||||||
libgit2.git_merge_file_input_init(theirsC, GIT_MERGE_FILE_INPUT_VERSION);
|
libgit2.git_merge_file_input_init(theirsC, GIT_MERGE_FILE_INPUT_VERSION);
|
||||||
ancestorC.ref.ptr = ancestor.toNativeUtf8().cast<Int8>();
|
ancestorC.ref.ptr = ancestor.toChar();
|
||||||
ancestorC.ref.size = ancestor.length;
|
ancestorC.ref.size = ancestor.length;
|
||||||
oursC.ref.ptr = ours.toNativeUtf8().cast<Int8>();
|
Pointer<Char> ancestorLabelC = nullptr;
|
||||||
|
oursC.ref.ptr = ours.toChar();
|
||||||
oursC.ref.size = ours.length;
|
oursC.ref.size = ours.length;
|
||||||
theirsC.ref.ptr = theirs.toNativeUtf8().cast<Int8>();
|
Pointer<Char> oursLabelC = nullptr;
|
||||||
|
theirsC.ref.ptr = theirs.toChar();
|
||||||
theirsC.ref.size = theirs.length;
|
theirsC.ref.size = theirs.length;
|
||||||
|
Pointer<Char> theirsLabelC = nullptr;
|
||||||
|
|
||||||
final opts = calloc<git_merge_file_options>();
|
final opts = calloc<git_merge_file_options>();
|
||||||
libgit2.git_merge_file_options_init(opts, GIT_MERGE_FILE_OPTIONS_VERSION);
|
libgit2.git_merge_file_options_init(opts, GIT_MERGE_FILE_OPTIONS_VERSION);
|
||||||
opts.ref.favor = favor;
|
opts.ref.favor = favor;
|
||||||
opts.ref.flags = flags;
|
opts.ref.flags = flags;
|
||||||
if (ancestorLabel.isNotEmpty) {
|
if (ancestorLabel.isNotEmpty) {
|
||||||
opts.ref.ancestor_label = ancestorLabel.toNativeUtf8().cast<Int8>();
|
ancestorLabelC = ancestorLabel.toChar();
|
||||||
|
opts.ref.ancestor_label = ancestorLabelC;
|
||||||
}
|
}
|
||||||
if (oursLabel.isNotEmpty) {
|
if (oursLabel.isNotEmpty) {
|
||||||
opts.ref.our_label = oursLabel.toNativeUtf8().cast<Int8>();
|
oursLabelC = oursLabel.toChar();
|
||||||
|
opts.ref.our_label = oursLabelC;
|
||||||
}
|
}
|
||||||
if (theirsLabel.isNotEmpty) {
|
if (theirsLabel.isNotEmpty) {
|
||||||
opts.ref.their_label = theirsLabel.toNativeUtf8().cast<Int8>();
|
theirsLabelC = theirsLabel.toChar();
|
||||||
|
opts.ref.their_label = theirsLabelC;
|
||||||
}
|
}
|
||||||
|
|
||||||
libgit2.git_merge_file(out, ancestorC, oursC, theirsC, opts);
|
libgit2.git_merge_file(out, ancestorC, oursC, theirsC, opts);
|
||||||
|
|
||||||
calloc.free(ancestorC);
|
calloc.free(ancestorC);
|
||||||
|
calloc.free(ancestorLabelC);
|
||||||
calloc.free(oursC);
|
calloc.free(oursC);
|
||||||
|
calloc.free(oursLabelC);
|
||||||
calloc.free(theirsC);
|
calloc.free(theirsC);
|
||||||
|
calloc.free(theirsLabelC);
|
||||||
calloc.free(opts);
|
calloc.free(opts);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.len);
|
final result = out.ref.ptr.toDartString(length: out.ref.len);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -225,24 +235,54 @@ String mergeFile({
|
||||||
String mergeFileFromIndex({
|
String mergeFileFromIndex({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required Pointer<git_index_entry>? ancestorPointer,
|
required Pointer<git_index_entry>? ancestorPointer,
|
||||||
|
required String ancestorLabel,
|
||||||
required Pointer<git_index_entry> oursPointer,
|
required Pointer<git_index_entry> oursPointer,
|
||||||
|
required String oursLabel,
|
||||||
required Pointer<git_index_entry> theirsPointer,
|
required Pointer<git_index_entry> theirsPointer,
|
||||||
|
required String theirsLabel,
|
||||||
|
required int favor,
|
||||||
|
required int flags,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_merge_file_result>();
|
final out = calloc<git_merge_file_result>();
|
||||||
|
final opts = calloc<git_merge_file_options>();
|
||||||
|
Pointer<Char> ancestorLabelC = nullptr;
|
||||||
|
Pointer<Char> oursLabelC = nullptr;
|
||||||
|
Pointer<Char> theirsLabelC = nullptr;
|
||||||
|
|
||||||
|
libgit2.git_merge_file_options_init(opts, GIT_MERGE_FILE_OPTIONS_VERSION);
|
||||||
|
opts.ref.favor = favor;
|
||||||
|
opts.ref.flags = flags;
|
||||||
|
if (ancestorLabel.isNotEmpty) {
|
||||||
|
ancestorLabelC = ancestorLabel.toChar();
|
||||||
|
opts.ref.ancestor_label = ancestorLabelC;
|
||||||
|
}
|
||||||
|
if (oursLabel.isNotEmpty) {
|
||||||
|
oursLabelC = oursLabel.toChar();
|
||||||
|
opts.ref.our_label = oursLabelC;
|
||||||
|
}
|
||||||
|
if (theirsLabel.isNotEmpty) {
|
||||||
|
theirsLabelC = theirsLabel.toChar();
|
||||||
|
opts.ref.their_label = theirsLabelC;
|
||||||
|
}
|
||||||
|
|
||||||
final error = libgit2.git_merge_file_from_index(
|
final error = libgit2.git_merge_file_from_index(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
ancestorPointer ?? nullptr,
|
ancestorPointer ?? nullptr,
|
||||||
oursPointer,
|
oursPointer,
|
||||||
theirsPointer,
|
theirsPointer,
|
||||||
nullptr,
|
opts,
|
||||||
);
|
);
|
||||||
|
|
||||||
late final String result;
|
late final String result;
|
||||||
if (out.ref.ptr != nullptr) {
|
if (out.ref.ptr != nullptr) {
|
||||||
result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.len);
|
result = out.ref.ptr.toDartString(length: out.ref.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calloc.free(ancestorLabelC);
|
||||||
|
calloc.free(oursLabelC);
|
||||||
|
calloc.free(theirsLabelC);
|
||||||
|
calloc.free(opts);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
|
|
|
@ -3,16 +3,24 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Returns list of notes for repository. The returned notes must be freed with
|
/// Returns list of notes for repository. The returned notes must be freed with
|
||||||
/// [free].
|
/// [free].
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
List<Map<String, Pointer>> list({
|
||||||
final notesRef = 'refs/notes/commits'.toNativeUtf8().cast<Int8>();
|
required Pointer<git_repository> repoPointer,
|
||||||
|
required String notesRef,
|
||||||
|
}) {
|
||||||
|
final notesRefC = notesRef.toChar();
|
||||||
final iterator = calloc<Pointer<git_iterator>>();
|
final iterator = calloc<Pointer<git_iterator>>();
|
||||||
final iteratorError = libgit2.git_note_iterator_new(iterator, repo, notesRef);
|
final iteratorError = libgit2.git_note_iterator_new(
|
||||||
|
iterator,
|
||||||
|
repoPointer,
|
||||||
|
notesRefC,
|
||||||
|
);
|
||||||
|
|
||||||
if (iteratorError < 0) {
|
if (iteratorError < 0) {
|
||||||
calloc.free(iterator);
|
calloc.free(iterator);
|
||||||
|
@ -28,7 +36,7 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
||||||
nextError = libgit2.git_note_next(noteOid, annotatedOid, iterator.value);
|
nextError = libgit2.git_note_next(noteOid, annotatedOid, iterator.value);
|
||||||
if (nextError >= 0) {
|
if (nextError >= 0) {
|
||||||
final out = calloc<Pointer<git_note>>();
|
final out = calloc<Pointer<git_note>>();
|
||||||
libgit2.git_note_read(out, repo, notesRef, annotatedOid);
|
libgit2.git_note_read(out, repoPointer, notesRefC, annotatedOid);
|
||||||
|
|
||||||
final note = out.value;
|
final note = out.value;
|
||||||
|
|
||||||
|
@ -41,7 +49,7 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
||||||
calloc.free(noteOid);
|
calloc.free(noteOid);
|
||||||
}
|
}
|
||||||
|
|
||||||
calloc.free(notesRef);
|
calloc.free(notesRefC);
|
||||||
libgit2.git_note_iterator_free(iterator.value);
|
libgit2.git_note_iterator_free(iterator.value);
|
||||||
calloc.free(iterator);
|
calloc.free(iterator);
|
||||||
|
|
||||||
|
@ -54,10 +62,10 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
|
||||||
Pointer<git_note> lookup({
|
Pointer<git_note> lookup({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required Pointer<git_oid> oidPointer,
|
required Pointer<git_oid> oidPointer,
|
||||||
String notesRef = 'refs/notes/commits',
|
required String notesRef,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_note>>();
|
final out = calloc<Pointer<git_note>>();
|
||||||
final notesRefC = notesRef.toNativeUtf8().cast<Int8>();
|
final notesRefC = notesRef.toChar();
|
||||||
final error = libgit2.git_note_read(out, repoPointer, notesRefC, oidPointer);
|
final error = libgit2.git_note_read(out, repoPointer, notesRefC, oidPointer);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -85,8 +93,8 @@ Pointer<git_oid> create({
|
||||||
bool force = false,
|
bool force = false,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final notesRefC = notesRef.toNativeUtf8().cast<Int8>();
|
final notesRefC = notesRef.toChar();
|
||||||
final noteC = note.toNativeUtf8().cast<Int8>();
|
final noteC = note.toChar();
|
||||||
final forceC = force ? 1 : 0;
|
final forceC = force ? 1 : 0;
|
||||||
final error = libgit2.git_note_create(
|
final error = libgit2.git_note_create(
|
||||||
out,
|
out,
|
||||||
|
@ -120,7 +128,7 @@ void delete({
|
||||||
required Pointer<git_signature> committerPointer,
|
required Pointer<git_signature> committerPointer,
|
||||||
required Pointer<git_oid> oidPointer,
|
required Pointer<git_oid> oidPointer,
|
||||||
}) {
|
}) {
|
||||||
final notesRefC = notesRef.toNativeUtf8().cast<Int8>();
|
final notesRefC = notesRef.toChar();
|
||||||
|
|
||||||
final error = libgit2.git_note_remove(
|
final error = libgit2.git_note_remove(
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -142,7 +150,7 @@ Pointer<git_oid> id(Pointer<git_note> note) => libgit2.git_note_id(note);
|
||||||
|
|
||||||
/// Get the note message.
|
/// Get the note message.
|
||||||
String message(Pointer<git_note> note) {
|
String message(Pointer<git_note> note) {
|
||||||
return libgit2.git_note_message(note).cast<Utf8>().toDartString();
|
return libgit2.git_note_message(note).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free memory allocated for note object.
|
/// Free memory allocated for note object.
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/oid.dart' as oid_bindings;
|
import 'package:libgit2dart/src/bindings/oid.dart' as oid_bindings;
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/oid.dart';
|
import 'package:libgit2dart/src/oid.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ void addDiskAlternate({
|
||||||
required Pointer<git_odb> odbPointer,
|
required Pointer<git_odb> odbPointer,
|
||||||
required String path,
|
required String path,
|
||||||
}) {
|
}) {
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
libgit2.git_odb_add_disk_alternate(odbPointer, pathC);
|
libgit2.git_odb_add_disk_alternate(odbPointer, pathC);
|
||||||
calloc.free(pathC);
|
calloc.free(pathC);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +95,7 @@ int _forEachCb(
|
||||||
List<Oid> objects(Pointer<git_odb> odb) {
|
List<Oid> objects(Pointer<git_odb> odb) {
|
||||||
const except = -1;
|
const except = -1;
|
||||||
final cb =
|
final cb =
|
||||||
Pointer.fromFunction<Int32 Function(Pointer<git_oid>, Pointer<Void>)>(
|
Pointer.fromFunction<Int Function(Pointer<git_oid>, Pointer<Void>)>(
|
||||||
_forEachCb,
|
_forEachCb,
|
||||||
except,
|
except,
|
||||||
);
|
);
|
||||||
|
@ -184,7 +185,7 @@ Pointer<git_oid> write({
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
}
|
||||||
|
|
||||||
final bufferC = data.toNativeUtf8().cast<Int8>();
|
final bufferC = data.toChar();
|
||||||
libgit2.git_odb_stream_write(stream.value, bufferC, data.length);
|
libgit2.git_odb_stream_write(stream.value, bufferC, data.length);
|
||||||
|
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
|
|
|
@ -2,12 +2,13 @@ import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Parse N characters of a hex formatted object id into a git_oid.
|
/// Parse N characters of a hex formatted object id into a git_oid.
|
||||||
Pointer<git_oid> fromStrN(String hex) {
|
Pointer<git_oid> fromStrN(String hex) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final hexC = hex.toNativeUtf8().cast<Int8>();
|
final hexC = hex.toChar();
|
||||||
libgit2.git_oid_fromstrn(out, hexC, hex.length);
|
libgit2.git_oid_fromstrn(out, hexC, hex.length);
|
||||||
|
|
||||||
calloc.free(hexC);
|
calloc.free(hexC);
|
||||||
|
@ -18,7 +19,7 @@ Pointer<git_oid> fromStrN(String hex) {
|
||||||
/// Parse a hex formatted object id into a git_oid.
|
/// Parse a hex formatted object id into a git_oid.
|
||||||
Pointer<git_oid> fromSHA(String hex) {
|
Pointer<git_oid> fromSHA(String hex) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final hexC = hex.toNativeUtf8().cast<Int8>();
|
final hexC = hex.toChar();
|
||||||
libgit2.git_oid_fromstr(out, hexC);
|
libgit2.git_oid_fromstr(out, hexC);
|
||||||
|
|
||||||
calloc.free(hexC);
|
calloc.free(hexC);
|
||||||
|
@ -27,9 +28,9 @@ Pointer<git_oid> fromSHA(String hex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copy an already raw oid into a git_oid structure.
|
/// Copy an already raw oid into a git_oid structure.
|
||||||
Pointer<git_oid> fromRaw(Array<Uint8> raw) {
|
Pointer<git_oid> fromRaw(Array<UnsignedChar> raw) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final rawC = calloc<Uint8>(20);
|
final rawC = calloc<UnsignedChar>(20);
|
||||||
|
|
||||||
for (var i = 0; i < 20; i++) {
|
for (var i = 0; i < 20; i++) {
|
||||||
rawC[i] = raw[i];
|
rawC[i] = raw[i];
|
||||||
|
@ -44,10 +45,10 @@ Pointer<git_oid> fromRaw(Array<Uint8> raw) {
|
||||||
|
|
||||||
/// Format a git_oid into a hex string.
|
/// Format a git_oid into a hex string.
|
||||||
String toSHA(Pointer<git_oid> id) {
|
String toSHA(Pointer<git_oid> id) {
|
||||||
final out = calloc<Int8>(40);
|
final out = calloc<Char>(40);
|
||||||
libgit2.git_oid_fmt(out, id);
|
libgit2.git_oid_fmt(out, id);
|
||||||
|
|
||||||
final result = out.cast<Utf8>().toDartString(length: 40);
|
final result = out.toDartString(length: 40);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Initialize a new packbuilder. The returned packbuilder must be freed with
|
/// Initialize a new packbuilder. The returned packbuilder must be freed with
|
||||||
|
@ -121,7 +122,7 @@ void write({
|
||||||
required Pointer<git_packbuilder> packbuilderPointer,
|
required Pointer<git_packbuilder> packbuilderPointer,
|
||||||
String? path,
|
String? path,
|
||||||
}) {
|
}) {
|
||||||
final pathC = path?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final pathC = path?.toChar() ?? nullptr;
|
||||||
final error = libgit2.git_packbuilder_write(
|
final error = libgit2.git_packbuilder_write(
|
||||||
packbuilderPointer,
|
packbuilderPointer,
|
||||||
pathC,
|
pathC,
|
||||||
|
@ -153,7 +154,7 @@ int writtenCount(Pointer<git_packbuilder> pb) {
|
||||||
/// correct after the packfile has been written.
|
/// correct after the packfile has been written.
|
||||||
String name(Pointer<git_packbuilder> pb) {
|
String name(Pointer<git_packbuilder> pb) {
|
||||||
final result = libgit2.git_packbuilder_name(pb);
|
final result = libgit2.git_packbuilder_name(pb);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set number of threads to spawn.
|
/// Set number of threads to spawn.
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Directly generate a patch from the difference between two buffers. The
|
/// Directly generate a patch from the difference between two buffers. The
|
||||||
|
@ -17,11 +18,11 @@ Pointer<git_patch> fromBuffers({
|
||||||
required 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?.toChar() ?? nullptr;
|
||||||
final oldAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final oldAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||||
final oldLen = oldBuffer?.length ?? 0;
|
final oldLen = oldBuffer?.length ?? 0;
|
||||||
final newBufferC = newBuffer?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final newBufferC = newBuffer?.toChar() ?? nullptr;
|
||||||
final newAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final newAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||||
final newLen = newBuffer?.length ?? 0;
|
final newLen = newBuffer?.length ?? 0;
|
||||||
final opts = _diffOptionsInit(
|
final opts = _diffOptionsInit(
|
||||||
flags: flags,
|
flags: flags,
|
||||||
|
@ -65,8 +66,8 @@ Pointer<git_patch> fromBlobs({
|
||||||
required 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?.toChar() ?? nullptr;
|
||||||
final newAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final newAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||||
final opts = _diffOptionsInit(
|
final opts = _diffOptionsInit(
|
||||||
flags: flags,
|
flags: flags,
|
||||||
contextLines: contextLines,
|
contextLines: contextLines,
|
||||||
|
@ -104,9 +105,9 @@ Pointer<git_patch> fromBlobAndBuffer({
|
||||||
required 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?.toChar() ?? nullptr;
|
||||||
final bufferC = buffer?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final bufferC = buffer?.toChar() ?? nullptr;
|
||||||
final bufferAsPathC = oldAsPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final bufferAsPathC = oldAsPath?.toChar() ?? nullptr;
|
||||||
final bufferLen = buffer?.length ?? 0;
|
final bufferLen = buffer?.length ?? 0;
|
||||||
final opts = _diffOptionsInit(
|
final opts = _diffOptionsInit(
|
||||||
flags: flags,
|
flags: flags,
|
||||||
|
@ -175,8 +176,8 @@ Map<String, Object> hunk({
|
||||||
required int hunkIndex,
|
required int hunkIndex,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_diff_hunk>>();
|
final out = calloc<Pointer<git_diff_hunk>>();
|
||||||
final linesInHunk = calloc<Int64>();
|
final linesInHunk = calloc<Size>();
|
||||||
libgit2.git_patch_get_hunk(out, linesInHunk.cast(), patchPointer, hunkIndex);
|
libgit2.git_patch_get_hunk(out, linesInHunk, patchPointer, hunkIndex);
|
||||||
|
|
||||||
final hunk = out.value;
|
final hunk = out.value;
|
||||||
final linesN = linesInHunk.value;
|
final linesN = linesInHunk.value;
|
||||||
|
@ -189,9 +190,9 @@ Map<String, Object> hunk({
|
||||||
|
|
||||||
/// Get line counts of each type in a patch.
|
/// Get line counts of each type in a patch.
|
||||||
Map<String, int> lineStats(Pointer<git_patch> patch) {
|
Map<String, int> lineStats(Pointer<git_patch> patch) {
|
||||||
final context = calloc<Uint64>();
|
final context = calloc<Size>();
|
||||||
final insertions = calloc<Uint64>();
|
final insertions = calloc<Size>();
|
||||||
final deletions = calloc<Uint64>();
|
final deletions = calloc<Size>();
|
||||||
libgit2.git_patch_line_stats(
|
libgit2.git_patch_line_stats(
|
||||||
context,
|
context,
|
||||||
insertions,
|
insertions,
|
||||||
|
@ -235,7 +236,7 @@ String text(Pointer<git_patch> patch) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final error = libgit2.git_patch_to_buf(out, patch);
|
final error = libgit2.git_patch_to_buf(out, patch);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Initializes a rebase operation to rebase the changes in [branchPointer]
|
/// Initializes a rebase operation to rebase the changes in [branchPointer]
|
||||||
|
@ -128,7 +129,7 @@ void commit({
|
||||||
required String? message,
|
required String? message,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final messageC = message?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final messageC = message?.toChar() ?? nullptr;
|
||||||
|
|
||||||
final error = libgit2.git_rebase_commit(
|
final error = libgit2.git_rebase_commit(
|
||||||
out,
|
out,
|
||||||
|
@ -163,7 +164,7 @@ Pointer<git_oid> origHeadOid(Pointer<git_rebase> rebase) =>
|
||||||
/// Gets the original HEAD ref name for merge rebases.
|
/// Gets the original HEAD ref name for merge rebases.
|
||||||
String origHeadName(Pointer<git_rebase> rebase) {
|
String origHeadName(Pointer<git_rebase> rebase) {
|
||||||
final result = libgit2.git_rebase_orig_head_name(rebase);
|
final result = libgit2.git_rebase_orig_head_name(rebase);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the onto id for merge rebases.
|
/// Gets the onto id for merge rebases.
|
||||||
|
@ -172,7 +173,7 @@ Pointer<git_oid> ontoOid(Pointer<git_rebase> rebase) =>
|
||||||
|
|
||||||
/// Gets the onto ref name for merge rebases.
|
/// Gets the onto ref name for merge rebases.
|
||||||
String ontoName(Pointer<git_rebase> rebase) {
|
String ontoName(Pointer<git_rebase> rebase) {
|
||||||
return libgit2.git_rebase_onto_name(rebase).cast<Utf8>().toDartString();
|
return libgit2.git_rebase_onto_name(rebase).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free memory allocated for rebase object.
|
/// Free memory allocated for rebase object.
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Get the type of a reference.
|
/// Get the type of a reference.
|
||||||
|
@ -55,7 +56,7 @@ Pointer<git_reference> lookup({
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_reference>>();
|
final out = calloc<Pointer<git_reference>>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final error = libgit2.git_reference_lookup(out, repoPointer, nameC);
|
final error = libgit2.git_reference_lookup(out, repoPointer, nameC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -72,7 +73,7 @@ Pointer<git_reference> lookup({
|
||||||
|
|
||||||
/// Get the full name of a reference.
|
/// Get the full name of a reference.
|
||||||
String name(Pointer<git_reference> ref) {
|
String name(Pointer<git_reference> ref) {
|
||||||
return libgit2.git_reference_name(ref).cast<Utf8>().toDartString();
|
return libgit2.git_reference_name(ref).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the reference's short name.
|
/// Get the reference's short name.
|
||||||
|
@ -80,7 +81,7 @@ String name(Pointer<git_reference> ref) {
|
||||||
/// This will transform the reference name into a name "human-readable" version.
|
/// This will transform the reference name into a name "human-readable" version.
|
||||||
/// If no shortname is appropriate, it will return the full name.
|
/// If no shortname is appropriate, it will return the full name.
|
||||||
String shorthand(Pointer<git_reference> ref) {
|
String shorthand(Pointer<git_reference> ref) {
|
||||||
return libgit2.git_reference_shorthand(ref).cast<Utf8>().toDartString();
|
return libgit2.git_reference_shorthand(ref).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rename an existing reference. The returned reference must be freed with
|
/// Rename an existing reference. The returned reference must be freed with
|
||||||
|
@ -104,9 +105,9 @@ Pointer<git_reference> rename({
|
||||||
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.toChar();
|
||||||
final forceC = force == true ? 1 : 0;
|
final forceC = force == true ? 1 : 0;
|
||||||
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||||
final error = libgit2.git_reference_rename(
|
final error = libgit2.git_reference_rename(
|
||||||
out,
|
out,
|
||||||
refPointer,
|
refPointer,
|
||||||
|
@ -140,9 +141,7 @@ List<String> list(Pointer<git_repository> repo) {
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < array.ref.count; i++) {
|
for (var i = 0; i < array.ref.count; i++) {
|
||||||
result.add(
|
result.add(array.ref.strings.elementAt(i).value.toDartString());
|
||||||
array.ref.strings.elementAt(i).value.cast<Utf8>().toDartString(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +155,7 @@ bool hasLog({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final result = libgit2.git_reference_has_log(repoPointer, nameC);
|
final result = libgit2.git_reference_has_log(repoPointer, nameC);
|
||||||
|
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
|
@ -173,7 +172,7 @@ void ensureLog({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required String refName,
|
required String refName,
|
||||||
}) {
|
}) {
|
||||||
final refNameC = refName.toNativeUtf8().cast<Int8>();
|
final refNameC = refName.toChar();
|
||||||
final error = libgit2.git_reference_ensure_log(repoPointer, refNameC);
|
final error = libgit2.git_reference_ensure_log(repoPointer, refNameC);
|
||||||
|
|
||||||
calloc.free(refNameC);
|
calloc.free(refNameC);
|
||||||
|
@ -237,9 +236,9 @@ Pointer<git_reference> createDirect({
|
||||||
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.toChar();
|
||||||
final forceC = force == true ? 1 : 0;
|
final forceC = force == true ? 1 : 0;
|
||||||
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||||
final error = libgit2.git_reference_create(
|
final error = libgit2.git_reference_create(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -295,10 +294,10 @@ Pointer<git_reference> createSymbolic({
|
||||||
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.toChar();
|
||||||
final targetC = target.toNativeUtf8().cast<Int8>();
|
final targetC = target.toChar();
|
||||||
final forceC = force == true ? 1 : 0;
|
final forceC = force == true ? 1 : 0;
|
||||||
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||||
final error = libgit2.git_reference_symbolic_create(
|
final error = libgit2.git_reference_symbolic_create(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -348,7 +347,7 @@ Pointer<git_reference> setTarget({
|
||||||
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?.toChar() ?? nullptr;
|
||||||
final error = libgit2.git_reference_set_target(
|
final error = libgit2.git_reference_set_target(
|
||||||
out,
|
out,
|
||||||
refPointer,
|
refPointer,
|
||||||
|
@ -388,8 +387,8 @@ Pointer<git_reference> setTargetSymbolic({
|
||||||
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.toChar();
|
||||||
final logMessageC = logMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final logMessageC = logMessage?.toChar() ?? nullptr;
|
||||||
final error = libgit2.git_reference_symbolic_set_target(
|
final error = libgit2.git_reference_symbolic_set_target(
|
||||||
out,
|
out,
|
||||||
refPointer,
|
refPointer,
|
||||||
|
@ -410,14 +409,6 @@ Pointer<git_reference> setTargetSymbolic({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compare two references.
|
|
||||||
bool compare({
|
|
||||||
required Pointer<git_reference> ref1Pointer,
|
|
||||||
required Pointer<git_reference> ref2Pointer,
|
|
||||||
}) {
|
|
||||||
return libgit2.git_reference_cmp(ref1Pointer, ref2Pointer) == 0 || false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Recursively peel reference until object of the specified type is found.
|
/// Recursively peel reference until object of the specified type is found.
|
||||||
///
|
///
|
||||||
/// The retrieved peeled object is owned by the repository and should be closed
|
/// The retrieved peeled object is owned by the repository and should be closed
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Read the reflog for the given reference. The returned reflog must be
|
/// Read the reflog for the given reference. The returned reflog must be
|
||||||
|
@ -15,7 +16,7 @@ Pointer<git_reflog> read({
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_reflog>>();
|
final out = calloc<Pointer<git_reflog>>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
libgit2.git_reflog_read(out, repoPointer, nameC);
|
libgit2.git_reflog_read(out, repoPointer, nameC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -43,7 +44,7 @@ void delete({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
libgit2.git_reflog_delete(repoPointer, nameC);
|
libgit2.git_reflog_delete(repoPointer, nameC);
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
}
|
}
|
||||||
|
@ -60,8 +61,8 @@ void rename({
|
||||||
required String oldName,
|
required String oldName,
|
||||||
required String newName,
|
required String newName,
|
||||||
}) {
|
}) {
|
||||||
final oldNameC = oldName.toNativeUtf8().cast<Int8>();
|
final oldNameC = oldName.toChar();
|
||||||
final newNameC = newName.toNativeUtf8().cast<Int8>();
|
final newNameC = newName.toChar();
|
||||||
final error = libgit2.git_reflog_rename(repoPointer, oldNameC, newNameC);
|
final error = libgit2.git_reflog_rename(repoPointer, oldNameC, newNameC);
|
||||||
|
|
||||||
calloc.free(oldNameC);
|
calloc.free(oldNameC);
|
||||||
|
@ -81,8 +82,7 @@ void add({
|
||||||
required Pointer<git_signature> committerPointer,
|
required Pointer<git_signature> committerPointer,
|
||||||
required String message,
|
required String message,
|
||||||
}) {
|
}) {
|
||||||
final messageC =
|
final messageC = message.isEmpty ? nullptr : message.toChar();
|
||||||
message.isEmpty ? nullptr : message.toNativeUtf8().cast<Int8>();
|
|
||||||
|
|
||||||
final error = libgit2.git_reflog_append(
|
final error = libgit2.git_reflog_append(
|
||||||
reflogPointer,
|
reflogPointer,
|
||||||
|
@ -130,7 +130,7 @@ Pointer<git_reflog_entry> getByIndex({
|
||||||
/// Get the log message.
|
/// Get the log message.
|
||||||
String entryMessage(Pointer<git_reflog_entry> entry) {
|
String entryMessage(Pointer<git_reflog_entry> entry) {
|
||||||
final result = libgit2.git_reflog_entry_message(entry);
|
final result = libgit2.git_reflog_entry_message(entry);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the committer of this entry. The returned signature must be freed.
|
/// Get the committer of this entry. The returned signature must be freed.
|
||||||
|
|
|
@ -3,16 +3,17 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Get the source specifier.
|
/// Get the source specifier.
|
||||||
String source(Pointer<git_refspec> refspec) {
|
String source(Pointer<git_refspec> refspec) {
|
||||||
return libgit2.git_refspec_src(refspec).cast<Utf8>().toDartString();
|
return libgit2.git_refspec_src(refspec).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the destination specifier.
|
/// Get the destination specifier.
|
||||||
String destination(Pointer<git_refspec> refspec) {
|
String destination(Pointer<git_refspec> refspec) {
|
||||||
return libgit2.git_refspec_dst(refspec).cast<Utf8>().toDartString();
|
return libgit2.git_refspec_dst(refspec).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the force update setting.
|
/// Get the force update setting.
|
||||||
|
@ -22,7 +23,7 @@ bool force(Pointer<git_refspec> refspec) {
|
||||||
|
|
||||||
/// Get the refspec's string.
|
/// Get the refspec's string.
|
||||||
String string(Pointer<git_refspec> refspec) {
|
String string(Pointer<git_refspec> refspec) {
|
||||||
return libgit2.git_refspec_string(refspec).cast<Utf8>().toDartString();
|
return libgit2.git_refspec_string(refspec).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the refspec's direction.
|
/// Get the refspec's direction.
|
||||||
|
@ -34,7 +35,7 @@ bool matchesSource({
|
||||||
required Pointer<git_refspec> refspecPointer,
|
required Pointer<git_refspec> refspecPointer,
|
||||||
required String refname,
|
required String refname,
|
||||||
}) {
|
}) {
|
||||||
final refnameC = refname.toNativeUtf8().cast<Int8>();
|
final refnameC = refname.toChar();
|
||||||
final result = libgit2.git_refspec_src_matches(refspecPointer, refnameC);
|
final result = libgit2.git_refspec_src_matches(refspecPointer, refnameC);
|
||||||
|
|
||||||
calloc.free(refnameC);
|
calloc.free(refnameC);
|
||||||
|
@ -47,7 +48,7 @@ bool matchesDestination({
|
||||||
required Pointer<git_refspec> refspecPointer,
|
required Pointer<git_refspec> refspecPointer,
|
||||||
required String refname,
|
required String refname,
|
||||||
}) {
|
}) {
|
||||||
final refnameC = refname.toNativeUtf8().cast<Int8>();
|
final refnameC = refname.toChar();
|
||||||
final result = libgit2.git_refspec_dst_matches(refspecPointer, refnameC);
|
final result = libgit2.git_refspec_dst_matches(refspecPointer, refnameC);
|
||||||
|
|
||||||
calloc.free(refnameC);
|
calloc.free(refnameC);
|
||||||
|
@ -63,10 +64,10 @@ String transform({
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final error = libgit2.git_refspec_transform(out, refspecPointer, nameC);
|
final error = libgit2.git_refspec_transform(out, refspecPointer, nameC);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -88,10 +89,10 @@ String rTransform({
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final error = libgit2.git_refspec_rtransform(out, refspecPointer, nameC);
|
final error = libgit2.git_refspec_rtransform(out, refspecPointer, nameC);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
||||||
import 'package:libgit2dart/src/callbacks.dart';
|
import 'package:libgit2dart/src/callbacks.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/oid.dart';
|
import 'package:libgit2dart/src/oid.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
|
@ -13,10 +14,9 @@ List<String> list(Pointer<git_repository> repo) {
|
||||||
final out = calloc<git_strarray>();
|
final out = calloc<git_strarray>();
|
||||||
libgit2.git_remote_list(out, repo);
|
libgit2.git_remote_list(out, repo);
|
||||||
|
|
||||||
final result = <String>[];
|
final result = <String>[
|
||||||
for (var i = 0; i < out.ref.count; i++) {
|
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
];
|
||||||
}
|
|
||||||
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ Pointer<git_remote> lookup({
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_remote>>();
|
final out = calloc<Pointer<git_remote>>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final error = libgit2.git_remote_lookup(out, repoPointer, nameC);
|
final error = libgit2.git_remote_lookup(out, repoPointer, nameC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -59,8 +59,8 @@ Pointer<git_remote> create({
|
||||||
required 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.toChar();
|
||||||
final urlC = url.toNativeUtf8().cast<Int8>();
|
final urlC = url.toChar();
|
||||||
final error = libgit2.git_remote_create(out, repoPointer, nameC, urlC);
|
final error = libgit2.git_remote_create(out, repoPointer, nameC, urlC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -87,9 +87,9 @@ Pointer<git_remote> createWithFetchSpec({
|
||||||
required 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.toChar();
|
||||||
final urlC = url.toNativeUtf8().cast<Int8>();
|
final urlC = url.toChar();
|
||||||
final fetchC = fetch.toNativeUtf8().cast<Int8>();
|
final fetchC = fetch.toChar();
|
||||||
final error = libgit2.git_remote_create_with_fetchspec(
|
final error = libgit2.git_remote_create_with_fetchspec(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -122,7 +122,7 @@ void delete({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final error = libgit2.git_remote_delete(repoPointer, nameC);
|
final error = libgit2.git_remote_delete(repoPointer, nameC);
|
||||||
|
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
|
@ -151,8 +151,8 @@ List<String> rename({
|
||||||
required String newName,
|
required String newName,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_strarray>();
|
final out = calloc<git_strarray>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final newNameC = newName.toNativeUtf8().cast<Int8>();
|
final newNameC = newName.toChar();
|
||||||
final error = libgit2.git_remote_rename(out, repoPointer, nameC, newNameC);
|
final error = libgit2.git_remote_rename(out, repoPointer, nameC, newNameC);
|
||||||
|
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
|
@ -162,11 +162,12 @@ List<String> rename({
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
final result = <String>[];
|
final result = <String>[
|
||||||
for (var i = 0; i < out.ref.count; i++) {
|
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
];
|
||||||
}
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,8 +183,8 @@ void setUrl({
|
||||||
required String remote,
|
required String remote,
|
||||||
required String url,
|
required String url,
|
||||||
}) {
|
}) {
|
||||||
final remoteC = remote.toNativeUtf8().cast<Int8>();
|
final remoteC = remote.toChar();
|
||||||
final urlC = url.toNativeUtf8().cast<Int8>();
|
final urlC = url.toChar();
|
||||||
final error = libgit2.git_remote_set_url(repoPointer, remoteC, urlC);
|
final error = libgit2.git_remote_set_url(repoPointer, remoteC, urlC);
|
||||||
|
|
||||||
calloc.free(remoteC);
|
calloc.free(remoteC);
|
||||||
|
@ -205,8 +206,8 @@ void setPushUrl({
|
||||||
required String remote,
|
required String remote,
|
||||||
required String url,
|
required String url,
|
||||||
}) {
|
}) {
|
||||||
final remoteC = remote.toNativeUtf8().cast<Int8>();
|
final remoteC = remote.toChar();
|
||||||
final urlC = url.toNativeUtf8().cast<Int8>();
|
final urlC = url.toChar();
|
||||||
final error = libgit2.git_remote_set_pushurl(repoPointer, remoteC, urlC);
|
final error = libgit2.git_remote_set_pushurl(repoPointer, remoteC, urlC);
|
||||||
|
|
||||||
calloc.free(remoteC);
|
calloc.free(remoteC);
|
||||||
|
@ -220,12 +221,12 @@ void setPushUrl({
|
||||||
/// Get the remote's name.
|
/// Get the remote's name.
|
||||||
String name(Pointer<git_remote> remote) {
|
String name(Pointer<git_remote> remote) {
|
||||||
final result = libgit2.git_remote_name(remote);
|
final result = libgit2.git_remote_name(remote);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the remote's url.
|
/// Get the remote's url.
|
||||||
String url(Pointer<git_remote> remote) {
|
String url(Pointer<git_remote> remote) {
|
||||||
return libgit2.git_remote_url(remote).cast<Utf8>().toDartString();
|
return libgit2.git_remote_url(remote).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the remote's url for pushing.
|
/// Get the remote's url for pushing.
|
||||||
|
@ -233,7 +234,7 @@ String url(Pointer<git_remote> remote) {
|
||||||
/// Returns empty string if no special url for pushing is set.
|
/// Returns empty string if no special url for pushing is set.
|
||||||
String pushUrl(Pointer<git_remote> remote) {
|
String pushUrl(Pointer<git_remote> remote) {
|
||||||
final result = libgit2.git_remote_pushurl(remote);
|
final result = libgit2.git_remote_pushurl(remote);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the number of refspecs for a remote.
|
/// Get the number of refspecs for a remote.
|
||||||
|
@ -253,11 +254,12 @@ List<String> fetchRefspecs(Pointer<git_remote> remote) {
|
||||||
final out = calloc<git_strarray>();
|
final out = calloc<git_strarray>();
|
||||||
libgit2.git_remote_get_fetch_refspecs(out, remote);
|
libgit2.git_remote_get_fetch_refspecs(out, remote);
|
||||||
|
|
||||||
final result = <String>[];
|
final result = <String>[
|
||||||
for (var i = 0; i < out.ref.count; i++) {
|
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
];
|
||||||
}
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,11 +268,12 @@ List<String> pushRefspecs(Pointer<git_remote> remote) {
|
||||||
final out = calloc<git_strarray>();
|
final out = calloc<git_strarray>();
|
||||||
libgit2.git_remote_get_push_refspecs(out, remote);
|
libgit2.git_remote_get_push_refspecs(out, remote);
|
||||||
|
|
||||||
final result = <String>[];
|
final result = <String>[
|
||||||
for (var i = 0; i < out.ref.count; i++) {
|
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
];
|
||||||
}
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,8 +288,8 @@ void addFetch({
|
||||||
required String remote,
|
required String remote,
|
||||||
required String refspec,
|
required String refspec,
|
||||||
}) {
|
}) {
|
||||||
final remoteC = remote.toNativeUtf8().cast<Int8>();
|
final remoteC = remote.toChar();
|
||||||
final refspecC = refspec.toNativeUtf8().cast<Int8>();
|
final refspecC = refspec.toChar();
|
||||||
final error = libgit2.git_remote_add_fetch(repoPointer, remoteC, refspecC);
|
final error = libgit2.git_remote_add_fetch(repoPointer, remoteC, refspecC);
|
||||||
|
|
||||||
calloc.free(remoteC);
|
calloc.free(remoteC);
|
||||||
|
@ -308,8 +311,8 @@ void addPush({
|
||||||
required String remote,
|
required String remote,
|
||||||
required String refspec,
|
required String refspec,
|
||||||
}) {
|
}) {
|
||||||
final remoteC = remote.toNativeUtf8().cast<Int8>();
|
final remoteC = remote.toChar();
|
||||||
final refspecC = refspec.toNativeUtf8().cast<Int8>();
|
final refspecC = refspec.toChar();
|
||||||
final error = libgit2.git_remote_add_push(repoPointer, remoteC, refspecC);
|
final error = libgit2.git_remote_add_push(repoPointer, remoteC, refspecC);
|
||||||
|
|
||||||
calloc.free(remoteC);
|
calloc.free(remoteC);
|
||||||
|
@ -375,7 +378,7 @@ void connect({
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
List<Map<String, Object?>> lsRemotes(Pointer<git_remote> remote) {
|
List<Map<String, Object?>> lsRemotes(Pointer<git_remote> remote) {
|
||||||
final out = calloc<Pointer<Pointer<git_remote_head>>>();
|
final out = calloc<Pointer<Pointer<git_remote_head>>>();
|
||||||
final size = calloc<Uint64>();
|
final size = calloc<Size>();
|
||||||
libgit2.git_remote_ls(out, size, remote);
|
libgit2.git_remote_ls(out, size, remote);
|
||||||
|
|
||||||
final result = <Map<String, Object?>>[];
|
final result = <Map<String, Object?>>[];
|
||||||
|
@ -387,12 +390,11 @@ List<Map<String, Object?>> lsRemotes(Pointer<git_remote> remote) {
|
||||||
|
|
||||||
remote['local'] = local;
|
remote['local'] = local;
|
||||||
remote['loid'] = local ? Oid.fromRaw(out[0][i].ref.loid) : null;
|
remote['loid'] = local ? Oid.fromRaw(out[0][i].ref.loid) : null;
|
||||||
remote['name'] = out[0][i].ref.name == nullptr
|
remote['name'] =
|
||||||
? ''
|
out[0][i].ref.name == nullptr ? '' : out[0][i].ref.name.toDartString();
|
||||||
: out[0][i].ref.name.cast<Utf8>().toDartString();
|
|
||||||
remote['symref'] = out[0][i].ref.symref_target == nullptr
|
remote['symref'] = out[0][i].ref.symref_target == nullptr
|
||||||
? ''
|
? ''
|
||||||
: out[0][i].ref.symref_target.cast<Utf8>().toDartString();
|
: out[0][i].ref.symref_target.toDartString();
|
||||||
remote['oid'] = Oid.fromRaw(out[0][i].ref.oid);
|
remote['oid'] = Oid.fromRaw(out[0][i].ref.oid);
|
||||||
|
|
||||||
result.add(remote);
|
result.add(remote);
|
||||||
|
@ -419,9 +421,8 @@ void fetch({
|
||||||
String? proxyOption,
|
String? proxyOption,
|
||||||
}) {
|
}) {
|
||||||
final refspecsC = calloc<git_strarray>();
|
final refspecsC = calloc<git_strarray>();
|
||||||
final refspecsPointers =
|
final refspecsPointers = refspecs.map((e) => e.toChar()).toList();
|
||||||
refspecs.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
final strArray = calloc<Pointer<Char>>(refspecs.length);
|
||||||
final strArray = calloc<Pointer<Int8>>(refspecs.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < refspecs.length; i++) {
|
for (var i = 0; i < refspecs.length; i++) {
|
||||||
strArray[i] = refspecsPointers[i];
|
strArray[i] = refspecsPointers[i];
|
||||||
|
@ -429,7 +430,7 @@ void fetch({
|
||||||
|
|
||||||
refspecsC.ref.count = refspecs.length;
|
refspecsC.ref.count = refspecs.length;
|
||||||
refspecsC.ref.strings = strArray;
|
refspecsC.ref.strings = strArray;
|
||||||
final reflogMessageC = reflogMessage?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final reflogMessageC = reflogMessage?.toChar() ?? nullptr;
|
||||||
|
|
||||||
final proxyOptions = _proxyOptionsInit(proxyOption);
|
final proxyOptions = _proxyOptionsInit(proxyOption);
|
||||||
|
|
||||||
|
@ -475,9 +476,8 @@ void push({
|
||||||
String? proxyOption,
|
String? proxyOption,
|
||||||
}) {
|
}) {
|
||||||
final refspecsC = calloc<git_strarray>();
|
final refspecsC = calloc<git_strarray>();
|
||||||
final refspecsPointers =
|
final refspecsPointers = refspecs.map((e) => e.toChar()).toList();
|
||||||
refspecs.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
final strArray = calloc<Pointer<Char>>(refspecs.length);
|
||||||
final strArray = calloc<Pointer<Int8>>(refspecs.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < refspecs.length; i++) {
|
for (var i = 0; i < refspecs.length; i++) {
|
||||||
strArray[i] = refspecsPointers[i];
|
strArray[i] = refspecsPointers[i];
|
||||||
|
@ -566,7 +566,7 @@ Pointer<git_proxy_options> _proxyOptionsInit(String? proxyOption) {
|
||||||
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_AUTO;
|
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_AUTO;
|
||||||
} else {
|
} else {
|
||||||
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_SPECIFIED;
|
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_SPECIFIED;
|
||||||
proxyOptions.ref.url = proxyOption.toNativeUtf8().cast<Int8>();
|
proxyOptions.ref.url = proxyOption.toChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
return proxyOptions;
|
return proxyOptions;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/remote.dart' as remote_bindings;
|
import 'package:libgit2dart/src/bindings/remote.dart' as remote_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/repository.dart'
|
import 'package:libgit2dart/src/bindings/repository.dart'
|
||||||
as repository_bindings;
|
as repository_bindings;
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
class RemoteCallbacks {
|
class RemoteCallbacks {
|
||||||
|
@ -29,11 +30,11 @@ class RemoteCallbacks {
|
||||||
|
|
||||||
/// Callback for messages received by the transport.
|
/// Callback for messages received by the transport.
|
||||||
static int sidebandProgressCb(
|
static int sidebandProgressCb(
|
||||||
Pointer<Int8> progressOutput,
|
Pointer<Char> progressOutput,
|
||||||
int length,
|
int length,
|
||||||
Pointer<Void> payload,
|
Pointer<Void> payload,
|
||||||
) {
|
) {
|
||||||
sidebandProgress!(progressOutput.cast<Utf8>().toDartString(length: length));
|
sidebandProgress!(progressOutput.toDartString(length: length));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +43,12 @@ class RemoteCallbacks {
|
||||||
|
|
||||||
/// A callback that will be called for every reference.
|
/// A callback that will be called for every reference.
|
||||||
static int updateTipsCb(
|
static int updateTipsCb(
|
||||||
Pointer<Int8> refname,
|
Pointer<Char> refname,
|
||||||
Pointer<git_oid> oldOid,
|
Pointer<git_oid> oldOid,
|
||||||
Pointer<git_oid> newOid,
|
Pointer<git_oid> newOid,
|
||||||
Pointer<Void> payload,
|
Pointer<Void> payload,
|
||||||
) {
|
) {
|
||||||
updateTips!(refname.cast<Utf8>().toDartString(), Oid(oldOid), Oid(newOid));
|
updateTips!(refname.toDartString(), Oid(oldOid), Oid(newOid));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,13 +59,12 @@ class RemoteCallbacks {
|
||||||
/// not empty, the update was rejected by the remote server
|
/// not empty, the update was rejected by the remote server
|
||||||
/// and [message] contains the reason given.
|
/// and [message] contains the reason given.
|
||||||
static int pushUpdateReferenceCb(
|
static int pushUpdateReferenceCb(
|
||||||
Pointer<Int8> refname,
|
Pointer<Char> refname,
|
||||||
Pointer<Int8> message,
|
Pointer<Char> message,
|
||||||
Pointer<Void> payload,
|
Pointer<Void> payload,
|
||||||
) {
|
) {
|
||||||
final messageResult =
|
final messageResult = message == nullptr ? '' : message.toDartString();
|
||||||
message == nullptr ? '' : message.cast<Utf8>().toDartString();
|
pushUpdateReference!(refname.toDartString(), messageResult);
|
||||||
pushUpdateReference!(refname.cast<Utf8>().toDartString(), messageResult);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ class RemoteCallbacks {
|
||||||
static int remoteCb(
|
static int remoteCb(
|
||||||
Pointer<Pointer<git_remote>> remote,
|
Pointer<Pointer<git_remote>> remote,
|
||||||
Pointer<git_repository> repo,
|
Pointer<git_repository> repo,
|
||||||
Pointer<Int8> name,
|
Pointer<Char> name,
|
||||||
Pointer<Int8> url,
|
Pointer<Char> url,
|
||||||
Pointer<Void> payload,
|
Pointer<Void> payload,
|
||||||
) {
|
) {
|
||||||
late final Pointer<git_remote> remotePointer;
|
late final Pointer<git_remote> remotePointer;
|
||||||
|
@ -110,7 +110,7 @@ class RemoteCallbacks {
|
||||||
/// A callback used to create the new repository into which to clone.
|
/// A callback used to create the new repository into which to clone.
|
||||||
static int repositoryCb(
|
static int repositoryCb(
|
||||||
Pointer<Pointer<git_repository>> repo,
|
Pointer<Pointer<git_repository>> repo,
|
||||||
Pointer<Int8> path,
|
Pointer<Char> path,
|
||||||
int bare,
|
int bare,
|
||||||
Pointer<Void> payload,
|
Pointer<Void> payload,
|
||||||
) {
|
) {
|
||||||
|
@ -147,15 +147,15 @@ class RemoteCallbacks {
|
||||||
/// requires authentication in order to connect to it.
|
/// requires authentication in order to connect to it.
|
||||||
static int credentialsCb(
|
static int credentialsCb(
|
||||||
Pointer<Pointer<git_credential>> credPointer,
|
Pointer<Pointer<git_credential>> credPointer,
|
||||||
Pointer<Int8> url,
|
Pointer<Char> url,
|
||||||
Pointer<Int8> username,
|
Pointer<Char> username,
|
||||||
int allowedTypes,
|
int allowedTypes,
|
||||||
Pointer<Void> payload,
|
Pointer<Void> payload,
|
||||||
) {
|
) {
|
||||||
if (payload.cast<Int8>().value == 2) {
|
if (payload.cast<Char>().value == 2) {
|
||||||
libgit2.git_error_set_str(
|
libgit2.git_error_set_str(
|
||||||
git_error_t.GIT_ERROR_INVALID,
|
git_error_t.GIT_ERROR_INVALID,
|
||||||
'Incorrect credentials.'.toNativeUtf8().cast<Int8>(),
|
'Incorrect credentials.'.toChar(),
|
||||||
);
|
);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ class RemoteCallbacks {
|
||||||
if (allowedTypes & credentialType.value != credentialType.value) {
|
if (allowedTypes & credentialType.value != credentialType.value) {
|
||||||
libgit2.git_error_set_str(
|
libgit2.git_error_set_str(
|
||||||
git_error_t.GIT_ERROR_INVALID,
|
git_error_t.GIT_ERROR_INVALID,
|
||||||
'Invalid credential type $credentialType'.toNativeUtf8().cast<Int8>(),
|
'Invalid credential type $credentialType'.toChar(),
|
||||||
);
|
);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
||||||
import 'package:libgit2dart/src/callbacks.dart';
|
import 'package:libgit2dart/src/callbacks.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/remote.dart';
|
import 'package:libgit2dart/src/remote.dart';
|
||||||
import 'package:libgit2dart/src/repository.dart';
|
import 'package:libgit2dart/src/repository.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
@ -17,7 +18,7 @@ import 'package:libgit2dart/src/util.dart';
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_repository> open(String path) {
|
Pointer<git_repository> open(String path) {
|
||||||
final out = calloc<Pointer<git_repository>>();
|
final out = calloc<Pointer<git_repository>>();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final error = libgit2.git_repository_open(out, pathC);
|
final error = libgit2.git_repository_open(out, pathC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -44,15 +45,15 @@ String discover({
|
||||||
String? ceilingDirs,
|
String? ceilingDirs,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final startPathC = startPath.toNativeUtf8().cast<Int8>();
|
final startPathC = startPath.toChar();
|
||||||
final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final ceilingDirsC = ceilingDirs?.toChar() ?? nullptr;
|
||||||
|
|
||||||
libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC);
|
libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC);
|
||||||
|
|
||||||
calloc.free(startPathC);
|
calloc.free(startPathC);
|
||||||
calloc.free(ceilingDirsC);
|
calloc.free(ceilingDirsC);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -75,12 +76,12 @@ Pointer<git_repository> init({
|
||||||
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.toChar();
|
||||||
final workdirPathC = workdirPath?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final workdirPathC = workdirPath?.toChar() ?? nullptr;
|
||||||
final descriptionC = description?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final descriptionC = description?.toChar() ?? nullptr;
|
||||||
final templatePathC = templatePath?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final templatePathC = templatePath?.toChar() ?? nullptr;
|
||||||
final initialHeadC = initialHead?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final initialHeadC = initialHead?.toChar() ?? nullptr;
|
||||||
final originUrlC = originUrl?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final originUrlC = originUrl?.toChar() ?? nullptr;
|
||||||
final opts = calloc<git_repository_init_options>();
|
final opts = calloc<git_repository_init_options>();
|
||||||
libgit2.git_repository_init_options_init(
|
libgit2.git_repository_init_options_init(
|
||||||
opts,
|
opts,
|
||||||
|
@ -124,16 +125,14 @@ Pointer<git_repository> clone({
|
||||||
required String localPath,
|
required String localPath,
|
||||||
required bool bare,
|
required bool bare,
|
||||||
RemoteCallback? remoteCallback,
|
RemoteCallback? remoteCallback,
|
||||||
// Repository Function(String, bool)? repository,
|
|
||||||
RepositoryCallback? repositoryCallback,
|
RepositoryCallback? repositoryCallback,
|
||||||
String? checkoutBranch,
|
String? checkoutBranch,
|
||||||
required 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.toChar();
|
||||||
final localPathC = localPath.toNativeUtf8().cast<Int8>();
|
final localPathC = localPath.toChar();
|
||||||
final checkoutBranchC =
|
final checkoutBranchC = checkoutBranch?.toChar() ?? nullptr;
|
||||||
checkoutBranch?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
|
||||||
|
|
||||||
final cloneOptions = calloc<git_clone_options>();
|
final cloneOptions = calloc<git_clone_options>();
|
||||||
libgit2.git_clone_options_init(cloneOptions, GIT_CLONE_OPTIONS_VERSION);
|
libgit2.git_clone_options_init(cloneOptions, GIT_CLONE_OPTIONS_VERSION);
|
||||||
|
@ -188,7 +187,7 @@ Pointer<git_repository> clone({
|
||||||
/// Returns the path to the `.git` folder for normal repositories or the
|
/// Returns the path to the `.git` folder for normal repositories or the
|
||||||
/// repository itself for bare repositories.
|
/// repository itself for bare repositories.
|
||||||
String path(Pointer<git_repository> repo) {
|
String path(Pointer<git_repository> repo) {
|
||||||
return libgit2.git_repository_path(repo).cast<Utf8>().toDartString();
|
return libgit2.git_repository_path(repo).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the path of the shared common directory for this repository.
|
/// Get the path of the shared common directory for this repository.
|
||||||
|
@ -197,7 +196,7 @@ String path(Pointer<git_repository> repo) {
|
||||||
/// If the repository is a worktree, it is the parent repo's `.git` folder.
|
/// If the repository is a worktree, it is the parent repo's `.git` folder.
|
||||||
/// Otherwise, it is the `.git` folder.
|
/// Otherwise, it is the `.git` folder.
|
||||||
String commonDir(Pointer<git_repository> repo) {
|
String commonDir(Pointer<git_repository> repo) {
|
||||||
return libgit2.git_repository_commondir(repo).cast<Utf8>().toDartString();
|
return libgit2.git_repository_commondir(repo).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the currently active namespace for this repository.
|
/// Get the currently active namespace for this repository.
|
||||||
|
@ -206,11 +205,7 @@ String commonDir(Pointer<git_repository> repo) {
|
||||||
/// empty string is returned.
|
/// empty string is returned.
|
||||||
String getNamespace(Pointer<git_repository> repo) {
|
String getNamespace(Pointer<git_repository> repo) {
|
||||||
final result = libgit2.git_repository_get_namespace(repo);
|
final result = libgit2.git_repository_get_namespace(repo);
|
||||||
if (result == nullptr) {
|
return result == nullptr ? '' : result.toDartString();
|
||||||
return '';
|
|
||||||
} else {
|
|
||||||
return result.cast<Utf8>().toDartString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the active namespace for this repository.
|
/// Sets the active namespace for this repository.
|
||||||
|
@ -224,7 +219,7 @@ void setNamespace({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
String? namespace,
|
String? namespace,
|
||||||
}) {
|
}) {
|
||||||
final namespaceC = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final namespaceC = namespace?.toChar() ?? nullptr;
|
||||||
libgit2.git_repository_set_namespace(repoPointer, namespaceC);
|
libgit2.git_repository_set_namespace(repoPointer, namespaceC);
|
||||||
calloc.free(namespaceC);
|
calloc.free(namespaceC);
|
||||||
}
|
}
|
||||||
|
@ -311,8 +306,8 @@ void setIdentity({
|
||||||
String? name,
|
String? name,
|
||||||
String? email,
|
String? email,
|
||||||
}) {
|
}) {
|
||||||
final nameC = name?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final nameC = name?.toChar() ?? nullptr;
|
||||||
final emailC = email?.toNativeUtf8().cast<Int8>() ?? nullptr;
|
final emailC = email?.toChar() ?? nullptr;
|
||||||
|
|
||||||
libgit2.git_repository_set_ident(repoPointer, nameC, emailC);
|
libgit2.git_repository_set_ident(repoPointer, nameC, emailC);
|
||||||
|
|
||||||
|
@ -324,16 +319,16 @@ void setIdentity({
|
||||||
///
|
///
|
||||||
/// Returns list with name and email respectively.
|
/// Returns list with name and email respectively.
|
||||||
List<String> identity(Pointer<git_repository> repo) {
|
List<String> identity(Pointer<git_repository> repo) {
|
||||||
final name = calloc<Pointer<Int8>>();
|
final name = calloc<Pointer<Char>>();
|
||||||
final email = calloc<Pointer<Int8>>();
|
final email = calloc<Pointer<Char>>();
|
||||||
libgit2.git_repository_ident(name, email, repo);
|
libgit2.git_repository_ident(name, email, repo);
|
||||||
final identity = <String>[];
|
final identity = <String>[];
|
||||||
|
|
||||||
if (name.value == nullptr && email.value == nullptr) {
|
if (name.value == nullptr && email.value == nullptr) {
|
||||||
return identity;
|
return identity;
|
||||||
} else {
|
} else {
|
||||||
identity.add(name.value.cast<Utf8>().toDartString());
|
identity.add(name.value.toDartString());
|
||||||
identity.add(email.value.cast<Utf8>().toDartString());
|
identity.add(email.value.toDartString());
|
||||||
}
|
}
|
||||||
|
|
||||||
calloc.free(name);
|
calloc.free(name);
|
||||||
|
@ -417,7 +412,7 @@ String message(Pointer<git_repository> repo) {
|
||||||
final out = calloc<git_buf>();
|
final out = calloc<git_buf>();
|
||||||
final error = libgit2.git_repository_message(out, repo);
|
final error = libgit2.git_repository_message(out, repo);
|
||||||
|
|
||||||
final result = out.ref.ptr.cast<Utf8>().toDartString(length: out.ref.size);
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
libgit2.git_buf_dispose(out);
|
libgit2.git_buf_dispose(out);
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
@ -495,7 +490,7 @@ void setHead({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required String refname,
|
required String refname,
|
||||||
}) {
|
}) {
|
||||||
final refnameC = refname.toNativeUtf8().cast<Int8>();
|
final refnameC = refname.toChar();
|
||||||
final error = libgit2.git_repository_set_head(repoPointer, refnameC);
|
final error = libgit2.git_repository_set_head(repoPointer, refnameC);
|
||||||
|
|
||||||
calloc.free(refnameC);
|
calloc.free(refnameC);
|
||||||
|
@ -546,7 +541,7 @@ void setWorkdir({
|
||||||
required String path,
|
required String path,
|
||||||
required bool updateGitlink,
|
required bool updateGitlink,
|
||||||
}) {
|
}) {
|
||||||
final workdirC = path.toNativeUtf8().cast<Int8>();
|
final workdirC = path.toChar();
|
||||||
final updateGitlinkC = updateGitlink ? 1 : 0;
|
final updateGitlinkC = updateGitlink ? 1 : 0;
|
||||||
final error = libgit2.git_repository_set_workdir(
|
final error = libgit2.git_repository_set_workdir(
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -582,12 +577,7 @@ void stateCleanup(Pointer<git_repository> repo) {
|
||||||
/// If the repository is bare, this function will always return empty string.
|
/// If the repository is bare, this function will always return empty string.
|
||||||
String workdir(Pointer<git_repository> repo) {
|
String workdir(Pointer<git_repository> repo) {
|
||||||
final result = libgit2.git_repository_workdir(repo);
|
final result = libgit2.git_repository_workdir(repo);
|
||||||
|
return result == nullptr ? '' : result.toDartString();
|
||||||
if (result == nullptr) {
|
|
||||||
return '';
|
|
||||||
} else {
|
|
||||||
return result.cast<Utf8>().toDartString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free a previously allocated repository.
|
/// Free a previously allocated repository.
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Sets the current head to the specified commit oid and optionally resets the
|
/// Sets the current head to the specified commit oid and optionally resets the
|
||||||
|
@ -16,30 +17,67 @@ import 'package:libgit2dart/src/util.dart';
|
||||||
/// HARD reset will trigger a MIXED reset and the working directory will be
|
/// HARD reset will trigger a MIXED reset and the working directory will be
|
||||||
/// replaced with the content of the index. (Untracked and ignored files will
|
/// replaced with the content of the index. (Untracked and ignored files will
|
||||||
/// be left alone, however.)
|
/// be left alone, however.)
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void reset({
|
void reset({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required Pointer<git_object> targetPointer,
|
required Pointer<git_object> targetPointer,
|
||||||
required int resetType,
|
required int resetType,
|
||||||
required Pointer<git_checkout_options> checkoutOptsPointer,
|
int? strategy,
|
||||||
|
String? checkoutDirectory,
|
||||||
|
List<String>? pathspec,
|
||||||
}) {
|
}) {
|
||||||
libgit2.git_reset(repoPointer, targetPointer, resetType, checkoutOptsPointer);
|
final opts = calloc<git_checkout_options>();
|
||||||
|
libgit2.git_checkout_options_init(opts, GIT_CHECKOUT_OPTIONS_VERSION);
|
||||||
|
|
||||||
|
if (strategy != null) {
|
||||||
|
opts.ref.checkout_strategy = strategy;
|
||||||
|
}
|
||||||
|
if (checkoutDirectory != null) {
|
||||||
|
opts.ref.target_directory = checkoutDirectory.toChar();
|
||||||
|
}
|
||||||
|
var pathPointers = <Pointer<Char>>[];
|
||||||
|
Pointer<Pointer<Char>> strArray = nullptr;
|
||||||
|
if (pathspec != null) {
|
||||||
|
pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||||
|
strArray = calloc(pathspec.length);
|
||||||
|
for (var i = 0; i < pathspec.length; i++) {
|
||||||
|
strArray[i] = pathPointers[i];
|
||||||
|
}
|
||||||
|
opts.ref.paths.strings = strArray;
|
||||||
|
opts.ref.paths.count = pathspec.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
final error = libgit2.git_reset(repoPointer, targetPointer, resetType, opts);
|
||||||
|
|
||||||
|
for (final p in pathPointers) {
|
||||||
|
calloc.free(p);
|
||||||
|
}
|
||||||
|
calloc.free(strArray);
|
||||||
|
calloc.free(opts);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates some entries in the index from the target commit tree.
|
/// Updates some entries in the index from the target commit tree.
|
||||||
///
|
///
|
||||||
/// The scope of the updated entries is determined by the paths being passed in
|
/// The scope of the updated entries is determined by the paths being passed in
|
||||||
/// the pathspec parameters.
|
/// the [pathspec] parameters.
|
||||||
|
///
|
||||||
|
/// Passing a null [targetPointer] will result in removing entries in the index
|
||||||
|
/// matching the provided [pathspec]s.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void resetDefault({
|
void resetDefault({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required Pointer<git_object> targetPointer,
|
required Pointer<git_object>? targetPointer,
|
||||||
required List<String> pathspec,
|
required List<String> pathspec,
|
||||||
}) {
|
}) {
|
||||||
final pathspecC = calloc<git_strarray>();
|
final pathspecC = calloc<git_strarray>();
|
||||||
final pathPointers =
|
final pathPointers = pathspec.map((e) => e.toChar()).toList();
|
||||||
pathspec.map((e) => e.toNativeUtf8().cast<Int8>()).toList();
|
final strArray = calloc<Pointer<Char>>(pathspec.length);
|
||||||
final strArray = calloc<Pointer<Int8>>(pathspec.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < pathspec.length; i++) {
|
for (var i = 0; i < pathspec.length; i++) {
|
||||||
strArray[i] = pathPointers[i];
|
strArray[i] = pathPointers[i];
|
||||||
|
@ -50,7 +88,7 @@ void resetDefault({
|
||||||
|
|
||||||
final error = libgit2.git_reset_default(
|
final error = libgit2.git_reset_default(
|
||||||
repoPointer,
|
repoPointer,
|
||||||
targetPointer,
|
targetPointer ?? nullptr,
|
||||||
pathspecC,
|
pathspecC,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Parse a revision string for from, to, and intent.
|
/// Parse a revision string for from, to, and intent.
|
||||||
|
@ -16,7 +17,7 @@ Pointer<git_revspec> revParse({
|
||||||
required String spec,
|
required String spec,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_revspec>();
|
final out = calloc<git_revspec>();
|
||||||
final specC = spec.toNativeUtf8().cast<Int8>();
|
final specC = spec.toChar();
|
||||||
|
|
||||||
final error = libgit2.git_revparse(out, repoPointer, specC);
|
final error = libgit2.git_revparse(out, repoPointer, specC);
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ Pointer<git_object> revParseSingle({
|
||||||
required String spec,
|
required String spec,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_object>>();
|
final out = calloc<Pointer<git_object>>();
|
||||||
final specC = spec.toNativeUtf8().cast<Int8>();
|
final specC = spec.toChar();
|
||||||
|
|
||||||
final error = libgit2.git_revparse_single(out, repoPointer, specC);
|
final error = libgit2.git_revparse_single(out, repoPointer, specC);
|
||||||
|
|
||||||
|
@ -76,7 +77,7 @@ List<Pointer> revParseExt({
|
||||||
}) {
|
}) {
|
||||||
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.toChar();
|
||||||
|
|
||||||
final error = libgit2.git_revparse_ext(
|
final error = libgit2.git_revparse_ext(
|
||||||
objectOut,
|
objectOut,
|
||||||
|
@ -85,8 +86,7 @@ List<Pointer> revParseExt({
|
||||||
specC,
|
specC,
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = <Pointer>[];
|
final result = <Pointer>[objectOut.value];
|
||||||
result.add(objectOut.value);
|
|
||||||
if (referenceOut.value != nullptr) {
|
if (referenceOut.value != nullptr) {
|
||||||
result.add(referenceOut.value);
|
result.add(referenceOut.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/commit.dart' as commit_bindings;
|
import 'package:libgit2dart/src/bindings/commit.dart' as commit_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Allocate a new revision walker to iterate through a repo. The returned
|
/// Allocate a new revision walker to iterate through a repo. The returned
|
||||||
|
@ -81,7 +82,7 @@ void pushGlob({
|
||||||
required Pointer<git_revwalk> walkerPointer,
|
required Pointer<git_revwalk> walkerPointer,
|
||||||
required String glob,
|
required String glob,
|
||||||
}) {
|
}) {
|
||||||
final globC = glob.toNativeUtf8().cast<Int8>();
|
final globC = glob.toChar();
|
||||||
libgit2.git_revwalk_push_glob(walkerPointer, globC);
|
libgit2.git_revwalk_push_glob(walkerPointer, globC);
|
||||||
calloc.free(globC);
|
calloc.free(globC);
|
||||||
}
|
}
|
||||||
|
@ -99,7 +100,7 @@ void pushRef({
|
||||||
required Pointer<git_revwalk> walkerPointer,
|
required Pointer<git_revwalk> walkerPointer,
|
||||||
required String refName,
|
required String refName,
|
||||||
}) {
|
}) {
|
||||||
final refNameC = refName.toNativeUtf8().cast<Int8>();
|
final refNameC = refName.toChar();
|
||||||
final error = libgit2.git_revwalk_push_ref(walkerPointer, refNameC);
|
final error = libgit2.git_revwalk_push_ref(walkerPointer, refNameC);
|
||||||
|
|
||||||
calloc.free(refNameC);
|
calloc.free(refNameC);
|
||||||
|
@ -119,7 +120,7 @@ void pushRange({
|
||||||
required Pointer<git_revwalk> walkerPointer,
|
required Pointer<git_revwalk> walkerPointer,
|
||||||
required String range,
|
required String range,
|
||||||
}) {
|
}) {
|
||||||
final rangeC = range.toNativeUtf8().cast<Int8>();
|
final rangeC = range.toChar();
|
||||||
final error = libgit2.git_revwalk_push_range(walkerPointer, rangeC);
|
final error = libgit2.git_revwalk_push_range(walkerPointer, rangeC);
|
||||||
|
|
||||||
calloc.free(rangeC);
|
calloc.free(rangeC);
|
||||||
|
@ -144,11 +145,12 @@ void pushRange({
|
||||||
List<Pointer<git_commit>> walk({
|
List<Pointer<git_commit>> walk({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required Pointer<git_revwalk> walkerPointer,
|
required Pointer<git_revwalk> walkerPointer,
|
||||||
|
required int limit,
|
||||||
}) {
|
}) {
|
||||||
final result = <Pointer<git_commit>>[];
|
final result = <Pointer<git_commit>>[];
|
||||||
var error = 0;
|
var error = 0;
|
||||||
|
|
||||||
while (error == 0) {
|
void next() {
|
||||||
final oid = calloc<git_oid>();
|
final oid = calloc<git_oid>();
|
||||||
error = libgit2.git_revwalk_next(oid, walkerPointer);
|
error = libgit2.git_revwalk_next(oid, walkerPointer);
|
||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
|
@ -157,10 +159,21 @@ List<Pointer<git_commit>> walk({
|
||||||
oidPointer: oid,
|
oidPointer: oid,
|
||||||
);
|
);
|
||||||
result.add(commit);
|
result.add(commit);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
calloc.free(oid);
|
calloc.free(oid);
|
||||||
|
} else {
|
||||||
|
calloc.free(oid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (limit == 0) {
|
||||||
|
while (error == 0) {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var i = 0; i < limit; i++) {
|
||||||
|
next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -199,7 +212,7 @@ void hideGlob({
|
||||||
required Pointer<git_revwalk> walkerPointer,
|
required Pointer<git_revwalk> walkerPointer,
|
||||||
required String glob,
|
required String glob,
|
||||||
}) {
|
}) {
|
||||||
final globC = glob.toNativeUtf8().cast<Int8>();
|
final globC = glob.toChar();
|
||||||
libgit2.git_revwalk_hide_glob(walkerPointer, globC);
|
libgit2.git_revwalk_hide_glob(walkerPointer, globC);
|
||||||
calloc.free(globC);
|
calloc.free(globC);
|
||||||
}
|
}
|
||||||
|
@ -217,7 +230,7 @@ void hideRef({
|
||||||
required Pointer<git_revwalk> walkerPointer,
|
required Pointer<git_revwalk> walkerPointer,
|
||||||
required String refName,
|
required String refName,
|
||||||
}) {
|
}) {
|
||||||
final refNameC = refName.toNativeUtf8().cast<Int8>();
|
final refNameC = refName.toChar();
|
||||||
final error = libgit2.git_revwalk_hide_ref(walkerPointer, refNameC);
|
final error = libgit2.git_revwalk_hide_ref(walkerPointer, refNameC);
|
||||||
|
|
||||||
calloc.free(refNameC);
|
calloc.free(refNameC);
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Create a new action signature. The returned signature must be freed with
|
/// Create a new action signature. The returned signature must be freed with
|
||||||
|
@ -19,8 +20,8 @@ Pointer<git_signature> create({
|
||||||
required 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.toChar();
|
||||||
final emailC = email.toNativeUtf8().cast<Int8>();
|
final emailC = email.toChar();
|
||||||
final error = libgit2.git_signature_new(out, nameC, emailC, time, offset);
|
final error = libgit2.git_signature_new(out, nameC, emailC, time, offset);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -42,8 +43,8 @@ Pointer<git_signature> create({
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Pointer<git_signature> now({required String name, required 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.toChar();
|
||||||
final emailC = email.toNativeUtf8().cast<Int8>();
|
final emailC = email.toChar();
|
||||||
final error = libgit2.git_signature_now(out, nameC, emailC);
|
final error = libgit2.git_signature_now(out, nameC, emailC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/checkout.dart' as checkout_bindings;
|
import 'package:libgit2dart/src/bindings/checkout.dart' as checkout_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/oid.dart';
|
import 'package:libgit2dart/src/oid.dart';
|
||||||
import 'package:libgit2dart/src/stash.dart';
|
import 'package:libgit2dart/src/stash.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
@ -18,7 +19,7 @@ Pointer<git_oid> save({
|
||||||
required 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?.toChar() ?? nullptr;
|
||||||
final error = libgit2.git_stash_save(
|
final error = libgit2.git_stash_save(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -143,16 +144,12 @@ var _stashList = <Stash>[];
|
||||||
/// A callback function to iterate over all the stashed states.
|
/// A callback function to iterate over all the stashed states.
|
||||||
int _stashCb(
|
int _stashCb(
|
||||||
int index,
|
int index,
|
||||||
Pointer<Int8> message,
|
Pointer<Char> message,
|
||||||
Pointer<git_oid> oid,
|
Pointer<git_oid> oid,
|
||||||
Pointer<Void> payload,
|
Pointer<Void> payload,
|
||||||
) {
|
) {
|
||||||
_stashList.add(
|
_stashList.add(
|
||||||
Stash(
|
Stash(index: index, message: message.toDartString(), oid: Oid(oid)),
|
||||||
index: index,
|
|
||||||
message: message.cast<Utf8>().toDartString(),
|
|
||||||
oid: Oid(oid),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Gather file status information and populate the git_status_list. The
|
/// Gather file status information and populate the git_status_list. The
|
||||||
|
@ -62,8 +63,8 @@ Pointer<git_status_entry> getByIndex({
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
int file({required Pointer<git_repository> repoPointer, required String path}) {
|
int file({required Pointer<git_repository> repoPointer, required String path}) {
|
||||||
final out = calloc<Uint32>();
|
final out = calloc<UnsignedInt>();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final error = libgit2.git_status_file(out, repoPointer, pathC);
|
final error = libgit2.git_status_file(out, repoPointer, pathC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
import 'package:libgit2dart/src/bindings/remote_callbacks.dart';
|
||||||
import 'package:libgit2dart/src/callbacks.dart';
|
import 'package:libgit2dart/src/callbacks.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// List of submodule paths.
|
/// List of submodule paths.
|
||||||
|
@ -15,7 +16,7 @@ List<String> _pathsList = [];
|
||||||
/// Function to be called with the name of each submodule.
|
/// Function to be called with the name of each submodule.
|
||||||
int _listCb(
|
int _listCb(
|
||||||
Pointer<git_submodule> submodule,
|
Pointer<git_submodule> submodule,
|
||||||
Pointer<Int8> name,
|
Pointer<Char> name,
|
||||||
Pointer<Void> payload,
|
Pointer<Void> payload,
|
||||||
) {
|
) {
|
||||||
_pathsList.add(path(submodule));
|
_pathsList.add(path(submodule));
|
||||||
|
@ -26,7 +27,7 @@ int _listCb(
|
||||||
List<String> list(Pointer<git_repository> repo) {
|
List<String> list(Pointer<git_repository> repo) {
|
||||||
const except = -1;
|
const except = -1;
|
||||||
final callback = Pointer.fromFunction<
|
final callback = Pointer.fromFunction<
|
||||||
Int32 Function(Pointer<git_submodule>, Pointer<Int8>, Pointer<Void>)>(
|
Int Function(Pointer<git_submodule>, Pointer<Char>, Pointer<Void>)>(
|
||||||
_listCb,
|
_listCb,
|
||||||
except,
|
except,
|
||||||
);
|
);
|
||||||
|
@ -50,7 +51,7 @@ Pointer<git_submodule> lookup({
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_submodule>>();
|
final out = calloc<Pointer<git_submodule>>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
|
|
||||||
final error = libgit2.git_submodule_lookup(out, repoPointer, nameC);
|
final error = libgit2.git_submodule_lookup(out, repoPointer, nameC);
|
||||||
|
|
||||||
|
@ -159,8 +160,8 @@ Pointer<git_submodule> addSetup({
|
||||||
bool useGitlink = true,
|
bool useGitlink = true,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_submodule>>();
|
final out = calloc<Pointer<git_submodule>>();
|
||||||
final urlC = url.toNativeUtf8().cast<Int8>();
|
final urlC = url.toChar();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
final useGitlinkC = useGitlink ? 1 : 0;
|
final useGitlinkC = useGitlink ? 1 : 0;
|
||||||
final error = libgit2.git_submodule_add_setup(
|
final error = libgit2.git_submodule_add_setup(
|
||||||
out,
|
out,
|
||||||
|
@ -232,8 +233,8 @@ int status({
|
||||||
required String name,
|
required String name,
|
||||||
required int ignore,
|
required int ignore,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Uint32>();
|
final out = calloc<UnsignedInt>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
libgit2.git_submodule_status(out, repoPointer, nameC, ignore);
|
libgit2.git_submodule_status(out, repoPointer, nameC, ignore);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -269,7 +270,7 @@ void reload({
|
||||||
|
|
||||||
/// Get the name of submodule.
|
/// Get the name of submodule.
|
||||||
String name(Pointer<git_submodule> submodule) {
|
String name(Pointer<git_submodule> submodule) {
|
||||||
return libgit2.git_submodule_name(submodule).cast<Utf8>().toDartString();
|
return libgit2.git_submodule_name(submodule).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the path to the submodule.
|
/// Get the path to the submodule.
|
||||||
|
@ -277,12 +278,12 @@ String name(Pointer<git_submodule> submodule) {
|
||||||
/// The path is almost always the same as the submodule name, but the two
|
/// The path is almost always the same as the submodule name, but the two
|
||||||
/// are actually not required to match.
|
/// are actually not required to match.
|
||||||
String path(Pointer<git_submodule> submodule) {
|
String path(Pointer<git_submodule> submodule) {
|
||||||
return libgit2.git_submodule_path(submodule).cast<Utf8>().toDartString();
|
return libgit2.git_submodule_path(submodule).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the URL for the submodule.
|
/// Get the URL for the submodule.
|
||||||
String url(Pointer<git_submodule> submodule) {
|
String url(Pointer<git_submodule> submodule) {
|
||||||
return libgit2.git_submodule_url(submodule).cast<Utf8>().toDartString();
|
return libgit2.git_submodule_url(submodule).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the URL for the submodule in the configuration.
|
/// Set the URL for the submodule in the configuration.
|
||||||
|
@ -294,8 +295,8 @@ void setUrl({
|
||||||
required String name,
|
required String name,
|
||||||
required String url,
|
required String url,
|
||||||
}) {
|
}) {
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final urlC = url.toNativeUtf8().cast<Int8>();
|
final urlC = url.toChar();
|
||||||
|
|
||||||
libgit2.git_submodule_set_url(repoPointer, nameC, urlC);
|
libgit2.git_submodule_set_url(repoPointer, nameC, urlC);
|
||||||
|
|
||||||
|
@ -306,7 +307,7 @@ void setUrl({
|
||||||
/// Get the branch for the submodule.
|
/// Get the branch for the submodule.
|
||||||
String branch(Pointer<git_submodule> submodule) {
|
String branch(Pointer<git_submodule> submodule) {
|
||||||
final result = libgit2.git_submodule_branch(submodule);
|
final result = libgit2.git_submodule_branch(submodule);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the branch for the submodule in the configuration.
|
/// Set the branch for the submodule in the configuration.
|
||||||
|
@ -318,8 +319,8 @@ void setBranch({
|
||||||
required String name,
|
required String name,
|
||||||
required String branch,
|
required String branch,
|
||||||
}) {
|
}) {
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final branchC = branch.toNativeUtf8().cast<Int8>();
|
final branchC = branch.toChar();
|
||||||
|
|
||||||
libgit2.git_submodule_set_branch(repoPointer, nameC, branchC);
|
libgit2.git_submodule_set_branch(repoPointer, nameC, branchC);
|
||||||
|
|
||||||
|
@ -369,7 +370,7 @@ void setIgnore({
|
||||||
required String name,
|
required String name,
|
||||||
required int ignore,
|
required int ignore,
|
||||||
}) {
|
}) {
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
libgit2.git_submodule_set_ignore(repoPointer, nameC, ignore);
|
libgit2.git_submodule_set_ignore(repoPointer, nameC, ignore);
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
}
|
}
|
||||||
|
@ -389,7 +390,7 @@ void setUpdateRule({
|
||||||
required String name,
|
required String name,
|
||||||
required int update,
|
required int update,
|
||||||
}) {
|
}) {
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
libgit2.git_submodule_set_update(repoPointer, nameC, update);
|
libgit2.git_submodule_set_update(repoPointer, nameC, update);
|
||||||
calloc.free(nameC);
|
calloc.free(nameC);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Fill a list with all the tags in the repository.
|
/// Fill a list with all the tags in the repository.
|
||||||
|
@ -12,16 +13,16 @@ List<String> list(Pointer<git_repository> repo) {
|
||||||
final out = calloc<git_strarray>();
|
final out = calloc<git_strarray>();
|
||||||
final error = libgit2.git_tag_list(out, repo);
|
final error = libgit2.git_tag_list(out, repo);
|
||||||
|
|
||||||
final result = <String>[];
|
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
for (var i = 0; i < out.ref.count; i++) {
|
final result = <String>[
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||||
}
|
];
|
||||||
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,13 +81,12 @@ Pointer<git_oid> targetOid(Pointer<git_tag> tag) =>
|
||||||
Pointer<git_oid> id(Pointer<git_tag> tag) => libgit2.git_tag_id(tag);
|
Pointer<git_oid> id(Pointer<git_tag> tag) => libgit2.git_tag_id(tag);
|
||||||
|
|
||||||
/// Get the name of a tag.
|
/// Get the name of a tag.
|
||||||
String name(Pointer<git_tag> tag) =>
|
String name(Pointer<git_tag> tag) => libgit2.git_tag_name(tag).toDartString();
|
||||||
libgit2.git_tag_name(tag).cast<Utf8>().toDartString();
|
|
||||||
|
|
||||||
/// Get the message of a tag.
|
/// Get the message of a tag.
|
||||||
String message(Pointer<git_tag> tag) {
|
String message(Pointer<git_tag> tag) {
|
||||||
final result = libgit2.git_tag_message(tag);
|
final result = libgit2.git_tag_message(tag);
|
||||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
return result == nullptr ? '' : result.toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the tagger (author) of a tag. The returned signature must be freed.
|
/// Get the tagger (author) of a tag. The returned signature must be freed.
|
||||||
|
@ -115,8 +115,8 @@ Pointer<git_oid> createAnnotated({
|
||||||
required bool force,
|
required bool force,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final tagNameC = tagName.toNativeUtf8().cast<Int8>();
|
final tagNameC = tagName.toChar();
|
||||||
final messageC = message.toNativeUtf8().cast<Int8>();
|
final messageC = message.toChar();
|
||||||
final error = libgit2.git_tag_create(
|
final error = libgit2.git_tag_create(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -155,7 +155,7 @@ Pointer<git_oid> createLightweight({
|
||||||
required bool force,
|
required bool force,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<git_oid>();
|
final out = calloc<git_oid>();
|
||||||
final tagNameC = tagName.toNativeUtf8().cast<Int8>();
|
final tagNameC = tagName.toChar();
|
||||||
final error = libgit2.git_tag_create_lightweight(
|
final error = libgit2.git_tag_create_lightweight(
|
||||||
out,
|
out,
|
||||||
repoPointer,
|
repoPointer,
|
||||||
|
@ -183,7 +183,7 @@ void delete({
|
||||||
required Pointer<git_repository> repoPointer,
|
required Pointer<git_repository> repoPointer,
|
||||||
required String tagName,
|
required String tagName,
|
||||||
}) {
|
}) {
|
||||||
final tagNameC = tagName.toNativeUtf8().cast<Int8>();
|
final tagNameC = tagName.toChar();
|
||||||
final error = libgit2.git_tag_delete(repoPointer, tagNameC);
|
final error = libgit2.git_tag_delete(repoPointer, tagNameC);
|
||||||
|
|
||||||
calloc.free(tagNameC);
|
calloc.free(tagNameC);
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Get the id of a tree.
|
/// Get the id of a tree.
|
||||||
|
@ -59,7 +60,7 @@ Pointer<git_tree_entry> getByName({
|
||||||
required Pointer<git_tree> treePointer,
|
required Pointer<git_tree> treePointer,
|
||||||
required String filename,
|
required String filename,
|
||||||
}) {
|
}) {
|
||||||
final filenameC = filename.toNativeUtf8().cast<Int8>();
|
final filenameC = filename.toChar();
|
||||||
final result = libgit2.git_tree_entry_byname(treePointer, filenameC);
|
final result = libgit2.git_tree_entry_byname(treePointer, filenameC);
|
||||||
|
|
||||||
calloc.free(filenameC);
|
calloc.free(filenameC);
|
||||||
|
@ -83,7 +84,7 @@ Pointer<git_tree_entry> getByPath({
|
||||||
required String path,
|
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.toChar();
|
||||||
final error = libgit2.git_tree_entry_bypath(out, rootPointer, pathC);
|
final error = libgit2.git_tree_entry_bypath(out, rootPointer, pathC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -107,7 +108,7 @@ Pointer<git_oid> entryId(Pointer<git_tree_entry> entry) =>
|
||||||
|
|
||||||
/// Get the filename of a tree entry.
|
/// Get the filename of a tree entry.
|
||||||
String entryName(Pointer<git_tree_entry> entry) =>
|
String entryName(Pointer<git_tree_entry> entry) =>
|
||||||
libgit2.git_tree_entry_name(entry).cast<Utf8>().toDartString();
|
libgit2.git_tree_entry_name(entry).toDartString();
|
||||||
|
|
||||||
/// Get the UNIX file attributes of a tree entry.
|
/// Get the UNIX file attributes of a tree entry.
|
||||||
int entryFilemode(Pointer<git_tree_entry> entry) =>
|
int entryFilemode(Pointer<git_tree_entry> entry) =>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Create a new tree builder. The returned tree builder must be freed with
|
/// Create a new tree builder. The returned tree builder must be freed with
|
||||||
|
@ -53,7 +54,7 @@ Pointer<git_tree_entry> getByFilename({
|
||||||
required Pointer<git_treebuilder> builderPointer,
|
required Pointer<git_treebuilder> builderPointer,
|
||||||
required String filename,
|
required String filename,
|
||||||
}) {
|
}) {
|
||||||
final filenameC = filename.toNativeUtf8().cast<Int8>();
|
final filenameC = filename.toChar();
|
||||||
final result = libgit2.git_treebuilder_get(builderPointer, filenameC);
|
final result = libgit2.git_treebuilder_get(builderPointer, filenameC);
|
||||||
|
|
||||||
calloc.free(filenameC);
|
calloc.free(filenameC);
|
||||||
|
@ -82,7 +83,7 @@ void add({
|
||||||
required Pointer<git_oid> oidPointer,
|
required Pointer<git_oid> oidPointer,
|
||||||
required int filemode,
|
required int filemode,
|
||||||
}) {
|
}) {
|
||||||
final filenameC = filename.toNativeUtf8().cast<Int8>();
|
final filenameC = filename.toChar();
|
||||||
final error = libgit2.git_treebuilder_insert(
|
final error = libgit2.git_treebuilder_insert(
|
||||||
nullptr,
|
nullptr,
|
||||||
builderPointer,
|
builderPointer,
|
||||||
|
@ -105,7 +106,7 @@ void remove({
|
||||||
required Pointer<git_treebuilder> builderPointer,
|
required Pointer<git_treebuilder> builderPointer,
|
||||||
required String filename,
|
required String filename,
|
||||||
}) {
|
}) {
|
||||||
final filenameC = filename.toNativeUtf8().cast<Int8>();
|
final filenameC = filename.toChar();
|
||||||
final error = libgit2.git_treebuilder_remove(builderPointer, filenameC);
|
final error = libgit2.git_treebuilder_remove(builderPointer, filenameC);
|
||||||
|
|
||||||
calloc.free(filenameC);
|
calloc.free(filenameC);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/error.dart';
|
import 'package:libgit2dart/src/error.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
/// Add a new working tree. The returned worktree must be freed with [free].
|
/// Add a new working tree. The returned worktree must be freed with [free].
|
||||||
|
@ -20,8 +21,8 @@ Pointer<git_worktree> create({
|
||||||
Pointer<git_reference>? refPointer,
|
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.toChar();
|
||||||
final pathC = path.toNativeUtf8().cast<Int8>();
|
final pathC = path.toChar();
|
||||||
|
|
||||||
final opts = calloc<git_worktree_add_options>();
|
final opts = calloc<git_worktree_add_options>();
|
||||||
libgit2.git_worktree_add_options_init(opts, GIT_WORKTREE_ADD_OPTIONS_VERSION);
|
libgit2.git_worktree_add_options_init(opts, GIT_WORKTREE_ADD_OPTIONS_VERSION);
|
||||||
|
@ -56,7 +57,7 @@ Pointer<git_worktree> lookup({
|
||||||
required String name,
|
required String name,
|
||||||
}) {
|
}) {
|
||||||
final out = calloc<Pointer<git_worktree>>();
|
final out = calloc<Pointer<git_worktree>>();
|
||||||
final nameC = name.toNativeUtf8().cast<Int8>();
|
final nameC = name.toChar();
|
||||||
final error = libgit2.git_worktree_lookup(out, repoPointer, nameC);
|
final error = libgit2.git_worktree_lookup(out, repoPointer, nameC);
|
||||||
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
|
@ -95,8 +96,16 @@ bool isPrunable(Pointer<git_worktree> wt) {
|
||||||
/// Prune working tree.
|
/// Prune working tree.
|
||||||
///
|
///
|
||||||
/// Prune the working tree, that is remove the git data structures on disk.
|
/// Prune the working tree, that is remove the git data structures on disk.
|
||||||
void prune(Pointer<git_worktree> wt) {
|
void prune({required Pointer<git_worktree> worktreePointer, int? flags}) {
|
||||||
libgit2.git_worktree_prune(wt, nullptr);
|
final opts = calloc<git_worktree_prune_options>();
|
||||||
|
libgit2.git_worktree_prune_options_init(
|
||||||
|
opts,
|
||||||
|
GIT_WORKTREE_PRUNE_OPTIONS_VERSION,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (flags != null) opts.ref.flags = flags;
|
||||||
|
|
||||||
|
libgit2.git_worktree_prune(worktreePointer, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List names of linked working trees.
|
/// List names of linked working trees.
|
||||||
|
@ -110,23 +119,24 @@ List<String> list(Pointer<git_repository> repo) {
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
throw LibGit2Error(libgit2.git_error_last());
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
} else {
|
} else {
|
||||||
final result = <String>[];
|
final result = <String>[
|
||||||
for (var i = 0; i < out.ref.count; i++) {
|
for (var i = 0; i < out.ref.count; i++) out.ref.strings[i].toDartString()
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
];
|
||||||
}
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the name of the worktree.
|
/// Retrieve the name of the worktree.
|
||||||
String name(Pointer<git_worktree> wt) {
|
String name(Pointer<git_worktree> wt) {
|
||||||
return libgit2.git_worktree_name(wt).cast<Utf8>().toDartString();
|
return libgit2.git_worktree_name(wt).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the filesystem path for the worktree.
|
/// Retrieve the filesystem path for the worktree.
|
||||||
String path(Pointer<git_worktree> wt) {
|
String path(Pointer<git_worktree> wt) {
|
||||||
return libgit2.git_worktree_path(wt).cast<Utf8>().toDartString();
|
return libgit2.git_worktree_path(wt).toDartString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if worktree is locked.
|
/// Check if worktree is locked.
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/blame.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/blame.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Blame with IterableMixin<BlameHunk> {
|
class Blame with IterableMixin<BlameHunk> {
|
||||||
/// Returns the blame for a single file.
|
/// Returns the blame for a single file.
|
||||||
|
@ -120,7 +122,8 @@ final _finalizer = Finalizer<Pointer<git_blame>>(
|
||||||
);
|
);
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
|
|
||||||
class BlameHunk {
|
@immutable
|
||||||
|
class BlameHunk extends Equatable {
|
||||||
/// Initializes a new instance of the [BlameHunk] class from
|
/// Initializes a new instance of the [BlameHunk] class from
|
||||||
/// provided pointer to blame hunk object in memory.
|
/// provided pointer to blame hunk object in memory.
|
||||||
const BlameHunk._(this._blameHunkPointer);
|
const BlameHunk._(this._blameHunkPointer);
|
||||||
|
@ -171,8 +174,7 @@ class BlameHunk {
|
||||||
|
|
||||||
/// Path to the file where this hunk originated, as of the commit specified by
|
/// Path to the file where this hunk originated, as of the commit specified by
|
||||||
/// [originCommitOid].
|
/// [originCommitOid].
|
||||||
String get originPath =>
|
String get originPath => _blameHunkPointer.ref.orig_path.toDartString();
|
||||||
_blameHunkPointer.ref.orig_path.cast<Utf8>().toDartString();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
|
@ -183,6 +185,19 @@ class BlameHunk {
|
||||||
'originCommitter: $originCommitter, originCommitOid: $originCommitOid, '
|
'originCommitter: $originCommitter, originCommitOid: $originCommitOid, '
|
||||||
'originPath: $originPath}';
|
'originPath: $originPath}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
linesCount,
|
||||||
|
isBoundary,
|
||||||
|
finalStartLineNumber,
|
||||||
|
finalCommitter,
|
||||||
|
finalCommitOid,
|
||||||
|
originStartLineNumber,
|
||||||
|
originCommitter,
|
||||||
|
originCommitOid,
|
||||||
|
originPath,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BlameIterator implements Iterator<BlameHunk> {
|
class _BlameIterator implements Iterator<BlameHunk> {
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/blob.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/blob.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Blob {
|
@immutable
|
||||||
|
class Blob extends Equatable {
|
||||||
/// Initializes a new instance of [Blob] class from provided pointer to
|
/// Initializes a new instance of [Blob] class from provided pointer to
|
||||||
/// blob object in memory.
|
/// blob object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Use [Blob.lookup] instead.
|
/// Note: For internal use. Use [Blob.lookup] instead.
|
||||||
|
@internal
|
||||||
Blob(this._blobPointer) {
|
Blob(this._blobPointer) {
|
||||||
_finalizer.attach(this, _blobPointer, detach: this);
|
_finalizer.attach(this, _blobPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +31,7 @@ class Blob {
|
||||||
/// Pointer to memory address for allocated blob object.
|
/// Pointer to memory address for allocated blob object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_blob> get pointer => _blobPointer;
|
Pointer<git_blob> get pointer => _blobPointer;
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@ -124,6 +129,9 @@ class Blob {
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Blob{oid: $oid, isBinary: $isBinary, size: $size}';
|
return 'Blob{oid: $oid, isBinary: $isBinary, size: $size}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/branch.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/branch.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/reference.dart' as reference_bindings;
|
import 'package:libgit2dart/src/bindings/reference.dart' as reference_bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Branch {
|
@immutable
|
||||||
|
class Branch extends Equatable {
|
||||||
/// Initializes a new instance of [Branch] class from provided pointer to
|
/// Initializes a new instance of [Branch] class from provided pointer to
|
||||||
/// branch object in memory.
|
/// branch object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Instead, use one of:
|
/// Note: For internal use. Instead, use one of:
|
||||||
/// - [Branch.create]
|
/// - [Branch.create]
|
||||||
/// - [Branch.lookup]
|
/// - [Branch.lookup]
|
||||||
|
@internal
|
||||||
Branch(this._branchPointer) {
|
Branch(this._branchPointer) {
|
||||||
_finalizer.attach(this, _branchPointer, detach: this);
|
_finalizer.attach(this, _branchPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -71,6 +75,7 @@ class Branch {
|
||||||
/// Pointer to memory address for allocated branch object.
|
/// Pointer to memory address for allocated branch object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_reference> get pointer => _branchPointer;
|
Pointer<git_reference> get pointer => _branchPointer;
|
||||||
|
|
||||||
/// Returns a list of branches that can be found in a [repo]sitory for
|
/// Returns a list of branches that can be found in a [repo]sitory for
|
||||||
|
@ -228,6 +233,9 @@ class Branch {
|
||||||
return 'Branch{name: $name, target: $target, isHead: $isHead, '
|
return 'Branch{name: $name, target: $target, isHead: $isHead, '
|
||||||
'isCheckedOut: $isCheckedOut}';
|
'isCheckedOut: $isCheckedOut}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [target, name];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/commit.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/commit.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/graph.dart' as graph_bindings;
|
import 'package:libgit2dart/src/bindings/graph.dart' as graph_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Commit {
|
@immutable
|
||||||
|
class Commit extends Equatable {
|
||||||
/// Initializes a new instance of [Commit] class from provided pointer to
|
/// Initializes a new instance of [Commit] class from provided pointer to
|
||||||
/// commit object in memory.
|
/// commit object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Use [Commit.lookup] instead.
|
/// Note: For internal use. Use [Commit.lookup] instead.
|
||||||
|
@internal
|
||||||
Commit(this._commitPointer) {
|
Commit(this._commitPointer) {
|
||||||
_finalizer.attach(this, _commitPointer, detach: this);
|
_finalizer.attach(this, _commitPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +32,7 @@ class Commit {
|
||||||
/// Pointer to memory address for allocated commit object.
|
/// Pointer to memory address for allocated commit object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_commit> get pointer => _commitPointer;
|
Pointer<git_commit> get pointer => _commitPointer;
|
||||||
|
|
||||||
/// Creates new commit in the [repo]sitory.
|
/// Creates new commit in the [repo]sitory.
|
||||||
|
@ -186,23 +191,64 @@ class Commit {
|
||||||
|
|
||||||
/// Reverts commit, producing changes in the index and working directory.
|
/// Reverts commit, producing changes in the index and working directory.
|
||||||
///
|
///
|
||||||
|
/// [mainline] is parent of the commit if it is a merge (i.e. 1, 2, etc.).
|
||||||
|
///
|
||||||
|
/// [mergeFavor] is one of the optional [GitMergeFileFavor] flags for
|
||||||
|
/// handling conflicting content.
|
||||||
|
///
|
||||||
|
/// [mergeFlags] is optional combination of [GitMergeFlag] flags.
|
||||||
|
///
|
||||||
|
/// [mergeFileFlags] is optional combination of [GitMergeFileFlag] flags.
|
||||||
|
///
|
||||||
|
/// [checkoutStrategy] is optional combination of [GitCheckout] flags.
|
||||||
|
///
|
||||||
|
/// [checkoutDirectory] is optional alternative checkout path to workdir.
|
||||||
|
///
|
||||||
|
/// [checkoutPaths] is optional list of files to checkout (by default all
|
||||||
|
/// paths are processed).
|
||||||
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void revert() {
|
void revert({
|
||||||
|
int mainline = 0,
|
||||||
|
GitMergeFileFavor? mergeFavor,
|
||||||
|
Set<GitMergeFlag>? mergeFlags,
|
||||||
|
Set<GitMergeFileFlag>? mergeFileFlags,
|
||||||
|
Set<GitCheckout>? checkoutStrategy,
|
||||||
|
String? checkoutDirectory,
|
||||||
|
List<String>? checkoutPaths,
|
||||||
|
}) {
|
||||||
bindings.revert(
|
bindings.revert(
|
||||||
repoPointer: bindings.owner(_commitPointer),
|
repoPointer: bindings.owner(_commitPointer),
|
||||||
commitPointer: _commitPointer,
|
commitPointer: _commitPointer,
|
||||||
|
mainline: mainline,
|
||||||
|
mergeFavor: mergeFavor?.value,
|
||||||
|
mergeFlags: mergeFlags?.fold(0, (acc, e) => acc! | e.value),
|
||||||
|
mergeFileFlags: mergeFileFlags?.fold(0, (acc, e) => acc! | e.value),
|
||||||
|
checkoutStrategy: checkoutStrategy?.fold(0, (acc, e) => acc! | e.value),
|
||||||
|
checkoutDirectory: checkoutDirectory,
|
||||||
|
checkoutPaths: checkoutPaths,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reverts commit against provided [commit], producing an index that
|
/// Reverts commit against provided [commit], producing an index that
|
||||||
/// reflects the result of the revert.
|
/// reflects the result of the revert.
|
||||||
///
|
///
|
||||||
/// [mainline] is parent of the commit if it is a merge (i.e. 1, 2).
|
/// [mainline] is parent of the commit if it is a merge (i.e. 1, 2, etc.).
|
||||||
|
///
|
||||||
|
/// [mergeFavor] is one of the optional [GitMergeFileFavor] flags for
|
||||||
|
/// handling conflicting content.
|
||||||
|
///
|
||||||
|
/// [mergeFlags] is optional combination of [GitMergeFlag] flags.
|
||||||
|
///
|
||||||
|
/// [mergeFileFlags] is optional combination of [GitMergeFileFlag] flags.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Index revertTo({
|
Index revertTo({
|
||||||
required Commit commit,
|
required Commit commit,
|
||||||
int mainline = 0,
|
int mainline = 0,
|
||||||
|
GitMergeFileFavor? mergeFavor,
|
||||||
|
Set<GitMergeFlag>? mergeFlags,
|
||||||
|
Set<GitMergeFileFlag>? mergeFileFlags,
|
||||||
}) {
|
}) {
|
||||||
return Index(
|
return Index(
|
||||||
bindings.revertCommit(
|
bindings.revertCommit(
|
||||||
|
@ -210,6 +256,9 @@ class Commit {
|
||||||
revertCommitPointer: _commitPointer,
|
revertCommitPointer: _commitPointer,
|
||||||
ourCommitPointer: commit.pointer,
|
ourCommitPointer: commit.pointer,
|
||||||
mainline: mainline,
|
mainline: mainline,
|
||||||
|
mergeFavor: mergeFavor?.value,
|
||||||
|
mergeFlags: mergeFlags?.fold(0, (acc, e) => acc! | e.value),
|
||||||
|
mergeFileFlags: mergeFileFlags?.fold(0, (acc, e) => acc! | e.value),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -261,18 +310,11 @@ class Commit {
|
||||||
|
|
||||||
/// List of parent commits [Oid]s.
|
/// List of parent commits [Oid]s.
|
||||||
List<Oid> get parents {
|
List<Oid> get parents {
|
||||||
final parents = <Oid>[];
|
|
||||||
final parentCount = bindings.parentCount(_commitPointer);
|
final parentCount = bindings.parentCount(_commitPointer);
|
||||||
|
return <Oid>[
|
||||||
for (var i = 0; i < parentCount; i++) {
|
for (var i = 0; i < parentCount; i++)
|
||||||
final parentOid = bindings.parentId(
|
Oid(bindings.parentId(commitPointer: _commitPointer, position: i))
|
||||||
commitPointer: _commitPointer,
|
];
|
||||||
position: i,
|
|
||||||
);
|
|
||||||
parents.add(Oid(parentOid));
|
|
||||||
}
|
|
||||||
|
|
||||||
return parents;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the specified parent of the commit at provided 0-based [position].
|
/// Returns the specified parent of the commit at provided 0-based [position].
|
||||||
|
@ -338,6 +380,9 @@ class Commit {
|
||||||
'messageEncoding: $messageEncoding, time: $time, committer: $committer,'
|
'messageEncoding: $messageEncoding, time: $time, committer: $committer,'
|
||||||
' author: $author}';
|
' author: $author}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -2,11 +2,14 @@ import 'dart:collection';
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/config.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/config.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Config with IterableMixin<ConfigEntry> {
|
class Config with IterableMixin<ConfigEntry> {
|
||||||
/// Initializes a new instance of [Config] class from provided
|
/// Initializes a new instance of [Config] class from provided
|
||||||
|
@ -17,6 +20,7 @@ class Config with IterableMixin<ConfigEntry> {
|
||||||
/// - [Config.system]
|
/// - [Config.system]
|
||||||
/// - [Config.global]
|
/// - [Config.global]
|
||||||
/// - [Config.xdg]
|
/// - [Config.xdg]
|
||||||
|
@internal
|
||||||
Config(this._configPointer) {
|
Config(this._configPointer) {
|
||||||
_finalizer.attach(this, _configPointer, detach: this);
|
_finalizer.attach(this, _configPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -96,8 +100,8 @@ class Config with IterableMixin<ConfigEntry> {
|
||||||
configPointer: _configPointer,
|
configPointer: _configPointer,
|
||||||
variable: variable,
|
variable: variable,
|
||||||
);
|
);
|
||||||
final name = entryPointer.ref.name.cast<Utf8>().toDartString();
|
final name = entryPointer.ref.name.toDartString();
|
||||||
final value = entryPointer.ref.value.cast<Utf8>().toDartString();
|
final value = entryPointer.ref.value.toDartString();
|
||||||
final includeDepth = entryPointer.ref.include_depth;
|
final includeDepth = entryPointer.ref.include_depth;
|
||||||
final level = GitConfigLevel.values.firstWhere(
|
final level = GitConfigLevel.values.firstWhere(
|
||||||
(e) => entryPointer.ref.level == e.value,
|
(e) => entryPointer.ref.level == e.value,
|
||||||
|
@ -209,8 +213,9 @@ final _finalizer = Finalizer<Pointer<git_config>>(
|
||||||
);
|
);
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
|
|
||||||
class ConfigEntry {
|
@immutable
|
||||||
ConfigEntry._({
|
class ConfigEntry extends Equatable {
|
||||||
|
const ConfigEntry._({
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.value,
|
required this.value,
|
||||||
required this.includeDepth,
|
required this.includeDepth,
|
||||||
|
@ -234,6 +239,9 @@ class ConfigEntry {
|
||||||
return 'ConfigEntry{name: $name, value: $value, '
|
return 'ConfigEntry{name: $name, value: $value, '
|
||||||
'includeDepth: $includeDepth, level: $level}';
|
'includeDepth: $includeDepth, level: $level}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [name, value, includeDepth, level];
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ConfigIterator implements Iterator<ConfigEntry> {
|
class _ConfigIterator implements Iterator<ConfigEntry> {
|
||||||
|
@ -258,8 +266,8 @@ class _ConfigIterator implements Iterator<ConfigEntry> {
|
||||||
} else {
|
} else {
|
||||||
error = libgit2.git_config_next(entry, _iteratorPointer);
|
error = libgit2.git_config_next(entry, _iteratorPointer);
|
||||||
if (error != -31) {
|
if (error != -31) {
|
||||||
final name = entry.value.ref.name.cast<Utf8>().toDartString();
|
final name = entry.value.ref.name.toDartString();
|
||||||
final value = entry.value.ref.value.cast<Utf8>().toDartString();
|
final value = entry.value.ref.value.toDartString();
|
||||||
final includeDepth = entry.value.ref.include_depth;
|
final includeDepth = entry.value.ref.include_depth;
|
||||||
final level = GitConfigLevel.values.firstWhere(
|
final level = GitConfigLevel.values.firstWhere(
|
||||||
(e) => entry.value.ref.level == e.value,
|
(e) => entry.value.ref.level == e.value,
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/diff.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/diff.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Diff {
|
@immutable
|
||||||
|
class Diff extends Equatable {
|
||||||
/// Initializes a new instance of [Diff] class from provided
|
/// Initializes a new instance of [Diff] class from provided
|
||||||
/// pointer to diff object in memory.
|
/// pointer to diff object in memory.
|
||||||
///
|
///
|
||||||
|
@ -18,6 +21,7 @@ class Diff {
|
||||||
/// - [Diff.treeToWorkdirWithIndex]
|
/// - [Diff.treeToWorkdirWithIndex]
|
||||||
/// - [Diff.treeToTree]
|
/// - [Diff.treeToTree]
|
||||||
/// - [Diff.parse]
|
/// - [Diff.parse]
|
||||||
|
@internal
|
||||||
Diff(this._diffPointer) {
|
Diff(this._diffPointer) {
|
||||||
_finalizer.attach(this, _diffPointer, detach: this);
|
_finalizer.attach(this, _diffPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -273,6 +277,7 @@ class Diff {
|
||||||
/// Pointer to memory address for allocated diff object.
|
/// Pointer to memory address for allocated diff object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_diff> get pointer => _diffPointer;
|
Pointer<git_diff> get pointer => _diffPointer;
|
||||||
|
|
||||||
/// How many diff records are there in a diff.
|
/// How many diff records are there in a diff.
|
||||||
|
@ -282,28 +287,18 @@ class Diff {
|
||||||
/// revisions.
|
/// revisions.
|
||||||
List<DiffDelta> get deltas {
|
List<DiffDelta> get deltas {
|
||||||
final length = bindings.length(_diffPointer);
|
final length = bindings.length(_diffPointer);
|
||||||
final deltas = <DiffDelta>[];
|
return <DiffDelta>[
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++)
|
||||||
deltas.add(
|
DiffDelta(bindings.getDeltaByIndex(diffPointer: _diffPointer, index: i))
|
||||||
DiffDelta(
|
];
|
||||||
bindings.getDeltaByIndex(
|
|
||||||
diffPointer: _diffPointer,
|
|
||||||
index: i,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return deltas;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A List of [Patch]es.
|
/// A List of [Patch]es.
|
||||||
List<Patch> get patches {
|
List<Patch> get patches {
|
||||||
final length = bindings.length(_diffPointer);
|
final length = bindings.length(_diffPointer);
|
||||||
final patches = <Patch>[];
|
return <Patch>[
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) Patch.fromDiff(diff: this, index: i)
|
||||||
patches.add(Patch.fromDiff(diff: this, index: i));
|
];
|
||||||
}
|
|
||||||
return patches;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The patch diff text.
|
/// The patch diff text.
|
||||||
|
@ -461,8 +456,11 @@ class Diff {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Diff{length: $length}';
|
return 'Diff{length: $length, patchOid: $patchOid}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [patchOid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
@ -471,9 +469,13 @@ final _finalizer = Finalizer<Pointer<git_diff>>(
|
||||||
);
|
);
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
|
|
||||||
class DiffDelta {
|
@immutable
|
||||||
|
class DiffDelta extends Equatable {
|
||||||
/// Initializes a new instance of [DiffDelta] class from provided
|
/// Initializes a new instance of [DiffDelta] class from provided
|
||||||
/// pointer to diff delta object in memory.
|
/// pointer to diff delta object in memory.
|
||||||
|
///
|
||||||
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
const DiffDelta(this._diffDeltaPointer);
|
const DiffDelta(this._diffDeltaPointer);
|
||||||
|
|
||||||
/// Pointer to memory address for allocated diff delta object.
|
/// Pointer to memory address for allocated diff delta object.
|
||||||
|
@ -519,6 +521,16 @@ class DiffDelta {
|
||||||
return 'DiffDelta{status: $status, flags: $flags, similarity: $similarity, '
|
return 'DiffDelta{status: $status, flags: $flags, similarity: $similarity, '
|
||||||
'numberOfFiles: $numberOfFiles, oldFile: $oldFile, newFile: $newFile}';
|
'numberOfFiles: $numberOfFiles, oldFile: $oldFile, newFile: $newFile}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
status,
|
||||||
|
flags,
|
||||||
|
similarity,
|
||||||
|
numberOfFiles,
|
||||||
|
oldFile,
|
||||||
|
newFile,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Description of one side of a delta.
|
/// Description of one side of a delta.
|
||||||
|
@ -526,7 +538,8 @@ class DiffDelta {
|
||||||
/// Although this is called a "file", it could represent a file, a symbolic
|
/// Although this is called a "file", it could represent a file, a symbolic
|
||||||
/// link, a submodule commit id, or even a tree (although that only if you
|
/// link, a submodule commit id, or even a tree (although that only if you
|
||||||
/// are tracking type changes or ignored/untracked directories).
|
/// are tracking type changes or ignored/untracked directories).
|
||||||
class DiffFile {
|
@immutable
|
||||||
|
class DiffFile extends Equatable {
|
||||||
/// Initializes a new instance of [DiffFile] class from provided diff file
|
/// Initializes a new instance of [DiffFile] class from provided diff file
|
||||||
/// object.
|
/// object.
|
||||||
const DiffFile._(this._diffFile);
|
const DiffFile._(this._diffFile);
|
||||||
|
@ -538,7 +551,7 @@ class DiffFile {
|
||||||
Oid get oid => Oid.fromRaw(_diffFile.id);
|
Oid get oid => Oid.fromRaw(_diffFile.id);
|
||||||
|
|
||||||
/// Path to the entry relative to the working directory of the repository.
|
/// Path to the entry relative to the working directory of the repository.
|
||||||
String get path => _diffFile.path.cast<Utf8>().toDartString();
|
String get path => _diffFile.path.toDartString();
|
||||||
|
|
||||||
/// Size of the entry in bytes.
|
/// Size of the entry in bytes.
|
||||||
int get size => _diffFile.size;
|
int get size => _diffFile.size;
|
||||||
|
@ -560,6 +573,9 @@ class DiffFile {
|
||||||
return 'DiffFile{oid: $oid, path: $path, size: $size, flags: $flags, '
|
return 'DiffFile{oid: $oid, path: $path, size: $size, flags: $flags, '
|
||||||
'mode: $mode}';
|
'mode: $mode}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid, path, size, flags, mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiffStats {
|
class DiffStats {
|
||||||
|
@ -567,6 +583,7 @@ class DiffStats {
|
||||||
/// pointer to diff stats object in memory.
|
/// pointer to diff stats object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
DiffStats(this._diffStatsPointer) {
|
DiffStats(this._diffStatsPointer) {
|
||||||
_statsFinalizer.attach(this, _diffStatsPointer, detach: this);
|
_statsFinalizer.attach(this, _diffStatsPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
// coverage:ignore-file
|
// coverage:ignore-file
|
||||||
|
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
/// Details of the last error that occurred.
|
/// Details of the last error that occurred.
|
||||||
class LibGit2Error {
|
class LibGit2Error {
|
||||||
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
LibGit2Error(this._errorPointer);
|
LibGit2Error(this._errorPointer);
|
||||||
|
|
||||||
final Pointer<git_error> _errorPointer;
|
final Pointer<git_error> _errorPointer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() => _errorPointer.ref.message.toDartString();
|
||||||
return _errorPointer.ref.message.cast<Utf8>().toDartString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
36
lib/src/extensions.dart
Normal file
36
lib/src/extensions.dart
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// coverage:ignore-file
|
||||||
|
|
||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:ffi/ffi.dart';
|
||||||
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
|
||||||
|
extension IsValidSHA on String {
|
||||||
|
bool isValidSHA() {
|
||||||
|
final hexRegExp = RegExp(r'^[0-9a-fA-F]+$');
|
||||||
|
return hexRegExp.hasMatch(this) &&
|
||||||
|
(GIT_OID_MINPREFIXLEN <= length && GIT_OID_HEXSZ >= length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ToChar on String {
|
||||||
|
/// Creates a zero-terminated [Utf8] code-unit array from this String,
|
||||||
|
/// casts it to the C `char` type and returns allocated pointer to result.
|
||||||
|
Pointer<Char> toChar() => toNativeUtf8().cast<Char>();
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ToDartString on Pointer<Char> {
|
||||||
|
/// Converts this UTF-8 encoded string to a Dart string.
|
||||||
|
///
|
||||||
|
/// Decodes the UTF-8 code units of this zero-terminated byte array as
|
||||||
|
/// Unicode code points and creates a Dart string containing those code
|
||||||
|
/// points.
|
||||||
|
///
|
||||||
|
/// If [length] is provided, zero-termination is ignored and the result can
|
||||||
|
/// contain NUL characters.
|
||||||
|
///
|
||||||
|
/// If [length] is not provided, the returned string is the string up til but
|
||||||
|
/// not including the first NUL character.
|
||||||
|
String toDartString({int? length}) =>
|
||||||
|
cast<Utf8>().toDartString(length: length);
|
||||||
|
}
|
|
@ -1173,3 +1173,37 @@ enum GitBlobFilter {
|
||||||
const GitBlobFilter(this.value);
|
const GitBlobFilter(this.value);
|
||||||
final int value;
|
final int value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Flags for APIs that add files matching pathspec.
|
||||||
|
enum GitIndexAddOption {
|
||||||
|
defaults(0),
|
||||||
|
|
||||||
|
/// Skip the checking of ignore rules.
|
||||||
|
force(1),
|
||||||
|
|
||||||
|
/// Disable glob expansion and force exact matching of files in working
|
||||||
|
/// directory.
|
||||||
|
disablePathspecMatch(2),
|
||||||
|
|
||||||
|
/// Check that each entry in the pathspec is an exact match to a filename on
|
||||||
|
/// disk is either not ignored or already in the index.
|
||||||
|
checkPathspec(4);
|
||||||
|
|
||||||
|
const GitIndexAddOption(this.value);
|
||||||
|
final int value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Flags to alter working tree pruning behavior.
|
||||||
|
enum GitWorktree {
|
||||||
|
/// Prune working tree even if working tree is valid.
|
||||||
|
pruneValid(1),
|
||||||
|
|
||||||
|
/// Prune working tree even if it is locked.
|
||||||
|
pruneLocked(2),
|
||||||
|
|
||||||
|
/// Prune checked out working tree.
|
||||||
|
pruneWorkingTree(4);
|
||||||
|
|
||||||
|
const GitWorktree(this.value);
|
||||||
|
final int value;
|
||||||
|
}
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/index.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/index.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Index with IterableMixin<IndexEntry> {
|
class Index with IterableMixin<IndexEntry> {
|
||||||
/// Initializes a new instance of [Index] class from provided
|
/// Initializes a new instance of [Index] class from provided
|
||||||
/// pointer to index object in memory.
|
/// pointer to index object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Index(this._indexPointer) {
|
Index(this._indexPointer) {
|
||||||
_finalizer.attach(this, _indexPointer, detach: this);
|
_finalizer.attach(this, _indexPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +32,7 @@ class Index with IterableMixin<IndexEntry> {
|
||||||
/// Pointer to memory address for allocated index object.
|
/// Pointer to memory address for allocated index object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_index> get pointer => _indexPointer;
|
Pointer<git_index> get pointer => _indexPointer;
|
||||||
|
|
||||||
/// Full path to the index file on disk.
|
/// Full path to the index file on disk.
|
||||||
|
@ -213,9 +217,18 @@ class Index with IterableMixin<IndexEntry> {
|
||||||
/// that matches will be added to the index (either updating an existing
|
/// that matches will be added to the index (either updating an existing
|
||||||
/// entry or adding a new entry).
|
/// entry or adding a new entry).
|
||||||
///
|
///
|
||||||
|
/// [flags] is optional combination of [GitIndexAddOption] flags.
|
||||||
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void addAll(List<String> pathspec) {
|
void addAll(
|
||||||
bindings.addAll(indexPointer: _indexPointer, pathspec: pathspec);
|
List<String> pathspec, {
|
||||||
|
Set<GitIndexAddOption> flags = const {GitIndexAddOption.defaults},
|
||||||
|
}) {
|
||||||
|
bindings.addAll(
|
||||||
|
indexPointer: _indexPointer,
|
||||||
|
pathspec: pathspec,
|
||||||
|
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates all index entries to match the working directory.
|
/// Updates all index entries to match the working directory.
|
||||||
|
@ -323,10 +336,12 @@ final _finalizer = Finalizer<Pointer<git_index>>(
|
||||||
);
|
);
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
|
|
||||||
class IndexEntry {
|
@immutable
|
||||||
|
class IndexEntry extends Equatable {
|
||||||
/// Initializes a new instance of [IndexEntry] class.
|
/// Initializes a new instance of [IndexEntry] class.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
const IndexEntry(this._indexEntryPointer);
|
const IndexEntry(this._indexEntryPointer);
|
||||||
|
|
||||||
final Pointer<git_index_entry> _indexEntryPointer;
|
final Pointer<git_index_entry> _indexEntryPointer;
|
||||||
|
@ -334,6 +349,7 @@ class IndexEntry {
|
||||||
/// Pointer to memory address for allocated index entry object.
|
/// Pointer to memory address for allocated index entry object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_index_entry> get pointer => _indexEntryPointer;
|
Pointer<git_index_entry> get pointer => _indexEntryPointer;
|
||||||
|
|
||||||
/// [Oid] of the index entry.
|
/// [Oid] of the index entry.
|
||||||
|
@ -342,10 +358,9 @@ class IndexEntry {
|
||||||
set oid(Oid oid) => _indexEntryPointer.ref.id = oid.pointer.ref;
|
set oid(Oid oid) => _indexEntryPointer.ref.id = oid.pointer.ref;
|
||||||
|
|
||||||
/// Path of the index entry.
|
/// Path of the index entry.
|
||||||
String get path => _indexEntryPointer.ref.path.cast<Utf8>().toDartString();
|
String get path => _indexEntryPointer.ref.path.toDartString();
|
||||||
|
|
||||||
set path(String path) =>
|
set path(String path) => _indexEntryPointer.ref.path = path.toChar();
|
||||||
_indexEntryPointer.ref.path = path.toNativeUtf8().cast<Int8>();
|
|
||||||
|
|
||||||
/// UNIX file attributes of a index entry.
|
/// UNIX file attributes of a index entry.
|
||||||
GitFilemode get mode {
|
GitFilemode get mode {
|
||||||
|
@ -367,12 +382,16 @@ class IndexEntry {
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'IndexEntry{oid: $oid, path: $path, mode: $mode, stage: $stage}';
|
return 'IndexEntry{oid: $oid, path: $path, mode: $mode, stage: $stage}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid, path, mode, stage];
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConflictEntry {
|
class ConflictEntry {
|
||||||
/// Initializes a new instance of [ConflictEntry] class.
|
/// Initializes a new instance of [ConflictEntry] class.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
const ConflictEntry(
|
const ConflictEntry(
|
||||||
this._indexPointer,
|
this._indexPointer,
|
||||||
this._path,
|
this._path,
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
|
||||||
class Libgit2 {
|
class Libgit2 {
|
||||||
|
@ -12,9 +13,9 @@ class Libgit2 {
|
||||||
static String get version {
|
static String get version {
|
||||||
libgit2.git_libgit2_init();
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
final major = calloc<Int32>();
|
final major = calloc<Int>();
|
||||||
final minor = calloc<Int32>();
|
final minor = calloc<Int>();
|
||||||
final rev = calloc<Int32>();
|
final rev = calloc<Int>();
|
||||||
libgit2.git_libgit2_version(major, minor, rev);
|
libgit2.git_libgit2_version(major, minor, rev);
|
||||||
|
|
||||||
final version = '${major.value}.${minor.value}.${rev.value}';
|
final version = '${major.value}.${minor.value}.${rev.value}';
|
||||||
|
@ -35,28 +36,509 @@ class Libgit2 {
|
||||||
.toSet();
|
.toSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Maximum mmap window size.
|
||||||
|
static int get mmapWindowSize {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final out = calloc<Int>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_mwindow_size(out);
|
||||||
|
final result = out.value;
|
||||||
|
calloc.free(out);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static set mmapWindowSize(int value) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_set_mwindow_size(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maximum memory that will be mapped in total by the library.
|
||||||
|
///
|
||||||
|
/// The default (0) is unlimited.
|
||||||
|
static int get mmapWindowMappedLimit {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final out = calloc<Int>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_mwindow_mapped_limit(out);
|
||||||
|
final result = out.value;
|
||||||
|
calloc.free(out);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static set mmapWindowMappedLimit(int value) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_set_mwindow_mapped_limit(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maximum number of files that will be mapped at any time by the library.
|
||||||
|
///
|
||||||
|
/// The default (0) is unlimited.
|
||||||
|
static int get mmapWindowFileLimit {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final out = calloc<Int>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_mwindow_file_limit(out);
|
||||||
|
final result = out.value;
|
||||||
|
calloc.free(out);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static set mmapWindowFileLimit(int value) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_set_mwindow_file_limit(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns search path for a given [level] of config data.
|
||||||
|
///
|
||||||
|
/// [level] must be one of:
|
||||||
|
/// - [GitConfigLevel.system]
|
||||||
|
/// - [GitConfigLevel.global]
|
||||||
|
/// - [GitConfigLevel.xdg]
|
||||||
|
/// - [GitConfigLevel.programData]
|
||||||
|
static String getConfigSearchPath(GitConfigLevel level) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final out = calloc<git_buf>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_search_path(level.value, out);
|
||||||
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
|
libgit2.git_buf_dispose(out);
|
||||||
|
calloc.free(out);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the search path for a [level] of config data. The search path
|
||||||
|
/// applied to shared attributes and ignore files.
|
||||||
|
///
|
||||||
|
/// [path] lists directories delimited by `:`.
|
||||||
|
/// Pass null to reset to the default (generally based on environment
|
||||||
|
/// variables). Use magic path `$PATH` to include the old value of the path
|
||||||
|
/// (if you want to prepend or append, for instance).
|
||||||
|
///
|
||||||
|
/// [level] must be one of:
|
||||||
|
/// - [GitConfigLevel.system]
|
||||||
|
/// - [GitConfigLevel.global]
|
||||||
|
/// - [GitConfigLevel.xdg]
|
||||||
|
/// - [GitConfigLevel.programData]
|
||||||
|
static void setConfigSearchPath({
|
||||||
|
required GitConfigLevel level,
|
||||||
|
required String? path,
|
||||||
|
}) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final pathC = path?.toChar() ?? nullptr;
|
||||||
|
libgit2Opts.git_libgit2_opts_set_search_path(level.value, pathC);
|
||||||
|
calloc.free(pathC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the maximum data size for the given [type] of object to be
|
||||||
|
/// considered eligible for caching in memory. Setting the [value] to
|
||||||
|
/// zero means that that type of object will not be cached.
|
||||||
|
///
|
||||||
|
/// Defaults to 0 for [GitObject.blob] (i.e. won't cache blobs) and 4k
|
||||||
|
/// for [GitObject.commit], [GitObject.tree] and [GitObject.tag].
|
||||||
|
static void setCacheObjectLimit({
|
||||||
|
required GitObject type,
|
||||||
|
required int value,
|
||||||
|
}) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_set_cache_object_limit(type.value, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the maximum total data size that will be cached in memory
|
||||||
|
/// across all repositories before libgit2 starts evicting objects
|
||||||
|
/// from the cache. This is a soft limit, in that the library might
|
||||||
|
/// briefly exceed it, but will start aggressively evicting objects
|
||||||
|
/// from cache when that happens.
|
||||||
|
///
|
||||||
|
/// The default cache size is 256MB.
|
||||||
|
static void setCacheMaxSize(int bytes) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_set_cache_max_size(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [CachedMemory] object containing current bytes in cache and the maximum
|
||||||
|
/// that would be allowed in the cache.
|
||||||
|
static CachedMemory get cachedMemory {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final current = calloc<Int>();
|
||||||
|
final allowed = calloc<Int>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_cached_memory(current, allowed);
|
||||||
|
|
||||||
|
final result = CachedMemory._(
|
||||||
|
current: current.value,
|
||||||
|
allowed: allowed.value,
|
||||||
|
);
|
||||||
|
|
||||||
|
calloc.free(current);
|
||||||
|
calloc.free(allowed);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enables caching.
|
||||||
|
static void enableCaching() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_caching(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disables caching completely.
|
||||||
|
///
|
||||||
|
/// Because caches are repository-specific, disabling the cache
|
||||||
|
/// cannot immediately clear all cached objects, but each cache will
|
||||||
|
/// be cleared on the next attempt to update anything in it.
|
||||||
|
static void disableCaching() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_caching(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Default template path.
|
||||||
|
static String get templatePath {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final out = calloc<git_buf>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_template_path(out);
|
||||||
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
|
libgit2.git_buf_dispose(out);
|
||||||
|
calloc.free(out);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static set templatePath(String path) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final pathC = path.toChar();
|
||||||
|
libgit2Opts.git_libgit2_opts_set_template_path(pathC);
|
||||||
|
|
||||||
|
calloc.free(pathC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the SSL certificate-authority locations.
|
||||||
|
///
|
||||||
|
/// - [file] is the location of a file containing several
|
||||||
|
/// certificates concatenated together.
|
||||||
|
/// - [path] is the location of a directory holding several
|
||||||
|
/// certificates, one per file.
|
||||||
|
///
|
||||||
|
/// Either parameter may be null, but not both.
|
||||||
|
///
|
||||||
|
/// Throws [ArgumentError] if both arguments are null.
|
||||||
|
static void setSSLCertLocations({String? file, String? path}) {
|
||||||
|
if (file == null && path == null) {
|
||||||
|
throw ArgumentError("Both file and path can't be null");
|
||||||
|
} else {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final fileC = file?.toChar() ?? nullptr;
|
||||||
|
final pathC = path?.toChar() ?? nullptr;
|
||||||
|
|
||||||
|
libgit2Opts.git_libgit2_opts_set_ssl_cert_locations(fileC, pathC);
|
||||||
|
|
||||||
|
calloc.free(fileC);
|
||||||
|
calloc.free(pathC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Value of the User-Agent header.
|
||||||
|
///
|
||||||
|
/// This value will be appended to "git/1.0", for compatibility with other
|
||||||
|
/// git clients.
|
||||||
|
static String get userAgent {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final out = calloc<git_buf>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_user_agent(out);
|
||||||
|
final result = out.ref.ptr.toDartString(length: out.ref.size);
|
||||||
|
|
||||||
|
libgit2.git_buf_dispose(out);
|
||||||
|
calloc.free(out);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static set userAgent(String userAgent) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final userAgentC = userAgent.toChar();
|
||||||
|
libgit2Opts.git_libgit2_opts_set_user_agent(userAgentC);
|
||||||
|
|
||||||
|
calloc.free(userAgentC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enables strict input validation when creating new objects
|
||||||
|
/// to ensure that all inputs to the new objects are valid.
|
||||||
|
///
|
||||||
|
/// For example, when this is enabled, the parent(s) and tree inputs
|
||||||
|
/// will be validated when creating a new commit.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void enableStrictObjectCreation() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_strict_object_creation(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disables strict input validation when creating new objects.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void disableStrictObjectCreation() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_strict_object_creation(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enables validation of a symbolic ref target when creating it.
|
||||||
|
///
|
||||||
|
/// For example, `foobar` is not a valid ref, therefore `foobar` is
|
||||||
|
/// not a valid target for a symbolic ref by default, whereas
|
||||||
|
/// `refs/heads/foobar` is.
|
||||||
|
///
|
||||||
|
/// Disabling this bypasses validation so that an arbitrary strings
|
||||||
|
/// such as `foobar` can be used for a symbolic ref target.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void enableStrictSymbolicRefCreation() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_strict_symbolic_ref_creation(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disables validation of a symbolic ref target when creating it.
|
||||||
|
///
|
||||||
|
/// For example, `foobar` is not a valid ref, therefore `foobar` is
|
||||||
|
/// not a valid target for a symbolic ref by default, whereas
|
||||||
|
/// `refs/heads/foobar` is.
|
||||||
|
///
|
||||||
|
/// Disabling this bypasses validation so that an arbitrary strings
|
||||||
|
/// such as `foobar` can be used for a symbolic ref target.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void disableStrictSymbolicRefCreation() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_strict_symbolic_ref_creation(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enables the use of "offset deltas" when creating packfiles,
|
||||||
|
/// and the negotiation of them when talking to a remote server.
|
||||||
|
///
|
||||||
|
/// Offset deltas store a delta base location as an offset into the
|
||||||
|
/// packfile from the current location, which provides a shorter encoding
|
||||||
|
/// and thus smaller resultant packfiles.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void enableOffsetDelta() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_offset_delta(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disables the use of "offset deltas" when creating packfiles,
|
||||||
|
/// and the negotiation of them when talking to a remote server.
|
||||||
|
///
|
||||||
|
/// Offset deltas store a delta base location as an offset into the
|
||||||
|
/// packfile from the current location, which provides a shorter encoding
|
||||||
|
/// and thus smaller resultant packfiles.
|
||||||
|
///
|
||||||
|
/// Packfiles containing offset deltas can still be read.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void disableOffsetDelta() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_offset_delta(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enables synchronized writes of files in the gitdir using `fsync`
|
||||||
|
/// (or the platform equivalent) to ensure that new object data
|
||||||
|
/// is written to permanent storage, not simply cached.
|
||||||
|
///
|
||||||
|
/// Disabled by default.
|
||||||
|
static void enableFsyncGitdir() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_fsync_gitdir(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disables synchronized writes of files in the gitdir using `fsync`
|
||||||
|
/// (or the platform equivalent).
|
||||||
|
///
|
||||||
|
/// Disabled by default.
|
||||||
|
static void disableFsyncGitdir() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_fsync_gitdir(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enables strict verification of object hashsums when reading objects from
|
||||||
|
/// disk.
|
||||||
|
///
|
||||||
|
/// This may impact performance due to an additional checksum calculation
|
||||||
|
/// on each object.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void enableStrictHashVerification() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_strict_hash_verification(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disables strict verification of object hashsums when reading objects from
|
||||||
|
/// disk.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void disableStrictHashVerification() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_strict_hash_verification(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enables check for unsaved changes in the index before beginning any
|
||||||
|
/// operation that reloads the index from disk (e.g., checkout).
|
||||||
|
///
|
||||||
|
/// If there are unsaved changes, the instruction will fail (using
|
||||||
|
/// the FORCE flag to checkout will still overwrite these changes).
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void enableUnsavedIndexSafety() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_unsaved_index_safety(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disables check for unsaved changes in the index before beginning any
|
||||||
|
/// operation that reloads the index from disk (e.g., checkout).
|
||||||
|
///
|
||||||
|
/// If there are unsaved changes, the instruction will fail (using
|
||||||
|
/// the FORCE flag to checkout will still overwrite these changes).
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
|
static void disableUnsavedIndexSafety() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_unsaved_index_safety(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maximum number of objects libgit2 will allow in a pack file when
|
||||||
|
/// downloading a pack file from a remote. This can be used to limit maximum
|
||||||
|
/// memory usage when fetching from an untrusted remote.
|
||||||
|
static int get packMaxObjects {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final out = calloc<Int>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_pack_max_objects(out);
|
||||||
|
final result = out.value;
|
||||||
|
calloc.free(out);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static set packMaxObjects(int value) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_set_pack_max_objects(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enables checks of .keep file existence to be skipped when accessing
|
||||||
|
/// packfiles.
|
||||||
|
static void enablePackKeepFileChecks() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_disable_pack_keep_file_checks(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disables checks of .keep file existence to be skipped when accessing
|
||||||
|
/// packfiles, which can help performance with remote filesystems.
|
||||||
|
static void disablePackKeepFileChecks() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_disable_pack_keep_file_checks(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When connecting to a server using NTLM or Negotiate
|
||||||
|
/// authentication, use expect/continue when POSTing data.
|
||||||
|
///
|
||||||
|
/// This option is not available on Windows.
|
||||||
|
static void enableHttpExpectContinue() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_http_expect_continue(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When connecting to a server using NTLM or Negotiate
|
||||||
|
/// authentication, don't use expect/continue when POSTing data.
|
||||||
|
///
|
||||||
|
/// This option is not available on Windows.
|
||||||
|
static void disableHttpExpectContinue() {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
libgit2Opts.git_libgit2_opts_enable_http_expect_continue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List of git extensions that are supported.
|
||||||
|
///
|
||||||
|
/// This is the list of built-in extensions supported by libgit2 and
|
||||||
|
/// custom extensions that have been added.
|
||||||
|
///
|
||||||
|
/// Extensions supported by libgit2 may be negated by prefixing
|
||||||
|
/// them with a `!`. For example: setting extensions to
|
||||||
|
/// `"!noop", "newext"` indicates that the caller does not want
|
||||||
|
/// to support repositories with the `noop` extension but does want
|
||||||
|
/// to support repositories with the `newext` extension.
|
||||||
|
///
|
||||||
|
/// Extensions that have been negated will not be returned.
|
||||||
|
static List<String> get extensions {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final array = calloc<git_strarray>();
|
||||||
|
libgit2Opts.git_libgit2_opts_get_extensions(array);
|
||||||
|
|
||||||
|
final result = <String>[
|
||||||
|
for (var i = 0; i < array.ref.count; i++)
|
||||||
|
array.ref.strings.elementAt(i).value.toDartString()
|
||||||
|
];
|
||||||
|
|
||||||
|
calloc.free(array);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static set extensions(List<String> extensions) {
|
||||||
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
|
final array = calloc<Pointer<Char>>(extensions.length);
|
||||||
|
for (var i = 0; i < extensions.length; i++) {
|
||||||
|
array[i] = extensions[i].toChar();
|
||||||
|
}
|
||||||
|
|
||||||
|
libgit2Opts.git_libgit2_opts_set_extensions(array, extensions.length);
|
||||||
|
|
||||||
|
for (var i = 0; i < extensions.length; i++) {
|
||||||
|
calloc.free(array[i]);
|
||||||
|
}
|
||||||
|
calloc.free(array);
|
||||||
|
}
|
||||||
|
|
||||||
/// Owner validation setting for repository directories.
|
/// Owner validation setting for repository directories.
|
||||||
|
///
|
||||||
|
/// Enabled by default.
|
||||||
static bool get ownerValidation {
|
static bool get ownerValidation {
|
||||||
libgit2.git_libgit2_init();
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
final out = calloc<Int8>();
|
final out = calloc<Int>();
|
||||||
libgit2.git_libgit2_opts(
|
libgit2Opts.git_libgit2_opts_get_owner_validation(out);
|
||||||
git_libgit2_opt_t.GIT_OPT_GET_OWNER_VALIDATION,
|
|
||||||
out,
|
|
||||||
);
|
|
||||||
final result = out.value;
|
final result = out.value;
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result == 1 || false;
|
return result == 1 || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets owner validation setting for repository directories.
|
|
||||||
static set ownerValidation(bool value) {
|
static set ownerValidation(bool value) {
|
||||||
libgit2.git_libgit2_init();
|
libgit2.git_libgit2_init();
|
||||||
|
|
||||||
final valueC = value ? 1 : 0;
|
final valueC = value ? 1 : 0;
|
||||||
libgit2.git_libgit2_opts_set(
|
libgit2Opts.git_libgit2_opts_set_owner_validation(valueC);
|
||||||
git_libgit2_opt_t.GIT_OPT_SET_OWNER_VALIDATION,
|
}
|
||||||
valueC,
|
}
|
||||||
);
|
|
||||||
|
/// Current bytes in cache and the maximum that would be allowed in the cache.
|
||||||
|
class CachedMemory {
|
||||||
|
const CachedMemory._({required this.current, required this.allowed});
|
||||||
|
|
||||||
|
final int current;
|
||||||
|
final int allowed;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'CachedMemory{current: $current, allowed: $allowed}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,18 +265,43 @@ class Merge {
|
||||||
/// given common [ancestor] as the baseline, producing a string that reflects
|
/// given common [ancestor] as the baseline, producing a string that reflects
|
||||||
/// the merge result containing possible conflicts.
|
/// the merge result containing possible conflicts.
|
||||||
///
|
///
|
||||||
|
/// [ancestorLabel] is optional label for the ancestor file side of the
|
||||||
|
/// conflict which will be prepended to labels in diff3-format merge files.
|
||||||
|
///
|
||||||
|
/// [oursLabel] is optional label for our file side of the conflict which
|
||||||
|
/// will be prepended to labels in merge files.
|
||||||
|
///
|
||||||
|
/// [theirsLabel] is optional label for their file side of the conflict which
|
||||||
|
/// will be prepended to labels in merge files.
|
||||||
|
///
|
||||||
|
/// [favor] is one of the [GitMergeFileFavor] flags for handling conflicting
|
||||||
|
/// content. Defaults to [GitMergeFileFavor.normal].
|
||||||
|
///
|
||||||
|
/// [flags] is a combination of [GitMergeFileFlag] flags. Defaults to
|
||||||
|
/// [GitMergeFileFlag.defaults].
|
||||||
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
static String fileFromIndex({
|
static String fileFromIndex({
|
||||||
required Repository repo,
|
required Repository repo,
|
||||||
required IndexEntry? ancestor,
|
required IndexEntry? ancestor,
|
||||||
|
String ancestorLabel = '',
|
||||||
required IndexEntry ours,
|
required IndexEntry ours,
|
||||||
|
String oursLabel = '',
|
||||||
required IndexEntry theirs,
|
required IndexEntry theirs,
|
||||||
|
String theirsLabel = '',
|
||||||
|
GitMergeFileFavor favor = GitMergeFileFavor.normal,
|
||||||
|
Set<GitMergeFileFlag> flags = const {GitMergeFileFlag.defaults},
|
||||||
}) {
|
}) {
|
||||||
return bindings.mergeFileFromIndex(
|
return bindings.mergeFileFromIndex(
|
||||||
repoPointer: repo.pointer,
|
repoPointer: repo.pointer,
|
||||||
ancestorPointer: ancestor?.pointer,
|
ancestorPointer: ancestor?.pointer,
|
||||||
|
ancestorLabel: ancestorLabel,
|
||||||
oursPointer: ours.pointer,
|
oursPointer: ours.pointer,
|
||||||
|
oursLabel: oursLabel,
|
||||||
theirsPointer: theirs.pointer,
|
theirsPointer: theirs.pointer,
|
||||||
|
theirsLabel: theirsLabel,
|
||||||
|
favor: favor.value,
|
||||||
|
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/note.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/note.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Note {
|
@immutable
|
||||||
|
class Note extends Equatable {
|
||||||
/// Initializes a new instance of the [Note] class from provided
|
/// Initializes a new instance of the [Note] class from provided
|
||||||
/// pointer to note and annotatedOid objects in memory.
|
/// pointer to note and annotatedOid objects in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Use [Note.lookup] instead.
|
/// Note: For internal use. Use [Note.lookup] instead.
|
||||||
|
@internal
|
||||||
Note(this._notePointer, this._annotatedOidPointer) {
|
Note(this._notePointer, this._annotatedOidPointer) {
|
||||||
_finalizer.attach(this, _notePointer, detach: this);
|
_finalizer.attach(this, _notePointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -111,9 +115,17 @@ class Note {
|
||||||
|
|
||||||
/// Returns list of notes for [repo]sitory.
|
/// Returns list of notes for [repo]sitory.
|
||||||
///
|
///
|
||||||
|
/// [notesRef] is the canonical name of the reference to use. Defaults to "refs/notes/commits".
|
||||||
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
static List<Note> list(Repository repo) {
|
static List<Note> list(
|
||||||
final notesPointers = bindings.list(repo.pointer);
|
Repository repo, {
|
||||||
|
String notesRef = 'refs/notes/commits',
|
||||||
|
}) {
|
||||||
|
final notesPointers = bindings.list(
|
||||||
|
repoPointer: repo.pointer,
|
||||||
|
notesRef: notesRef,
|
||||||
|
);
|
||||||
return notesPointers
|
return notesPointers
|
||||||
.map(
|
.map(
|
||||||
(e) => Note(
|
(e) => Note(
|
||||||
|
@ -143,6 +155,9 @@ class Note {
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Note{oid: $oid, message: $message, annotatedOid: $annotatedOid}';
|
return 'Note{oid: $oid, message: $message, annotatedOid: $annotatedOid}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/odb.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/odb.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Odb {
|
@immutable
|
||||||
|
class Odb extends Equatable {
|
||||||
/// Initializes a new instance of [Odb] class from provided
|
/// Initializes a new instance of [Odb] class from provided
|
||||||
/// pointer to Odb object in memory.
|
/// pointer to Odb object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Odb(this._odbPointer) {
|
Odb(this._odbPointer) {
|
||||||
_finalizer.attach(this, _odbPointer, detach: this);
|
_finalizer.attach(this, _odbPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +33,7 @@ class Odb {
|
||||||
/// Pointer to memory address for allocated oid object.
|
/// Pointer to memory address for allocated oid object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_odb> get pointer => _odbPointer;
|
Pointer<git_odb> get pointer => _odbPointer;
|
||||||
|
|
||||||
/// Adds an on-disk alternate to an existing Object DB.
|
/// Adds an on-disk alternate to an existing Object DB.
|
||||||
|
@ -101,6 +106,9 @@ class Odb {
|
||||||
bindings.free(_odbPointer);
|
bindings.free(_odbPointer);
|
||||||
_finalizer.detach(this);
|
_finalizer.detach(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [objects];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
@ -109,7 +117,8 @@ final _finalizer = Finalizer<Pointer<git_odb>>(
|
||||||
);
|
);
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
|
|
||||||
class OdbObject {
|
@immutable
|
||||||
|
class OdbObject extends Equatable {
|
||||||
/// Initializes a new instance of the [OdbObject] class from
|
/// Initializes a new instance of the [OdbObject] class from
|
||||||
/// provided pointer to odbObject object in memory.
|
/// provided pointer to odbObject object in memory.
|
||||||
OdbObject._(this._odbObjectPointer) {
|
OdbObject._(this._odbObjectPointer) {
|
||||||
|
@ -144,6 +153,9 @@ class OdbObject {
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'OdbObject{oid: $oid, type: $type, size: $size}';
|
return 'OdbObject{oid: $oid, type: $type, size: $size}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/odb.dart' as odb_bindings;
|
import 'package:libgit2dart/src/bindings/odb.dart' as odb_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/oid.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/oid.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class Oid {
|
class Oid extends Equatable {
|
||||||
/// Initializes a new instance of [Oid] class from provided
|
/// Initializes a new instance of [Oid] class from provided
|
||||||
/// pointer to Oid object in memory.
|
/// pointer to Oid object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Use [Oid.fromSHA] instead.
|
/// Note: For internal use. Use [Oid.fromSHA] instead.
|
||||||
|
@internal
|
||||||
Oid(this._oidPointer);
|
Oid(this._oidPointer);
|
||||||
|
|
||||||
/// Initializes a new instance of [Oid] class by determining if an object can
|
/// Initializes a new instance of [Oid] class by determining if an object can
|
||||||
|
@ -23,7 +25,7 @@ class Oid {
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
Oid.fromSHA({required Repository repo, required String sha}) {
|
Oid.fromSHA({required Repository repo, required String sha}) {
|
||||||
if (isValidShaHex(sha)) {
|
if (sha.isValidSHA()) {
|
||||||
if (sha.length == 40) {
|
if (sha.length == 40) {
|
||||||
_oidPointer = bindings.fromSHA(sha);
|
_oidPointer = bindings.fromSHA(sha);
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,6 +42,9 @@ class Oid {
|
||||||
|
|
||||||
/// Initializes a new instance of [Oid] class from provided raw git_oid
|
/// Initializes a new instance of [Oid] class from provided raw git_oid
|
||||||
/// structure.
|
/// structure.
|
||||||
|
///
|
||||||
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Oid.fromRaw(git_oid raw) {
|
Oid.fromRaw(git_oid raw) {
|
||||||
_oidPointer = bindings.fromRaw(raw.id);
|
_oidPointer = bindings.fromRaw(raw.id);
|
||||||
}
|
}
|
||||||
|
@ -49,18 +54,12 @@ class Oid {
|
||||||
/// Pointer to memory address for allocated oid object.
|
/// Pointer to memory address for allocated oid object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_oid> get pointer => _oidPointer;
|
Pointer<git_oid> get pointer => _oidPointer;
|
||||||
|
|
||||||
/// Hexadecimal SHA string.
|
/// Hexadecimal SHA string.
|
||||||
String get sha => bindings.toSHA(_oidPointer);
|
String get sha => bindings.toSHA(_oidPointer);
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
return (other is Oid) &&
|
|
||||||
(bindings.compare(aPointer: _oidPointer, bPointer: other._oidPointer) ==
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator <(Oid other) {
|
bool operator <(Oid other) {
|
||||||
return bindings.compare(
|
return bindings.compare(
|
||||||
aPointer: _oidPointer,
|
aPointer: _oidPointer,
|
||||||
|
@ -93,9 +92,9 @@ class Oid {
|
||||||
1;
|
1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override // coverage:ignore-line
|
|
||||||
int get hashCode => _oidPointer.address.hashCode; // coverage:ignore-line
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => 'Oid{sha: $sha}';
|
String toString() => 'Oid{sha: $sha}';
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [sha];
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/packbuilder.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/packbuilder.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class PackBuilder {
|
class PackBuilder {
|
||||||
/// Initializes a new instance of [PackBuilder] class.
|
/// Initializes a new instance of [PackBuilder] class.
|
||||||
|
@ -9,6 +10,7 @@ class PackBuilder {
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
PackBuilder(Repository repo) {
|
PackBuilder(Repository repo) {
|
||||||
_packbuilderPointer = bindings.init(repo.pointer);
|
_packbuilderPointer = bindings.init(repo.pointer);
|
||||||
_finalizer.attach(this, _packbuilderPointer, detach: this);
|
_finalizer.attach(this, _packbuilderPointer, detach: this);
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/patch.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/patch.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Patch {
|
@immutable
|
||||||
|
class Patch extends Equatable {
|
||||||
/// Initializes a new instance of [Patch] class from provided
|
/// Initializes a new instance of [Patch] class from provided
|
||||||
/// pointer to patch object in memory and pointers to old and new blobs/buffers.
|
/// pointer to patch object in memory and pointers to old and new blobs/buffers.
|
||||||
///
|
///
|
||||||
|
@ -15,6 +18,7 @@ class Patch {
|
||||||
/// - [Patch.fromBlobAndBuffer]
|
/// - [Patch.fromBlobAndBuffer]
|
||||||
/// - [Patch.fromBuffers]
|
/// - [Patch.fromBuffers]
|
||||||
/// - [Patch.fromDiff]
|
/// - [Patch.fromDiff]
|
||||||
|
@internal
|
||||||
Patch(this._patchPointer) {
|
Patch(this._patchPointer) {
|
||||||
_finalizer.attach(this, _patchPointer, detach: this);
|
_finalizer.attach(this, _patchPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -234,10 +238,10 @@ class Patch {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final intHeader = <int>[];
|
final intHeader = <int>[
|
||||||
for (var i = 0; i < hunkPointer.ref.header_len; i++) {
|
for (var i = 0; i < hunkPointer.ref.header_len; i++)
|
||||||
intHeader.add(hunkPointer.ref.header[i]);
|
hunkPointer.ref.header[i]
|
||||||
}
|
];
|
||||||
|
|
||||||
hunks.add(
|
hunks.add(
|
||||||
DiffHunk._(
|
DiffHunk._(
|
||||||
|
@ -264,6 +268,9 @@ class Patch {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => 'Patch{size: ${size()}, delta: $delta}';
|
String toString() => 'Patch{size: ${size()}, delta: $delta}';
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [delta];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
@ -296,7 +303,8 @@ class PatchStats {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiffHunk {
|
@immutable
|
||||||
|
class DiffHunk extends Equatable {
|
||||||
const DiffHunk._({
|
const DiffHunk._({
|
||||||
required this.linesCount,
|
required this.linesCount,
|
||||||
required this.index,
|
required this.index,
|
||||||
|
@ -338,9 +346,22 @@ class DiffHunk {
|
||||||
'oldStart: $oldStart, oldLines: $oldLines, newStart: $newStart, '
|
'oldStart: $oldStart, oldLines: $oldLines, newStart: $newStart, '
|
||||||
'newLines: $newLines, header: $header}';
|
'newLines: $newLines, header: $header}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
linesCount,
|
||||||
|
index,
|
||||||
|
oldStart,
|
||||||
|
oldLines,
|
||||||
|
newStart,
|
||||||
|
newLines,
|
||||||
|
header,
|
||||||
|
lines
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiffLine {
|
@immutable
|
||||||
|
class DiffLine extends Equatable {
|
||||||
const DiffLine._({
|
const DiffLine._({
|
||||||
required this.origin,
|
required this.origin,
|
||||||
required this.oldLineNumber,
|
required this.oldLineNumber,
|
||||||
|
@ -374,4 +395,14 @@ class DiffLine {
|
||||||
'newLineNumber: $newLineNumber, numLines: $numLines, '
|
'newLineNumber: $newLineNumber, numLines: $numLines, '
|
||||||
'contentOffset: $contentOffset, content: $content}';
|
'contentOffset: $contentOffset, content: $content}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
origin,
|
||||||
|
oldLineNumber,
|
||||||
|
newLineNumber,
|
||||||
|
numLines,
|
||||||
|
contentOffset,
|
||||||
|
content,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,18 +47,13 @@ class Rebase {
|
||||||
|
|
||||||
/// List of operations that are to be applied.
|
/// List of operations that are to be applied.
|
||||||
List<RebaseOperation> get operations {
|
List<RebaseOperation> get operations {
|
||||||
final result = <RebaseOperation>[];
|
|
||||||
final operationsCount = bindings.operationsCount(_rebasePointer);
|
final operationsCount = bindings.operationsCount(_rebasePointer);
|
||||||
|
return <RebaseOperation>[
|
||||||
for (var i = 0; i < operationsCount; i++) {
|
for (var i = 0; i < operationsCount; i++)
|
||||||
final operation = bindings.getOperationByIndex(
|
RebaseOperation._(
|
||||||
rebase: _rebasePointer,
|
bindings.getOperationByIndex(rebase: _rebasePointer, index: i),
|
||||||
index: i,
|
)
|
||||||
);
|
];
|
||||||
result.add(RebaseOperation._(operation));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Index of the rebase operation that is currently being applied. If the
|
/// Index of the rebase operation that is currently being applied. If the
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/object.dart' as object_bindings;
|
import 'package:libgit2dart/src/bindings/object.dart' as object_bindings;
|
||||||
|
@ -7,13 +8,16 @@ import 'package:libgit2dart/src/bindings/refdb.dart' as refdb_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/reference.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/reference.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/repository.dart'
|
import 'package:libgit2dart/src/bindings/repository.dart'
|
||||||
as repository_bindings;
|
as repository_bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Reference {
|
@immutable
|
||||||
|
class Reference extends Equatable {
|
||||||
/// Initializes a new instance of the [Reference] class.
|
/// Initializes a new instance of the [Reference] class.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Instead, use one of:
|
/// Note: For internal use. Instead, use one of:
|
||||||
/// - [Reference.create]
|
/// - [Reference.create]
|
||||||
/// - [Reference.lookup]
|
/// - [Reference.lookup]
|
||||||
|
@internal
|
||||||
Reference(this._refPointer) {
|
Reference(this._refPointer) {
|
||||||
_finalizer.attach(this, _refPointer, detach: this);
|
_finalizer.attach(this, _refPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -79,11 +83,12 @@ class Reference {
|
||||||
_finalizer.attach(this, _refPointer, detach: this);
|
_finalizer.attach(this, _refPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
late Pointer<git_reference> _refPointer;
|
late final Pointer<git_reference> _refPointer;
|
||||||
|
|
||||||
/// Pointer to memory address for allocated reference object.
|
/// Pointer to memory address for allocated reference object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_reference> get pointer => _refPointer;
|
Pointer<git_reference> get pointer => _refPointer;
|
||||||
|
|
||||||
/// Deletes an existing reference with provided [name].
|
/// Deletes an existing reference with provided [name].
|
||||||
|
@ -124,6 +129,39 @@ class Reference {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the [target] of reference with provided [name].
|
||||||
|
///
|
||||||
|
/// [target] being either Oid for direct reference or string reference name
|
||||||
|
/// for symbolic reference.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured or [ArgumentError] if [target]
|
||||||
|
/// is not [Oid] or string.
|
||||||
|
static void setTarget({
|
||||||
|
required Repository repo,
|
||||||
|
required String name,
|
||||||
|
required Object target,
|
||||||
|
String? logMessage,
|
||||||
|
}) {
|
||||||
|
final ref = Reference.lookup(repo: repo, name: name);
|
||||||
|
if (target is Oid) {
|
||||||
|
bindings.setTarget(
|
||||||
|
refPointer: ref.pointer,
|
||||||
|
oidPointer: target.pointer,
|
||||||
|
logMessage: logMessage,
|
||||||
|
);
|
||||||
|
} else if (target is String) {
|
||||||
|
bindings.setTargetSymbolic(
|
||||||
|
refPointer: ref.pointer,
|
||||||
|
target: target,
|
||||||
|
logMessage: logMessage,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw ArgumentError.value(
|
||||||
|
'$target must be either Oid or String reference name',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// List of all the references names that can be found in a [repo]sitory.
|
/// List of all the references names that can be found in a [repo]sitory.
|
||||||
///
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
@ -167,43 +205,9 @@ class Reference {
|
||||||
///
|
///
|
||||||
/// Throws an [Exception] if error occured.
|
/// Throws an [Exception] if error occured.
|
||||||
Oid get target {
|
Oid get target {
|
||||||
late final Pointer<git_oid> oidPointer;
|
return type == ReferenceType.direct
|
||||||
|
? Oid(bindings.target(_refPointer))
|
||||||
if (type == ReferenceType.direct) {
|
: Oid(bindings.target(bindings.resolve(_refPointer)));
|
||||||
oidPointer = bindings.target(_refPointer);
|
|
||||||
} else {
|
|
||||||
oidPointer = bindings.target(bindings.resolve(_refPointer));
|
|
||||||
}
|
|
||||||
return Oid(oidPointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates the [target] of this reference.
|
|
||||||
///
|
|
||||||
/// [target] being either Oid for direct reference or string reference name
|
|
||||||
/// for symbolic reference.
|
|
||||||
///
|
|
||||||
/// Throws a [LibGit2Error] if error occured or [ArgumentError] if [target]
|
|
||||||
/// is not [Oid] or string.
|
|
||||||
void setTarget({required Object target, String? logMessage}) {
|
|
||||||
if (target is Oid) {
|
|
||||||
final newPointer = bindings.setTarget(
|
|
||||||
refPointer: _refPointer,
|
|
||||||
oidPointer: target.pointer,
|
|
||||||
logMessage: logMessage,
|
|
||||||
);
|
|
||||||
_refPointer = newPointer;
|
|
||||||
} else if (target is String) {
|
|
||||||
final newPointer = bindings.setTargetSymbolic(
|
|
||||||
refPointer: _refPointer,
|
|
||||||
target: target,
|
|
||||||
logMessage: logMessage,
|
|
||||||
);
|
|
||||||
_refPointer = newPointer;
|
|
||||||
} else {
|
|
||||||
throw ArgumentError.value(
|
|
||||||
'$target must be either Oid or String reference name',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively peel reference until object of the specified [type] is found.
|
/// Recursively peel reference until object of the specified [type] is found.
|
||||||
|
@ -272,17 +276,6 @@ class Reference {
|
||||||
/// Whether reference is a tag.
|
/// Whether reference is a tag.
|
||||||
bool get isTag => bindings.isTag(_refPointer);
|
bool get isTag => bindings.isTag(_refPointer);
|
||||||
|
|
||||||
/// Compares two references.
|
|
||||||
bool equals(Reference other) {
|
|
||||||
return bindings.compare(
|
|
||||||
ref1Pointer: _refPointer,
|
|
||||||
ref2Pointer: other._refPointer,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compares two references.
|
|
||||||
bool notEquals(Reference other) => !equals(other);
|
|
||||||
|
|
||||||
/// Releases memory allocated for reference object.
|
/// Releases memory allocated for reference object.
|
||||||
void free() {
|
void free() {
|
||||||
bindings.free(_refPointer);
|
bindings.free(_refPointer);
|
||||||
|
@ -295,6 +288,9 @@ class Reference {
|
||||||
'isBranch: $isBranch, isNote: $isNote, isRemote: $isRemote, '
|
'isBranch: $isBranch, isNote: $isNote, isRemote: $isRemote, '
|
||||||
'isTag: $isTag}';
|
'isTag: $isTag}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [target];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/reference.dart' as reference_bindings;
|
import 'package:libgit2dart/src/bindings/reference.dart' as reference_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/reflog.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/reflog.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class RefLog with IterableMixin<RefLogEntry> {
|
class RefLog with IterableMixin<RefLogEntry> {
|
||||||
/// Initializes a new instance of [RefLog] class from provided [Reference].
|
/// Initializes a new instance of [RefLog] class from provided [Reference].
|
||||||
|
@ -109,7 +111,8 @@ final _finalizer = Finalizer<Pointer<git_reflog>>(
|
||||||
);
|
);
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
|
|
||||||
class RefLogEntry {
|
@immutable
|
||||||
|
class RefLogEntry extends Equatable {
|
||||||
/// Initializes a new instance of [RefLogEntry] class from provided
|
/// Initializes a new instance of [RefLogEntry] class from provided
|
||||||
/// pointer to RefLogEntry object in memory.
|
/// pointer to RefLogEntry object in memory.
|
||||||
const RefLogEntry._(this._entryPointer);
|
const RefLogEntry._(this._entryPointer);
|
||||||
|
@ -133,6 +136,9 @@ class RefLogEntry {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => 'RefLogEntry{message: $message, committer: $committer}';
|
String toString() => 'RefLogEntry{message: $message, committer: $committer}';
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [message, committer, newOid, oldOid];
|
||||||
}
|
}
|
||||||
|
|
||||||
class _RefLogIterator implements Iterator<RefLogEntry> {
|
class _RefLogIterator implements Iterator<RefLogEntry> {
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/refspec.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/refspec.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Refspec {
|
@immutable
|
||||||
|
class Refspec extends Equatable {
|
||||||
/// Initializes a new instance of the [Refspec] class
|
/// Initializes a new instance of the [Refspec] class
|
||||||
/// from provided pointer to refspec object in memory.
|
/// from provided pointer to refspec object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
const Refspec(this._refspecPointer);
|
const Refspec(this._refspecPointer);
|
||||||
|
|
||||||
/// Pointer to memory address for allocated refspec object.
|
/// Pointer to memory address for allocated refspec object.
|
||||||
|
@ -72,6 +76,9 @@ class Refspec {
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Refspec{source: $source, destination: $destination, force: $force, '
|
return 'Refspec{source: $source, destination: $destination, force: $force, '
|
||||||
'string: $string}';
|
'string: $string, direction: $direction}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [source, destination, force, string, direction];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/remote.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/remote.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Remote {
|
@immutable
|
||||||
|
class Remote extends Equatable {
|
||||||
/// Lookups remote with provided [name] in a [repo]sitory.
|
/// Lookups remote with provided [name] in a [repo]sitory.
|
||||||
///
|
///
|
||||||
/// The [name] will be checked for validity.
|
/// The [name] will be checked for validity.
|
||||||
|
@ -208,20 +211,16 @@ class Remote {
|
||||||
final refs = bindings.lsRemotes(_remotePointer);
|
final refs = bindings.lsRemotes(_remotePointer);
|
||||||
bindings.disconnect(_remotePointer);
|
bindings.disconnect(_remotePointer);
|
||||||
|
|
||||||
final result = <RemoteReference>[];
|
return <RemoteReference>[
|
||||||
for (final ref in refs) {
|
for (final ref in refs)
|
||||||
result.add(
|
|
||||||
RemoteReference._(
|
RemoteReference._(
|
||||||
isLocal: ref['local']! as bool,
|
isLocal: ref['local']! as bool,
|
||||||
localId: ref['loid'] as Oid?,
|
localId: ref['loid'] as Oid?,
|
||||||
name: ref['name']! as String,
|
name: ref['name']! as String,
|
||||||
oid: ref['oid']! as Oid,
|
oid: ref['oid']! as Oid,
|
||||||
symRef: ref['symref']! as String,
|
symRef: ref['symref']! as String,
|
||||||
),
|
)
|
||||||
);
|
];
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Downloads new data and updates tips.
|
/// Downloads new data and updates tips.
|
||||||
|
@ -310,6 +309,9 @@ class Remote {
|
||||||
return 'Remote{name: $name, url: $url, pushUrl: $pushUrl, '
|
return 'Remote{name: $name, url: $url, pushUrl: $pushUrl, '
|
||||||
'refspecCount: $refspecCount}';
|
'refspecCount: $refspecCount}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [name];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
@ -325,6 +327,7 @@ class TransferProgress {
|
||||||
/// pointer to transfer progress object in memory.
|
/// pointer to transfer progress object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
const TransferProgress(this._transferProgressPointer);
|
const TransferProgress(this._transferProgressPointer);
|
||||||
|
|
||||||
/// Pointer to memory address for allocated transfer progress object.
|
/// Pointer to memory address for allocated transfer progress object.
|
||||||
|
@ -378,7 +381,8 @@ class RemoteCallback {
|
||||||
final String? fetch;
|
final String? fetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
class RemoteReference {
|
@immutable
|
||||||
|
class RemoteReference extends Equatable {
|
||||||
const RemoteReference._({
|
const RemoteReference._({
|
||||||
required this.isLocal,
|
required this.isLocal,
|
||||||
required this.localId,
|
required this.localId,
|
||||||
|
@ -408,4 +412,7 @@ class RemoteReference {
|
||||||
return 'RemoteReference{isLocal: $isLocal, localId: $localId, '
|
return 'RemoteReference{isLocal: $isLocal, localId: $localId, '
|
||||||
'name: $name, oid: $oid, symRef: $symRef}';
|
'name: $name, oid: $oid, symRef: $symRef}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [isLocal, localId, name, oid, symRef];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:ffi/ffi.dart';
|
import 'package:ffi/ffi.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
|
|
||||||
import 'package:libgit2dart/src/bindings/attr.dart' as attr_bindings;
|
import 'package:libgit2dart/src/bindings/attr.dart' as attr_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/describe.dart' as describe_bindings;
|
import 'package:libgit2dart/src/bindings/describe.dart' as describe_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/graph.dart' as graph_bindings;
|
import 'package:libgit2dart/src/bindings/graph.dart' as graph_bindings;
|
||||||
|
@ -12,8 +12,10 @@ import 'package:libgit2dart/src/bindings/repository.dart' as bindings;
|
||||||
import 'package:libgit2dart/src/bindings/reset.dart' as reset_bindings;
|
import 'package:libgit2dart/src/bindings/reset.dart' as reset_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/status.dart' as status_bindings;
|
import 'package:libgit2dart/src/bindings/status.dart' as status_bindings;
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Repository {
|
@immutable
|
||||||
|
class Repository extends Equatable {
|
||||||
/// Initializes a new instance of the [Repository] class from provided
|
/// Initializes a new instance of the [Repository] class from provided
|
||||||
/// pointer to repository object in memory.
|
/// pointer to repository object in memory.
|
||||||
///
|
///
|
||||||
|
@ -21,6 +23,7 @@ class Repository {
|
||||||
/// - [Repository.init]
|
/// - [Repository.init]
|
||||||
/// - [Repository.open]
|
/// - [Repository.open]
|
||||||
/// - [Repository.clone]
|
/// - [Repository.clone]
|
||||||
|
@internal
|
||||||
Repository(Pointer<git_repository> pointer) {
|
Repository(Pointer<git_repository> pointer) {
|
||||||
_repoPointer = pointer;
|
_repoPointer = pointer;
|
||||||
_finalizer.attach(this, _repoPointer, detach: this);
|
_finalizer.attach(this, _repoPointer, detach: this);
|
||||||
|
@ -159,6 +162,7 @@ class Repository {
|
||||||
/// Pointer to memory address for allocated repository object.
|
/// Pointer to memory address for allocated repository object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_repository> get pointer => _repoPointer;
|
Pointer<git_repository> get pointer => _repoPointer;
|
||||||
|
|
||||||
/// Looks for a git repository and return its path. The lookup start from
|
/// Looks for a git repository and return its path. The lookup start from
|
||||||
|
@ -553,8 +557,23 @@ class Repository {
|
||||||
///
|
///
|
||||||
/// [resetType] is one of the [GitReset] flags.
|
/// [resetType] is one of the [GitReset] flags.
|
||||||
///
|
///
|
||||||
|
/// [strategy], [checkoutDirectory] and [pathspec] are optional checkout
|
||||||
|
/// options to be used for a HARD reset.
|
||||||
|
///
|
||||||
|
/// [strategy] is optional combination of [GitCheckout] flags.
|
||||||
|
///
|
||||||
|
/// [checkoutDirectory] is optional alternative checkout path to workdir.
|
||||||
|
///
|
||||||
|
/// [pathspec] is optional list of files to checkout.
|
||||||
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void reset({required Oid oid, required GitReset resetType}) {
|
void reset({
|
||||||
|
required Oid oid,
|
||||||
|
required GitReset resetType,
|
||||||
|
Set<GitCheckout>? strategy,
|
||||||
|
String? checkoutDirectory,
|
||||||
|
List<String>? pathspec,
|
||||||
|
}) {
|
||||||
final object = object_bindings.lookup(
|
final object = object_bindings.lookup(
|
||||||
repoPointer: _repoPointer,
|
repoPointer: _repoPointer,
|
||||||
oidPointer: oid.pointer,
|
oidPointer: oid.pointer,
|
||||||
|
@ -565,7 +584,9 @@ class Repository {
|
||||||
repoPointer: _repoPointer,
|
repoPointer: _repoPointer,
|
||||||
targetPointer: object,
|
targetPointer: object,
|
||||||
resetType: resetType.value,
|
resetType: resetType.value,
|
||||||
checkoutOptsPointer: nullptr,
|
strategy: strategy?.fold(0, (acc, e) => acc! | e.value),
|
||||||
|
checkoutDirectory: checkoutDirectory,
|
||||||
|
pathspec: pathspec,
|
||||||
);
|
);
|
||||||
|
|
||||||
object_bindings.free(object);
|
object_bindings.free(object);
|
||||||
|
@ -576,13 +597,19 @@ class Repository {
|
||||||
/// The scope of the updated entries is determined by the paths being passed
|
/// The scope of the updated entries is determined by the paths being passed
|
||||||
/// in the [pathspec].
|
/// in the [pathspec].
|
||||||
///
|
///
|
||||||
|
/// Passing a null [oid] will result in removing entries in the index
|
||||||
|
/// matching the provided [pathspec]s.
|
||||||
|
///
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
void resetDefault({required Oid oid, required List<String> pathspec}) {
|
void resetDefault({required Oid? oid, required List<String> pathspec}) {
|
||||||
final object = object_bindings.lookup(
|
Pointer<git_object>? object;
|
||||||
|
if (oid != null) {
|
||||||
|
object = object_bindings.lookup(
|
||||||
repoPointer: _repoPointer,
|
repoPointer: _repoPointer,
|
||||||
oidPointer: oid.pointer,
|
oidPointer: oid.pointer,
|
||||||
type: GitObject.commit.value,
|
type: GitObject.commit.value,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
reset_bindings.resetDefault(
|
reset_bindings.resetDefault(
|
||||||
repoPointer: _repoPointer,
|
repoPointer: _repoPointer,
|
||||||
|
@ -741,6 +768,9 @@ class Repository {
|
||||||
|
|
||||||
return packbuilder.writtenLength;
|
return packbuilder.writtenLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [path];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
@ -821,10 +851,14 @@ class RepositoryCallback {
|
||||||
final String? originUrl;
|
final String? originUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Identity {
|
@immutable
|
||||||
|
class Identity extends Equatable {
|
||||||
/// Identity to use for reflogs.
|
/// Identity to use for reflogs.
|
||||||
const Identity({required this.name, required this.email});
|
const Identity({required this.name, required this.email});
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
final String email;
|
final String email;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [name, email];
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,9 @@ class RevParse {
|
||||||
spec: spec,
|
spec: spec,
|
||||||
);
|
);
|
||||||
object = Commit(pointers[0].cast<git_commit>());
|
object = Commit(pointers[0].cast<git_commit>());
|
||||||
if (pointers.length == 2) {
|
reference = pointers.length == 2
|
||||||
reference = Reference(pointers[1].cast<git_reference>());
|
? Reference(pointers[1].cast<git_reference>())
|
||||||
} else {
|
: null;
|
||||||
reference = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Object found by a revision string.
|
/// Object found by a revision string.
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:ffi';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/revwalk.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/revwalk.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class RevWalk {
|
class RevWalk {
|
||||||
/// Initializes a new instance of the [RevWalk] class.
|
/// Initializes a new instance of the [RevWalk] class.
|
||||||
|
@ -15,15 +16,20 @@ class RevWalk {
|
||||||
/// Pointer to memory address for allocated [RevWalk] object.
|
/// Pointer to memory address for allocated [RevWalk] object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_revwalk> get pointer => _revWalkPointer;
|
Pointer<git_revwalk> get pointer => _revWalkPointer;
|
||||||
|
|
||||||
/// Returns the list of commits from the revision walk.
|
/// Returns the list of commits from the revision walk.
|
||||||
///
|
///
|
||||||
|
/// [limit] is optional number of commits to walk (by default walks through
|
||||||
|
/// all of the commits pushed onto the walker).
|
||||||
|
///
|
||||||
/// Default sorting is reverse chronological order (default in git).
|
/// Default sorting is reverse chronological order (default in git).
|
||||||
List<Commit> walk() {
|
List<Commit> walk({int limit = 0}) {
|
||||||
final pointers = bindings.walk(
|
final pointers = bindings.walk(
|
||||||
repoPointer: bindings.repository(_revWalkPointer),
|
repoPointer: bindings.repository(_revWalkPointer),
|
||||||
walkerPointer: _revWalkPointer,
|
walkerPointer: _revWalkPointer,
|
||||||
|
limit: limit,
|
||||||
);
|
);
|
||||||
|
|
||||||
return pointers.map((e) => Commit(e)).toList();
|
return pointers.map((e) => Commit(e)).toList();
|
||||||
|
|
|
@ -1,19 +1,22 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'package:ffi/ffi.dart';
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/signature.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/signature.dart' as bindings;
|
||||||
|
import 'package:libgit2dart/src/extensions.dart';
|
||||||
import 'package:libgit2dart/src/util.dart';
|
import 'package:libgit2dart/src/util.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class Signature {
|
class Signature extends Equatable {
|
||||||
/// Initializes a new instance of [Signature] class from provided pointer to
|
/// Initializes a new instance of [Signature] class from provided pointer to
|
||||||
/// signature object in memory.
|
/// signature object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Instead, use one of:
|
/// Note: For internal use. Instead, use one of:
|
||||||
/// - [Signature.create]
|
/// - [Signature.create]
|
||||||
/// - [Signature.defaultSignature]
|
/// - [Signature.defaultSignature]
|
||||||
|
@internal
|
||||||
Signature(Pointer<git_signature> pointer) {
|
Signature(Pointer<git_signature> pointer) {
|
||||||
_signaturePointer = bindings.duplicate(pointer);
|
_signaturePointer = bindings.duplicate(pointer);
|
||||||
_finalizer.attach(this, _signaturePointer, detach: this);
|
_finalizer.attach(this, _signaturePointer, detach: this);
|
||||||
|
@ -60,13 +63,14 @@ class Signature {
|
||||||
/// Pointer to memory address for allocated signature object.
|
/// Pointer to memory address for allocated signature object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_signature> get pointer => _signaturePointer;
|
Pointer<git_signature> get pointer => _signaturePointer;
|
||||||
|
|
||||||
/// Full name of the author.
|
/// Full name of the author.
|
||||||
String get name => _signaturePointer.ref.name.cast<Utf8>().toDartString();
|
String get name => _signaturePointer.ref.name.toDartString();
|
||||||
|
|
||||||
/// Email of the author.
|
/// Email of the author.
|
||||||
String get email => _signaturePointer.ref.email.cast<Utf8>().toDartString();
|
String get email => _signaturePointer.ref.email.toDartString();
|
||||||
|
|
||||||
/// Time in seconds from epoch.
|
/// Time in seconds from epoch.
|
||||||
int get time => _signaturePointer.ref.when.time;
|
int get time => _signaturePointer.ref.when.time;
|
||||||
|
@ -74,16 +78,8 @@ class Signature {
|
||||||
/// Timezone offset in minutes.
|
/// Timezone offset in minutes.
|
||||||
int get offset => _signaturePointer.ref.when.offset;
|
int get offset => _signaturePointer.ref.when.offset;
|
||||||
|
|
||||||
@override
|
/// Indicator for questionable '-0000' offsets in signature.
|
||||||
bool operator ==(Object other) {
|
String get sign => String.fromCharCode(_signaturePointer.ref.when.sign);
|
||||||
return (other is Signature) &&
|
|
||||||
(name == other.name) &&
|
|
||||||
(email == other.email) &&
|
|
||||||
(time == other.time) &&
|
|
||||||
(offset == other.offset) &&
|
|
||||||
(_signaturePointer.ref.when.sign ==
|
|
||||||
other._signaturePointer.ref.when.sign);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Releases memory allocated for signature object.
|
/// Releases memory allocated for signature object.
|
||||||
void free() {
|
void free() {
|
||||||
|
@ -91,15 +87,14 @@ class Signature {
|
||||||
_finalizer.detach(this);
|
_finalizer.detach(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override // coverage:ignore-line
|
|
||||||
int get hashCode =>
|
|
||||||
_signaturePointer.address.hashCode; // coverage:ignore-line
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Signature{name: $name, email: $email, time: $time, '
|
return 'Signature{name: $name, email: $email, time: $time, '
|
||||||
'offset: $offset}';
|
'offset: $sign$offset}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [name, email, time, offset, sign];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/stash.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/stash.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Stash {
|
@immutable
|
||||||
|
class Stash extends Equatable {
|
||||||
/// Initializes a new instance of [Stash] class from provided stash [index],
|
/// Initializes a new instance of [Stash] class from provided stash [index],
|
||||||
/// [message] and [oid].
|
/// [message] and [oid].
|
||||||
|
///
|
||||||
|
/// Note: For internal use. Use [Stash.create] instead to create stash.
|
||||||
|
@internal
|
||||||
const Stash({
|
const Stash({
|
||||||
required this.index,
|
required this.index,
|
||||||
required this.message,
|
required this.message,
|
||||||
|
@ -40,14 +46,12 @@ class Stash {
|
||||||
String? message,
|
String? message,
|
||||||
Set<GitStash> flags = const {GitStash.defaults},
|
Set<GitStash> flags = const {GitStash.defaults},
|
||||||
}) {
|
}) {
|
||||||
final flagsInt = flags.fold(0, (int acc, e) => acc | e.value);
|
|
||||||
|
|
||||||
return Oid(
|
return Oid(
|
||||||
bindings.save(
|
bindings.save(
|
||||||
repoPointer: repo.pointer,
|
repoPointer: repo.pointer,
|
||||||
stasherPointer: stasher.pointer,
|
stasherPointer: stasher.pointer,
|
||||||
message: message,
|
message: message,
|
||||||
flags: flagsInt,
|
flags: flags.fold(0, (int acc, e) => acc | e.value),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -146,4 +150,7 @@ class Stash {
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Stash{index: $index, message: $message, oid: $oid}';
|
return 'Stash{index: $index, message: $message, oid: $oid}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [index, message, oid];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/submodule.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/submodule.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Submodule {
|
@immutable
|
||||||
|
class Submodule extends Equatable {
|
||||||
/// Lookups submodule information by [name] or path (they are usually the
|
/// Lookups submodule information by [name] or path (they are usually the
|
||||||
/// same).
|
/// same).
|
||||||
///
|
///
|
||||||
|
@ -267,10 +270,23 @@ class Submodule {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Submodule{name: $name, path: $path, url: $url, status: $status, '
|
return 'Submodule{name: $name, path: $path, url: $url, branch: $branch, '
|
||||||
'branch: $branch, headOid: $headOid, indexOid: $indexOid, '
|
'headOid: $headOid, indexOid: $indexOid, workdirOid: $workdirOid, '
|
||||||
'workdirOid: $workdirOid, ignore: $ignore, updateRule: $updateRule}';
|
'ignore: $ignore, updateRule: $updateRule}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
name,
|
||||||
|
path,
|
||||||
|
url,
|
||||||
|
branch,
|
||||||
|
headOid,
|
||||||
|
indexOid,
|
||||||
|
workdirOid,
|
||||||
|
ignore,
|
||||||
|
updateRule,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/object.dart' as object_bindings;
|
import 'package:libgit2dart/src/bindings/object.dart' as object_bindings;
|
||||||
import 'package:libgit2dart/src/bindings/tag.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/tag.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Tag {
|
@immutable
|
||||||
|
class Tag extends Equatable {
|
||||||
/// Initializes a new instance of [Tag] class from provided pointer to
|
/// Initializes a new instance of [Tag] class from provided pointer to
|
||||||
/// tag object in memory.
|
/// tag object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Use [Tag.lookup] instead.
|
/// Note: For internal use. Use [Tag.lookup] instead.
|
||||||
|
@internal
|
||||||
Tag(this._tagPointer) {
|
Tag(this._tagPointer) {
|
||||||
_finalizer.attach(this, _tagPointer, detach: this);
|
_finalizer.attach(this, _tagPointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -205,11 +209,7 @@ class Tag {
|
||||||
/// Tagger (author) of a tag if there is one.
|
/// Tagger (author) of a tag if there is one.
|
||||||
Signature? get tagger {
|
Signature? get tagger {
|
||||||
final sigPointer = bindings.tagger(_tagPointer);
|
final sigPointer = bindings.tagger(_tagPointer);
|
||||||
if (sigPointer != nullptr) {
|
return sigPointer != nullptr ? Signature(sigPointer) : null;
|
||||||
return Signature(sigPointer);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Releases memory allocated for tag object.
|
/// Releases memory allocated for tag object.
|
||||||
|
@ -223,6 +223,9 @@ class Tag {
|
||||||
return 'Tag{oid: $oid, name: $name, message: $message, target: $target, '
|
return 'Tag{oid: $oid, name: $name, message: $message, target: $target, '
|
||||||
'tagger: $tagger}';
|
'tagger: $tagger}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [name];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/tree.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/tree.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Tree {
|
@immutable
|
||||||
|
class Tree extends Equatable {
|
||||||
/// Initializes a new instance of [Tree] class from provided pointer to
|
/// Initializes a new instance of [Tree] class from provided pointer to
|
||||||
/// tree object in memory.
|
/// tree object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use. Use [Tree.lookup] instead.
|
/// Note: For internal use. Use [Tree.lookup] instead.
|
||||||
|
@internal
|
||||||
Tree(this._treePointer) {
|
Tree(this._treePointer) {
|
||||||
_finalizer.attach(this, _treePointer, detach: this);
|
_finalizer.attach(this, _treePointer, detach: this);
|
||||||
}
|
}
|
||||||
|
@ -27,24 +31,16 @@ class Tree {
|
||||||
/// Pointer to memory address for allocated tree object.
|
/// Pointer to memory address for allocated tree object.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
|
@internal
|
||||||
Pointer<git_tree> get pointer => _treePointer;
|
Pointer<git_tree> get pointer => _treePointer;
|
||||||
|
|
||||||
/// List with tree entries of a tree.
|
/// List with tree entries of a tree.
|
||||||
List<TreeEntry> get entries {
|
List<TreeEntry> get entries {
|
||||||
final entryCount = bindings.entryCount(_treePointer);
|
final entryCount = bindings.entryCount(_treePointer);
|
||||||
final result = <TreeEntry>[];
|
return <TreeEntry>[
|
||||||
for (var i = 0; i < entryCount; i++) {
|
for (var i = 0; i < entryCount; i++)
|
||||||
result.add(
|
TreeEntry(bindings.getByIndex(treePointer: _treePointer, index: i))
|
||||||
TreeEntry(
|
];
|
||||||
bindings.getByIndex(
|
|
||||||
treePointer: _treePointer,
|
|
||||||
index: i,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lookups a tree entry in the tree.
|
/// Lookups a tree entry in the tree.
|
||||||
|
@ -102,6 +98,9 @@ class Tree {
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Tree{oid: $oid, length: $length}';
|
return 'Tree{oid: $oid, length: $length}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
@ -110,12 +109,14 @@ final _finalizer = Finalizer<Pointer<git_tree>>(
|
||||||
);
|
);
|
||||||
// coverage:ignore-end
|
// coverage:ignore-end
|
||||||
|
|
||||||
class TreeEntry {
|
@immutable
|
||||||
|
class TreeEntry extends Equatable {
|
||||||
/// Initializes a new instance of [TreeEntry] class from provided pointer to
|
/// Initializes a new instance of [TreeEntry] class from provided pointer to
|
||||||
/// tree entry object in memory.
|
/// tree entry object in memory.
|
||||||
///
|
///
|
||||||
/// Note: For internal use.
|
/// Note: For internal use.
|
||||||
TreeEntry(this._treeEntryPointer);
|
@internal
|
||||||
|
const TreeEntry(this._treeEntryPointer);
|
||||||
|
|
||||||
/// Initializes a new instance of [TreeEntry] class from provided pointer to
|
/// Initializes a new instance of [TreeEntry] class from provided pointer to
|
||||||
/// tree entry object in memory.
|
/// tree entry object in memory.
|
||||||
|
@ -150,6 +151,9 @@ class TreeEntry {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => 'TreeEntry{oid: $oid, name: $name, filemode: $filemode}';
|
String toString() => 'TreeEntry{oid: $oid, name: $name, filemode: $filemode}';
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [oid, name, filemode];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
// coverage:ignore-file
|
// coverage:ignore-file
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:cli_util/cli_logging.dart' show Ansi, Logger;
|
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
|
import 'package:libgit2dart/src/bindings/libgit2_opts_bindings.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:pub_cache/pub_cache.dart';
|
import 'package:pub_semver/pub_semver.dart';
|
||||||
|
|
||||||
const libgit2Version = '1.4.3';
|
const libgit2Version = '1.5.0';
|
||||||
final libDir = path.join('.dart_tool', 'libgit2');
|
final libDir = path.join('.dart_tool', 'libgit2');
|
||||||
|
|
||||||
String getLibName() {
|
String getLibName() {
|
||||||
|
@ -25,6 +26,20 @@ String getLibName() {
|
||||||
return 'libgit2-$libgit2Version.$ext';
|
return 'libgit2-$libgit2Version.$ext';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns location of the most recent verison of the libgit2dart package
|
||||||
|
/// contained in the cache.
|
||||||
|
String? checkCache() {
|
||||||
|
final cache = json.decode(
|
||||||
|
Process.runSync('dart', ['pub', 'cache', 'list']).stdout as String,
|
||||||
|
) as Map<String, dynamic>;
|
||||||
|
final packages = cache['packages'] as Map<String, dynamic>;
|
||||||
|
final libPackages = packages['libgit2dart'] as Map<String, dynamic>?;
|
||||||
|
final versions = libPackages?.keys.map((e) => Version.parse(e)).toList();
|
||||||
|
final latestVersion = libPackages?[Version.primary(versions!).toString()]
|
||||||
|
as Map<String, dynamic>?;
|
||||||
|
return latestVersion?['location'] as String?;
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks if [File]/[Link] exists for [path].
|
/// Checks if [File]/[Link] exists for [path].
|
||||||
bool _doesFileExist(String path) {
|
bool _doesFileExist(String path) {
|
||||||
return File(path).existsSync() || Link(path).existsSync();
|
return File(path).existsSync() || Link(path).existsSync();
|
||||||
|
@ -32,13 +47,8 @@ bool _doesFileExist(String path) {
|
||||||
|
|
||||||
/// Returns path to dynamic library if found.
|
/// Returns path to dynamic library if found.
|
||||||
String? _resolveLibPath(String name) {
|
String? _resolveLibPath(String name) {
|
||||||
var libPath = path.join(Directory.current.path, name);
|
|
||||||
|
|
||||||
// If lib is in Present Working Directory.
|
|
||||||
if (_doesFileExist(libPath)) return libPath;
|
|
||||||
|
|
||||||
// If lib is in Present Working Directory's '.dart_tool/libgit2/[platform]' folder.
|
// If lib is in Present Working Directory's '.dart_tool/libgit2/[platform]' folder.
|
||||||
libPath = path.join(
|
var libPath = path.join(
|
||||||
Directory.current.path,
|
Directory.current.path,
|
||||||
libDir,
|
libDir,
|
||||||
Platform.operatingSystem,
|
Platform.operatingSystem,
|
||||||
|
@ -50,22 +60,30 @@ String? _resolveLibPath(String name) {
|
||||||
libPath = path.join(Directory.current.path, Platform.operatingSystem, name);
|
libPath = path.join(Directory.current.path, Platform.operatingSystem, name);
|
||||||
if (_doesFileExist(libPath)) return libPath;
|
if (_doesFileExist(libPath)) return libPath;
|
||||||
|
|
||||||
String checkCache(PubCache pubCache) {
|
// If lib is in executable's folder.
|
||||||
final pubCacheDir =
|
libPath = path.join(path.dirname(Platform.resolvedExecutable), name);
|
||||||
pubCache.getLatestVersion('libgit2dart')!.resolve()!.location;
|
|
||||||
return path.join(pubCacheDir.path, Platform.operatingSystem, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If lib is in Dart's '.pub_cache' folder.
|
|
||||||
libPath = checkCache(PubCache());
|
|
||||||
if (_doesFileExist(libPath)) return libPath;
|
if (_doesFileExist(libPath)) return libPath;
|
||||||
|
|
||||||
// If lib is in Flutter's '.pub_cache' folder.
|
// If lib is in executable's bundled 'lib' folder.
|
||||||
final env = Platform.environment;
|
libPath = path.join(path.dirname(Platform.resolvedExecutable), 'lib', name);
|
||||||
if (env.containsKey('FLUTTER_ROOT')) {
|
if (_doesFileExist(libPath)) return libPath;
|
||||||
final flutterPubCache =
|
|
||||||
PubCache(Directory(path.join(env['FLUTTER_ROOT']!, '.pub-cache')));
|
// If lib is installed in system dir.
|
||||||
libPath = checkCache(flutterPubCache);
|
if (Platform.isMacOS || Platform.isLinux) {
|
||||||
|
final paths = [
|
||||||
|
'/usr/local/lib/libgit2.$libgit2Version.dylib',
|
||||||
|
'/usr/local/lib/libgit2.so.$libgit2Version',
|
||||||
|
'/usr/lib64/libgit2.so.$libgit2Version'
|
||||||
|
];
|
||||||
|
for (final path in paths) {
|
||||||
|
if (_doesFileExist(path)) return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If lib is in '.pub_cache' folder.
|
||||||
|
final cachedLocation = checkCache();
|
||||||
|
if (cachedLocation != null) {
|
||||||
|
libPath = path.join(cachedLocation, Platform.operatingSystem, name);
|
||||||
if (_doesFileExist(libPath)) return libPath;
|
if (_doesFileExist(libPath)) return libPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,26 +92,15 @@ String? _resolveLibPath(String name) {
|
||||||
|
|
||||||
DynamicLibrary loadLibrary(String name) {
|
DynamicLibrary loadLibrary(String name) {
|
||||||
try {
|
try {
|
||||||
return DynamicLibrary.open(
|
return DynamicLibrary.open(_resolveLibPath(name) ?? name);
|
||||||
_resolveLibPath(name) ?? name,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
final logger = Logger.standard();
|
stderr.writeln(
|
||||||
final ansi = Ansi(Ansi.terminalSupportsAnsi);
|
'Failed to open the library. Make sure that libgit2 library is bundled '
|
||||||
|
'with the application.',
|
||||||
logger.stderr(
|
|
||||||
'${ansi.red}Failed to open the library. Make sure that libgit2 '
|
|
||||||
'library is bundled with the application.${ansi.none}',
|
|
||||||
);
|
);
|
||||||
logger.stdout(ansi.none);
|
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final libgit2 = Libgit2(loadLibrary(getLibName()));
|
final libgit2 = Libgit2(loadLibrary(getLibName()));
|
||||||
|
final libgit2Opts = Libgit2Opts(loadLibrary(getLibName()));
|
||||||
bool isValidShaHex(String str) {
|
|
||||||
final hexRegExp = RegExp(r'^[0-9a-fA-F]+$');
|
|
||||||
return hexRegExp.hasMatch(str) &&
|
|
||||||
(GIT_OID_MINPREFIXLEN <= str.length && GIT_OID_HEXSZ >= str.length);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:libgit2dart/libgit2dart.dart';
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||||
import 'package:libgit2dart/src/bindings/worktree.dart' as bindings;
|
import 'package:libgit2dart/src/bindings/worktree.dart' as bindings;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
class Worktree {
|
@immutable
|
||||||
|
class Worktree extends Equatable {
|
||||||
/// Creates new worktree.
|
/// Creates new worktree.
|
||||||
///
|
///
|
||||||
/// If [ref] is provided, no new branch will be created but specified [ref]
|
/// If [ref] is provided, no new branch will be created but specified [ref]
|
||||||
|
@ -74,10 +77,15 @@ class Worktree {
|
||||||
/// Throws a [LibGit2Error] if error occured.
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
bool get isPrunable => bindings.isPrunable(_worktreePointer);
|
bool get isPrunable => bindings.isPrunable(_worktreePointer);
|
||||||
|
|
||||||
/// Prunes working tree.
|
/// Prunes working tree, that is removes the git data structures on disk.
|
||||||
///
|
///
|
||||||
/// Prune the working tree, that is remove the git data structures on disk.
|
/// [flags] is optional combination of [GitWorktree] flags.
|
||||||
void prune() => bindings.prune(_worktreePointer);
|
void prune([Set<GitWorktree>? flags]) {
|
||||||
|
bindings.prune(
|
||||||
|
worktreePointer: _worktreePointer,
|
||||||
|
flags: flags?.fold(0, (acc, e) => acc! | e.value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether worktree is valid.
|
/// Whether worktree is valid.
|
||||||
///
|
///
|
||||||
|
@ -93,8 +101,12 @@ class Worktree {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Worktree{name: $name, path: $path}';
|
return 'Worktree{name: $name, path: $path, isLocked: $isLocked, '
|
||||||
|
'isPrunable: $isPrunable, isValid: $isValid}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [name, path, isLocked, isValid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// coverage:ignore-start
|
// coverage:ignore-start
|
||||||
|
|
|
@ -20,6 +20,6 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
|
||||||
|
|
||||||
# List of absolute paths to libraries that should be bundled with the plugin
|
# List of absolute paths to libraries that should be bundled with the plugin
|
||||||
set(libgit2dart_bundled_libraries
|
set(libgit2dart_bundled_libraries
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/libgit2-1.4.3.so"
|
"${CMAKE_CURRENT_SOURCE_DIR}/libgit2-1.5.0.so"
|
||||||
PARENT_SCOPE
|
PARENT_SCOPE
|
||||||
)
|
)
|
||||||
|
|
Binary file not shown.
BIN
linux/libgit2-1.5.0.so
Normal file
BIN
linux/libgit2-1.5.0.so
Normal file
Binary file not shown.
Binary file not shown.
BIN
macos/libgit2-1.5.0.dylib
Normal file
BIN
macos/libgit2-1.5.0.dylib
Normal file
Binary file not shown.
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'libgit2dart'
|
s.name = 'libgit2dart'
|
||||||
s.version = '1.0.0'
|
s.version = '1.2.2'
|
||||||
s.summary = 'Dart bindings to libgit2.'
|
s.summary = 'Dart bindings to libgit2.'
|
||||||
s.description = <<-DESC
|
s.description = <<-DESC
|
||||||
Dart bindings to libgit2.
|
Dart bindings to libgit2.
|
||||||
|
@ -15,7 +15,7 @@ Dart bindings to libgit2.
|
||||||
s.source = { :path => '.' }
|
s.source = { :path => '.' }
|
||||||
s.source_files = 'Classes/**/*'
|
s.source_files = 'Classes/**/*'
|
||||||
s.dependency 'FlutterMacOS'
|
s.dependency 'FlutterMacOS'
|
||||||
s.vendored_libraries = 'libgit2-1.4.3.dylib'
|
s.vendored_libraries = 'libgit2-1.5.0.dylib'
|
||||||
|
|
||||||
s.platform = :osx, '10.11'
|
s.platform = :osx, '10.11'
|
||||||
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
|
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
|
||||||
|
|
16
pubspec.yaml
16
pubspec.yaml
|
@ -1,25 +1,25 @@
|
||||||
name: libgit2dart
|
name: libgit2dart
|
||||||
|
|
||||||
description: Dart bindings to libgit2.
|
description: Dart bindings to libgit2, provides ability to use libgit2 library in Dart and Flutter.
|
||||||
|
|
||||||
version: 1.0.0
|
version: 1.2.2
|
||||||
|
|
||||||
homepage: https://github.com/SkinnyMind/libgit2dart
|
homepage: https://github.com/SkinnyMind/libgit2dart
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.17.0 <3.0.0"
|
sdk: ">=2.18.0 <3.0.0"
|
||||||
flutter: ">=2.13.0-0.0.pre.578"
|
flutter: ">=3.3.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
args: ^2.3.0
|
args: ^2.3.0
|
||||||
cli_util: ^0.3.5
|
equatable: ^2.0.3
|
||||||
ffi: ^1.1.2
|
ffi: ^2.0.0
|
||||||
meta: ^1.7.0
|
meta: ^1.7.0
|
||||||
path: ^1.8.1
|
path: ^1.8.1
|
||||||
pub_cache: ^0.3.1
|
pub_semver: ^2.1.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
ffigen: ^4.1.2
|
ffigen: ^6.0.1
|
||||||
lints: ^2.0.0
|
lints: ^2.0.0
|
||||||
test: ^1.20.0
|
test: ^1.20.0
|
||||||
|
|
||||||
|
|
|
@ -107,5 +107,12 @@ void main() {
|
||||||
final annotated = AnnotatedCommit.lookup(repo: repo, oid: tip);
|
final annotated = AnnotatedCommit.lookup(repo: repo, oid: tip);
|
||||||
expect(() => annotated.free(), returnsNormally);
|
expect(() => annotated.free(), returnsNormally);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
expect(
|
||||||
|
AnnotatedCommit.lookup(repo: repo, oid: tip),
|
||||||
|
equals(AnnotatedCommit.lookup(repo: repo, oid: tip)),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,5 +211,12 @@ void main() {
|
||||||
final blame = Blame.file(repo: repo, path: 'feature_file');
|
final blame = Blame.file(repo: repo, path: 'feature_file');
|
||||||
expect(blame.toString(), contains('BlameHunk{'));
|
expect(blame.toString(), contains('BlameHunk{'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
expect(
|
||||||
|
Blame.file(repo: repo, path: 'feature_file'),
|
||||||
|
equals(Blame.file(repo: repo, path: 'feature_file')),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,5 +153,12 @@ void main() {
|
||||||
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
final blob = Blob.lookup(repo: repo, oid: repo[blobSHA]);
|
||||||
expect(blob.toString(), contains('Blob{'));
|
expect(blob.toString(), contains('Blob{'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
expect(
|
||||||
|
Blob.lookup(repo: repo, oid: repo[blobSHA]),
|
||||||
|
equals(Blob.lookup(repo: repo, oid: repo[blobSHA])),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,5 +327,12 @@ void main() {
|
||||||
final branch = Branch.lookup(repo: repo, name: 'master');
|
final branch = Branch.lookup(repo: repo, name: 'master');
|
||||||
expect(branch.toString(), contains('Branch{'));
|
expect(branch.toString(), contains('Branch{'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
expect(
|
||||||
|
Branch.lookup(repo: repo, name: 'master'),
|
||||||
|
equals(Branch.lookup(repo: repo, name: 'master')),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,109 @@ void main() {
|
||||||
expect(file.existsSync(), false);
|
expect(file.existsSync(), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('reverts merge commit to provided parent', () {
|
||||||
|
const masterContents = 'master contents';
|
||||||
|
final file = File(p.join(repo.workdir, 'another_feature_file'))
|
||||||
|
..createSync()
|
||||||
|
..writeAsStringSync(masterContents);
|
||||||
|
|
||||||
|
repo.index.add('another_feature_file');
|
||||||
|
repo.index.write();
|
||||||
|
|
||||||
|
// Creating commit on 'master' branch with file contents conflicting to
|
||||||
|
// 'feature' branch.
|
||||||
|
final masterTip = Commit.create(
|
||||||
|
repo: repo,
|
||||||
|
updateRef: 'HEAD',
|
||||||
|
message: 'master commit\n',
|
||||||
|
author: author,
|
||||||
|
committer: committer,
|
||||||
|
tree: Tree.lookup(repo: repo, oid: repo.index.writeTree()),
|
||||||
|
parents: [Commit.lookup(repo: repo, oid: repo.head.target)],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Switching to 'feature' branch.
|
||||||
|
Checkout.reference(repo: repo, name: 'refs/heads/feature');
|
||||||
|
repo.setHead('refs/heads/feature');
|
||||||
|
|
||||||
|
file.writeAsStringSync('feature contents');
|
||||||
|
|
||||||
|
repo.index.add('another_feature_file');
|
||||||
|
repo.index.write();
|
||||||
|
|
||||||
|
// Creating commit on 'feature' branch with file contents conflicting to
|
||||||
|
// 'master' branch.
|
||||||
|
final featureTip = Commit.create(
|
||||||
|
repo: repo,
|
||||||
|
updateRef: 'HEAD',
|
||||||
|
message: 'feature commit\n',
|
||||||
|
author: author,
|
||||||
|
committer: committer,
|
||||||
|
tree: Tree.lookup(repo: repo, oid: repo.index.writeTree()),
|
||||||
|
parents: [Commit.lookup(repo: repo, oid: repo.head.target)],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Merging master branch.
|
||||||
|
Merge.commit(
|
||||||
|
repo: repo,
|
||||||
|
commit: AnnotatedCommit.lookup(
|
||||||
|
repo: repo,
|
||||||
|
oid: Oid.fromSHA(repo: repo, sha: masterTip.sha),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(repo.index.hasConflicts, true);
|
||||||
|
|
||||||
|
// "Resolving" conflict.
|
||||||
|
repo.index.updateAll(['another_feature_file']);
|
||||||
|
repo.index.write();
|
||||||
|
repo.stateCleanup();
|
||||||
|
|
||||||
|
// Creating merge commit.
|
||||||
|
final mergeOid = Commit.create(
|
||||||
|
repo: repo,
|
||||||
|
updateRef: 'HEAD',
|
||||||
|
message: 'merge commit\n',
|
||||||
|
author: author,
|
||||||
|
committer: committer,
|
||||||
|
tree: Tree.lookup(repo: repo, oid: repo.index.writeTree()),
|
||||||
|
parents: [
|
||||||
|
Commit.lookup(repo: repo, oid: featureTip),
|
||||||
|
Commit.lookup(repo: repo, oid: masterTip),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final mergeCommit = Commit.lookup(repo: repo, oid: mergeOid);
|
||||||
|
mergeCommit.revert(mainline: 2);
|
||||||
|
|
||||||
|
expect(file.readAsStringSync(), masterContents);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('reverts commit with provided merge options and checkout options', () {
|
||||||
|
final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||||
|
final file = File(p.join(repo.workdir, 'dir', 'dir_file.txt'));
|
||||||
|
expect(repo.index.find('dir/dir_file.txt'), true);
|
||||||
|
expect(file.existsSync(), true);
|
||||||
|
|
||||||
|
commit.revert(
|
||||||
|
mergeFavor: GitMergeFileFavor.ours,
|
||||||
|
mergeFlags: {GitMergeFlag.noRecursive, GitMergeFlag.skipREUC},
|
||||||
|
mergeFileFlags: {
|
||||||
|
GitMergeFileFlag.ignoreWhitespace,
|
||||||
|
GitMergeFileFlag.styleZdiff3
|
||||||
|
},
|
||||||
|
checkoutStrategy: {
|
||||||
|
GitCheckout.force,
|
||||||
|
GitCheckout.conflictStyleMerge,
|
||||||
|
},
|
||||||
|
checkoutDirectory: repo.workdir,
|
||||||
|
checkoutPaths: ['dir/dir_file.txt'],
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(repo.index.find('dir/dir_file.txt'), false);
|
||||||
|
expect(file.existsSync(), false);
|
||||||
|
});
|
||||||
|
|
||||||
test('throws when trying to revert and error occurs', () {
|
test('throws when trying to revert and error occurs', () {
|
||||||
expect(() => Commit(nullptr).revert(), throwsA(isA<LibGit2Error>()));
|
expect(() => Commit(nullptr).revert(), throwsA(isA<LibGit2Error>()));
|
||||||
});
|
});
|
||||||
|
@ -84,6 +187,25 @@ void main() {
|
||||||
expect(file.existsSync(), true);
|
expect(file.existsSync(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('reverts commit to provided commit with provided merge options', () {
|
||||||
|
final file = File(p.join(repo.workdir, 'dir', 'dir_file.txt'));
|
||||||
|
expect(repo.index.find('dir/dir_file.txt'), true);
|
||||||
|
expect(file.existsSync(), true);
|
||||||
|
|
||||||
|
final from = Commit.lookup(repo: repo, oid: repo['821ed6e']);
|
||||||
|
final revertIndex = from.revertTo(
|
||||||
|
commit: Commit.lookup(repo: repo, oid: repo['78b8bf1']),
|
||||||
|
mergeFavor: GitMergeFileFavor.ours,
|
||||||
|
mergeFlags: {GitMergeFlag.noRecursive, GitMergeFlag.skipREUC},
|
||||||
|
mergeFileFlags: {
|
||||||
|
GitMergeFileFlag.ignoreWhitespace,
|
||||||
|
GitMergeFileFlag.styleZdiff3
|
||||||
|
},
|
||||||
|
);
|
||||||
|
expect(revertIndex.find('dir/dir_file.txt'), false);
|
||||||
|
expect(file.existsSync(), true);
|
||||||
|
});
|
||||||
|
|
||||||
test('throws when trying to revert commit and error occurs', () {
|
test('throws when trying to revert commit and error occurs', () {
|
||||||
final nullCommit = Commit(nullptr);
|
final nullCommit = Commit(nullptr);
|
||||||
expect(
|
expect(
|
||||||
|
@ -396,5 +518,12 @@ Some description.
|
||||||
final commit = Commit.lookup(repo: repo, oid: tip);
|
final commit = Commit.lookup(repo: repo, oid: tip);
|
||||||
expect(commit.toString(), contains('Commit{'));
|
expect(commit.toString(), contains('Commit{'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
expect(
|
||||||
|
Commit.lookup(repo: repo, oid: tip),
|
||||||
|
equals(Commit.lookup(repo: repo, oid: tip)),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,5 +217,9 @@ void main() {
|
||||||
final entry = config.first;
|
final entry = config.first;
|
||||||
expect(entry.toString(), contains('ConfigEntry{'));
|
expect(entry.toString(), contains('ConfigEntry{'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
expect(Config.open(filePath), equals(Config.open(filePath)));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,10 +83,7 @@ void main() {
|
||||||
cloneDir.deleteSync(recursive: true);
|
cloneDir.deleteSync(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('clones repository with provided keypair', () {
|
||||||
testOn: '!linux',
|
|
||||||
'clones repository with provided keypair',
|
|
||||||
() {
|
|
||||||
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
||||||
final keypair = Keypair(
|
final keypair = Keypair(
|
||||||
username: 'git',
|
username: 'git',
|
||||||
|
@ -107,8 +104,7 @@ void main() {
|
||||||
if (Platform.isLinux || Platform.isMacOS) {
|
if (Platform.isLinux || Platform.isMacOS) {
|
||||||
cloneDir.deleteSync(recursive: true);
|
cloneDir.deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
test('throws when no credentials is provided', () {
|
test('throws when no credentials is provided', () {
|
||||||
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
||||||
|
@ -189,10 +185,7 @@ void main() {
|
||||||
cloneDir.deleteSync(recursive: true);
|
cloneDir.deleteSync(recursive: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('clones repository with provided keypair from memory', () {
|
||||||
testOn: '!linux',
|
|
||||||
'clones repository with provided keypair from memory',
|
|
||||||
() {
|
|
||||||
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
||||||
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
|
final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub'))
|
||||||
.readAsStringSync();
|
.readAsStringSync();
|
||||||
|
@ -217,8 +210,7 @@ void main() {
|
||||||
if (Platform.isLinux || Platform.isMacOS) {
|
if (Platform.isLinux || Platform.isMacOS) {
|
||||||
cloneDir.deleteSync(recursive: true);
|
cloneDir.deleteSync(recursive: true);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
test('throws when provided keypair from memory is incorrect', () {
|
test('throws when provided keypair from memory is incorrect', () {
|
||||||
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
final cloneDir = Directory.systemTemp.createTempSync('clone');
|
||||||
|
|
|
@ -580,5 +580,15 @@ index e69de29..c217c63 100644
|
||||||
expect(patch.delta.oldFile.toString(), contains('DiffFile{'));
|
expect(patch.delta.oldFile.toString(), contains('DiffFile{'));
|
||||||
expect(stats.toString(), contains('DiffStats{'));
|
expect(stats.toString(), contains('DiffStats{'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
expect(Diff.parse(patchText), equals(Diff.parse(patchText)));
|
||||||
|
|
||||||
|
final diff = Diff.parse(patchText);
|
||||||
|
expect(diff.deltas[0], equals(diff.deltas[0]));
|
||||||
|
|
||||||
|
final delta = diff.deltas[0];
|
||||||
|
expect(delta.oldFile, equals(delta.oldFile));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -551,4 +551,25 @@ void main() {
|
||||||
expect(actual, expected);
|
expect(actual, expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('GitIndexAddOption returns correct values', () {
|
||||||
|
const expected = {
|
||||||
|
GitIndexAddOption.defaults: 0,
|
||||||
|
GitIndexAddOption.force: 1,
|
||||||
|
GitIndexAddOption.disablePathspecMatch: 2,
|
||||||
|
GitIndexAddOption.checkPathspec: 4,
|
||||||
|
};
|
||||||
|
final actual = {for (final e in GitIndexAddOption.values) e: e.value};
|
||||||
|
expect(actual, expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GitWorktree returns correct values', () {
|
||||||
|
const expected = {
|
||||||
|
GitWorktree.pruneValid: 1,
|
||||||
|
GitWorktree.pruneLocked: 2,
|
||||||
|
GitWorktree.pruneWorkingTree: 4,
|
||||||
|
};
|
||||||
|
final actual = {for (final e in GitWorktree.values) e: e.value};
|
||||||
|
expect(actual, expected);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,10 @@ void main() {
|
||||||
group('addAll()', () {
|
group('addAll()', () {
|
||||||
test('adds with provided pathspec', () {
|
test('adds with provided pathspec', () {
|
||||||
index.clear();
|
index.clear();
|
||||||
index.addAll(['file', 'feature_file']);
|
index.addAll(
|
||||||
|
['file', 'feature_file'],
|
||||||
|
flags: {GitIndexAddOption.checkPathspec, GitIndexAddOption.force},
|
||||||
|
);
|
||||||
|
|
||||||
expect(index.length, 2);
|
expect(index.length, 2);
|
||||||
expect(index['file'].oid.sha, fileSha);
|
expect(index['file'].oid.sha, fileSha);
|
||||||
|
@ -509,5 +512,9 @@ void main() {
|
||||||
expect(index.toString(), contains('Index{'));
|
expect(index.toString(), contains('Index{'));
|
||||||
expect(index['file'].toString(), contains('IndexEntry{'));
|
expect(index['file'].toString(), contains('IndexEntry{'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
expect(repo.index, equals(repo.index));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,202 @@ void main() {
|
||||||
'directories', () {
|
'directories', () {
|
||||||
final oldValue = Libgit2.ownerValidation;
|
final oldValue = Libgit2.ownerValidation;
|
||||||
Libgit2.ownerValidation = !oldValue;
|
Libgit2.ownerValidation = !oldValue;
|
||||||
expect(Libgit2.ownerValidation, equals(!oldValue));
|
expect(Libgit2.ownerValidation, isNot(oldValue));
|
||||||
|
|
||||||
// Set it back
|
// Reset to avoid side effects in later tests
|
||||||
Libgit2.ownerValidation = oldValue;
|
Libgit2.ownerValidation = oldValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('sets and returns the maximum mmap window size', () {
|
||||||
|
final oldValue = Libgit2.mmapWindowSize;
|
||||||
|
Libgit2.mmapWindowSize = 420 * 1024;
|
||||||
|
expect(Libgit2.mmapWindowSize, isNot(oldValue));
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.mmapWindowSize = oldValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'sets and returns the maximum memory that will be mapped in total by '
|
||||||
|
'the library', () {
|
||||||
|
final oldValue = Libgit2.mmapWindowMappedLimit;
|
||||||
|
Libgit2.mmapWindowMappedLimit = 420 * 1024;
|
||||||
|
expect(Libgit2.mmapWindowMappedLimit, isNot(oldValue));
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.mmapWindowMappedLimit = oldValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'sets and returns the maximum number of files that will be mapped '
|
||||||
|
'at any time by the library', () {
|
||||||
|
final oldValue = Libgit2.mmapWindowFileLimit;
|
||||||
|
Libgit2.mmapWindowFileLimit = 69;
|
||||||
|
expect(Libgit2.mmapWindowFileLimit, isNot(oldValue));
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.mmapWindowFileLimit = oldValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets and returns the search path for a given level of config data',
|
||||||
|
() {
|
||||||
|
const paths = '/tmp/global:/tmp/another';
|
||||||
|
Libgit2.setConfigSearchPath(level: GitConfigLevel.global, path: paths);
|
||||||
|
expect(Libgit2.getConfigSearchPath(GitConfigLevel.global), paths);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.setConfigSearchPath(level: GitConfigLevel.global, path: null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'sets the maximum data size for the given type of object '
|
||||||
|
'to be considered eligible for caching in memory', () {
|
||||||
|
expect(
|
||||||
|
() => Libgit2.setCacheObjectLimit(type: GitObject.blob, value: 420),
|
||||||
|
returnsNormally,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.setCacheObjectLimit(type: GitObject.blob, value: 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets the maximum cache size', () {
|
||||||
|
expect(Libgit2.cachedMemory.allowed, 256 * (1024 * 1024));
|
||||||
|
|
||||||
|
Libgit2.setCacheMaxSize(128 * (1024 * 1024));
|
||||||
|
|
||||||
|
expect(Libgit2.cachedMemory.allowed, 128 * (1024 * 1024));
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.setCacheMaxSize(256 * (1024 * 1024));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns CachedMemory object', () {
|
||||||
|
expect(Libgit2.cachedMemory.allowed, 256 * (1024 * 1024));
|
||||||
|
expect(Libgit2.cachedMemory.toString(), contains('CachedMemory{'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('disables and enables caching', () {
|
||||||
|
expect(() => Libgit2.disableCaching(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.enableCaching();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets and returns the default template path', () {
|
||||||
|
final oldValue = Libgit2.templatePath;
|
||||||
|
Libgit2.templatePath = '/tmp/template';
|
||||||
|
expect(Libgit2.templatePath, isNot(oldValue));
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.templatePath = oldValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets location for ssl certificates', () {
|
||||||
|
expect(
|
||||||
|
() => Libgit2.setSSLCertLocations(file: 'etc/ssl/cert.pem'),
|
||||||
|
returnsNormally,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
() => Libgit2.setSSLCertLocations(path: 'etc/ssl/certs/'),
|
||||||
|
returnsNormally,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('throws when trying to set both ssl certificates location to null',
|
||||||
|
() {
|
||||||
|
expect(
|
||||||
|
() => Libgit2.setSSLCertLocations(),
|
||||||
|
throwsA(isA<ArgumentError>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets and returns the User-Agent header', () {
|
||||||
|
final oldValue = Libgit2.userAgent;
|
||||||
|
Libgit2.userAgent = 'Mozilla/5.0';
|
||||||
|
expect(Libgit2.userAgent, isNot(oldValue));
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.userAgent = oldValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('disables and enables strict object creation', () {
|
||||||
|
expect(() => Libgit2.disableStrictObjectCreation(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.enableStrictObjectCreation();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('disables and enables strict symbolic reference creation', () {
|
||||||
|
expect(() => Libgit2.disableStrictSymbolicRefCreation(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.enableStrictSymbolicRefCreation();
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'disables and enables the use of offset deltas when creating packfiles',
|
||||||
|
() {
|
||||||
|
expect(() => Libgit2.disableOffsetDelta(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.enableOffsetDelta();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('enables and disables the fsync of files in gitdir', () {
|
||||||
|
expect(() => Libgit2.enableFsyncGitdir(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.disableFsyncGitdir();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('disables and enables strict hash verification', () {
|
||||||
|
expect(() => Libgit2.disableStrictHashVerification(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.enableStrictHashVerification();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('disables and enables check for unsaved changes in index', () {
|
||||||
|
expect(() => Libgit2.disableUnsavedIndexSafety(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.enableUnsavedIndexSafety();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets and returns the pack maximum objects', () {
|
||||||
|
final oldValue = Libgit2.packMaxObjects;
|
||||||
|
Libgit2.packMaxObjects = 69;
|
||||||
|
expect(Libgit2.packMaxObjects, isNot(oldValue));
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.packMaxObjects = oldValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('disables and enables check for unsaved changes in index', () {
|
||||||
|
expect(() => Libgit2.disablePackKeepFileChecks(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.enablePackKeepFileChecks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'disables and enables check for unsaved changes in index',
|
||||||
|
testOn: '!windows',
|
||||||
|
() {
|
||||||
|
expect(() => Libgit2.disableHttpExpectContinue(), returnsNormally);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.enableHttpExpectContinue();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('sets and returns the list of git extensions', () {
|
||||||
|
Libgit2.extensions = ['newext', 'anotherext'];
|
||||||
|
expect(Libgit2.extensions, ['noop', 'newext', 'anotherext']);
|
||||||
|
|
||||||
|
// Reset to avoid side effects in later tests
|
||||||
|
Libgit2.extensions = ['!newext', '!anotherext'];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,31 +168,38 @@ Another feature edit
|
||||||
expect(diff, diffExpected);
|
expect(diff, diffExpected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('merges with provided merge flags and file flags', () {
|
test('merges with provided options', () {
|
||||||
const diffExpected = """
|
const diffExpected = """
|
||||||
\<<<<<<< conflict_file
|
\<<<<<<< ours
|
||||||
master conflict edit
|
Feature edit on feature branch
|
||||||
|
||||||| ancestor
|
||||||
|
Feature edit
|
||||||
=======
|
=======
|
||||||
conflict branch edit
|
Another feature edit
|
||||||
>>>>>>> conflict_file
|
>>>>>>> theirs
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
Checkout.reference(repo: repo, name: 'refs/heads/feature');
|
||||||
|
repo.setHead('refs/heads/feature');
|
||||||
|
|
||||||
Merge.commit(
|
Merge.commit(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
commit: AnnotatedCommit.lookup(
|
commit: AnnotatedCommit.lookup(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
oid: Branch.lookup(repo: repo, name: 'conflict-branch').target,
|
oid: Branch.lookup(repo: repo, name: 'ancestor-conflict').target,
|
||||||
),
|
),
|
||||||
mergeFlags: {GitMergeFlag.noRecursive},
|
|
||||||
fileFlags: {GitMergeFileFlag.ignoreWhitespaceEOL},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final conflictedFile = repo.index.conflicts['conflict_file']!;
|
final conflictedFile = repo.index.conflicts['feature_file']!;
|
||||||
final diff = Merge.fileFromIndex(
|
final diff = Merge.fileFromIndex(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
ancestor: null,
|
ancestor: conflictedFile.ancestor,
|
||||||
|
ancestorLabel: 'ancestor',
|
||||||
ours: conflictedFile.our!,
|
ours: conflictedFile.our!,
|
||||||
|
oursLabel: 'ours',
|
||||||
theirs: conflictedFile.their!,
|
theirs: conflictedFile.their!,
|
||||||
|
theirsLabel: 'theirs',
|
||||||
|
flags: {GitMergeFileFlag.styleDiff3},
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(diff, diffExpected);
|
expect(diff, diffExpected);
|
||||||
|
|
|
@ -134,5 +134,13 @@ void main() {
|
||||||
final note = Note.lookup(repo: repo, annotatedOid: repo['821ed6e']);
|
final note = Note.lookup(repo: repo, annotatedOid: repo['821ed6e']);
|
||||||
expect(note.toString(), contains('Note{'));
|
expect(note.toString(), contains('Note{'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('supports value comparison', () {
|
||||||
|
final oid = repo.head.target;
|
||||||
|
expect(
|
||||||
|
Note.lookup(repo: repo, annotatedOid: oid),
|
||||||
|
equals(Note.lookup(repo: repo, annotatedOid: oid)),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue