From 85b645f144208ca47177e9ce165e8bdfaf454b89 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 12 Dec 2022 16:40:26 +0100 Subject: [PATCH] ShowController: Make showing branches a part of show process Change-Id: I23d994fd489fc6a6f02419452ad2b07c756a9cd3 Reviewed-by: Reviewed-by: Orgad Shaneh --- src/plugins/git/gitclient.cpp | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index b3eb3a57cf7..97f3b7c0755 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -446,6 +446,7 @@ Tasking::Group ShowController::reloadRecipe() QString m_header; QString m_body; + QString m_branches; QString m_precedes; QStringList m_follows; @@ -454,6 +455,8 @@ Tasking::Group ShowController::reloadRecipe() const auto updateDescription = [this](const ReloadStorage &storage) { QString desc = storage.m_header; + if (!storage.m_branches.isEmpty()) + desc.append("Branches: " + storage.m_branches + '\n'); if (!storage.m_precedes.isEmpty()) desc.append("Precedes: " + storage.m_precedes + '\n'); QStringList follows; @@ -486,7 +489,7 @@ Tasking::Group ShowController::reloadRecipe() } const int lastHeaderLine = output.indexOf("\n\n") + 1; data->m_commit = output.mid(7, 12); - data->m_header = output.left(lastHeaderLine) + Constants::EXPAND_BRANCHES + '\n'; + data->m_header = output.left(lastHeaderLine); data->m_body = output.mid(lastHeaderLine + 1); updateDescription(*data); }; @@ -497,6 +500,55 @@ Tasking::Group ShowController::reloadRecipe() return GroupConfig(); }; + const auto setupBranches = [this, storage](QtcProcess &process) { + storage->m_branches = busyMessage; + setupCommand(process, {"branch", noColorOption, "-a", "--contains", storage->m_commit}); + VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine()); + }; + const auto onBranchesDone = [storage, updateDescription](const QtcProcess &process) { + ReloadStorage *data = storage.activeStorage(); + data->m_branches.clear(); + const QString remotePrefix = "remotes/"; + const QString localPrefix = ""; + const int prefixLength = remotePrefix.length(); + QStringList branches; + QString previousRemote = localPrefix; + bool first = true; + const QStringList branchList = process.cleanedStdOut().split('\n'); + for (const QString &branch : branchList) { + const QString b = branch.mid(2).trimmed(); + if (b.isEmpty()) + continue; + if (b.startsWith(remotePrefix)) { + const int nextSlash = b.indexOf('/', prefixLength); + if (nextSlash < 0) + continue; + const QString remote = b.mid(prefixLength, nextSlash - prefixLength); + if (remote != previousRemote) { + data->m_branches += branchesDisplay(previousRemote, &branches, &first) + '\n'; + branches.clear(); + previousRemote = remote; + } + branches << b.mid(nextSlash + 1); + } else { + branches << b; + } + } + if (branches.isEmpty()) { + if (previousRemote == localPrefix) + data->m_branches += Tr::tr(""); + } else { + data->m_branches += branchesDisplay(previousRemote, &branches, &first); + } + data->m_branches = data->m_branches.trimmed(); + updateDescription(*data); + }; + const auto onBranchesError = [storage, updateDescription](const QtcProcess &) { + ReloadStorage *data = storage.activeStorage(); + data->m_branches.clear(); + updateDescription(*data); + }; + const auto setupPrecedes = [this, storage](QtcProcess &process) { storage->m_precedes = busyMessage; setupCommand(process, {"describe", "--contains", storage->m_commit}); @@ -578,6 +630,7 @@ Tasking::Group ShowController::reloadRecipe() parallel, optional, DynamicSetup(desciptionDetailsSetup), + Process(setupBranches, onBranchesDone, onBranchesError), Process(setupPrecedes, onPrecedesDone, onPrecedesError), Tree(setupFollows) }