From 9f346c99f72c0d2bab3974dc7b8df410c3ef40b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Wed, 13 Oct 2021 19:23:34 +0300 Subject: [PATCH] feat: add more toString overrides for debugging --- README.md | 2 +- lib/src/blame.dart | 9 +++++++++ lib/src/blob.dart | 5 +++++ lib/src/branch.dart | 2 +- lib/src/commit.dart | 5 ++++- lib/src/credentials.dart | 20 ++++++++++++++++++++ lib/src/diff.dart | 33 +++++++++++++++++++++++++++++++++ lib/src/index.dart | 7 +++++-- lib/src/note.dart | 5 +++++ lib/src/odb.dart | 5 +++++ lib/src/packbuilder.dart | 5 +++++ lib/src/patch.dart | 3 +++ lib/src/rebase.dart | 3 +++ lib/src/reference.dart | 9 +++++---- lib/src/reflog.dart | 2 +- lib/src/refspec.dart | 5 +++++ lib/src/remote.dart | 12 ++++++++++++ lib/src/repository.dart | 8 ++++++++ lib/src/revparse.dart | 10 ++++++++++ lib/src/signature.dart | 6 +++--- lib/src/stash.dart | 2 +- lib/src/submodule.dart | 7 +++++++ lib/src/tag.dart | 5 +++++ lib/src/tree.dart | 13 +++++++++---- lib/src/treebuilder.dart | 5 +++++ lib/src/worktree.dart | 5 +++++ 26 files changed, 175 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 1e19b98..9bba1cf 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ To run all tests and generate coverage report use the following commands: ```sh $ dart pub global activate coverage $ dart test --coverage="coverage" -$ format_coverage --lcov --in=coverage --out=coverage/lcov.info --packages=.packages --report-on=lib +$ format_coverage --lcov --check-ignore --in=coverage --out=coverage/lcov.info --packages=.packages --report-on=lib ``` To view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov): diff --git a/lib/src/blame.dart b/lib/src/blame.dart index 1681277..dc8dd4b 100644 --- a/lib/src/blame.dart +++ b/lib/src/blame.dart @@ -132,6 +132,15 @@ class BlameHunk { /// specified by [originCommitOid]. String get originPath => _blameHunkPointer.ref.orig_path.cast().toDartString(); + + @override + String toString() { + return 'BlameHunk{linesCount: $linesCount, isBoundary: $isBoundary, ' + 'finalStartLineNumber: $finalStartLineNumber, finalCommitter: $finalCommitter, ' + 'finalCommitOid: $finalCommitOid, originStartLineNumber: $originStartLineNumber, ' + 'originCommitter: $originCommitter, originCommitOid: $originCommitOid, ' + 'originPath: $originPath}'; + } } class _BlameIterator implements Iterator { diff --git a/lib/src/blob.dart b/lib/src/blob.dart index 12c4200..e9696ac 100644 --- a/lib/src/blob.dart +++ b/lib/src/blob.dart @@ -136,4 +136,9 @@ class Blob { /// Releases memory allocated for blob object. void free() => bindings.free(_blobPointer); + + @override + String toString() { + return 'Blob{oid: $oid, isBinary: $isBinary, size: $size}'; + } } diff --git a/lib/src/branch.dart b/lib/src/branch.dart index 3b70dcc..b4a0388 100644 --- a/lib/src/branch.dart +++ b/lib/src/branch.dart @@ -150,6 +150,6 @@ class Branch { @override String toString() { - return 'Branch{name: $name, target: $target}'; + return 'Branch{name: $name, target: $target, isHead: $isHead, isCheckedOut: $isCheckedOut}'; } } diff --git a/lib/src/commit.dart b/lib/src/commit.dart index 0147cf7..ed3d913 100644 --- a/lib/src/commit.dart +++ b/lib/src/commit.dart @@ -109,5 +109,8 @@ class Commit { void free() => bindings.free(_commitPointer); @override - String toString() => 'Commit{oid: $oid}'; + String toString() { + return 'Commit{oid: $oid, message: $message, messageEncoding: $messageEncoding, ' + 'time: $time, committer: $committer, author: $author}'; + } } diff --git a/lib/src/credentials.dart b/lib/src/credentials.dart index 6c5c385..f580dba 100644 --- a/lib/src/credentials.dart +++ b/lib/src/credentials.dart @@ -14,6 +14,9 @@ class Username implements Credentials { @override GitCredential get credentialType => GitCredential.username; + + @override + String toString() => 'Username{username: $username}'; } /// Plain-text username and password credential. @@ -28,6 +31,11 @@ class UserPass implements Credentials { @override GitCredential get credentialType => GitCredential.userPassPlainText; + + @override + String toString() { + return 'UserPass{username: $username, password: $password}'; + } } /// Passphrase-protected ssh key credential. @@ -53,6 +61,12 @@ class Keypair implements Credentials { @override GitCredential get credentialType => GitCredential.sshKey; + + @override + String toString() { + return 'Keypair{username: $username, pubKey: $pubKey, privateKey: $privateKey, ' + 'passPhrase: $passPhrase}'; + } } /// Ssh key credential used for querying an ssh-agent. @@ -89,4 +103,10 @@ class KeypairFromMemory implements Credentials { @override GitCredential get credentialType => GitCredential.sshMemory; + + @override + String toString() { + return 'KeypairFromAgent{username: $username, pubKey: $pubKey, privateKey: $privateKey, ' + 'passPhrase: $passPhrase}'; + } } diff --git a/lib/src/diff.dart b/lib/src/diff.dart index 7a14406..b5e57a5 100644 --- a/lib/src/diff.dart +++ b/lib/src/diff.dart @@ -119,6 +119,11 @@ class Diff { /// Releases memory allocated for diff object. void free() => bindings.free(_diffPointer); + + @override + String toString() { + return 'Diff{length: $length}'; + } } class DiffDelta { @@ -166,6 +171,12 @@ class DiffDelta { /// Represents the "to" side of the diff. DiffFile get newFile => DiffFile(_diffDeltaPointer.ref.new_file); + + @override + String toString() { + return 'DiffDelta{status: $status, flags: $flags, similarity: $similarity, ' + 'numberOfFiles: $numberOfFiles, oldFile: $oldFile, newFile: $newFile}'; + } } /// Description of one side of a delta. @@ -200,6 +211,11 @@ class DiffFile { GitFilemode get mode { return GitFilemode.values.singleWhere((e) => _diffFile.mode == e.value); } + + @override + String toString() { + return 'DiffFile{oid: $oid, path: $path, size: $size, flags: $flags, mode: $mode}'; + } } class DiffStats { @@ -234,6 +250,11 @@ class DiffStats { /// Releases memory allocated for diff stats object. void free() => bindings.statsFree(_diffStatsPointer); + + @override + String toString() { + return 'DiffStats{insertions: $insertions, deletions: $deletions, filesChanged: $filesChanged}'; + } } class DiffHunk { @@ -293,6 +314,12 @@ class DiffHunk { } return lines; } + + @override + String toString() { + return 'DiffHunk{linesCount: $linesCount, index: $index, oldStart: $oldStart, ' + 'oldLines: $oldLines, newStart: $newStart, newLines: $newLines, header: $header}'; + } } class DiffLine { @@ -325,4 +352,10 @@ class DiffLine { /// Returns content of the diff line. String get content => _diffLinePointer.ref.content.cast().toDartString(); + + @override + String toString() { + return 'DiffLine{oldLineNumber: $oldLineNumber, newLineNumber: $newLineNumber, ' + 'numLines: $numLines, contentOffset: $contentOffset, content: $content}'; + } } diff --git a/lib/src/index.dart b/lib/src/index.dart index 0849af3..4108ce1 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -220,6 +220,9 @@ class Index with IterableMixin { /// Releases memory allocated for index object. void free() => bindings.free(_indexPointer); + @override + String toString() => 'Index{hasConflicts: $hasConflicts}'; + @override Iterator get iterator => _IndexIterator(_indexPointer); } @@ -261,7 +264,7 @@ class IndexEntry { @override String toString() { - return 'IndexEntry{path: $path, sha: $sha}'; + return 'IndexEntry{oid: $oid, path: $path, mode: $mode}'; } String _oidToHex(git_oid oid) { @@ -306,7 +309,7 @@ class ConflictEntry { @override String toString() => - 'ConflictEntry{ancestor: $ancestor, our: $our, their: $their}'; + 'ConflictEntry{ancestor: $ancestor, our: $our, their: $their, path: $_path}'; } class _IndexIterator implements Iterator { diff --git a/lib/src/note.dart b/lib/src/note.dart index d29d4ff..4b62446 100644 --- a/lib/src/note.dart +++ b/lib/src/note.dart @@ -101,4 +101,9 @@ class Note { /// Releases memory allocated for note object. void free() => bindings.free(_notePointer); + + @override + String toString() { + return 'Note{oid: $oid, message: $message, annotatedOid: $annotatedOid}'; + } } diff --git a/lib/src/odb.dart b/lib/src/odb.dart index 2660259..29525d5 100644 --- a/lib/src/odb.dart +++ b/lib/src/odb.dart @@ -125,4 +125,9 @@ class OdbObject { /// Releases memory allocated for odbObject object. void free() => bindings.objectFree(_odbObjectPointer); + + @override + String toString() { + return 'OdbObject{oid: $oid, type: $type, size: $size}'; + } } diff --git a/lib/src/packbuilder.dart b/lib/src/packbuilder.dart index 2f7c5ec..83f9fae 100644 --- a/lib/src/packbuilder.dart +++ b/lib/src/packbuilder.dart @@ -70,4 +70,9 @@ class PackBuilder { /// Releases memory allocated for packbuilder object. void free() => bindings.free(_packbuilderPointer); + + @override + String toString() { + return 'PackBuilder{length: $length, writtenLength: $writtenLength}'; + } } diff --git a/lib/src/patch.dart b/lib/src/patch.dart index c4da45a..2002edc 100644 --- a/lib/src/patch.dart +++ b/lib/src/patch.dart @@ -155,4 +155,7 @@ class Patch { } bindings.free(_patchPointer); } + + @override + String toString() => 'Patch{size: $size, delta: $delta}'; } diff --git a/lib/src/rebase.dart b/lib/src/rebase.dart index c10b300..0b943fb 100644 --- a/lib/src/rebase.dart +++ b/lib/src/rebase.dart @@ -137,4 +137,7 @@ class RebaseOperation { ? '' : _rebaseOperationPointer.ref.exec.cast().toDartString(); } + + @override + String toString() => 'RebaseOperation{type: $type, oid: $oid}'; } diff --git a/lib/src/reference.dart b/lib/src/reference.dart index c07e6ed..82a1085 100644 --- a/lib/src/reference.dart +++ b/lib/src/reference.dart @@ -272,14 +272,15 @@ class Reference { ); } - @override - int get hashCode => _refPointer.address.hashCode; - /// Releases memory allocated for reference object. void free() => bindings.free(_refPointer); + @override + int get hashCode => _refPointer.address.hashCode; + @override String toString() { - return 'Reference{name: $name, target: $target}'; + return 'Reference{name: $name, target: $target, type: $type, isBranch: $isBranch, ' + 'isNote: $isNote, isRemote: $isRemote, isTag: $isTag}'; } } diff --git a/lib/src/reflog.dart b/lib/src/reflog.dart index 2e3ec27..eb8c183 100644 --- a/lib/src/reflog.dart +++ b/lib/src/reflog.dart @@ -50,7 +50,7 @@ class RefLogEntry { Signature get committer => Signature(bindings.entryCommiter(_entryPointer)); @override - String toString() => 'ReflogEntry{message: $message}'; + String toString() => 'ReflogEntry{message: $message, committer: $committer}'; } class _RefLogIterator implements Iterator { diff --git a/lib/src/refspec.dart b/lib/src/refspec.dart index 6532701..2d2886a 100644 --- a/lib/src/refspec.dart +++ b/lib/src/refspec.dart @@ -65,4 +65,9 @@ class Refspec { name: name, ); } + + @override + String toString() { + return 'Refspec{source: $source, destination: $destination, force: $force, string: $string}'; + } } diff --git a/lib/src/remote.dart b/lib/src/remote.dart index b7f4e4f..5a9844c 100644 --- a/lib/src/remote.dart +++ b/lib/src/remote.dart @@ -263,6 +263,11 @@ class Remote { /// Releases memory allocated for remote object. void free() => bindings.free(_remotePointer); + + @override + String toString() { + return 'Remote{name: $name, url: $url, pushUrl: $pushUrl, refspecCount: $refspecCount}'; + } } /// Provides callers information about the progress of indexing a packfile, either @@ -295,4 +300,11 @@ class TransferProgress { /// Returns number of bytes received up to now. int get receivedBytes => _transferProgressPointer.ref.received_bytes; + + @override + String toString() { + return 'TransferProgress{totalObjects: $totalObjects, indexedObjects: $indexedObjects, ' + 'receivedObjects: $receivedObjects, localObjects: $localObjects, totalDeltas: $totalDeltas, ' + 'indexedDeltas: $indexedDeltas, receivedBytes: $receivedBytes}'; + } } diff --git a/lib/src/repository.dart b/lib/src/repository.dart index 2c543ba..6a72f33 100644 --- a/lib/src/repository.dart +++ b/lib/src/repository.dart @@ -308,6 +308,14 @@ class Repository { /// Releases memory allocated for repository object. void free() => bindings.free(_repoPointer); + @override + String toString() { + return 'Repository{path: $path, commonDir: $commonDir, namespace: $namespace, ' + 'isBare: $isBare, isEmpty: $isEmpty, isHeadDetached: $isHeadDetached, ' + 'isBranchUnborn: $isBranchUnborn, isShallow: $isShallow, isWorktree: $isWorktree, ' + 'state: $state, workdir: $workdir}'; + } + /// Returns the configuration file for this repository. /// /// If a configuration file has not been set, the default config set for the repository diff --git a/lib/src/revparse.dart b/lib/src/revparse.dart index 4002d67..fb3f8f7 100644 --- a/lib/src/revparse.dart +++ b/lib/src/revparse.dart @@ -63,6 +63,11 @@ class RevParse { spec: spec, )); } + + @override + String toString() { + return 'RevParse{object: $object, reference: $reference}'; + } } class RevSpec { @@ -89,4 +94,9 @@ class RevSpec { .where((e) => _revSpecPointer.ref.flags & e.value == e.value) .toSet(); } + + @override + String toString() { + return 'RevSpec{from: $from, to: $to, flags: $flags}'; + } } diff --git a/lib/src/signature.dart b/lib/src/signature.dart index bc6685b..0324d1d 100644 --- a/lib/src/signature.dart +++ b/lib/src/signature.dart @@ -75,12 +75,12 @@ class Signature { other._signaturePointer.ref.when.sign); } - @override - int get hashCode => _signaturePointer.address.hashCode; - /// Releases memory allocated for signature object. void free() => bindings.free(_signaturePointer); + @override + int get hashCode => _signaturePointer.address.hashCode; + @override String toString() { return 'Signature{name: $name, email: $email, time: $time, offset: $offset}'; diff --git a/lib/src/stash.dart b/lib/src/stash.dart index f29dd23..ed42322 100644 --- a/lib/src/stash.dart +++ b/lib/src/stash.dart @@ -106,6 +106,6 @@ class Stash { @override String toString() { - return 'Stash{index: $index, message: $message, sha: ${oid.sha}}'; + return 'Stash{index: $index, message: $message, oid: $oid}'; } } diff --git a/lib/src/submodule.dart b/lib/src/submodule.dart index a853ca2..c095924 100644 --- a/lib/src/submodule.dart +++ b/lib/src/submodule.dart @@ -279,4 +279,11 @@ class Submodule { /// Releases memory allocated for submodule object. void free() => bindings.free(_submodulePointer); + + @override + String toString() { + return 'Submodule{name: $name, path: $path, url: $url, status: $status, ' + 'branch: $branch, headOid: $headOid, indexOid: $indexOid, workdirOid: $workdirOid, ' + 'ignore: $ignore, updateRule: $updateRule}'; + } } diff --git a/lib/src/tag.dart b/lib/src/tag.dart index 3e16fe3..8cf8ac9 100644 --- a/lib/src/tag.dart +++ b/lib/src/tag.dart @@ -133,4 +133,9 @@ class Tag { /// Releases memory allocated for tag object. void free() => bindings.free(_tagPointer); + + @override + String toString() { + return 'Tag{oid: $oid, name: $name, message: $message, target: $target, tagger: $tagger}'; + } } diff --git a/lib/src/tree.dart b/lib/src/tree.dart index fd35143..8dfb894 100644 --- a/lib/src/tree.dart +++ b/lib/src/tree.dart @@ -132,6 +132,11 @@ class Tree { /// Releases memory allocated for tree object. void free() => bindings.free(_treePointer); + + @override + String toString() { + return 'Tree{oid: $oid, length: $length}'; + } } class TreeEntry { @@ -194,12 +199,12 @@ class TreeEntry { 1); } - @override - int get hashCode => _treeEntryPointer.address.hashCode; - /// Releases memory allocated for tree entry object. void free() => bindings.entryFree(_treeEntryPointer); @override - String toString() => 'TreeEntry{oid: $oid, name: $name}'; + int get hashCode => _treeEntryPointer.address.hashCode; + + @override + String toString() => 'TreeEntry{oid: $oid, name: $name, filemode: $filemode}'; } diff --git a/lib/src/treebuilder.dart b/lib/src/treebuilder.dart index 850d077..6caab11 100644 --- a/lib/src/treebuilder.dart +++ b/lib/src/treebuilder.dart @@ -81,4 +81,9 @@ class TreeBuilder { /// Releases memory allocated for tree builder object and all the entries. void free() => bindings.free(_treeBuilderPointer); + + @override + String toString() { + return 'TreeBuilder{length: $length}'; + } } diff --git a/lib/src/worktree.dart b/lib/src/worktree.dart index c573a57..6788a9a 100644 --- a/lib/src/worktree.dart +++ b/lib/src/worktree.dart @@ -61,4 +61,9 @@ class Worktree { /// Releases memory allocated for worktree object. void free() => bindings.free(_worktreePointer); + + @override + String toString() { + return 'Worktree{name: $name, path: $path}'; + } }