mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(patch)!: divide Patch.create() into specific methods (#38)
BREAKING CHANGE: remove patch generation methods from Blob class
This commit is contained in:
parent
08cbe8a17f
commit
0844f03387
106 changed files with 156 additions and 6171 deletions
|
@ -57,9 +57,9 @@ Pointer<git_patch> fromBuffers({
|
|||
/// You can use the standard patch accessor functions to read the patch data,
|
||||
/// and you must free the patch when done.
|
||||
Pointer<git_patch> fromBlobs({
|
||||
required Pointer<git_blob> oldBlobPointer,
|
||||
required Pointer<git_blob>? oldBlobPointer,
|
||||
String? oldAsPath,
|
||||
required Pointer<git_blob> newBlobPointer,
|
||||
required Pointer<git_blob>? newBlobPointer,
|
||||
String? newAsPath,
|
||||
required int flags,
|
||||
required int contextLines,
|
||||
|
@ -76,9 +76,9 @@ Pointer<git_patch> fromBlobs({
|
|||
|
||||
libgit2.git_patch_from_blobs(
|
||||
out,
|
||||
oldBlobPointer,
|
||||
oldBlobPointer ?? nullptr,
|
||||
oldAsPathC,
|
||||
newBlobPointer,
|
||||
newBlobPointer ?? nullptr,
|
||||
newAsPathC,
|
||||
opts,
|
||||
);
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'dart:ffi';
|
|||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'package:libgit2dart/src/bindings/blob.dart' as bindings;
|
||||
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
|
||||
import 'package:libgit2dart/src/bindings/patch.dart' as patch_bindings;
|
||||
|
||||
class Blob {
|
||||
/// Initializes a new instance of [Blob] class from provided pointer to
|
||||
|
@ -85,87 +84,6 @@ class Blob {
|
|||
/// **IMPORTANT**: Should be freed to release allocated memory.
|
||||
Blob duplicate() => Blob(bindings.duplicate(_blobPointer));
|
||||
|
||||
/// Directly generates a [Patch] from the difference between two blobs.
|
||||
///
|
||||
/// [newBlob] is the blob for new side of diff, or null for empty blob.
|
||||
///
|
||||
/// [oldAsPath] treat old blob as if it had this filename, can be null.
|
||||
///
|
||||
/// [newAsPath] treat new blob as if it had this filename, can be null.
|
||||
///
|
||||
/// [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.
|
||||
Patch diff({
|
||||
required Blob? newBlob,
|
||||
String? oldAsPath,
|
||||
String? newAsPath,
|
||||
Set<GitDiff> flags = const {GitDiff.normal},
|
||||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
return Patch(
|
||||
patch_bindings.fromBlobs(
|
||||
oldBlobPointer: _blobPointer,
|
||||
oldAsPath: oldAsPath,
|
||||
newBlobPointer: newBlob?.pointer ?? nullptr,
|
||||
newAsPath: newAsPath,
|
||||
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Directly generates a [Patch] from the difference between the blob and a
|
||||
/// buffer.
|
||||
///
|
||||
/// [buffer] is the raw data for new side of diff, or null for empty.
|
||||
///
|
||||
/// [oldAsPath] treat old blob as if it had this filename, can be null.
|
||||
///
|
||||
/// [bufferAsPath] treat buffer as if it had this filename, can be null.
|
||||
///
|
||||
/// [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.
|
||||
Patch diffToBuffer({
|
||||
required String? buffer,
|
||||
String? oldAsPath,
|
||||
String? bufferAsPath,
|
||||
Set<GitDiff> flags = const {GitDiff.normal},
|
||||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
return Patch(
|
||||
patch_bindings.fromBlobAndBuffer(
|
||||
oldBlobPointer: _blobPointer,
|
||||
oldAsPath: oldAsPath,
|
||||
buffer: buffer,
|
||||
bufferAsPath: bufferAsPath,
|
||||
flags: flags.fold(0, (acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns filtered content of a blob.
|
||||
///
|
||||
/// This applies filters as if the blob was being checked out to the working
|
||||
|
|
|
@ -12,14 +12,15 @@ class Patch {
|
|||
/// **IMPORTANT**: Should be freed to release allocated memory.
|
||||
Patch(this._patchPointer);
|
||||
|
||||
/// Directly generates a patch from the difference between two blobs, buffers
|
||||
/// or blob and a buffer.
|
||||
/// Directly generates a [Patch] from the difference between two blobs.
|
||||
///
|
||||
/// [a] and [b] can be [Blob], [String] or null.
|
||||
/// [oldBlob] is the blob for old side of diff, or null for empty blob.
|
||||
///
|
||||
/// [aPath] treat [a] as if it had this filename, can be null.
|
||||
/// [newBlob] is the blob for new side of diff, or null for empty blob.
|
||||
///
|
||||
/// [bPath] treat [b] as if it had this filename, can be null.
|
||||
/// [oldBlobPath] treat old blob as if it had this filename, can be null.
|
||||
///
|
||||
/// [newBlobPath] treat new blob as if it had this filename, can be null.
|
||||
///
|
||||
/// [flags] is a combination of [GitDiff] flags. Defaults to [GitDiff.normal].
|
||||
///
|
||||
|
@ -30,56 +31,111 @@ class Patch {
|
|||
/// boundaries before the hunks will be merged into one. Defaults to 0.
|
||||
///
|
||||
/// **IMPORTANT**: Should be freed to release allocated memory.
|
||||
Patch.create({
|
||||
required Object? a,
|
||||
required Object? b,
|
||||
String? aPath,
|
||||
String? bPath,
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Patch.fromBlobs({
|
||||
required Blob? oldBlob,
|
||||
required Blob? newBlob,
|
||||
String? oldBlobPath,
|
||||
String? newBlobPath,
|
||||
Set<GitDiff> flags = const {GitDiff.normal},
|
||||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
final flagsInt = flags.fold(0, (int acc, e) => acc | e.value);
|
||||
_patchPointer = bindings.fromBlobs(
|
||||
oldBlobPointer: oldBlob?.pointer,
|
||||
oldAsPath: oldBlobPath,
|
||||
newBlobPointer: newBlob?.pointer,
|
||||
newAsPath: newBlobPath,
|
||||
flags: flags.fold(0, (int acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
);
|
||||
}
|
||||
|
||||
if (a is Blob?) {
|
||||
if (b is Blob?) {
|
||||
_patchPointer = bindings.fromBlobs(
|
||||
oldBlobPointer: a?.pointer ?? nullptr,
|
||||
oldAsPath: aPath,
|
||||
newBlobPointer: b?.pointer ?? nullptr,
|
||||
newAsPath: bPath,
|
||||
flags: flagsInt,
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
);
|
||||
} else if (b is String?) {
|
||||
_patchPointer = bindings.fromBlobAndBuffer(
|
||||
oldBlobPointer: a?.pointer,
|
||||
oldAsPath: aPath,
|
||||
buffer: b as String?,
|
||||
bufferAsPath: bPath,
|
||||
flags: flagsInt,
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
);
|
||||
} else {
|
||||
throw ArgumentError('Provided argument(s) is not Blob or String');
|
||||
}
|
||||
} else if ((a is String?) && (b is String?)) {
|
||||
_patchPointer = bindings.fromBuffers(
|
||||
oldBuffer: a as String?,
|
||||
oldAsPath: aPath,
|
||||
newBuffer: b,
|
||||
newAsPath: bPath,
|
||||
flags: flagsInt,
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
);
|
||||
} else {
|
||||
throw ArgumentError('Provided argument(s) is not Blob or String');
|
||||
}
|
||||
/// Directly generates a [Patch] from the difference between the blob and a
|
||||
/// buffer.
|
||||
///
|
||||
/// [blob] is the blob for old side of diff, or null for empty blob.
|
||||
///
|
||||
/// [buffer] is the raw data for new side of diff, or null for empty.
|
||||
///
|
||||
/// [blobPath] treat old blob as if it had this filename, can be null.
|
||||
///
|
||||
/// [bufferPath] treat buffer as if it had this filename, can be null.
|
||||
///
|
||||
/// [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.
|
||||
Patch.fromBlobAndBuffer({
|
||||
required Blob? blob,
|
||||
required String? buffer,
|
||||
String? blobPath,
|
||||
String? bufferPath,
|
||||
Set<GitDiff> flags = const {GitDiff.normal},
|
||||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
_patchPointer = bindings.fromBlobAndBuffer(
|
||||
oldBlobPointer: blob?.pointer,
|
||||
oldAsPath: blobPath,
|
||||
buffer: buffer,
|
||||
bufferAsPath: bufferPath,
|
||||
flags: flags.fold(0, (int acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
);
|
||||
}
|
||||
|
||||
/// Directly generates a [Patch] from the difference between two buffers
|
||||
///
|
||||
/// [oldBuffer] is the raw data for old side of diff, or null for empty.
|
||||
///
|
||||
/// [newBuffer] is the raw data for new side of diff, or null for empty.
|
||||
///
|
||||
/// [oldBufferPath] treat old buffer as if it had this filename, can be null.
|
||||
///
|
||||
/// [newBufferPath] treat new buffer as if it had this filename, can be null.
|
||||
///
|
||||
/// [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.
|
||||
Patch.fromBuffers({
|
||||
required String? oldBuffer,
|
||||
required String? newBuffer,
|
||||
String? oldBufferPath,
|
||||
String? newBufferPath,
|
||||
Set<GitDiff> flags = const {GitDiff.normal},
|
||||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
_patchPointer = bindings.fromBuffers(
|
||||
oldBuffer: oldBuffer,
|
||||
oldAsPath: oldBufferPath,
|
||||
newBuffer: newBuffer,
|
||||
newAsPath: newBufferPath,
|
||||
flags: flags.fold(0, (int acc, e) => acc | e.value),
|
||||
contextLines: contextLines,
|
||||
interhunkLines: interhunkLines,
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a patch for an entry in the diff list.
|
||||
|
|
|
@ -1409,39 +1409,6 @@ class Repository {
|
|||
);
|
||||
}
|
||||
|
||||
/// Returns a [Patch] with changes between the blobs.
|
||||
///
|
||||
/// [a] is the blob for old side of diff.
|
||||
///
|
||||
/// [b] is the blob for new side of diff.
|
||||
///
|
||||
/// [aPath] treat [a] blob as if it had this filename, can be null.
|
||||
///
|
||||
/// [bPath] treat [b] blob as if it had this filename, can be null.
|
||||
///
|
||||
/// [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.
|
||||
Patch diffBlobs({
|
||||
required Blob a,
|
||||
required Blob b,
|
||||
String? aPath,
|
||||
String? bPath,
|
||||
Set<GitDiff> flags = const {GitDiff.normal},
|
||||
int contextLines = 3,
|
||||
int interhunkLines = 0,
|
||||
}) {
|
||||
return a.diff(newBlob: b, oldAsPath: aPath, newAsPath: bPath);
|
||||
}
|
||||
|
||||
/// Returns list of all the stashed states, first being the most recent.
|
||||
List<Stash> get stashes => Stash.list(this);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue