feat(repository)!: add more aliases for api methods

BREAKING CHANGE: Make repository entry point for most operations
This commit is contained in:
Aleksey Kulikov 2021-10-11 20:06:36 +03:00
parent 9205a3ad82
commit 3a0fa75929
51 changed files with 1380 additions and 1062 deletions

View file

@ -9,7 +9,7 @@ import '../util.dart';
/// Return a list of branches.
///
/// Throws a [LibGit2Error] if error occured.
List<String> list({
List<Pointer<git_reference>> list({
required Pointer<git_repository> repoPointer,
required int flags,
}) {
@ -24,7 +24,7 @@ List<String> list({
throw LibGit2Error(libgit2.git_error_last());
}
var result = <String>[];
var result = <Pointer<git_reference>>[];
var error = 0;
while (error == 0) {
@ -32,10 +32,8 @@ List<String> list({
final refType = calloc<Int32>();
error = libgit2.git_branch_next(reference, refType, iterator.value);
if (error == 0) {
final refName = reference_bindings.shorthand(reference.value);
result.add(refName);
result.add(reference.value);
calloc.free(refType);
calloc.free(reference);
} else {
break;
}
@ -129,11 +127,8 @@ void delete(Pointer<git_reference> branch) {
///
/// The new branch name will be checked for validity.
///
/// Note that if the move succeeds, the old reference object will not be valid anymore,
/// and will be freed immediately.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> rename({
void rename({
required Pointer<git_reference> branchPointer,
required String newBranchName,
required bool force,
@ -149,8 +144,7 @@ Pointer<git_reference> rename({
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
reference_bindings.free(branchPointer);
return out.value;
reference_bindings.free(out.value);
}
}

View file

@ -3,7 +3,6 @@ import 'package:ffi/ffi.dart';
import '../error.dart';
import 'libgit2_bindings.dart';
import '../util.dart';
import 'oid.dart' as oid_bindings;
/// Lookup a commit object from a repository.
///
@ -92,26 +91,21 @@ Pointer<git_oid> create({
required String message,
required Pointer<git_tree> treePointer,
required int parentCount,
required List<String> parents,
required List<Pointer<git_commit>> parents,
}) {
final out = calloc<git_oid>();
final updateRefC = updateRef?.toNativeUtf8().cast<Int8>() ?? nullptr;
final messageEncodingC =
messageEncoding?.toNativeUtf8().cast<Int8>() ?? nullptr;
final messageC = message.toNativeUtf8().cast<Int8>();
Pointer<Pointer<git_commit>> parentsC =
calloc.call<Pointer<git_commit>>(parentCount);
final parentsC = calloc<Pointer<git_commit>>(parentCount);
if (parents.isNotEmpty) {
for (var i = 0; i < parentCount; i++) {
final oid = oid_bindings.fromSHA(parents[i]);
var commit = calloc<IntPtr>();
commit = lookup(repoPointer: repoPointer, oidPointer: oid).cast();
parentsC[i] = commit.cast();
parentsC[i] = parents[i];
}
} else {
final commit = calloc<IntPtr>();
parentsC[0] = commit.cast();
parentsC[0] = nullptr;
}
final error = libgit2.git_commit_create(
@ -130,9 +124,6 @@ Pointer<git_oid> create({
calloc.free(updateRefC);
calloc.free(messageEncodingC);
calloc.free(messageC);
for (var i = 0; i < parentCount; i++) {
free(parentsC[i]);
}
calloc.free(parentsC);
if (error < 0) {

View file

@ -107,10 +107,10 @@ Pointer<git_oid> create({
}
}
/// Remove the note for an object.
/// Delete the note for an object.
///
/// Throws a [LibGit2Error] if error occured.
void remove({
void delete({
required Pointer<git_repository> repoPointer,
String notesRef = 'refs/notes/commits',
required Pointer<git_signature> authorPointer,

View file

@ -130,5 +130,5 @@ void remove({
}
}
/// Free a tree builder to release memory.
/// Free a tree builder and all the entries to release memory.
void free(Pointer<git_treebuilder> bld) => libgit2.git_treebuilder_free(bld);

View file

@ -20,13 +20,22 @@ Pointer<git_worktree> create({
final out = calloc<Pointer<git_worktree>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final pathC = path.toNativeUtf8().cast<Int8>();
final opts =
calloc<git_worktree_add_options>(sizeOf<git_worktree_add_options>());
opts.ref.version = 1;
opts.ref.lock = 0;
final opts = calloc<git_worktree_add_options>();
final optsError = libgit2.git_worktree_add_options_init(
opts,
GIT_WORKTREE_ADD_OPTIONS_VERSION,
);
if (optsError < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
opts.ref.ref = nullptr;
if (refPointer != null) {
opts.ref.ref = refPointer;
}
final error = libgit2.git_worktree_add(out, repoPointer, nameC, pathC, opts);
calloc.free(nameC);
@ -82,6 +91,7 @@ List<String> list(Pointer<git_repository> repo) {
final result = <String>[];
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
for (var i = 0; i < out.ref.count; i++) {

View file

@ -8,18 +8,16 @@ class Blob {
/// Initializes a new instance of [Blob] class from provided pointer to
/// blob object in memory.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
Blob(this._blobPointer);
/// Initializes a new instance of [Blob] class from provided
/// [Repository] object and [sha] hex string.
/// Lookups a blob object for provided [id] in a [repo]sitory.
///
/// Should be freed with `free()` to release allocated memory.
Blob.lookup({required Repository repo, required String sha}) {
final oid = Oid.fromSHA(repo: repo, sha: sha);
/// Should be freed to release allocated memory.
Blob.lookup({required Repository repo, required Oid id}) {
_blobPointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
oidPointer: id.pointer,
);
}

View file

@ -4,134 +4,131 @@ import 'bindings/libgit2_bindings.dart';
import 'bindings/branch.dart' as bindings;
import 'bindings/reference.dart' as reference_bindings;
class Branches {
/// Initializes a new instance of the [Branches] class
/// from provided [Repository] object.
Branches(Repository repo) {
_repoPointer = repo.pointer;
}
/// Pointer to memory address for allocated repository object.
late final Pointer<git_repository> _repoPointer;
/// Returns a list of all branches that can be found in a repository.
class Branch {
/// Initializes a new instance of [Branch] class from provided pointer to
/// branch object in memory.
///
/// Throws a [LibGit2Error] if error occured.
List<String> list() {
return bindings.list(
repoPointer: _repoPointer,
flags: GitBranch.all.value,
);
}
/// Returns a list of local branches that can be found in a repository.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get local {
return bindings.list(
repoPointer: _repoPointer,
flags: GitBranch.local.value,
);
}
/// Returns a list of remote branches that can be found in a repository.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get remote {
return bindings.list(
repoPointer: _repoPointer,
flags: GitBranch.remote.value,
);
}
/// Lookups a branch by its name in a repository.
///
/// The generated reference must be freed. The branch name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Branch operator [](String branchName) {
final ref = Reference(
reference_bindings.lookupDWIM(
repoPointer: _repoPointer,
name: branchName,
),
);
late final GitBranch type;
ref.isBranch ? type = GitBranch.local : GitBranch.remote;
ref.free();
return Branch(bindings.lookup(
repoPointer: _repoPointer,
branchName: branchName,
branchType: type.value,
));
}
/// Should be freed with [free] to release allocated memory when no longer
/// needed.
Branch(this._branchPointer);
/// Creates a new branch pointing at a [target] commit.
///
/// A new direct reference will be created pointing to this target commit.
/// If [force] is true and a reference already exists with the given name, it'll be replaced.
///
/// The returned reference must be freed.
/// Should be freed with [free] to release allocated memory when no longer
/// needed.
///
/// The branch name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Reference create({
Branch.create({
required Repository repo,
required String name,
required Commit target,
bool force = false,
}) {
return Reference(bindings.create(
repoPointer: _repoPointer,
_branchPointer = bindings.create(
repoPointer: repo.pointer,
branchName: name,
targetPointer: target.pointer,
force: force,
));
);
}
}
class Branch {
/// Initializes a new instance of [Branch] class from provided pointer to
/// branch object in memory.
/// Lookups a branch by its [name] in a [repo]sitory.
///
/// Should be freed with `free()` to release allocated memory.
const Branch(this._branchPointer);
/// The branch name will be checked for validity.
///
/// Should be freed with [free] to release allocated memory when no longer
/// needed.
///
/// Throws a [LibGit2Error] if error occured.
Branch.lookup({required Repository repo, required String name}) {
final ref = Reference(
reference_bindings.lookupDWIM(
repoPointer: repo.pointer,
name: name,
),
);
late final GitBranch type;
ref.isBranch ? type = GitBranch.local : GitBranch.remote;
ref.free();
_branchPointer = bindings.lookup(
repoPointer: repo.pointer,
branchName: name,
branchType: type.value,
);
}
late final Pointer<git_reference> _branchPointer;
/// Pointer to memory address for allocated branch object.
final Pointer<git_reference> _branchPointer;
Pointer<git_reference> get pointer => _branchPointer;
/// Returns the OID pointed to by a branch.
/// Returns a list of branches that can be found in a [repo]sitory for provided [type].
/// Default is all branches (local and remote).
///
/// Throws an exception if error occured.
Oid get target => Oid(reference_bindings.target(_branchPointer));
/// IMPORTANT: Branches must be freed manually when no longer needed to prevent
/// memory leak.
///
/// Throws a [LibGit2Error] if error occured.
static List<Branch> list({
required Repository repo,
GitBranch type = GitBranch.all,
}) {
final pointers = bindings.list(
repoPointer: repo.pointer,
flags: type.value,
);
final result = <Branch>[];
for (var pointer in pointers) {
result.add(Branch(pointer));
}
return result;
}
/// Deletes an existing branch reference.
///
/// Note that if the deletion succeeds, the reference object will not be valid anymore,
/// and will be freed.
///
/// Throws a [LibGit2Error] if error occured.
void delete() => bindings.delete(_branchPointer);
static void delete({required Repository repo, required String name}) {
final branch = Branch.lookup(repo: repo, name: name);
bindings.delete(branch.pointer);
}
/// Renames an existing local branch reference.
///
/// The new branch name will be checked for validity.
///
/// Note that if the move succeeds, the old reference object will not be valid anymore,
/// and will be freed immediately.
///
/// If [force] is true, existing branch will be overwritten.
///
/// Throws a [LibGit2Error] if error occured.
Branch rename({required String newName, bool force = false}) {
return Branch(bindings.rename(
branchPointer: _branchPointer,
static void rename({
required Repository repo,
required String oldName,
required String newName,
bool force = false,
}) {
final branch = Branch.lookup(repo: repo, name: oldName);
bindings.rename(
branchPointer: branch.pointer,
newBranchName: newName,
force: force,
));
);
branch.free();
}
/// Returns the OID pointed to by a branch.
///
/// Throws an exception if error occured.
Oid get target => Oid(reference_bindings.target(_branchPointer));
/// Checks if HEAD points to the given branch.
///
/// Throws a [LibGit2Error] if error occured.
@ -155,4 +152,9 @@ class Branch {
/// Releases memory allocated for branch object.
void free() => bindings.free(_branchPointer);
@override
String toString() {
return 'Branch{name: $name, target: $target}';
}
}

View file

@ -8,18 +8,16 @@ class Commit {
/// Initializes a new instance of [Commit] class from provided pointer to
/// commit object in memory.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
Commit(this._commitPointer);
/// Initializes a new instance of [Commit] class from provided [Repository] object
/// and [sha] hex string.
/// Lookups commit object for provided [id] in a [repo]sitory.
///
/// Should be freed with `free()` to release allocated memory.
Commit.lookup({required Repository repo, required String sha}) {
final oid = Oid.fromSHA(repo: repo, sha: sha);
/// Should be freed to release allocated memory.
Commit.lookup({required Repository repo, required Oid id}) {
_commitPointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
oidPointer: id.pointer,
);
}
@ -42,14 +40,14 @@ class Commit {
required String message,
required Signature author,
required Signature commiter,
required String treeSHA,
required List<String> parents,
required Tree tree,
required List<Commit> parents,
String? updateRef,
String? messageEncoding,
}) {
final tree = Tree.lookup(repo: repo, sha: treeSHA);
final parentsPointers = parents.map((parent) => parent.pointer).toList();
final result = Oid(bindings.create(
return Oid(bindings.create(
repoPointer: repo.pointer,
updateRef: updateRef,
authorPointer: author.pointer,
@ -58,12 +56,8 @@ class Commit {
message: message,
treePointer: tree.pointer,
parentCount: parents.length,
parents: parents,
parents: parentsPointers,
));
tree.free();
return result;
}
/// Returns the encoding for the message of a commit, as a string

View file

@ -139,25 +139,9 @@ class Index with IterableMixin<IndexEntry> {
bindings.read(indexPointer: _indexPointer, force: force);
/// Updates the contents of an existing index object in memory by reading from the
/// specified tree.
void readTree(Object target) {
late final Tree tree;
if (target is Oid) {
final repo = Repository(bindings.owner(_indexPointer));
tree = Tree.lookup(repo: repo, sha: target.sha);
} else if (target is Tree) {
tree = target;
} else if (target is String) {
final repo = Repository(bindings.owner(_indexPointer));
tree = Tree.lookup(repo: repo, sha: target);
} else {
throw ArgumentError.value(
'$target should be either Oid object, SHA hex string or Tree object');
}
/// specified [tree].
void readTree(Tree tree) {
bindings.readTree(indexPointer: _indexPointer, treePointer: tree.pointer);
tree.free();
}
/// Writes an existing index object from memory back to disk using an atomic file lock.

View file

@ -3,43 +3,44 @@ import 'package:libgit2dart/libgit2dart.dart';
import 'bindings/libgit2_bindings.dart';
import 'bindings/note.dart' as bindings;
class Notes {
/// Initializes a new instance of the [Notes] class from
/// provided [Repository] object.
Notes(Repository repo) {
_repoPointer = repo.pointer;
}
class Note {
/// Initializes a new instance of the [Note] class from provided
/// pointer to note and annotatedId objects in memory.
Note(this._notePointer, this._annotatedIdPointer);
/// Pointer to memory address for allocated repository object.
late final Pointer<git_repository> _repoPointer;
/// Reads the note for an object.
/// Reads the note for an [annotatedId].
///
/// The note must be freed manually by the user.
/// IMPORTANT: Notes must be freed manually when no longer needed to prevent
/// memory leak.
///
/// Throws a [LibGit2Error] if error occured.
static Note lookup({
Note.lookup({
required Repository repo,
required Oid annotatedId,
String notesRef = 'refs/notes/commits',
}) {
final note = bindings.lookup(
_notePointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: annotatedId.pointer,
notesRef: notesRef,
);
return Note(note, annotatedId.pointer, repo.pointer);
_annotatedIdPointer = annotatedId.pointer;
}
/// Adds a note for an [object].
/// Pointer to memory address for allocated note object.
late final Pointer<git_note> _notePointer;
/// Pointer to memory address for allocated annotetedId object.
late final Pointer<git_oid> _annotatedIdPointer;
/// Adds a note for an [annotatedId].
///
/// Throws a [LibGit2Error] if error occured.
static Oid create({
required Repository repo,
required Signature author,
required Signature committer,
required Oid object,
required Oid annotatedId,
required String note,
String notesRef = 'refs/notes/commits',
bool force = false,
@ -48,62 +49,49 @@ class Notes {
repoPointer: repo.pointer,
authorPointer: author.pointer,
committerPointer: committer.pointer,
oidPointer: object.pointer,
oidPointer: annotatedId.pointer,
note: note,
notesRef: notesRef,
force: force,
));
}
/// Returns list of notes for repository.
///
/// Notes must be freed manually by the user.
/// Deletes the note for an [annotatedId].
///
/// Throws a [LibGit2Error] if error occured.
List<Note> get list {
final notesPointers = bindings.list(_repoPointer);
static void delete({
required Repository repo,
required Oid annotatedId,
required Signature author,
required Signature committer,
String notesRef = 'refs/notes/commits',
}) {
bindings.delete(
repoPointer: repo.pointer,
authorPointer: author.pointer,
committerPointer: committer.pointer,
oidPointer: annotatedId.pointer,
);
}
/// Returns list of notes for repository.
///
/// IMPORTANT: Notes must be freed manually when no longer needed to prevent
/// memory leak.
///
/// Throws a [LibGit2Error] if error occured.
static List<Note> list(Repository repo) {
final notesPointers = bindings.list(repo.pointer);
var result = <Note>[];
for (var note in notesPointers) {
result.add(Note(
note['note'] as Pointer<git_note>,
note['annotatedId'] as Pointer<git_oid>,
_repoPointer,
));
}
return result;
}
}
class Note {
/// Initializes a new instance of the [Note] class from provided
/// pointer to note object in memory.
Note(this._notePointer, this._annotatedIdPointer, this._repoPointer);
/// Pointer to memory address for allocated note object.
final Pointer<git_note> _notePointer;
/// Pointer to memory address for allocated annotetedId object.
final Pointer<git_oid> _annotatedIdPointer;
/// Pointer to memory address for allocated repository object.
final Pointer<git_repository> _repoPointer;
/// Removes the note for an [object].
///
/// Throws a [LibGit2Error] if error occured.
void remove({
required Signature author,
required Signature committer,
String notesRef = 'refs/notes/commits',
}) {
bindings.remove(
repoPointer: _repoPointer,
authorPointer: author.pointer,
committerPointer: committer.pointer,
oidPointer: annotatedId.pointer,
);
}
/// Returns the note object's [Oid].
Oid get id => Oid(bindings.id(_notePointer));

View file

@ -7,53 +7,31 @@ import 'bindings/refdb.dart' as refdb_bindings;
import 'bindings/repository.dart' as repository_bindings;
import 'util.dart';
class References {
/// Initializes a new instance of the [References] class
/// from provided [Repository] object.
References(Repository repo) {
_repoPointer = repo.pointer;
}
/// Pointer to memory address for allocated repository object.
late final Pointer<git_repository> _repoPointer;
/// Returns a list of all the references that can be found in a repository.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get list => bindings.list(_repoPointer);
/// Returns number of all the references that can be found in a repository.
int get length => list.length;
/// Returns a [Reference] by lookingup [name] in a repository.
///
/// Should be freed with `free()` to release allocated memory.
///
/// The name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Reference operator [](String name) {
return Reference(bindings.lookup(repoPointer: _repoPointer, name: name));
}
class Reference {
/// Initializes a new instance of the [Reference] class.
/// Should be freed to release allocated memory.
Reference(this._refPointer);
/// Creates a new reference.
///
/// The reference will be created in the repository and written to the disk.
/// The reference will be created in the [repo]sitory and written to the disk.
/// The generated [Reference] object must be freed by the user.
///
/// Valid reference names must follow one of two patterns:
/// Valid reference [name]s must follow one of two patterns:
///
/// Top-level names must contain only capital letters and underscores, and must begin and end
/// with a letter. (e.g. "HEAD", "ORIG_HEAD").
/// Names prefixed with "refs/" can be almost anything. You must avoid the characters
/// '~', '^', ':', '\', '?', '[', and '*', and the sequences ".." and "@{" which have
/// special meaning to revparse.
/// Throws a [LibGit2Error] if a reference already exists with the given name
/// unless force is true, in which case it will be overwritten.
///
/// The message for the reflog will be ignored if the reference does not belong in the
/// Throws a [LibGit2Error] if a reference already exists with the given [name]
/// unless [force] is true, in which case it will be overwritten.
///
/// The [logMessage] message for the reflog will be ignored if the reference does not belong in the
/// standard set (HEAD, branches and remote-tracking branches) and it does not have a reflog.
Reference create({
Reference.create({
required Repository repo,
required String name,
required Object target,
bool force = false,
@ -66,7 +44,6 @@ class References {
oid = target;
isDirect = true;
} else if (isValidShaHex(target as String)) {
final repo = Repository(_repoPointer);
oid = Oid.fromSHA(repo: repo, sha: target);
isDirect = true;
} else {
@ -74,46 +51,97 @@ class References {
}
if (isDirect) {
return Reference(bindings.createDirect(
repoPointer: _repoPointer,
_refPointer = bindings.createDirect(
repoPointer: repo.pointer,
name: name,
oidPointer: oid.pointer,
force: force,
logMessage: logMessage,
));
);
} else {
return Reference(bindings.createSymbolic(
repoPointer: _repoPointer,
_refPointer = bindings.createSymbolic(
repoPointer: repo.pointer,
name: name,
target: target as String,
force: force,
logMessage: logMessage,
));
);
}
}
/// Suggests that the given refdb compress or optimize its references.
/// This mechanism is implementation specific. For on-disk reference databases,
/// for example, this may pack all loose references.
/// Lookups reference [name] in a [repo]sitory.
///
/// Should be freed to release allocated memory.
///
/// The [name] will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
void compress() {
final refdb = repository_bindings.refdb(_repoPointer);
refdb_bindings.compress(refdb);
refdb_bindings.free(refdb);
Reference.lookup({required Repository repo, required String name}) {
_refPointer = bindings.lookup(repoPointer: repo.pointer, name: name);
}
}
class Reference {
/// Initializes a new instance of the [Reference] class.
/// Should be freed with `free()` to release allocated memory.
Reference(this._refPointer);
late Pointer<git_reference> _refPointer;
/// Pointer to memory address for allocated reference object.
Pointer<git_reference> get pointer => _refPointer;
/// Deletes an existing reference with provided [name].
///
/// This method works for both direct and symbolic references.
///
/// Throws a [LibGit2Error] if error occured.
static void delete({required Repository repo, required String name}) {
final ref = Reference.lookup(repo: repo, name: name);
bindings.delete(ref.pointer);
ref.free();
}
/// Renames an existing reference.
///
/// This method works for both direct and symbolic references.
///
/// The [newName] will be checked for validity.
///
/// If the [force] flag is set to false, and there's already a reference with the given name,
/// the renaming will fail.
///
/// IMPORTANT: The user needs to write a proper reflog entry [logMessage] if the reflog is
/// enabled for the repository. We only rename the reflog if it exists.
///
/// Throws a [LibGit2Error] if error occured.
static void rename({
required Repository repo,
required String oldName,
required String newName,
bool force = false,
String? logMessage,
}) {
final ref = Reference.lookup(repo: repo, name: oldName);
bindings.rename(
refPointer: ref.pointer,
newName: newName,
force: force,
logMessage: logMessage,
);
ref.free();
}
/// Returns a list of all the references that can be found in a [repo]sitory.
///
/// Throws a [LibGit2Error] if error occured.
static List<String> list(Repository repo) => bindings.list(repo.pointer);
/// Suggests that the [repo]sitory's refdb compress or optimize its references.
/// This mechanism is implementation specific. For on-disk reference databases,
/// for example, this may pack all loose references.
///
/// Throws a [LibGit2Error] if error occured.
static void compress(Repository repo) {
final refdb = repository_bindings.refdb(repo.pointer);
refdb_bindings.compress(refdb);
refdb_bindings.free(refdb);
}
/// Returns the type of the reference.
ReferenceType get type {
return bindings.referenceType(_refPointer) == 1
@ -180,6 +208,8 @@ class Reference {
/// ```dart
/// final commit = ref.peel(GitObject.commit) as Commit;
/// final tree = ref.peel(GitObject.tree) as Tree;
/// final blob = ref.peel(GitObject.blob) as Blob;
/// final tag = ref.peel(GitObject.tag) as Tag;
/// ```
///
/// Throws a [LibGit2Error] if error occured.
@ -207,32 +237,6 @@ class Reference {
/// If no shortname is appropriate, it will return the full name.
String get shorthand => bindings.shorthand(_refPointer);
/// Renames an existing reference.
///
/// This method works for both direct and symbolic references.
///
/// The new name will be checked for validity.
///
/// If the force flag is not enabled, and there's already a reference with the given name,
/// the renaming will fail.
///
/// IMPORTANT: The user needs to write a proper reflog entry if the reflog is enabled for
/// the repository. We only rename the reflog if it exists.
///
/// Throws a [LibGit2Error] if error occured.
void rename({
required String newName,
bool force = false,
String? logMessage,
}) {
_refPointer = bindings.rename(
refPointer: _refPointer,
newName: newName,
force: force,
logMessage: logMessage,
);
}
/// Checks if a reflog exists for the specified reference [name].
///
/// Throws a [LibGit2Error] if error occured.
@ -261,14 +265,6 @@ class Reference {
/// Returns the repository where a reference resides.
Repository get owner => Repository(bindings.owner(_refPointer));
/// Delete an existing reference.
///
/// This method works for both direct and symbolic references.
/// The reference will be immediately removed on disk but the memory will not be freed.
///
/// Throws a [LibGit2Error] if the reference has changed from the time it was looked up.
void delete() => bindings.delete(_refPointer);
@override
bool operator ==(other) {
return (other is Reference) &&
@ -283,4 +279,9 @@ class Reference {
/// Releases memory allocated for reference object.
void free() => bindings.free(_refPointer);
@override
String toString() {
return 'Reference{name: $name, target: $target}';
}
}

View file

@ -3,70 +3,63 @@ import 'package:libgit2dart/libgit2dart.dart';
import 'bindings/libgit2_bindings.dart';
import 'bindings/remote.dart' as bindings;
class Remotes {
/// Initializes a new instance of the [Remotes] class from
/// provided [Repository] object.
Remotes(Repository repo) {
_repoPointer = repo.pointer;
}
class Remote {
/// Initializes a new instance of [Remote] class from provided pointer
/// to remote object in memory.
Remote(this._remotePointer);
/// Pointer to memory address for allocated repository object.
late final Pointer<git_repository> _repoPointer;
/// Returns a list of the configured remotes for a repo.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get list {
return bindings.list(_repoPointer);
}
/// Returns number of the configured remotes for a repo.
int get length => list.length;
/// Returns [Remote] by looking up [name] in a repository.
/// Initializes a new instance of [Remote] class by looking up remote with
/// provided [name] in a [repo]sitory.
///
/// The name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Remote operator [](String name) {
return Remote(bindings.lookup(repoPointer: _repoPointer, name: name));
Remote.lookup({required Repository repo, required String name}) {
_remotePointer = bindings.lookup(repoPointer: repo.pointer, name: name);
}
/// Adds a remote to the repository's configuration with the default [fetch]
/// refspec if none provided .
/// Initializes a new instance of [Remote] class by adding a remote with
/// provided [name] and [url] to the [repo]sitory's configuration with the
/// default [fetch] refspec if none provided .
///
/// Throws a [LibGit2Error] if error occured.
Remote create({
Remote.create({
required Repository repo,
required String name,
required String url,
String? fetch,
}) {
if (fetch == null) {
return Remote(bindings.create(
repoPointer: _repoPointer,
_remotePointer = bindings.create(
repoPointer: repo.pointer,
name: name,
url: url,
));
);
} else {
return Remote(bindings.createWithFetchSpec(
repoPointer: _repoPointer,
_remotePointer = bindings.createWithFetchSpec(
repoPointer: repo.pointer,
name: name,
url: url,
fetch: fetch,
));
);
}
}
late final Pointer<git_remote> _remotePointer;
/// Pointer to memory address for allocated remote object.
Pointer<git_remote> get pointer => _remotePointer;
/// Deletes an existing persisted remote.
///
/// All remote-tracking branches and configuration settings for the remote will be removed.
///
/// Throws a [LibGit2Error] if error occured.
void delete(String name) {
bindings.delete(repoPointer: _repoPointer, name: name);
static void delete({required Repository repo, required String name}) {
bindings.delete(repoPointer: repo.pointer, name: name);
}
/// Give the remote a new name.
/// Gives the remote a new name.
///
/// Returns list of non-default refspecs that cannot be renamed.
///
@ -78,23 +71,38 @@ class Remotes {
/// their list of refspecs.
///
/// Throws a [LibGit2Error] if error occured.
List<String> rename({required String remote, required String newName}) {
static List<String> rename({
required Repository repo,
required String oldName,
required String newName,
}) {
return bindings.rename(
repoPointer: _repoPointer,
name: remote,
repoPointer: repo.pointer,
name: oldName,
newName: newName,
);
}
/// Returns a list of the configured remotes for a [repo]sitory.
///
/// Throws a [LibGit2Error] if error occured.
static List<String> list(Repository repo) {
return bindings.list(repo.pointer);
}
/// Sets the remote's url in the configuration.
///
/// Remote objects already in memory will not be affected. This assumes the common
/// case of a single-url remote and will otherwise return an error.
///
/// Throws a [LibGit2Error] if error occured.
void setUrl({required String remote, required String url}) {
static void setUrl({
required Repository repo,
required String remote,
required String url,
}) {
bindings.setUrl(
repoPointer: _repoPointer,
repoPointer: repo.pointer,
remote: remote,
url: url,
);
@ -106,9 +114,13 @@ class Remotes {
/// case of a single-url remote and will otherwise return an error.
///
/// Throws a [LibGit2Error] if error occured.
void setPushUrl({required String remote, required String url}) {
static void setPushUrl({
required Repository repo,
required String remote,
required String url,
}) {
bindings.setPushUrl(
repoPointer: _repoPointer,
repoPointer: repo.pointer,
remote: remote,
url: url,
);
@ -119,9 +131,13 @@ class Remotes {
/// No loaded remote instances will be affected.
///
/// Throws a [LibGit2Error] if error occured.
void addFetch({required String remote, required String refspec}) {
static void addFetch({
required Repository repo,
required String remote,
required String refspec,
}) {
bindings.addFetch(
repoPointer: _repoPointer,
repoPointer: repo.pointer,
remote: remote,
refspec: refspec,
);
@ -132,24 +148,17 @@ class Remotes {
/// No loaded remote instances will be affected.
///
/// Throws a [LibGit2Error] if error occured.
void addPush({required String remote, required String refspec}) {
static void addPush({
required Repository repo,
required String remote,
required String refspec,
}) {
bindings.addPush(
repoPointer: _repoPointer,
repoPointer: repo.pointer,
remote: remote,
refspec: refspec,
);
}
}
class Remote {
/// Initializes a new instance of [Remote] class from provided pointer
/// to remote object in memory.
const Remote(this._remotePointer);
final Pointer<git_remote> _remotePointer;
/// Pointer to memory address for allocated remote object.
Pointer<git_remote> get pointer => _remotePointer;
/// Returns the remote's name.
String get name => bindings.name(_remotePointer);

View file

@ -130,6 +130,16 @@ class Repository {
);
}
/// Returns [Oid] object if it can be found in the ODB of repository with
/// provided hexadecimal [sha] string that is 40 characters long or shorter.
///
/// Throws [ArgumentError] if provided [sha] hex string is not valid.
///
/// Throws a [LibGit2Error] if error occured.
Oid operator [](String sha) {
return Oid.fromSHA(repo: this, sha: sha);
}
/// Returns path to the `.git` folder for normal repositories
/// or path to the repository itself for bare repositories.
String get path => bindings.path(_repoPointer);
@ -322,8 +332,89 @@ class Repository {
/// Must be freed once it's no longer being used.
Reference get head => Reference(bindings.head(_repoPointer));
/// Returns [References] object.
References get references => References(this);
/// Returns a list of all the references that can be found in a repository.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get references => Reference.list(this);
/// Lookups reference [name] in a [repo]sitory.
///
/// Should be freed to release allocated memory.
///
/// The [name] will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Reference lookupReference(String name) {
return Reference.lookup(repo: this, name: name);
}
/// Creates a new reference.
///
/// The reference will be created in the repository and written to the disk.
/// The generated [Reference] object must be freed by the user.
///
/// Valid reference [name]s must follow one of two patterns:
///
/// Top-level names must contain only capital letters and underscores, and must begin and end
/// with a letter. (e.g. "HEAD", "ORIG_HEAD").
/// Names prefixed with "refs/" can be almost anything. You must avoid the characters
/// '~', '^', ':', '\', '?', '[', and '*', and the sequences ".." and "@{" which have
/// special meaning to revparse.
///
/// Throws a [LibGit2Error] if a reference already exists with the given [name]
/// unless [force] is true, in which case it will be overwritten.
///
/// The [logMessage] message for the reflog will be ignored if the reference does not belong in the
/// standard set (HEAD, branches and remote-tracking branches) and it does not have a reflog.
Reference createReference({
required String name,
required Object target,
bool force = false,
String? logMessage,
}) {
return Reference.create(
repo: this,
name: name,
target: target,
force: force,
logMessage: logMessage,
);
}
/// Deletes an existing reference with provided [name].
///
/// This method works for both direct and symbolic references.
///
/// Throws a [LibGit2Error] if error occured.
void deleteReference(String name) => Reference.delete(repo: this, name: name);
/// Renames an existing reference.
///
/// This method works for both direct and symbolic references.
///
/// The [newName] will be checked for validity.
///
/// If the [force] flag is set to false, and there's already a reference with the given name,
/// the renaming will fail.
///
/// IMPORTANT: The user needs to write a proper reflog entry [logMessage] if the reflog is
/// enabled for the repository. We only rename the reflog if it exists.
///
/// Throws a [LibGit2Error] if error occured.
void renameReference({
required String oldName,
required String newName,
bool force = false,
String? logMessage,
}) {
Reference.rename(
repo: this,
oldName: oldName,
newName: newName,
force: force,
logMessage: logMessage,
);
}
/// Returns [Index] file for this repository.
///
@ -337,39 +428,11 @@ class Repository {
/// Throws a [LibGit2Error] if error occured.
Odb get odb => Odb(bindings.odb(_repoPointer));
/// Looksup git object (commit, tree, blob, tag) for provided [sha] hex string.
/// Lookups a tree object for provided [id].
///
/// Returned object should be explicitly downcasted to one of four of git object types.
///
/// ```dart
/// final commit = repo['s0m3sh4'] as Commit;
/// final tree = repo['s0m3sh4'] as Tree;
/// final blob = repo['s0m3sh4'] as Blob;
/// final tag = repo['s0m3sh4'] as Tag;
/// ```
///
/// Throws [ArgumentError] if provided [sha] is not pointing to commit, tree, blob or tag.
Object operator [](String sha) {
final oid = Oid.fromSHA(repo: this, sha: sha);
final object = object_bindings.lookup(
repoPointer: _repoPointer,
oidPointer: oid.pointer,
type: GitObject.any.value,
);
final type = object_bindings.type(object);
if (type == GitObject.commit.value) {
return Commit(object.cast());
} else if (type == GitObject.tree.value) {
return Tree(object.cast());
} else if (type == GitObject.blob.value) {
return Blob(object.cast());
} else if (type == GitObject.tag.value) {
return Tag(object.cast());
} else {
throw ArgumentError.value(
'$sha should be pointing to either commit, tree, blob or a tag');
}
/// Should be freed to release allocated memory.
Tree lookupTree(Oid id) {
return Tree.lookup(repo: this, id: id);
}
/// Creates a new action signature with default user and now timestamp.
@ -410,6 +473,13 @@ class Repository {
return RevParse.single(repo: this, spec: spec);
}
/// Lookups commit object for provided [id].
///
/// Should be freed to release allocated memory.
Commit lookupCommit(Oid id) {
return Commit.lookup(repo: this, id: id);
}
/// Creates new commit in the repository.
///
/// [updateRef] is name of the reference that will be updated to point to this commit.
@ -423,8 +493,8 @@ class Repository {
required String message,
required Signature author,
required Signature commiter,
required String treeSHA,
required List<String> parents,
required Tree tree,
required List<Commit> parents,
String? updateRef,
String? messageEncoding,
}) {
@ -433,7 +503,7 @@ class Repository {
message: message,
author: author,
commiter: commiter,
treeSHA: treeSHA,
tree: tree,
parents: parents,
);
}
@ -464,6 +534,13 @@ class Repository {
return RevParse.range(repo: this, spec: spec);
}
/// Lookups a blob object for provided [id].
///
/// Should be freed to release allocated memory.
Blob lookupBlob(Oid id) {
return Blob.lookup(repo: this, id: id);
}
/// Creates a new blob from a [content] string and writes it to ODB.
///
/// Throws a [LibGit2Error] if error occured.
@ -487,12 +564,22 @@ class Repository {
return Blob.createFromDisk(repo: this, path: path);
}
/// Creates a new tag in the repository from provided Oid object.
/// Returns a list with all the tags in the repository.
///
/// A new reference will also be created pointing to this tag object. If force is true
/// Throws a [LibGit2Error] if error occured.
List<String> get tags => Tag.list(this);
/// Lookups tag object for provided [id].
///
/// Should be freed to release allocated memory.
Tag lookupTag(Oid id) => Tag.lookup(repo: this, id: id);
/// Creates a new tag in the repository for provided [target] object.
///
/// A new reference will also be created pointing to this tag object. If [force] is true
/// and a reference already exists with the given name, it'll be replaced.
///
/// The message will not be cleaned up.
/// The [message] will not be cleaned up.
///
/// The tag name will be checked for validity. You must avoid the characters
/// '~', '^', ':', '\', '?', '[', and '*', and the sequences ".." and "@{" which have
@ -501,7 +588,7 @@ class Repository {
/// Throws a [LibGit2Error] if error occured.
Oid createTag({
required String tagName,
required String target,
required Oid target,
required GitObject targetType,
required Signature tagger,
required String message,
@ -517,13 +604,93 @@ class Repository {
force: force);
}
/// Returns a list with all the tags in the repository.
/// Deletes an existing tag reference with provided [name].
///
/// The tag [name] will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get tags => Tag.list(this);
void deleteTag(String name) => Tag.delete(repo: this, name: name);
/// Returns a [Branches] object.
Branches get branches => Branches(this);
/// Returns a list of all branches that can be found in a repository.
///
/// IMPORTANT: Branches must be freed manually when no longer needed to prevent
/// memory leak.
///
/// Throws a [LibGit2Error] if error occured.
List<Branch> get branches => Branch.list(repo: this);
/// Returns a list of local branches that can be found in a repository.
///
/// IMPORTANT: Branches must be freed manually when no longer needed to prevent
/// memory leak.
///
/// Throws a [LibGit2Error] if error occured.
List<Branch> get branchesLocal =>
Branch.list(repo: this, type: GitBranch.local);
/// Returns a list of remote branches that can be found in a repository.
///
/// IMPORTANT: Branches must be freed manually when no longer needed to prevent
/// memory leak.
///
/// Throws a [LibGit2Error] if error occured.
List<Branch> get branchesRemote =>
Branch.list(repo: this, type: GitBranch.remote);
/// Lookups a branch by its [name] in a repository.
///
/// The branch name will be checked for validity.
///
/// Should be freed to release allocated memory when no longer needed.
///
/// Throws a [LibGit2Error] if error occured.
Branch lookupBranch(String name) {
return Branch.lookup(repo: this, name: name);
}
/// Creates a new branch pointing at a [target] commit.
///
/// A new direct reference will be created pointing to this target commit.
/// If [force] is true and a reference already exists with the given name, it'll be replaced.
///
/// Should be freed with [free] to release allocated memory when no longer
/// needed.
///
/// The branch name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Branch createBranch({
required String name,
required Commit target,
bool force = false,
}) {
return Branch.create(
repo: this,
name: name,
target: target,
force: force,
);
}
/// Deletes an existing branch reference.
///
/// Throws a [LibGit2Error] if error occured.
void deleteBranch(String name) => Branch.delete(repo: this, name: name);
/// Renames an existing local branch reference.
///
/// The new branch name will be checked for validity.
///
/// If [force] is true, existing branch will be overwritten.
///
/// Throws a [LibGit2Error] if error occured.
void renameBranch({
required String oldName,
required String newName,
bool force = false,
}) {
Branch.rename(repo: this, oldName: oldName, newName: newName, force: force);
}
/// Checks status of the repository and returns map of file paths and their statuses.
///
@ -619,7 +786,7 @@ class Repository {
required Oid theirHead,
String ourRef = 'HEAD',
}) {
final ref = references[ourRef];
final ref = lookupReference(ourRef);
final head = commit_bindings.annotatedLookup(
repoPointer: _repoPointer,
oidPointer: theirHead.pointer,
@ -831,7 +998,7 @@ class Repository {
paths: paths,
);
} else {
final ref = references[refName];
final ref = lookupReference(refName);
final treeish = object_bindings.lookup(
repoPointer: _repoPointer,
oidPointer: ref.target.pointer,
@ -1062,8 +1229,57 @@ class Repository {
return stash_bindings.list(_repoPointer);
}
/// Returns [Remotes] object.
Remotes get remotes => Remotes(this);
/// Returns a list of the configured remotes for a repository.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get remotes => Remote.list(this);
/// Lookups remote with provided [name].
///
/// The name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
Remote lookupRemote(String name) {
return Remote.lookup(repo: this, name: name);
}
/// Adds a remote with provided [name] and [url] to the repository's
/// configuration with the default [fetch] refspec if none provided .
///
/// Throws a [LibGit2Error] if error occured.
Remote createRemote({
required String name,
required String url,
String? fetch,
}) {
return Remote.create(repo: this, name: name, url: url, fetch: fetch);
}
/// Deletes an existing persisted remote.
///
/// All remote-tracking branches and configuration settings for the remote will be removed.
///
/// Throws a [LibGit2Error] if error occured.
void deleteRemote(String name) => Remote.delete(repo: this, name: name);
/// Gives the remote a new name.
///
/// Returns list of non-default refspecs that cannot be renamed.
///
/// All remote-tracking branches and configuration settings for the remote are updated.
///
/// The new name will be checked for validity.
///
/// No loaded instances of a the remote with the old name will change their name or
/// their list of refspecs.
///
/// Throws a [LibGit2Error] if error occured.
List<String> renameRemote({
required String oldName,
required String newName,
}) {
return Remote.rename(repo: this, oldName: oldName, newName: newName);
}
/// Looks up the value of one git attribute for path.
///
@ -1132,49 +1348,69 @@ class Repository {
/// Returns list of notes for repository.
///
/// Notes must be freed manually.
/// IMPORTANT: Notes must be freed manually when no longer needed to prevent
/// memory leak.
///
/// Throws a [LibGit2Error] if error occured.
List<Note> get notes => Notes(this).list;
List<Note> get notes => Note.list(this);
/// Reads the note for an object.
/// Reads the note for an [annotatedId].
///
/// The note must be freed manually.
/// IMPORTANT: Notes must be freed manually when no longer needed to prevent
/// memory leak.
///
/// Throws a [LibGit2Error] if error occured.
Note lookupNote({
required Oid annotatedId,
String notesRef = 'refs/notes/commits',
}) {
return Notes.lookup(
return Note.lookup(
repo: this,
annotatedId: annotatedId,
notesRef: notesRef,
);
}
/// Adds a note for an [object].
/// Adds a note for an [annotatedId].
///
/// Throws a [LibGit2Error] if error occured.
Oid createNote({
required Signature author,
required Signature committer,
required Oid object,
required Oid annotatedId,
required String note,
String notesRef = 'refs/notes/commits',
bool force = false,
}) {
return Notes.create(
return Note.create(
repo: this,
author: author,
committer: committer,
object: object,
annotatedId: annotatedId,
note: note,
notesRef: notesRef,
force: force,
);
}
/// Deletes the note for an [annotatedId].
///
/// Throws a [LibGit2Error] if error occured.
void deleteNote({
required Oid annotatedId,
required Signature author,
required Signature committer,
String notesRef = 'refs/notes/commits',
}) {
Note.delete(
repo: this,
annotatedId: annotatedId,
author: author,
committer: committer,
notesRef: notesRef,
);
}
/// Checks if a commit is the descendant of another commit.
///
/// Note that a commit is not considered a descendant of itself, in contrast to
@ -1397,4 +1633,34 @@ class Repository {
callbacks: callbacks,
);
}
/// Returns list of names of linked working trees.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get worktrees => Worktree.list(this);
/// Lookups up existing worktree for provided [name].
///
/// Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Worktree lookupWorktree(String name) {
return Worktree.lookup(repo: this, name: name);
}
/// Creates new worktree.
///
/// If [ref] is provided, no new branch will be created but specified [ref] will
/// be used instead.
///
/// Should be freed with `free()` to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Worktree createWorktree({
required String name,
required String path,
Reference? ref,
}) {
return Worktree.create(repo: this, name: name, path: path, ref: ref);
}
}

View file

@ -8,18 +8,16 @@ class Tag {
/// Initializes a new instance of [Tag] class from provided pointer to
/// tag object in memory.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
Tag(this._tagPointer);
/// Initializes a new instance of [Tag] class from provided
/// [Repository] object and [sha] hex string.
/// Lookups tag object for provided [id] in a [repo]sitory.
///
/// Should be freed with `free()` to release allocated memory.
Tag.lookup({required Repository repo, required String sha}) {
final oid = Oid.fromSHA(repo: repo, sha: sha);
/// Should be freed to release allocated memory.
Tag.lookup({required Repository repo, required Oid id}) {
_tagPointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
oidPointer: id.pointer,
);
}
@ -28,12 +26,12 @@ class Tag {
/// Pointer to memory address for allocated tag object.
Pointer<git_tag> get pointer => _tagPointer;
/// Creates a new tag in the repository from provided Oid object.
/// Creates a new tag in the repository for provided [target] object.
///
/// A new reference will also be created pointing to this tag object. If force is true
/// A new reference will also be created pointing to this tag object. If [force] is true
/// and a reference already exists with the given name, it'll be replaced.
///
/// The message will not be cleaned up.
/// The [message] will not be cleaned up.
///
/// The tag name will be checked for validity. You must avoid the characters
/// '~', '^', ':', '\', '?', '[', and '*', and the sequences ".." and "@{" which have
@ -43,16 +41,15 @@ class Tag {
static Oid create({
required Repository repo,
required String tagName,
required String target,
required Oid target,
required GitObject targetType,
required Signature tagger,
required String message,
bool force = false,
}) {
final targetOid = Oid.fromSHA(repo: repo, sha: target);
final object = object_bindings.lookup(
repoPointer: repo.pointer,
oidPointer: targetOid.pointer,
oidPointer: target.pointer,
type: targetType.value,
);
final result = bindings.create(
@ -68,6 +65,15 @@ class Tag {
return Oid(result);
}
/// Deletes an existing tag reference with provided [name] in a [repo]sitory.
///
/// The tag [name] will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
static void delete({required Repository repo, required String name}) {
bindings.delete(repoPointer: repo.pointer, tagName: name);
}
/// Returns a list with all the tags in the repository.
///
/// Throws a [LibGit2Error] if error occured.
@ -123,16 +129,6 @@ class Tag {
}
}
/// Deletes an existing tag reference.
///
/// The tag name will be checked for validity.
///
/// Throws a [LibGit2Error] if error occured.
void delete() {
final owner = bindings.owner(_tagPointer);
bindings.delete(repoPointer: owner, tagName: name);
}
/// Releases memory allocated for tag object.
void free() => bindings.free(_tagPointer);
}

View file

@ -8,18 +8,16 @@ class Tree {
/// Initializes a new instance of [Tree] class from provided pointer to
/// tree object in memory.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
Tree(this._treePointer);
/// Initializes a new instance of [Tree] class from provided
/// [Repository] object and [sha] hex string.
/// Lookups a tree object for provided [id] in a [repo]sitory.
///
/// Should be freed with `free()` to release allocated memory.
Tree.lookup({required Repository repo, required String sha}) {
final oid = Oid.fromSHA(repo: repo, sha: sha);
/// Should be freed to release allocated memory.
Tree.lookup({required Repository repo, required Oid id}) {
_treePointer = bindings.lookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
oidPointer: id.pointer,
);
}

View file

@ -5,9 +5,9 @@ import 'bindings/treebuilder.dart' as bindings;
class TreeBuilder {
/// Initializes a new instance of [TreeBuilder] class from provided
/// [Repository] and optional [Tree] objects.
/// [repo]sitory and optional [tree] objects.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
TreeBuilder({required Repository repo, Tree? tree}) {
@ -79,6 +79,6 @@ class TreeBuilder {
);
}
/// Releases memory allocated for tree builder object.
/// Releases memory allocated for tree builder object and all the entries.
void free() => bindings.free(_treeBuilderPointer);
}