[sdk/kommit] src/gui: Keep one entry per repository in the recent list

Hamed Masafi <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit c2e11917302fa96013cade28c94f64261a6542d7 by Hamed Masafi, on behalf of Méven Car.
Committed on 17/08/2026 at 14:59.
Pushed by hamedmasafi into branch 'master'.

Keep one entry per repository in the recent list

The list held a path exactly as it was given, and Repository::path() ends with a
separator after opening a repository but not after creating one, so the same
repository opened from the command line and from the list itself took two places in
it, one with a trailing slash and one without.

Every path is now written with the separator at the end, on the way in and when the
list is read, so a list recorded the other way folds together the next time the
window opens.

M  +30   -9    src/gui/appwindow.cpp

https://invent.kde.org/sdk/kommit/-/commit/c2e11917302fa96013cade28c94f64261a6542d7

diff --git a/src/gui/appwindow.cpp b/src/gui/appwindow.cpp
index 65522da2..1f486d07 100644
--- a/src/gui/appwindow.cpp
+++ b/src/gui/appwindow.cpp
@@ -292,23 +292,44 @@ void AppWindow::changeLogs()
     ChangeLogsDialog d{this};
     d.exec();
 }
+namespace
+{
+/// A repository path as the recent list keeps it, with the separator at the end, so the same
+/// repository named with one and without one does not take two places in it.
+QString recentReposPath(const QString &path)
+{
+    if (path.isEmpty() || path.endsWith(QLatin1Char('/')))
+        return path;
+
+    return path + QLatin1Char('/');
+}
+}
+
 void AppWindow::initRecentRepos(const QString &newItem)
 {
     mRecentAction->menu()->clear();
     QSettings s;
     auto recentList = s.value(QStringLiteral("recent_files")).toStringList();
 
-    if (!newItem.isEmpty()) {
-        recentList.removeOne(newItem);
-        recentList.prepend(newItem);
-
-        if (recentList.size() > 10)
-            recentList = recentList.mid(0, 10);
-        s.setValue(QStringLiteral("recent_files"), recentList);
-        s.setValue(QStringLiteral("last_repo"), newItem);
-        s.sync();
+    // Every path with the separator at the end, both the one arriving and those written
+    // before the list was kept that way, so a repository does not take two places in it.
+    for (auto &entry : recentList)
+        entry = recentReposPath(entry);
+    recentList.removeDuplicates();
+
+    const auto item = recentReposPath(newItem);
+    if (!item.isEmpty()) {
+        recentList.removeAll(item);
+        recentList.prepend(item);
+        s.setValue(QStringLiteral("last_repo"), item);
     }
 
+    if (recentList.size() > 10)
+        recentList = recentList.mid(0, 10);
+
+    s.setValue(QStringLiteral("recent_files"), recentList);
+    s.sync();
+
     mRecentAction->setVisible(!recentList.isEmpty());
 
     int index{1};
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.