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

@ -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);