mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
Compare commits
2 commits
c35d336a56
...
4aea9a306a
Author | SHA1 | Date | |
---|---|---|---|
|
4aea9a306a | ||
|
ae2aef5e2e |
16 changed files with 79 additions and 108 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -1,3 +1,15 @@
|
||||||
|
## 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.
|
||||||
|
|
|
@ -13,10 +13,10 @@ 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++)
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||||
}
|
];
|
||||||
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
|
@ -162,11 +162,13 @@ 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++)
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||||
}
|
];
|
||||||
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,11 +255,13 @@ 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++)
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||||
}
|
];
|
||||||
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,11 +270,13 @@ 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++)
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||||
}
|
];
|
||||||
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,6 @@ 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,
|
||||||
|
|
|
@ -110,11 +110,13 @@ 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++)
|
||||||
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
|
out.ref.strings[i].cast<Utf8>().toDartString()
|
||||||
}
|
];
|
||||||
|
|
||||||
calloc.free(out);
|
calloc.free(out);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,18 +264,11 @@ class Commit extends Equatable {
|
||||||
|
|
||||||
/// 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].
|
||||||
|
|
|
@ -285,28 +285,18 @@ class Diff extends Equatable {
|
||||||
/// 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.
|
||||||
|
|
|
@ -237,10 +237,10 @@ class Patch extends Equatable {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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._(
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -203,14 +203,9 @@ class Reference extends Equatable {
|
||||||
///
|
///
|
||||||
/// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively peel reference until object of the specified [type] is found.
|
/// Recursively peel reference until object of the specified [type] is found.
|
||||||
|
|
|
@ -211,20 +211,16 @@ class Remote extends Equatable {
|
||||||
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.
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -43,14 +43,12 @@ class Stash extends Equatable {
|
||||||
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),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,11 +208,7 @@ class Tag extends Equatable {
|
||||||
/// 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.
|
||||||
|
|
|
@ -35,19 +35,10 @@ class Tree extends Equatable {
|
||||||
/// 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.
|
||||||
|
|
|
@ -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.1.0'
|
||||||
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.
|
||||||
|
|
|
@ -2,7 +2,7 @@ name: libgit2dart
|
||||||
|
|
||||||
description: Dart bindings to libgit2, provides ability to use libgit2 library in Dart and Flutter.
|
description: Dart bindings to libgit2, provides ability to use libgit2 library in Dart and Flutter.
|
||||||
|
|
||||||
version: 1.0.0
|
version: 1.1.0
|
||||||
|
|
||||||
homepage: https://github.com/SkinnyMind/libgit2dart
|
homepage: https://github.com/SkinnyMind/libgit2dart
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue