diff --git a/analysis_options.yaml b/analysis_options.yaml index 5f59a0d..5c17980 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,7 +1,6 @@ include: package:lints/recommended.yaml linter: rules: - - file_names - prefer_const_constructors - sort_constructors_first analyzer: diff --git a/lib/src/bindings/stash.dart b/lib/src/bindings/stash.dart index bb91e1b..fb72979 100644 --- a/lib/src/bindings/stash.dart +++ b/lib/src/bindings/stash.dart @@ -1,6 +1,7 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import '../error.dart'; +import '../oid.dart'; import '../stash.dart'; import 'checkout.dart' as checkout_bindings; import 'libgit2_bindings.dart'; @@ -142,7 +143,7 @@ int _stashCb( _stashList.add(Stash( index: index, message: message.cast().toDartString(), - oid: oid, + oid: Oid(oid), )); return 0; } diff --git a/lib/src/branch.dart b/lib/src/branch.dart index 1b9199f..56fe586 100644 --- a/lib/src/branch.dart +++ b/lib/src/branch.dart @@ -7,7 +7,6 @@ import 'reference.dart'; import 'repository.dart'; import 'oid.dart'; import 'git_types.dart'; -import 'util.dart'; class Branches { /// Initializes a new instance of the [Branches] class @@ -81,12 +80,10 @@ class Branch { /// branch object in memory. /// /// Should be freed with `free()` to release allocated memory. - Branch(this._branchPointer) { - libgit2.git_libgit2_init(); - } + const Branch(this._branchPointer); /// Pointer to memory address for allocated branch object. - late final Pointer _branchPointer; + final Pointer _branchPointer; /// Returns the OID pointed to by a branch. /// diff --git a/lib/src/config.dart b/lib/src/config.dart index 21cd0b5..a4a9015 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -144,11 +144,11 @@ class Config with IterableMixin { @override Iterator get iterator => - ConfigIterator(bindings.iterator(_configPointer)); + _ConfigIterator(bindings.iterator(_configPointer)); } class ConfigEntry { - ConfigEntry(this._configEntryPointer); + const ConfigEntry(this._configEntryPointer); /// Pointer to memory address for allocated config entry object. final Pointer _configEntryPointer; @@ -183,8 +183,8 @@ class ConfigEntry { } } -class ConfigIterator implements Iterator { - ConfigIterator(this._iteratorPointer); +class _ConfigIterator implements Iterator { + _ConfigIterator(this._iteratorPointer); /// Pointer to memory address for allocated config iterator. final Pointer _iteratorPointer; diff --git a/lib/src/diff.dart b/lib/src/diff.dart index a9ca618..2e66d10 100644 --- a/lib/src/diff.dart +++ b/lib/src/diff.dart @@ -122,7 +122,7 @@ class Diff { class DiffDelta { /// Initializes a new instance of [DiffDelta] class from provided /// pointer to diff delta object in memory. - DiffDelta(this._diffDeltaPointer); + const DiffDelta(this._diffDeltaPointer); /// Pointer to memory address for allocated diff delta object. final Pointer _diffDeltaPointer; @@ -182,7 +182,7 @@ class DiffDelta { /// are tracking type changes or ignored/untracked directories). class DiffFile { /// Initializes a new instance of [DiffFile] class from provided diff file object. - DiffFile(this._diffFile); + const DiffFile(this._diffFile); final git_diff_file _diffFile; @@ -223,7 +223,7 @@ class DiffFile { class DiffStats { /// Initializes a new instance of [DiffStats] class from provided /// pointer to diff stats object in memory. - DiffStats(this._diffStatsPointer); + const DiffStats(this._diffStatsPointer); /// Pointer to memory address for allocated diff delta object. final Pointer _diffStatsPointer; @@ -255,7 +255,7 @@ class DiffStats { class DiffHunk { /// Initializes a new instance of [DiffHunk] class from provided /// pointers to patch object and diff hunk object in memory and number of lines in hunk. - DiffHunk( + const DiffHunk( this._patchPointer, this._diffHunkPointer, this.linesCount, @@ -269,10 +269,10 @@ class DiffHunk { final Pointer _patchPointer; /// Returns count of total lines in this hunk. - late final int linesCount; + final int linesCount; /// Returns index of this hunk in the patch. - late final int index; + final int index; /// Returns starting line number in 'old file'. int get oldStart => _diffHunkPointer.ref.old_start; @@ -310,7 +310,7 @@ class DiffHunk { class DiffLine { /// Initializes a new instance of [DiffLine] class from provided /// pointer to diff line object in memory. - DiffLine(this._diffLinePointer); + const DiffLine(this._diffLinePointer); /// Pointer to memory address for allocated diff line object. final Pointer _diffLinePointer; diff --git a/lib/src/index.dart b/lib/src/index.dart index f45f4e0..cceccfb 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -9,18 +9,15 @@ import 'bindings/diff.dart' as diff_bindings; import 'oid.dart'; import 'git_types.dart'; import 'repository.dart'; -import 'util.dart'; class Index with IterableMixin { /// Initializes a new instance of [Index] class from provided /// pointer to index object in memory. /// /// Should be freed with `free()` to release allocated memory. - Index(this._indexPointer) { - libgit2.git_libgit2_init(); - } + const Index(this._indexPointer); - late final Pointer _indexPointer; + final Pointer _indexPointer; /// Pointer to memory address for allocated index object. Pointer get pointer => _indexPointer; @@ -237,10 +234,10 @@ class Index with IterableMixin { class IndexEntry { /// Initializes a new instance of [IndexEntry] class. - IndexEntry(this._indexEntryPointer); + const IndexEntry(this._indexEntryPointer); /// Pointer to memory address for allocated index entry object. - late final Pointer _indexEntryPointer; + final Pointer _indexEntryPointer; /// Unique identity of the index entry. Oid get id => Oid.fromRaw(_indexEntryPointer.ref.id); diff --git a/lib/src/odb.dart b/lib/src/odb.dart index 2c0358d..4be4637 100644 --- a/lib/src/odb.dart +++ b/lib/src/odb.dart @@ -1,16 +1,13 @@ import 'dart:ffi'; import 'bindings/libgit2_bindings.dart'; import 'bindings/odb.dart' as bindings; -import 'util.dart'; class Odb { /// Initializes a new instance of [Odb] class from provided /// pointer to Odb object in memory. - Odb(this._odbPointer) { - libgit2.git_libgit2_init(); - } + const Odb(this._odbPointer); - late final Pointer _odbPointer; + final Pointer _odbPointer; /// Pointer to memory address for allocated oid object. Pointer get pointer => _odbPointer; diff --git a/lib/src/oid.dart b/lib/src/oid.dart index 817e832..1222e91 100644 --- a/lib/src/oid.dart +++ b/lib/src/oid.dart @@ -7,9 +7,7 @@ import 'util.dart'; class Oid { /// Initializes a new instance of [Oid] class from provided /// pointer to Oid object in memory. - Oid(this._oidPointer) { - libgit2.git_libgit2_init(); - } + Oid(this._oidPointer); /// Initializes a new instance of [Oid] class by determining if an object can be found /// in the ODB of [repository] with provided hexadecimal [sha] string that is 40 characters @@ -34,7 +32,6 @@ class Oid { /// Initializes a new instance of [Oid] class from provided raw git_oid. Oid.fromRaw(git_oid raw) { - libgit2.git_libgit2_init(); _oidPointer = bindings.fromRaw(raw.id); } diff --git a/lib/src/patch.dart b/lib/src/patch.dart index fd156cc..f3615ab 100644 --- a/lib/src/patch.dart +++ b/lib/src/patch.dart @@ -5,16 +5,13 @@ 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 /// pointer to patch object in memory and pointers to old and new blobs/buffers. /// /// Should be freed with `free()` to release allocated memory. - Patch(this._patchPointer, this._aPointer, this._bPointer) { - libgit2.git_libgit2_init(); - } + Patch(this._patchPointer, this._aPointer, this._bPointer); /// Directly generates a patch from the difference between two blobs, buffers or /// blob and a buffer. diff --git a/lib/src/reflog.dart b/lib/src/reflog.dart index b67ad14..cbe3664 100644 --- a/lib/src/reflog.dart +++ b/lib/src/reflog.dart @@ -4,15 +4,12 @@ import 'bindings/libgit2_bindings.dart'; import 'bindings/reflog.dart' as bindings; import 'reference.dart'; import 'signature.dart'; -import 'util.dart'; class RefLog with IterableMixin { /// Initializes a new instance of [RefLog] class from provided [Reference]. /// /// Throws a [LibGit2Error] if error occured. RefLog(Reference ref) { - libgit2.git_libgit2_init(); - final repo = ref.owner; final name = ref.name; _reflogPointer = bindings.read(repo.pointer, name); @@ -38,10 +35,10 @@ class RefLog with IterableMixin { class RefLogEntry { /// Initializes a new instance of [RefLogEntry] class. - RefLogEntry(this._entryPointer); + const RefLogEntry(this._entryPointer); /// Pointer to memory address for allocated reflog entry object. - late final Pointer _entryPointer; + final Pointer _entryPointer; /// Returns the log message. String get message => bindings.entryMessage(_entryPointer); diff --git a/lib/src/refspec.dart b/lib/src/refspec.dart index 54bf501..2f4a925 100644 --- a/lib/src/refspec.dart +++ b/lib/src/refspec.dart @@ -8,7 +8,7 @@ import 'git_types.dart'; class Refspec { /// Initializes a new instance of the [Refspec] class /// from provided pointer to refspec object in memory. - Refspec(this._refspecPointer); + const Refspec(this._refspecPointer); /// Pointer to memory address for allocated refspec object. final Pointer _refspecPointer; diff --git a/lib/src/remote.dart b/lib/src/remote.dart index b0b03c6..d040d28 100644 --- a/lib/src/remote.dart +++ b/lib/src/remote.dart @@ -117,10 +117,10 @@ class Remotes { class Remote { /// Initializes a new instance of [Remote] class from provided pointer /// to remote object in memory. - Remote(this._remotePointer); + const Remote(this._remotePointer); /// Pointer to memory address for allocated remote object. - late final Pointer _remotePointer; + final Pointer _remotePointer; /// Returns the remote's name. String get name => bindings.name(_remotePointer); @@ -198,7 +198,7 @@ class Remote { class TransferProgress { /// Initializes a new instance of [TransferProgress] class from provided pointer /// to transfer progress object in memory. - TransferProgress(this._transferProgressPointer); + const TransferProgress(this._transferProgressPointer); /// Pointer to memory address for allocated transfer progress object. final Pointer _transferProgressPointer; diff --git a/lib/src/revparse.dart b/lib/src/revparse.dart index fc29f22..268dea8 100644 --- a/lib/src/revparse.dart +++ b/lib/src/revparse.dart @@ -60,10 +60,10 @@ class RevParse { class RevSpec { /// Initializes a new instance of [RevSpec] class from provided /// pointer to revspec object in memory. - RevSpec(this._revSpecPointer); + const RevSpec(this._revSpecPointer); /// Pointer to memory address for allocated revspec object. - late final Pointer _revSpecPointer; + final Pointer _revSpecPointer; /// The left element of the revspec; must be freed by the user. Commit get from => Commit(_revSpecPointer.ref.from.cast()); diff --git a/lib/src/signature.dart b/lib/src/signature.dart index 925e93a..9b58d75 100644 --- a/lib/src/signature.dart +++ b/lib/src/signature.dart @@ -10,9 +10,7 @@ class Signature { /// signature object in memory. /// /// Should be freed with `free()` to release allocated memory. - Signature(this._signaturePointer) { - libgit2.git_libgit2_init(); - } + Signature(this._signaturePointer); /// Initializes a new instance of [Signature] class from provided [name], [email], /// and optional [time] in seconds from epoch and [offset] in minutes. diff --git a/lib/src/stash.dart b/lib/src/stash.dart index 3e677ef..d661041 100644 --- a/lib/src/stash.dart +++ b/lib/src/stash.dart @@ -1,16 +1,12 @@ -import 'dart:ffi'; -import 'bindings/libgit2_bindings.dart'; import 'oid.dart'; class Stash { /// Initializes a new instance of [Stash] class. - Stash({ + const Stash({ required this.index, required this.message, - required Pointer oid, - }) { - this.oid = Oid(oid); - } + required this.oid, + }); /// The position within the stash list. final int index; @@ -19,7 +15,7 @@ class Stash { final String message; /// The commit oid of the stashed state. - late final Oid oid; + final Oid oid; @override String toString() { diff --git a/lib/src/tag.dart b/lib/src/tag.dart index 4f77016..0cf231e 100644 --- a/lib/src/tag.dart +++ b/lib/src/tag.dart @@ -9,16 +9,13 @@ import 'repository.dart'; import 'signature.dart'; import 'git_types.dart'; import 'tree.dart'; -import 'util.dart'; class Tag { /// Initializes a new instance of [Tag] class from provided pointer to /// tag object in memory. /// /// Should be freed with `free()` to release allocated memory. - Tag(this._tagPointer) { - libgit2.git_libgit2_init(); - } + Tag(this._tagPointer); /// Initializes a new instance of [Tag] class from provided /// [Repository] object and [sha] hex string. diff --git a/lib/src/tree.dart b/lib/src/tree.dart index 94829a2..3e2914c 100644 --- a/lib/src/tree.dart +++ b/lib/src/tree.dart @@ -7,16 +7,13 @@ import 'index.dart'; import 'repository.dart'; import 'oid.dart'; import 'git_types.dart'; -import 'util.dart'; class Tree { /// Initializes a new instance of [Tree] class from provided pointer to /// tree object in memory. /// /// Should be freed with `free()` to release allocated memory. - Tree(this._treePointer) { - libgit2.git_libgit2_init(); - } + Tree(this._treePointer); /// Initializes a new instance of [Tree] class from provided /// [Repository] object and [sha] hex string. @@ -142,7 +139,7 @@ class Tree { class TreeEntry { /// Initializes a new instance of [TreeEntry] class. - TreeEntry(this._treeEntryPointer); + const TreeEntry(this._treeEntryPointer); /// Pointer to memory address for allocated tree entry object. final Pointer _treeEntryPointer;