test: fix tests failing in ci

This commit is contained in:
Aleksey Kulikov 2021-10-27 17:35:20 +03:00
parent 7f0cd86e72
commit 0e329bd2b1
22 changed files with 291 additions and 257 deletions

View file

@ -9,7 +9,7 @@ import 'package:libgit2dart/src/util.dart';
///
/// You can use the standard patch accessor functions to read the patch data,
/// and you must free the patch when done.
Map<String, Pointer?> fromBuffers({
Pointer<git_patch> fromBuffers({
String? oldBuffer,
String? oldAsPath,
String? newBuffer,
@ -45,18 +45,18 @@ Map<String, Pointer?> fromBuffers({
calloc.free(oldAsPathC);
calloc.free(newAsPathC);
calloc.free(opts);
// We are not freeing buffers because patch object does not have reference to
// underlying buffers. So if the buffer is freed the patch text becomes
// corrupted.
// Returning map with pointers to patch and buffers because patch object does
// not have refenrece to underlying buffers or blobs. So if the buffer or blob is freed/removed
// the patch text becomes corrupted.
return {'patch': out.value, 'a': oldBufferC, 'b': newBufferC};
return out.value;
}
/// Directly generate a patch from the difference between two blobs.
///
/// You can use the standard patch accessor functions to read the patch data,
/// and you must free the patch when done.
Map<String, Pointer?> fromBlobs({
Pointer<git_patch> fromBlobs({
required Pointer<git_blob> oldBlobPointer,
String? oldAsPath,
required Pointer<git_blob> newBlobPointer,
@ -87,17 +87,14 @@ Map<String, Pointer?> fromBlobs({
calloc.free(newAsPathC);
calloc.free(opts);
// Returning map with pointers to patch and blobs because patch object does
// not have reference to underlying blobs. So if the blob is freed/removed the
// patch text becomes corrupted.
return {'patch': out.value, 'a': oldBlobPointer, 'b': newBlobPointer};
return out.value;
}
/// Directly generate a patch from the difference between a blob and a buffer.
///
/// You can use the standard patch accessor functions to read the patch data,
/// and you must free the patch when done.
Map<String, Pointer?> fromBlobAndBuffer({
Pointer<git_patch> fromBlobAndBuffer({
Pointer<git_blob>? oldBlobPointer,
String? oldAsPath,
String? buffer,
@ -131,10 +128,7 @@ Map<String, Pointer?> fromBlobAndBuffer({
calloc.free(bufferAsPathC);
calloc.free(opts);
// Returning map with pointers to patch and buffers because patch object does
// not have reference to underlying buffers or blobs. So if the buffer or
// blob is freed/removed the patch text becomes corrupted.
return {'patch': out.value, 'a': oldBlobPointer, 'b': bufferC};
return out.value;
}
/// Return a patch for an entry in the diff list.

View file

@ -107,20 +107,16 @@ class Blob {
int contextLines = 3,
int interhunkLines = 0,
}) {
final result = 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,
);
return Patch(
result['patch']! as Pointer<git_patch>,
result['a'],
result['b'],
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,
),
);
}
@ -152,20 +148,16 @@ class Blob {
int contextLines = 3,
int interhunkLines = 0,
}) {
final result = patch_bindings.fromBlobAndBuffer(
oldBlobPointer: _blobPointer,
oldAsPath: oldAsPath,
buffer: buffer,
bufferAsPath: bufferAsPath,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
);
return Patch(
result['patch']! as Pointer<git_patch>,
result['a'],
result['b'],
patch_bindings.fromBlobAndBuffer(
oldBlobPointer: _blobPointer,
oldAsPath: oldAsPath,
buffer: buffer,
bufferAsPath: bufferAsPath,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,
interhunkLines: interhunkLines,
),
);
}

View file

@ -177,8 +177,6 @@ class Config with IterableMixin<ConfigEntry> {
class ConfigEntry {
/// Initializes a new instance of [ConfigEntry] class from provided
/// pointer to config entry object in memory.
///
/// **IMPORTANT**: Should be freed to release allocated memory.
const ConfigEntry(this._configEntryPointer);
/// Pointer to memory address for allocated config entry object.
@ -200,9 +198,6 @@ class ConfigEntry {
);
}
/// Releases memory allocated for config entry object.
void free() => calloc.free(_configEntryPointer);
@override
String toString() {
return 'ConfigEntry{name: $name, value: $value, '

View file

@ -1,5 +1,5 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:libgit2dart/libgit2dart.dart';
import 'package:libgit2dart/src/bindings/libgit2_bindings.dart';
import 'package:libgit2dart/src/bindings/patch.dart' as bindings;
@ -10,7 +10,7 @@ class Patch {
/// pointer to patch object in memory and pointers to old and new blobs/buffers.
///
/// **IMPORTANT**: Should be freed to release allocated memory.
Patch(this._patchPointer, this._aPointer, this._bPointer);
Patch(this._patchPointer);
/// Directly generates a patch from the difference between two blobs, buffers
/// or blob and a buffer.
@ -42,11 +42,10 @@ class Patch {
libgit2.git_libgit2_init();
final int flagsInt = flags.fold(0, (acc, e) => acc | e.value);
var result = <String, Pointer?>{};
if (a is Blob?) {
if (b is Blob?) {
result = bindings.fromBlobs(
_patchPointer = bindings.fromBlobs(
oldBlobPointer: a?.pointer ?? nullptr,
oldAsPath: aPath,
newBlobPointer: b?.pointer ?? nullptr,
@ -56,7 +55,7 @@ class Patch {
interhunkLines: interhunkLines,
);
} else if (b is String?) {
result = bindings.fromBlobAndBuffer(
_patchPointer = bindings.fromBlobAndBuffer(
oldBlobPointer: a?.pointer,
oldAsPath: aPath,
buffer: b as String?,
@ -69,7 +68,7 @@ class Patch {
throw ArgumentError('Provided argument(s) is not Blob or String');
}
} else if ((a is String?) && (b is String?)) {
result = bindings.fromBuffers(
_patchPointer = bindings.fromBuffers(
oldBuffer: a as String?,
oldAsPath: aPath,
newBuffer: b,
@ -81,10 +80,6 @@ class Patch {
} else {
throw ArgumentError('Provided argument(s) is not Blob or String');
}
_patchPointer = result['patch']! as Pointer<git_patch>;
_aPointer = result['a'];
_bPointer = result['b'];
}
/// Creates a patch for an entry in the diff list.
@ -104,9 +99,6 @@ class Patch {
late final Pointer<git_patch> _patchPointer;
Pointer<NativeType>? _aPointer;
Pointer<NativeType>? _bPointer;
/// Pointer to memory address for allocated patch object.
Pointer<git_patch> get pointer => _patchPointer;
@ -163,15 +155,7 @@ class Patch {
}
/// Releases memory allocated for patch object.
void free() {
if (_aPointer != null) {
calloc.free(_aPointer!);
}
if (_bPointer != null) {
calloc.free(_bPointer!);
}
bindings.free(_patchPointer);
}
void free() => bindings.free(_patchPointer);
@override
String toString() => 'Patch{size: ${size()}, delta: $delta}';

View file

@ -1600,7 +1600,7 @@ class Repository {
/// List of notes for repository.
///
/// **IMPORTANT**: Notes must be freed to release allocated memory.
/// **IMPORTANT**: Notes Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
List<Note> get notes => Note.list(this);
@ -1611,7 +1611,7 @@ class Repository {
///
/// [notesRef] is the canonical name of the reference to use. Defaults to "refs/notes/commits".
///
/// **IMPORTANT**: Notes must be freed to release allocated memory.
/// **IMPORTANT**: Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Note lookupNote({