SUMMARY STEPS TO REPRODUCE 1. Run `kommit ~/git/repo` in the console OBSERVED RESULT Crash EXPECTED RESULT No crash SOFTWARE/OS VERSIONS Operating System: Fedora Linux 40 KDE Plasma Version: 6.0.4 KDE Frameworks Version: 6.2.0 Qt Version: 6.7.0 Kernel Version: 6.8.9-300.fc40.x86_64 (64-bit) Graphics Platform: Wayland Processors: 12 × 11th Gen Intel® Core™ i5-11600K @ 3.90GHz Memory: 31.1 ГиБ of RAM Graphics Processor: Mesa Intel® Graphics Manufacturer: Gigabyte Technology Co., Ltd. Product Name: B560M DS3H V2 ADDITIONAL INFORMATION
Created attachment 169430 [details] GDB backtrace
After some debugging it turns out that crash happens because return value from function `git_tag_lookup` is ignored it is non zero. I'm talking about this line of code: https://invent.kde.org/sdk/kommit/-/blob/5954f99cf5e5db96c13a73fd1752e4ad2211fa1e/src/libkommit/gitmanager.cpp?page=2#L1266 Proposed patch: ``` diff --git a/src/libkommit/gitmanager.cpp b/src/libkommit/gitmanager.cpp index c1b4244..8f8ce9f 100644 --- a/src/libkommit/gitmanager.cpp +++ b/src/libkommit/gitmanager.cpp @@ -1241,7 +1241,14 @@ void Manager::forEachTags(std::function<void(Tag *)> cb) Q_UNUSED(name) auto w = reinterpret_cast<wrapper *>(payload); git_tag *t; - git_tag_lookup(&t, w->repo, oid_c); + int ret = git_tag_lookup(&t, w->repo, oid_c); + if (ret) { + const auto err = git_error_last(); + if (err) { + qWarning().noquote().nospace() << "libgit2 error: " << err->message; + } + return 0; + } if (!t) return 0; ``` Macros PRINT_ERROR won't work here.
Created attachment 169431 [details] kommit-fix-crash.patch
P.S. After applying the patch console shows this errors: ``` libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB libgit2 error: the requested type does not match the type in the ODB ```
Some light on situation that `git_tag_lookup` is not working for all tags: git_tag_lookup only works for annotated tags: https://github.com/libgit2/libgit2/issues/5586 > git_tag_lookup to emphasise that this will not work for all tags. that it only works for annotated tags and not for lightweight tags
Thank you for this in-depth review. For now I've applied your proposed. But in next commits I'll work more on this, of course, with the help of the clues you gave.
If `git_tag_lookup` fails to find tag - you can use `git_commit_lookup` to get commit info. And later create `Tag` class instance from the commit, something like that: ``` Tag::Tag(const char *refName, git_commit *commit) { mName = QString(refName).remove(QRegularExpression("^refs/tags/")); mMessage = git_commit_message(commit); const auto author = git_commit_author(commit); mTagger.reset(new Signature{author}); } ```
Hi Yaroslav In new commit light tags are detected and the information are taken from commit. Please check it out and let me know the result.
Almost good but tag names is not displayed. You can test it with this git repo: ``` 1. mkdir /tmp/git && cd /tmp/git 2. git init 3. touch README.md && git add README.md && git commit -m 1 4. git tag some_tag kommit /tmp/git ```
Yes, because it doesn't has name, isn't logical?
But it has name and displayed for example with `git log` or `tig`.
Also in my example it's this is taken into account and name is taken from ref name `refs/tags/<tag>`: ``` mName = QString(refName).remove(QRegularExpression("^refs/tags/")); ```
Ok; you're right. please check out new commit
Looks good. Thanks!