refactor!: use class names instead of aliases from Repository in tests (#37)

BREAKING CHANGE: move API methods related to diffing into Diff class
This commit is contained in:
Aleksey Kulikov 2022-01-25 12:05:34 +03:00 committed by GitHub
parent 3e1ece4e6f
commit 08cbe8a17f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 943 additions and 834 deletions

View file

@ -66,7 +66,7 @@ Pointer<git_diff> indexToWorkdir({
/// Create a diff between a tree and repository index.
Pointer<git_diff> treeToIndex({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> treePointer,
required Pointer<git_tree>? treePointer,
required Pointer<git_index> indexPointer,
required int flags,
required int contextLines,
@ -82,7 +82,7 @@ Pointer<git_diff> treeToIndex({
libgit2.git_diff_tree_to_index(
out,
repoPointer,
treePointer,
treePointer ?? nullptr,
indexPointer,
opts,
);
@ -97,7 +97,7 @@ Pointer<git_diff> treeToIndex({
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToWorkdir({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> treePointer,
required Pointer<git_tree>? treePointer,
required int flags,
required int contextLines,
required int interhunkLines,
@ -112,7 +112,7 @@ Pointer<git_diff> treeToWorkdir({
final error = libgit2.git_diff_tree_to_workdir(
out,
repoPointer,
treePointer,
treePointer ?? nullptr,
opts,
);
@ -170,8 +170,8 @@ Pointer<git_diff> treeToWorkdirWithIndex({
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToTree({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> oldTreePointer,
required Pointer<git_tree> newTreePointer,
required Pointer<git_tree>? oldTreePointer,
required Pointer<git_tree>? newTreePointer,
required int flags,
required int contextLines,
required int interhunkLines,
@ -186,8 +186,8 @@ Pointer<git_diff> treeToTree({
final error = libgit2.git_diff_tree_to_tree(
out,
repoPointer,
oldTreePointer,
newTreePointer,
oldTreePointer ?? nullptr,
newTreePointer ?? nullptr,
opts,
);

View file

@ -41,7 +41,8 @@ class Branch {
);
}
/// Lookups a branch by its [name] and [type] in a [repo]sitory.
/// Lookups a branch by its [name] and [type] in a [repo]sitory. Lookups in
/// local branches by default.
///
/// The branch name will be checked for validity.
///

View file

@ -178,6 +178,38 @@ class Commit {
);
}
/// Reverts commit, producing changes in the index and working directory.
///
/// Throws a [LibGit2Error] if error occured.
void revert() {
bindings.revert(
repoPointer: bindings.owner(_commitPointer),
commitPointer: _commitPointer,
);
}
/// Reverts commit against provided [commit], producing an index that
/// reflects the result of the revert.
///
/// [mainline] is parent of the commit if it is a merge (i.e. 1, 2).
///
/// **IMPORTANT**: produced index should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Index revertTo({
required Commit commit,
int mainline = 0,
}) {
return Index(
bindings.revertCommit(
repoPointer: bindings.owner(_commitPointer),
revertCommitPointer: _commitPointer,
ourCommitPointer: commit.pointer,
mainline: mainline,
),
);
}
/// Wncoding for the message of a commit, as a string representing a standard
/// encoding name.
String get messageEncoding => bindings.messageEncoding(_commitPointer);

View file

@ -14,6 +14,118 @@ class Diff {
/// **IMPORTANT**: Should be freed to release allocated memory.
Diff(this._diffPointer);
/// Creates a diff between the [repo]sitory [index] and the workdir directory.
///
/// This matches the `git diff` command.
///
/// [repo] is the repository containing index.
///
/// [index] is the index to diff from.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
///
/// **IMPORTANT**: Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Diff.indexToWorkdir({
required Repository repo,
required Index index,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
_diffPointer = bindings.indexToWorkdir(
repoPointer: repo.pointer,
indexPointer: index.pointer,
flags: flags.fold(0, (int acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
);
}
/// Creates a diff between a [tree] and [repo]sitory [index].
///
/// This is equivalent to `git diff --cached <treeish>` or if you pass the
/// HEAD tree, then like `git diff --cached`.
///
/// [repo] is the repository containing the tree and index.
///
/// [tree] is the [Tree] object to diff from or null for empty tree.
///
/// [index] is the index to diff with.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
Diff.treeToIndex({
required Repository repo,
required Tree? tree,
required Index index,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
_diffPointer = bindings.treeToIndex(
repoPointer: repo.pointer,
treePointer: tree?.pointer,
indexPointer: index.pointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
);
}
/// Creates a diff between a [tree] and the working directory.
///
/// This is not the same as `git diff <treeish>` or
/// `git diff-index <treeish>`. Those commands use information from the
/// index, whereas this method strictly returns the differences between the
/// tree and the files in the working directory, regardless of the state of
/// the index. Use [Diff.treeToWorkdirWithIndex] to emulate those commands.
///
/// To see difference between this and [Diff.treeToWorkdirWithIndex],
/// consider the example of a staged file deletion where the file has then
/// been put back into the working directory and further modified. The
/// tree-to-workdir diff for that file is 'modified', but `git diff` would
/// show status 'deleted' since there is a staged delete.
///
/// [repo] is the repository containing the tree.
///
/// [tree] is the [Tree] object to diff from or null for empty tree.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
Diff.treeToWorkdir({
required Repository repo,
required Tree? tree,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
_diffPointer = bindings.treeToWorkdir(
repoPointer: repo.pointer,
treePointer: tree?.pointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
);
}
/// Creates a diff between a [tree] and the working directory using index
/// data to account for staged deletes, tracked files, etc.
///
@ -52,6 +164,83 @@ class Diff {
);
}
/// Creates a diff with the difference between two [Tree] objects.
///
/// This is equivalent to `git diff <old-tree> <new-tree>`.
///
/// [repo] is the repository containing the trees.
///
/// [oldTree] is the [Tree] object to diff from, or null for empty tree.
///
/// [newTree] is the [Tree] object to diff to, or null for empty tree.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
///
/// Throws a [LibGit2Error] if error occured or [ArgumentError] if both trees
/// are null.
Diff.treeToTree({
required Repository repo,
required Tree? oldTree,
required Tree? newTree,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
if (oldTree == null && newTree == null) {
throw ArgumentError('Both trees cannot be null');
}
_diffPointer = bindings.treeToTree(
repoPointer: repo.pointer,
oldTreePointer: oldTree?.pointer,
newTreePointer: newTree?.pointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
);
}
/// Creates a diff with the difference between two [Index] objects.
///
/// [repo] is the repository containing the indexes.
///
/// [oldIndex] is the [Index] object to diff from.
///
/// [newIndex] is the [Index] object to diff to.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
///
/// Throws a [LibGit2Error] if error occured.
Diff.indexToIndex({
required Repository repo,
required Index oldIndex,
required Index newIndex,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
_diffPointer = bindings.indexToIndex(
repoPointer: repo.pointer,
oldIndexPointer: oldIndex.pointer,
newIndexPointer: newIndex.pointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
);
}
/// Reads the [content]s of a git patch file into a git diff object.
///
/// The diff object produced is similar to the one that would be produced if
@ -138,6 +327,77 @@ class Diff {
);
}
/// Applies the diff to the [repo]sitory, making changes in the provided
/// [location].
///
/// [repo] is the repository to apply to.
///
/// [hunkIndex] is optional index of the hunk to apply.
///
/// [location] is the location to apply (workdir, index or both).
/// Defaults to workdir.
///
/// Throws a [LibGit2Error] if error occured.
void apply({
required Repository repo,
int? hunkIndex,
GitApplyLocation location = GitApplyLocation.workdir,
}) {
bindings.apply(
repoPointer: repo.pointer,
diffPointer: _diffPointer,
hunkIndex: hunkIndex,
location: location.value,
);
}
/// Checks if the diff will apply to provided [location].
///
/// [repo] is the repository to apply to.
///
/// [hunkIndex] is optional index of the hunk to apply.
///
/// [location] is the location to apply (workdir, index or both).
/// Defaults to workdir.
bool applies({
required Repository repo,
int? hunkIndex,
GitApplyLocation location = GitApplyLocation.workdir,
}) {
return bindings.apply(
repoPointer: repo.pointer,
diffPointer: _diffPointer,
hunkIndex: hunkIndex,
location: location.value,
check: true,
);
}
/// Applies the diff to the [tree], and returns the resulting image as an
/// index.
///
/// [repo] is the repository to apply to.
///
/// [tree] is the tree to apply the diff to.
///
/// [hunkIndex] is optional index of the hunk to apply.
///
/// Throws a [LibGit2Error] if error occured.
Index applyToTree({
required Repository repo,
required Tree tree,
int? hunkIndex,
}) {
return Index(
bindings.applyToTree(
repoPointer: repo.pointer,
diffPointer: _diffPointer,
treePointer: tree.pointer,
hunkIndex: hunkIndex,
),
);
}
/// Transforms a diff marking file renames, copies, etc.
///
/// This modifies a diff in place, replacing old entries that look like

View file

@ -3,7 +3,6 @@ import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:libgit2dart/libgit2dart.dart';
import 'package:libgit2dart/src/bindings/diff.dart' as diff_bindings;
import 'package:libgit2dart/src/bindings/index.dart' as bindings;
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
@ -300,91 +299,6 @@ class Index with IterableMixin<IndexEntry> {
void removeAll(List<String> path) =>
bindings.removeAll(indexPointer: _indexPointer, pathspec: path);
/// Creates a diff with the difference between two index objects.
///
/// [index] is the [Index] object to diff to.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
///
/// Throws a [LibGit2Error] if error occured.
Diff diffToIndex({
required Index index,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
return Diff(
diff_bindings.indexToIndex(
repoPointer: bindings.owner(_indexPointer),
oldIndexPointer: _indexPointer,
newIndexPointer: index.pointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
}
/// Creates a diff between the repository index and the workdir directory.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
Diff diffToWorkdir({
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
return Diff(
diff_bindings.indexToWorkdir(
repoPointer: bindings.owner(_indexPointer),
indexPointer: _indexPointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
}
/// Creates a diff between a tree and repository index.
///
/// [tree] is the [Tree] object to diff from.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
Diff diffToTree({
required Tree tree,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
return Diff(
diff_bindings.treeToIndex(
repoPointer: bindings.owner(_indexPointer),
treePointer: tree.pointer,
indexPointer: _indexPointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
}
/// Releases memory allocated for index object.
void free() => bindings.free(_indexPointer);

View file

@ -7,7 +7,6 @@ import 'package:libgit2dart/src/bindings/attr.dart' as attr_bindings;
import 'package:libgit2dart/src/bindings/checkout.dart' as checkout_bindings;
import 'package:libgit2dart/src/bindings/commit.dart' as commit_bindings;
import 'package:libgit2dart/src/bindings/describe.dart' as describe_bindings;
import 'package:libgit2dart/src/bindings/diff.dart' as diff_bindings;
import 'package:libgit2dart/src/bindings/graph.dart' as graph_bindings;
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
import 'package:libgit2dart/src/bindings/merge.dart' as merge_bindings;
@ -1410,82 +1409,6 @@ class Repository {
);
}
/// Returns a [Diff] with changes between the trees, tree and index, tree and
/// workdir or index and workdir.
///
/// If [b] is null, by default the [a] tree compared to working directory. If
/// [cached] is set to true the [a] tree compared to index/staging area.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
///
/// **IMPORTANT**: Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Diff diff({
Tree? a,
Tree? b,
bool cached = false,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
final flagsInt = flags.fold(0, (int acc, e) => acc | e.value);
if (a is Tree && b is Tree) {
return Diff(
diff_bindings.treeToTree(
repoPointer: _repoPointer,
oldTreePointer: a.pointer,
newTreePointer: b.pointer,
flags: flagsInt,
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
} else if (a is Tree && b == null) {
if (cached) {
return Diff(
diff_bindings.treeToIndex(
repoPointer: _repoPointer,
treePointer: a.pointer,
indexPointer: index.pointer,
flags: flagsInt,
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
} else {
return Diff(
diff_bindings.treeToWorkdir(
repoPointer: _repoPointer,
treePointer: a.pointer,
flags: flagsInt,
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
}
} else if (a == null && b == null) {
return Diff(
diff_bindings.indexToWorkdir(
repoPointer: _repoPointer,
indexPointer: index.pointer,
flags: flagsInt,
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
} else {
throw ArgumentError.notNull('a');
}
}
/// Returns a [Patch] with changes between the blobs.
///
/// [a] is the blob for old side of diff.
@ -1519,65 +1442,6 @@ class Repository {
return a.diff(newBlob: b, oldAsPath: aPath, newAsPath: bPath);
}
/// Applies the [diff] to the repository, making changes in the provided
/// [location] (directly in the working directory (default), the index or
/// both).
///
/// [hunkIndex] is optional index of the hunk to apply.
///
/// Throws a [LibGit2Error] if error occured.
void apply({
required Diff diff,
int? hunkIndex,
GitApplyLocation location = GitApplyLocation.workdir,
}) {
diff_bindings.apply(
repoPointer: _repoPointer,
diffPointer: diff.pointer,
hunkIndex: hunkIndex,
location: location.value,
);
}
/// Applies the [diff] to the [tree], and returns the resulting image as an
/// index.
///
/// [hunkIndex] is optional index of the hunk to apply.
///
/// Throws a [LibGit2Error] if error occured.
Index applyToTree({
required Diff diff,
required Tree tree,
int? hunkIndex,
}) {
return Index(
diff_bindings.applyToTree(
repoPointer: _repoPointer,
diffPointer: diff.pointer,
treePointer: tree.pointer,
hunkIndex: hunkIndex,
),
);
}
/// Checks if the [diff] will apply to provided [location] (the working
/// directory (default), the index or both).
///
/// [hunkIndex] is optional index of the hunk to apply.
bool applies({
required Diff diff,
int? hunkIndex,
GitApplyLocation location = GitApplyLocation.workdir,
}) {
return diff_bindings.apply(
repoPointer: _repoPointer,
diffPointer: diff.pointer,
hunkIndex: hunkIndex,
location: location.value,
check: true,
);
}
/// Returns list of all the stashed states, first being the most recent.
List<Stash> get stashes => Stash.list(this);
@ -1812,13 +1676,6 @@ class Repository {
);
}
/// List of notes for repository.
///
/// **IMPORTANT**: Notes Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
List<Note> get notes => Note.list(this);
/// Lookups the note for an [annotatedOid].
///
/// [annotatedOid] is the [Oid] of the git object to read the note from.
@ -2075,7 +1932,7 @@ class Repository {
required String submodule,
bool overwrite = false,
}) {
Submodule.init(repo: this, submodule: submodule, overwrite: overwrite);
Submodule.init(repo: this, name: submodule, overwrite: overwrite);
}
/// Updates a submodule. This will clone a missing submodule and checkout the
@ -2096,7 +1953,7 @@ class Repository {
}) {
Submodule.update(
repo: this,
submodule: submodule,
name: submodule,
init: init,
callbacks: callbacks,
);

View file

@ -14,8 +14,7 @@ class RevParse {
/// point to an intermediate reference. When such expressions are being
/// passed in, reference_out will be valued as well.
///
/// **IMPORTANT**: The returned object and reference should be freed to
/// release allocated memory.
/// **IMPORTANT**: Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
RevParse.ext({required Repository repo, required String spec}) {
@ -41,7 +40,7 @@ class RevParse {
/// See `man gitrevisions`, or https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions
/// for information on the syntax accepted.
///
/// The returned object should be released when no longer needed.
/// **IMPORTANT**: Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
static Commit single({required Repository repo, required String spec}) {

View file

@ -65,12 +65,12 @@ class Submodule {
/// Throws a [LibGit2Error] if error occured.
static void init({
required Repository repo,
required String submodule,
required String name,
bool overwrite = false,
}) {
final submodulePointer = bindings.lookup(
repoPointer: repo.pointer,
name: submodule,
name: name,
);
bindings.init(submodulePointer: submodulePointer, overwrite: overwrite);
@ -91,13 +91,13 @@ class Submodule {
/// Throws a [LibGit2Error] if error occured.
static void update({
required Repository repo,
required String submodule,
required String name,
bool init = false,
Callbacks callbacks = const Callbacks(),
}) {
final submodulePointer = bindings.lookup(
repoPointer: repo.pointer,
name: submodule,
name: name,
);
bindings.update(

View file

@ -1,7 +1,6 @@
import 'dart:ffi';
import 'package:libgit2dart/libgit2dart.dart';
import 'package:libgit2dart/src/bindings/diff.dart' as diff_bindings;
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
import 'package:libgit2dart/src/bindings/tree.dart' as bindings;
@ -90,93 +89,6 @@ class Tree {
/// Number of entries listed in a tree.
int get length => bindings.entryCount(_treePointer);
/// Creates a diff between a tree and the working directory.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
///
/// Throws a [LibGit2Error] if error occured.
Diff diffToWorkdir({
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
return Diff(
diff_bindings.treeToWorkdir(
repoPointer: bindings.owner(_treePointer),
treePointer: _treePointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
}
/// Creates a diff between a tree and repository index.
///
/// [index] is the [Index] object to diff to.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
Diff diffToIndex({
required Index index,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
return Diff(
diff_bindings.treeToIndex(
repoPointer: bindings.owner(_treePointer),
treePointer: _treePointer,
indexPointer: index.pointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
}
/// Creates a diff with the difference between two tree objects.
///
/// [tree] is the [Tree] object to diff to.
///
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
///
/// [contextLines] is the number of unchanged lines that define the boundary
/// of a hunk (and to display before and after). Defaults to 3.
///
/// [interhunkLines] is the maximum number of unchanged lines between hunk
/// boundaries before the hunks will be merged into one. Defaults to 0.
///
/// Throws a [LibGit2Error] if error occured.
Diff diffToTree({
required Tree tree,
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
int interhunkLines = 0,
}) {
return Diff(
diff_bindings.treeToTree(
repoPointer: bindings.owner(_treePointer),
oldTreePointer: _treePointer,
newTreePointer: tree.pointer,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
}
/// Releases memory allocated for tree object.
void free() => bindings.free(_treePointer);