mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(packbuilder): add more bindings and API methods (#25)
This commit is contained in:
parent
9791b6324c
commit
50a6087a5b
4 changed files with 173 additions and 7 deletions
|
@ -61,6 +61,55 @@ void addRecursively({
|
|||
}
|
||||
}
|
||||
|
||||
/// Insert a commit object.
|
||||
///
|
||||
/// This will add a commit as well as the completed referenced tree.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void addCommit({
|
||||
required Pointer<git_packbuilder> packbuilderPointer,
|
||||
required Pointer<git_oid> oidPointer,
|
||||
}) {
|
||||
final error = libgit2.git_packbuilder_insert_commit(
|
||||
packbuilderPointer,
|
||||
oidPointer,
|
||||
);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert a root tree object.
|
||||
///
|
||||
/// This will add the tree as well as all referenced trees and blobs.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void addTree({
|
||||
required Pointer<git_packbuilder> packbuilderPointer,
|
||||
required Pointer<git_oid> oidPointer,
|
||||
}) {
|
||||
final error = libgit2.git_packbuilder_insert_tree(
|
||||
packbuilderPointer,
|
||||
oidPointer,
|
||||
);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert objects as given by the walk.
|
||||
///
|
||||
/// Those commits and all objects they reference will be inserted into the
|
||||
/// packbuilder.
|
||||
void addWalk({
|
||||
required Pointer<git_packbuilder> packbuilderPointer,
|
||||
required Pointer<git_revwalk> walkerPointer,
|
||||
}) {
|
||||
libgit2.git_packbuilder_insert_walk(packbuilderPointer, walkerPointer);
|
||||
}
|
||||
|
||||
/// Write the new pack and corresponding index file to path.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
|
@ -94,6 +143,14 @@ int writtenCount(Pointer<git_packbuilder> pb) {
|
|||
return libgit2.git_packbuilder_written(pb);
|
||||
}
|
||||
|
||||
/// Get the packfile's hash.
|
||||
///
|
||||
/// A packfile's name is derived from the sorted hashing of all object names.
|
||||
/// This is only correct after the packfile has been written.
|
||||
Pointer<git_oid> hash(Pointer<git_packbuilder> pb) {
|
||||
return libgit2.git_packbuilder_hash(pb);
|
||||
}
|
||||
|
||||
/// Set number of threads to spawn.
|
||||
///
|
||||
/// By default, libgit2 won't spawn any threads at all; when set to 0,
|
||||
|
|
|
@ -41,6 +41,41 @@ class PackBuilder {
|
|||
);
|
||||
}
|
||||
|
||||
/// Adds a commit object.
|
||||
///
|
||||
/// This will add a commit as well as the completed referenced tree.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void addCommit(Oid oid) {
|
||||
bindings.addCommit(
|
||||
packbuilderPointer: _packbuilderPointer,
|
||||
oidPointer: oid.pointer,
|
||||
);
|
||||
}
|
||||
|
||||
/// Adds a root tree object.
|
||||
///
|
||||
/// This will add the tree as well as all referenced trees and blobs.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void addTree(Oid oid) {
|
||||
bindings.addTree(
|
||||
packbuilderPointer: _packbuilderPointer,
|
||||
oidPointer: oid.pointer,
|
||||
);
|
||||
}
|
||||
|
||||
/// Adds objects as given by the walker.
|
||||
///
|
||||
/// Those commits and all objects they reference will be inserted into the
|
||||
/// packbuilder.
|
||||
void addWalk(RevWalk walker) {
|
||||
bindings.addWalk(
|
||||
packbuilderPointer: _packbuilderPointer,
|
||||
walkerPointer: walker.pointer,
|
||||
);
|
||||
}
|
||||
|
||||
/// Writes the new pack and corresponding index file to [path] if provided
|
||||
/// or default location.
|
||||
///
|
||||
|
@ -55,6 +90,12 @@ class PackBuilder {
|
|||
/// Number of objects the packbuilder has already written out.
|
||||
int get writtenLength => bindings.writtenCount(_packbuilderPointer);
|
||||
|
||||
/// Packfile's hash.
|
||||
///
|
||||
/// A packfile's name is derived from the sorted hashing of all object names.
|
||||
/// This is only correct after the packfile has been written.
|
||||
Oid get hash => Oid(bindings.hash(_packbuilderPointer));
|
||||
|
||||
/// Sets and returns the number of threads to spawn.
|
||||
///
|
||||
/// By default, libgit2 won't spawn any threads at all. When set to 0,
|
||||
|
|
|
@ -11,9 +11,11 @@ class RevWalk {
|
|||
_revWalkPointer = bindings.create(repo.pointer);
|
||||
}
|
||||
|
||||
/// Pointer to memory address for allocated [RevWalk] object.
|
||||
late final Pointer<git_revwalk> _revWalkPointer;
|
||||
|
||||
/// Pointer to memory address for allocated [RevWalk] object.
|
||||
Pointer<git_revwalk> get pointer => _revWalkPointer;
|
||||
|
||||
/// Returns the list of commits from the revision walk.
|
||||
///
|
||||
/// Default sorting is reverse chronological order (default in git).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue