mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 00:29:20 +08:00
Core: Finish null safety migration
This commit is contained in:
@ -1,10 +1,6 @@
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:dart_git/dart_git.dart' as git;
|
||||
import 'package:git_bindings/git_bindings.dart';
|
||||
|
||||
@ -19,10 +15,10 @@ bool useDartGit = false;
|
||||
|
||||
class NoteRepoResult {
|
||||
bool error;
|
||||
String noteFilePath;
|
||||
String? noteFilePath;
|
||||
|
||||
NoteRepoResult({
|
||||
@required this.error,
|
||||
required this.error,
|
||||
this.noteFilePath,
|
||||
});
|
||||
}
|
||||
@ -33,10 +29,10 @@ class GitNoteRepository {
|
||||
final Settings settings;
|
||||
|
||||
GitNoteRepository({
|
||||
@required this.gitDirPath,
|
||||
@required this.settings,
|
||||
required this.gitDirPath,
|
||||
required this.settings,
|
||||
}) : _gitRepo = GitRepo(folderPath: gitDirPath) {
|
||||
// git-bindings aren't properly implemented in these platformsk
|
||||
// git-bindings aren't properly implemented in these platforms
|
||||
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
|
||||
useDartGit = true;
|
||||
}
|
||||
@ -61,7 +57,9 @@ class GitNoteRepository {
|
||||
}
|
||||
|
||||
Future<void> _commit(
|
||||
{String message, String authorEmail, String authorName}) async {
|
||||
{required String /*!*/ message,
|
||||
required String authorEmail,
|
||||
required String authorName}) async {
|
||||
if (useDartGit) {
|
||||
var repo = await git.GitRepository.load(gitDirPath);
|
||||
var author = git.GitAuthor(name: authorName, email: authorEmail);
|
||||
@ -225,6 +223,9 @@ class GitNoteRepository {
|
||||
Future<void> merge() async {
|
||||
var repo = await git.GitRepository.load(gitDirPath);
|
||||
var branch = await repo.currentBranch();
|
||||
if (branch == null) {
|
||||
throw Exception('No current branch found');
|
||||
}
|
||||
var branchConfig = repo.config.branch(branch);
|
||||
if (branchConfig == null) {
|
||||
logExceptionWarning(
|
||||
@ -232,12 +233,9 @@ class GitNoteRepository {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(branchConfig.name != null);
|
||||
assert(branchConfig.merge != null);
|
||||
|
||||
var remoteRef = await repo.remoteBranch(
|
||||
branchConfig.remote,
|
||||
branchConfig.trackingBranch(),
|
||||
branchConfig.remote!,
|
||||
branchConfig.trackingBranch()!,
|
||||
);
|
||||
if (remoteRef == null) {
|
||||
Log.i('Remote has no refs');
|
||||
@ -282,13 +280,15 @@ class GitNoteRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> numChanges() async {
|
||||
Future<int?> numChanges() async {
|
||||
try {
|
||||
var repo = await git.GitRepository.load(gitDirPath);
|
||||
var n = await repo.numChangesToPush();
|
||||
return n;
|
||||
} catch (_) {}
|
||||
return 0;
|
||||
} catch (ex, st) {
|
||||
Log.e("numChanges", ex: ex, stacktrace: st);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ bool shouldLogGitException(Exception ex) {
|
||||
if (ex is! GitException) {
|
||||
return false;
|
||||
}
|
||||
var msg = (ex as GitException).cause.toLowerCase();
|
||||
var msg = ex.cause.toLowerCase();
|
||||
for (var i = 0; i < ignoredMessages.length; i++) {
|
||||
if (msg.contains(ignoredMessages[i])) {
|
||||
return false;
|
||||
|
@ -1,5 +1,3 @@
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
@ -19,11 +17,11 @@ class Node {
|
||||
double forceX = 0.0;
|
||||
double forceY = 0.0;
|
||||
|
||||
String _label;
|
||||
String? _label;
|
||||
|
||||
Node(this.note);
|
||||
|
||||
String get label {
|
||||
String? get label {
|
||||
_label ??= note.pathSpec();
|
||||
return _label;
|
||||
}
|
||||
@ -43,10 +41,10 @@ class Graph extends ChangeNotifier {
|
||||
List<Node> nodes = [];
|
||||
List<Edge> edges = [];
|
||||
|
||||
Map<String, Set<int>> _neighbours = {};
|
||||
Map<String, int> _nodeIndexes;
|
||||
Map<String?, Set<int?>> _neighbours = {};
|
||||
Map<String?, int>? _nodeIndexes;
|
||||
|
||||
GraphNodeLayout initLayouter;
|
||||
late GraphNodeLayout initLayouter;
|
||||
|
||||
final double nodeSize = 50.0;
|
||||
|
||||
@ -78,6 +76,9 @@ class Graph extends ChangeNotifier {
|
||||
var node = _getNode(note);
|
||||
|
||||
var links = await node.note.fetchLinks();
|
||||
if (links == null) {
|
||||
return;
|
||||
}
|
||||
var linkResolver = LinkResolver(note);
|
||||
for (var l in links) {
|
||||
var noteB = linkResolver.resolveLink(l);
|
||||
@ -110,12 +111,12 @@ class Graph extends ChangeNotifier {
|
||||
startLayout();
|
||||
}
|
||||
|
||||
List<int> computeNeighbours(Node n) {
|
||||
List<int?> computeNeighbours(Node n) {
|
||||
if (_nodeIndexes == null) {
|
||||
_nodeIndexes = <String, int>{};
|
||||
_nodeIndexes = <String?, int>{};
|
||||
for (var i = 0; i < this.nodes.length; i++) {
|
||||
var node = this.nodes[i];
|
||||
_nodeIndexes[node.label] = i;
|
||||
_nodeIndexes![node.label] = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,15 +125,15 @@ class Graph extends ChangeNotifier {
|
||||
return _nodes.union(computeOverlappingNodes(n)).toList();
|
||||
}
|
||||
|
||||
var nodes = <int>{};
|
||||
var nodes = <int?>{};
|
||||
for (var edge in edges) {
|
||||
if (edge.a.label == n.label) {
|
||||
nodes.add(_nodeIndexes[edge.b.label]);
|
||||
nodes.add(_nodeIndexes![edge.b.label]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (edge.b.label == n.label) {
|
||||
nodes.add(_nodeIndexes[edge.a.label]);
|
||||
nodes.add(_nodeIndexes![edge.a.label]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -164,7 +165,7 @@ class Graph extends ChangeNotifier {
|
||||
return _nodes;
|
||||
}
|
||||
|
||||
Timer layoutTimer;
|
||||
Timer? layoutTimer;
|
||||
|
||||
void startLayout() {
|
||||
if (layoutTimer != null) {
|
||||
@ -191,7 +192,7 @@ class Graph extends ChangeNotifier {
|
||||
|
||||
void stopLayout() {
|
||||
if (layoutTimer != null) {
|
||||
layoutTimer.cancel();
|
||||
layoutTimer!.cancel();
|
||||
layoutTimer = null;
|
||||
}
|
||||
}
|
||||
@ -210,7 +211,7 @@ class GraphNodeLayout {
|
||||
double gap = 70;
|
||||
double nodeSize = 50;
|
||||
|
||||
GraphNodeLayout({@required this.maxWidth, @required this.maxHeight}) {
|
||||
GraphNodeLayout({required this.maxWidth, required this.maxHeight}) {
|
||||
x = startX;
|
||||
y = startY;
|
||||
}
|
||||
@ -288,7 +289,7 @@ bool _updateGraphPositions(Graph g) {
|
||||
var node1Neighbours = g.computeNeighbours(node1);
|
||||
|
||||
for (var j = 0; j < node1Neighbours.length; j++) {
|
||||
var i2 = node1Neighbours[j];
|
||||
var i2 = node1Neighbours[j]!;
|
||||
var node2 = g.nodes[i2];
|
||||
|
||||
if (i1 < i2) {
|
||||
|
@ -1,5 +1,3 @@
|
||||
// @dart=2.9
|
||||
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/core/notes_folder.dart';
|
||||
|
||||
|
@ -1,9 +1,5 @@
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:gitjournal/core/sorting_mode.dart';
|
||||
import 'package:gitjournal/utils/logger.dart';
|
||||
import 'note.dart';
|
||||
@ -13,14 +9,14 @@ import 'notes_folder_notifier.dart';
|
||||
class SortedNotesFolder with NotesFolderNotifier implements NotesFolder {
|
||||
final NotesFolder folder;
|
||||
|
||||
SortingMode _sortingMode;
|
||||
NoteSortingFunction _sortFunc;
|
||||
late SortingMode _sortingMode;
|
||||
late NoteSortingFunction _sortFunc;
|
||||
|
||||
List<Note> _notes = [];
|
||||
|
||||
SortedNotesFolder({
|
||||
@required this.folder,
|
||||
@required SortingMode sortingMode,
|
||||
required this.folder,
|
||||
required SortingMode sortingMode,
|
||||
}) {
|
||||
_sortingMode = sortingMode;
|
||||
_sortFunc = _sortingMode.sortingFunction();
|
||||
@ -155,7 +151,7 @@ class SortedNotesFolder with NotesFolderNotifier implements NotesFolder {
|
||||
SortingMode get sortingMode => _sortingMode;
|
||||
|
||||
@override
|
||||
NotesFolder get parent => folder.parent;
|
||||
NotesFolder? get parent => folder.parent;
|
||||
|
||||
@override
|
||||
String pathSpec() => folder.pathSpec();
|
||||
|
@ -1,13 +1,16 @@
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||
import 'package:gitjournal/core/processors/wiki_links_auto_add.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
|
||||
void main() {
|
||||
test('Should process body', () {
|
||||
var body =
|
||||
"GitJournal is the best? And it works quite well with Foam, Foam and Obsidian.";
|
||||
|
||||
var p = WikiLinksAutoAddProcessor(null);
|
||||
var folder = NotesFolderFS(null, '/', Settings(''));
|
||||
var p = WikiLinksAutoAddProcessor(folder);
|
||||
var newBody = p.processBody(body, ['GitJournal', 'Foam', 'Obsidian']);
|
||||
var expectedBody =
|
||||
"[[GitJournal]] is the best? And it works quite well with [[Foam]], [[Foam]] and [[Obsidian]].";
|
||||
|
Reference in New Issue
Block a user