diff --git a/lib/src/blob.dart b/lib/src/blob.dart index 7bd9d62..678c6c1 100644 --- a/lib/src/blob.dart +++ b/lib/src/blob.dart @@ -6,16 +6,13 @@ import 'git_types.dart'; import 'patch.dart'; import 'oid.dart'; import 'repository.dart'; -import 'util.dart'; class Blob { /// Initializes a new instance of [Blob] class from provided pointer to /// blob object in memory. /// /// Should be freed with `free()` to release allocated memory. - Blob(this._blobPointer) { - libgit2.git_libgit2_init(); - } + Blob(this._blobPointer); /// Initializes a new instance of [Blob] class from provided /// [Repository] object and [sha] hex string. diff --git a/lib/src/commit.dart b/lib/src/commit.dart index d2e4cdc..cb65f6a 100644 --- a/lib/src/commit.dart +++ b/lib/src/commit.dart @@ -6,16 +6,13 @@ import 'repository.dart'; import 'oid.dart'; import 'signature.dart'; import 'tree.dart'; -import 'util.dart'; class Commit { /// Initializes a new instance of [Commit] class from provided pointer to /// commit object in memory. /// /// Should be freed with `free()` to release allocated memory. - Commit(this._commitPointer) { - libgit2.git_libgit2_init(); - } + Commit(this._commitPointer); /// Initializes a new instance of [Commit] class from provided [Repository] object /// and [sha] hex string. diff --git a/lib/src/config.dart b/lib/src/config.dart index a4a9015..23dd041 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -12,9 +12,7 @@ class Config with IterableMixin { /// pointer to config object in memory. /// /// Should be freed with `free()` to release allocated memory. - Config(this._configPointer) { - libgit2.git_libgit2_init(); - } + Config(this._configPointer); /// Initializes a new instance of [Config] class from provided [path]. /// diff --git a/lib/src/diff.dart b/lib/src/diff.dart index 2e66d10..34878e8 100644 --- a/lib/src/diff.dart +++ b/lib/src/diff.dart @@ -13,9 +13,7 @@ class Diff { /// pointer to diff object in memory. /// /// Should be freed with `free()` to release allocated memory. - Diff(this._diffPointer) { - libgit2.git_libgit2_init(); - } + Diff(this._diffPointer); Diff.parse(String content) { libgit2.git_libgit2_init(); diff --git a/lib/src/patch.dart b/lib/src/patch.dart index f3615ab..6bdc2c3 100644 --- a/lib/src/patch.dart +++ b/lib/src/patch.dart @@ -5,6 +5,7 @@ import 'bindings/patch.dart' as bindings; import 'blob.dart'; import 'diff.dart'; import 'git_types.dart'; +import 'util.dart'; class Patch { /// Initializes a new instance of [Patch] class from provided @@ -30,6 +31,8 @@ class Patch { int contextLines = 3, int interhunkLines = 0, }) { + libgit2.git_libgit2_init(); + final int flagsInt = flags.fold(0, (previousValue, e) => previousValue | e.value); var result = {}; @@ -83,6 +86,8 @@ class Patch { /// /// Throws a [LibGit2Error] if error occured. Patch.fromDiff(Diff diff, int index) { + libgit2.git_libgit2_init(); + _patchPointer = bindings.fromDiff(diff.pointer, index); }