style: use conts for constructors

This commit is contained in:
Aleksey Kulikov 2021-09-23 10:48:23 +03:00
parent e0e16aea30
commit 7187d890d6
17 changed files with 39 additions and 69 deletions

View file

@ -1,7 +1,6 @@
include: package:lints/recommended.yaml include: package:lints/recommended.yaml
linter: linter:
rules: rules:
- file_names
- prefer_const_constructors - prefer_const_constructors
- sort_constructors_first - sort_constructors_first
analyzer: analyzer:

View file

@ -1,6 +1,7 @@
import 'dart:ffi'; import 'dart:ffi';
import 'package:ffi/ffi.dart'; import 'package:ffi/ffi.dart';
import '../error.dart'; import '../error.dart';
import '../oid.dart';
import '../stash.dart'; import '../stash.dart';
import 'checkout.dart' as checkout_bindings; import 'checkout.dart' as checkout_bindings;
import 'libgit2_bindings.dart'; import 'libgit2_bindings.dart';
@ -142,7 +143,7 @@ int _stashCb(
_stashList.add(Stash( _stashList.add(Stash(
index: index, index: index,
message: message.cast<Utf8>().toDartString(), message: message.cast<Utf8>().toDartString(),
oid: oid, oid: Oid(oid),
)); ));
return 0; return 0;
} }

View file

@ -7,7 +7,6 @@ import 'reference.dart';
import 'repository.dart'; import 'repository.dart';
import 'oid.dart'; import 'oid.dart';
import 'git_types.dart'; import 'git_types.dart';
import 'util.dart';
class Branches { class Branches {
/// Initializes a new instance of the [Branches] class /// Initializes a new instance of the [Branches] class
@ -81,12 +80,10 @@ class Branch {
/// branch object in memory. /// branch object in memory.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Branch(this._branchPointer) { const Branch(this._branchPointer);
libgit2.git_libgit2_init();
}
/// Pointer to memory address for allocated branch object. /// Pointer to memory address for allocated branch object.
late final Pointer<git_reference> _branchPointer; final Pointer<git_reference> _branchPointer;
/// Returns the OID pointed to by a branch. /// Returns the OID pointed to by a branch.
/// ///

View file

@ -144,11 +144,11 @@ class Config with IterableMixin<ConfigEntry> {
@override @override
Iterator<ConfigEntry> get iterator => Iterator<ConfigEntry> get iterator =>
ConfigIterator(bindings.iterator(_configPointer)); _ConfigIterator(bindings.iterator(_configPointer));
} }
class ConfigEntry { class ConfigEntry {
ConfigEntry(this._configEntryPointer); const ConfigEntry(this._configEntryPointer);
/// Pointer to memory address for allocated config entry object. /// Pointer to memory address for allocated config entry object.
final Pointer<git_config_entry> _configEntryPointer; final Pointer<git_config_entry> _configEntryPointer;
@ -183,8 +183,8 @@ class ConfigEntry {
} }
} }
class ConfigIterator implements Iterator<ConfigEntry> { class _ConfigIterator implements Iterator<ConfigEntry> {
ConfigIterator(this._iteratorPointer); _ConfigIterator(this._iteratorPointer);
/// Pointer to memory address for allocated config iterator. /// Pointer to memory address for allocated config iterator.
final Pointer<git_config_iterator> _iteratorPointer; final Pointer<git_config_iterator> _iteratorPointer;

View file

@ -122,7 +122,7 @@ class Diff {
class DiffDelta { class DiffDelta {
/// Initializes a new instance of [DiffDelta] class from provided /// Initializes a new instance of [DiffDelta] class from provided
/// pointer to diff delta object in memory. /// pointer to diff delta object in memory.
DiffDelta(this._diffDeltaPointer); const DiffDelta(this._diffDeltaPointer);
/// Pointer to memory address for allocated diff delta object. /// Pointer to memory address for allocated diff delta object.
final Pointer<git_diff_delta> _diffDeltaPointer; final Pointer<git_diff_delta> _diffDeltaPointer;
@ -182,7 +182,7 @@ class DiffDelta {
/// are tracking type changes or ignored/untracked directories). /// are tracking type changes or ignored/untracked directories).
class DiffFile { class DiffFile {
/// Initializes a new instance of [DiffFile] class from provided diff file object. /// Initializes a new instance of [DiffFile] class from provided diff file object.
DiffFile(this._diffFile); const DiffFile(this._diffFile);
final git_diff_file _diffFile; final git_diff_file _diffFile;
@ -223,7 +223,7 @@ class DiffFile {
class DiffStats { class DiffStats {
/// Initializes a new instance of [DiffStats] class from provided /// Initializes a new instance of [DiffStats] class from provided
/// pointer to diff stats object in memory. /// pointer to diff stats object in memory.
DiffStats(this._diffStatsPointer); const DiffStats(this._diffStatsPointer);
/// Pointer to memory address for allocated diff delta object. /// Pointer to memory address for allocated diff delta object.
final Pointer<git_diff_stats> _diffStatsPointer; final Pointer<git_diff_stats> _diffStatsPointer;
@ -255,7 +255,7 @@ class DiffStats {
class DiffHunk { class DiffHunk {
/// Initializes a new instance of [DiffHunk] class from provided /// 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. /// pointers to patch object and diff hunk object in memory and number of lines in hunk.
DiffHunk( const DiffHunk(
this._patchPointer, this._patchPointer,
this._diffHunkPointer, this._diffHunkPointer,
this.linesCount, this.linesCount,
@ -269,10 +269,10 @@ class DiffHunk {
final Pointer<git_patch> _patchPointer; final Pointer<git_patch> _patchPointer;
/// Returns count of total lines in this hunk. /// Returns count of total lines in this hunk.
late final int linesCount; final int linesCount;
/// Returns index of this hunk in the patch. /// Returns index of this hunk in the patch.
late final int index; final int index;
/// Returns starting line number in 'old file'. /// Returns starting line number in 'old file'.
int get oldStart => _diffHunkPointer.ref.old_start; int get oldStart => _diffHunkPointer.ref.old_start;
@ -310,7 +310,7 @@ class DiffHunk {
class DiffLine { class DiffLine {
/// Initializes a new instance of [DiffLine] class from provided /// Initializes a new instance of [DiffLine] class from provided
/// pointer to diff line object in memory. /// pointer to diff line object in memory.
DiffLine(this._diffLinePointer); const DiffLine(this._diffLinePointer);
/// Pointer to memory address for allocated diff line object. /// Pointer to memory address for allocated diff line object.
final Pointer<git_diff_line> _diffLinePointer; final Pointer<git_diff_line> _diffLinePointer;

View file

@ -9,18 +9,15 @@ import 'bindings/diff.dart' as diff_bindings;
import 'oid.dart'; import 'oid.dart';
import 'git_types.dart'; import 'git_types.dart';
import 'repository.dart'; import 'repository.dart';
import 'util.dart';
class Index with IterableMixin<IndexEntry> { class Index with IterableMixin<IndexEntry> {
/// Initializes a new instance of [Index] class from provided /// Initializes a new instance of [Index] class from provided
/// pointer to index object in memory. /// pointer to index object in memory.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Index(this._indexPointer) { const Index(this._indexPointer);
libgit2.git_libgit2_init();
}
late final Pointer<git_index> _indexPointer; final Pointer<git_index> _indexPointer;
/// Pointer to memory address for allocated index object. /// Pointer to memory address for allocated index object.
Pointer<git_index> get pointer => _indexPointer; Pointer<git_index> get pointer => _indexPointer;
@ -237,10 +234,10 @@ class Index with IterableMixin<IndexEntry> {
class IndexEntry { class IndexEntry {
/// Initializes a new instance of [IndexEntry] class. /// Initializes a new instance of [IndexEntry] class.
IndexEntry(this._indexEntryPointer); const IndexEntry(this._indexEntryPointer);
/// Pointer to memory address for allocated index entry object. /// Pointer to memory address for allocated index entry object.
late final Pointer<git_index_entry> _indexEntryPointer; final Pointer<git_index_entry> _indexEntryPointer;
/// Unique identity of the index entry. /// Unique identity of the index entry.
Oid get id => Oid.fromRaw(_indexEntryPointer.ref.id); Oid get id => Oid.fromRaw(_indexEntryPointer.ref.id);

View file

@ -1,16 +1,13 @@
import 'dart:ffi'; import 'dart:ffi';
import 'bindings/libgit2_bindings.dart'; import 'bindings/libgit2_bindings.dart';
import 'bindings/odb.dart' as bindings; import 'bindings/odb.dart' as bindings;
import 'util.dart';
class Odb { class Odb {
/// Initializes a new instance of [Odb] class from provided /// Initializes a new instance of [Odb] class from provided
/// pointer to Odb object in memory. /// pointer to Odb object in memory.
Odb(this._odbPointer) { const Odb(this._odbPointer);
libgit2.git_libgit2_init();
}
late final Pointer<git_odb> _odbPointer; final Pointer<git_odb> _odbPointer;
/// Pointer to memory address for allocated oid object. /// Pointer to memory address for allocated oid object.
Pointer<git_odb> get pointer => _odbPointer; Pointer<git_odb> get pointer => _odbPointer;

View file

@ -7,9 +7,7 @@ import 'util.dart';
class Oid { class Oid {
/// Initializes a new instance of [Oid] class from provided /// Initializes a new instance of [Oid] class from provided
/// pointer to Oid object in memory. /// pointer to Oid object in memory.
Oid(this._oidPointer) { Oid(this._oidPointer);
libgit2.git_libgit2_init();
}
/// Initializes a new instance of [Oid] class by determining if an object can be found /// 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 /// 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. /// Initializes a new instance of [Oid] class from provided raw git_oid.
Oid.fromRaw(git_oid raw) { Oid.fromRaw(git_oid raw) {
libgit2.git_libgit2_init();
_oidPointer = bindings.fromRaw(raw.id); _oidPointer = bindings.fromRaw(raw.id);
} }

View file

@ -5,16 +5,13 @@ import 'bindings/patch.dart' as bindings;
import 'blob.dart'; import 'blob.dart';
import 'diff.dart'; import 'diff.dart';
import 'git_types.dart'; import 'git_types.dart';
import 'util.dart';
class Patch { class Patch {
/// Initializes a new instance of [Patch] class from provided /// Initializes a new instance of [Patch] class from provided
/// pointer to patch object in memory and pointers to old and new blobs/buffers. /// pointer to patch object in memory and pointers to old and new blobs/buffers.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Patch(this._patchPointer, this._aPointer, this._bPointer) { Patch(this._patchPointer, this._aPointer, this._bPointer);
libgit2.git_libgit2_init();
}
/// Directly generates a patch from the difference between two blobs, buffers or /// Directly generates a patch from the difference between two blobs, buffers or
/// blob and a buffer. /// blob and a buffer.

View file

@ -4,15 +4,12 @@ import 'bindings/libgit2_bindings.dart';
import 'bindings/reflog.dart' as bindings; import 'bindings/reflog.dart' as bindings;
import 'reference.dart'; import 'reference.dart';
import 'signature.dart'; import 'signature.dart';
import 'util.dart';
class RefLog with IterableMixin<RefLogEntry> { class RefLog with IterableMixin<RefLogEntry> {
/// Initializes a new instance of [RefLog] class from provided [Reference]. /// Initializes a new instance of [RefLog] class from provided [Reference].
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
RefLog(Reference ref) { RefLog(Reference ref) {
libgit2.git_libgit2_init();
final repo = ref.owner; final repo = ref.owner;
final name = ref.name; final name = ref.name;
_reflogPointer = bindings.read(repo.pointer, name); _reflogPointer = bindings.read(repo.pointer, name);
@ -38,10 +35,10 @@ class RefLog with IterableMixin<RefLogEntry> {
class RefLogEntry { class RefLogEntry {
/// Initializes a new instance of [RefLogEntry] class. /// Initializes a new instance of [RefLogEntry] class.
RefLogEntry(this._entryPointer); const RefLogEntry(this._entryPointer);
/// Pointer to memory address for allocated reflog entry object. /// Pointer to memory address for allocated reflog entry object.
late final Pointer<git_reflog_entry> _entryPointer; final Pointer<git_reflog_entry> _entryPointer;
/// Returns the log message. /// Returns the log message.
String get message => bindings.entryMessage(_entryPointer); String get message => bindings.entryMessage(_entryPointer);

View file

@ -8,7 +8,7 @@ import 'git_types.dart';
class Refspec { class Refspec {
/// Initializes a new instance of the [Refspec] class /// Initializes a new instance of the [Refspec] class
/// from provided pointer to refspec object in memory. /// from provided pointer to refspec object in memory.
Refspec(this._refspecPointer); const Refspec(this._refspecPointer);
/// Pointer to memory address for allocated refspec object. /// Pointer to memory address for allocated refspec object.
final Pointer<git_refspec> _refspecPointer; final Pointer<git_refspec> _refspecPointer;

View file

@ -117,10 +117,10 @@ class Remotes {
class Remote { class Remote {
/// Initializes a new instance of [Remote] class from provided pointer /// Initializes a new instance of [Remote] class from provided pointer
/// to remote object in memory. /// to remote object in memory.
Remote(this._remotePointer); const Remote(this._remotePointer);
/// Pointer to memory address for allocated remote object. /// Pointer to memory address for allocated remote object.
late final Pointer<git_remote> _remotePointer; final Pointer<git_remote> _remotePointer;
/// Returns the remote's name. /// Returns the remote's name.
String get name => bindings.name(_remotePointer); String get name => bindings.name(_remotePointer);
@ -198,7 +198,7 @@ class Remote {
class TransferProgress { class TransferProgress {
/// Initializes a new instance of [TransferProgress] class from provided pointer /// Initializes a new instance of [TransferProgress] class from provided pointer
/// to transfer progress object in memory. /// to transfer progress object in memory.
TransferProgress(this._transferProgressPointer); const TransferProgress(this._transferProgressPointer);
/// Pointer to memory address for allocated transfer progress object. /// Pointer to memory address for allocated transfer progress object.
final Pointer<git_indexer_progress> _transferProgressPointer; final Pointer<git_indexer_progress> _transferProgressPointer;

View file

@ -60,10 +60,10 @@ class RevParse {
class RevSpec { class RevSpec {
/// Initializes a new instance of [RevSpec] class from provided /// Initializes a new instance of [RevSpec] class from provided
/// pointer to revspec object in memory. /// pointer to revspec object in memory.
RevSpec(this._revSpecPointer); const RevSpec(this._revSpecPointer);
/// Pointer to memory address for allocated revspec object. /// Pointer to memory address for allocated revspec object.
late final Pointer<git_revspec> _revSpecPointer; final Pointer<git_revspec> _revSpecPointer;
/// The left element of the revspec; must be freed by the user. /// The left element of the revspec; must be freed by the user.
Commit get from => Commit(_revSpecPointer.ref.from.cast()); Commit get from => Commit(_revSpecPointer.ref.from.cast());

View file

@ -10,9 +10,7 @@ class Signature {
/// signature object in memory. /// signature object in memory.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Signature(this._signaturePointer) { Signature(this._signaturePointer);
libgit2.git_libgit2_init();
}
/// Initializes a new instance of [Signature] class from provided [name], [email], /// Initializes a new instance of [Signature] class from provided [name], [email],
/// and optional [time] in seconds from epoch and [offset] in minutes. /// and optional [time] in seconds from epoch and [offset] in minutes.

View file

@ -1,16 +1,12 @@
import 'dart:ffi';
import 'bindings/libgit2_bindings.dart';
import 'oid.dart'; import 'oid.dart';
class Stash { class Stash {
/// Initializes a new instance of [Stash] class. /// Initializes a new instance of [Stash] class.
Stash({ const Stash({
required this.index, required this.index,
required this.message, required this.message,
required Pointer<git_oid> oid, required this.oid,
}) { });
this.oid = Oid(oid);
}
/// The position within the stash list. /// The position within the stash list.
final int index; final int index;
@ -19,7 +15,7 @@ class Stash {
final String message; final String message;
/// The commit oid of the stashed state. /// The commit oid of the stashed state.
late final Oid oid; final Oid oid;
@override @override
String toString() { String toString() {

View file

@ -9,16 +9,13 @@ import 'repository.dart';
import 'signature.dart'; import 'signature.dart';
import 'git_types.dart'; import 'git_types.dart';
import 'tree.dart'; import 'tree.dart';
import 'util.dart';
class Tag { class Tag {
/// Initializes a new instance of [Tag] class from provided pointer to /// Initializes a new instance of [Tag] class from provided pointer to
/// tag object in memory. /// tag object in memory.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Tag(this._tagPointer) { Tag(this._tagPointer);
libgit2.git_libgit2_init();
}
/// Initializes a new instance of [Tag] class from provided /// Initializes a new instance of [Tag] class from provided
/// [Repository] object and [sha] hex string. /// [Repository] object and [sha] hex string.

View file

@ -7,16 +7,13 @@ import 'index.dart';
import 'repository.dart'; import 'repository.dart';
import 'oid.dart'; import 'oid.dart';
import 'git_types.dart'; import 'git_types.dart';
import 'util.dart';
class Tree { class Tree {
/// Initializes a new instance of [Tree] class from provided pointer to /// Initializes a new instance of [Tree] class from provided pointer to
/// tree object in memory. /// tree object in memory.
/// ///
/// Should be freed with `free()` to release allocated memory. /// Should be freed with `free()` to release allocated memory.
Tree(this._treePointer) { Tree(this._treePointer);
libgit2.git_libgit2_init();
}
/// Initializes a new instance of [Tree] class from provided /// Initializes a new instance of [Tree] class from provided
/// [Repository] object and [sha] hex string. /// [Repository] object and [sha] hex string.
@ -142,7 +139,7 @@ class Tree {
class TreeEntry { class TreeEntry {
/// Initializes a new instance of [TreeEntry] class. /// Initializes a new instance of [TreeEntry] class.
TreeEntry(this._treeEntryPointer); const TreeEntry(this._treeEntryPointer);
/// Pointer to memory address for allocated tree entry object. /// Pointer to memory address for allocated tree entry object.
final Pointer<git_tree_entry> _treeEntryPointer; final Pointer<git_tree_entry> _treeEntryPointer;