summaryrefslogtreecommitdiff
path: root/src/plugins/git/gerrit/gerritpushdialog.cpp
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2013-07-11 11:31:55 +0300
committerOrgad Shaneh <orgads@gmail.com>2013-07-12 17:52:38 +0200
commitaa981f4066b4fd698c7c0b80e2646bec628e0c69 (patch)
tree53d5da0cdab3e9551fe5701be71bbad71c610d36 /src/plugins/git/gerrit/gerritpushdialog.cpp
parent624d9e2c4cd9c0d5d29a0e76e91a9e587b051010 (diff)
downloadqt-creator-aa981f4066b4fd698c7c0b80e2646bec628e0c69.tar.gz
PushToGerrit: Filter out stale branches
Change-Id: Ib4f1d7ead2c40f27be28fa45e042c3694c0444fd Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Petar Perisin <petar.perisin@gmail.com>
Diffstat (limited to 'src/plugins/git/gerrit/gerritpushdialog.cpp')
-rw-r--r--src/plugins/git/gerrit/gerritpushdialog.cpp43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/plugins/git/gerrit/gerritpushdialog.cpp b/src/plugins/git/gerrit/gerritpushdialog.cpp
index 87bc2d235d..25bc5a10bc 100644
--- a/src/plugins/git/gerrit/gerritpushdialog.cpp
+++ b/src/plugins/git/gerrit/gerritpushdialog.cpp
@@ -33,6 +33,7 @@
#include "../gitplugin.h"
#include "../gitclient.h"
+#include <QDateTime>
#include <QDir>
namespace Gerrit {
@@ -94,20 +95,23 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
error.clear();
args.clear();
- args << QLatin1String("-r");
-
- if (!gitClient->synchronousBranchCmd(m_workingDir, args, &output, &error))
+ QString remotesPrefix(QLatin1String("refs/remotes/"));
+ args << QLatin1String("--format=%(refname)\t%(committerdate:raw)")
+ << remotesPrefix;
+ if (!gitClient->synchronousForEachRefCmd(workingDir, args, &output))
return;
refs.clear();
refs = output.split(QLatin1String("\n"));
foreach (const QString &reference, refs) {
- if (reference.contains(head) || reference.isEmpty())
+ QStringList entries = reference.split(QLatin1Char('\t'));
+ if (entries.count() < 2 || entries.first().endsWith(head))
continue;
-
- int refBranchIndex = reference.indexOf(QLatin1Char('/'));
- m_remoteBranches.insertMulti(reference.left(refBranchIndex).trimmed(),
- reference.mid(refBranchIndex + 1).trimmed());
+ const QString ref = entries.at(0).mid(remotesPrefix.size());
+ int refBranchIndex = ref.indexOf(QLatin1Char('/'));
+ int timeT = entries.at(1).left(entries.at(1).indexOf(QLatin1Char(' '))).toInt();
+ BranchDate bd(ref.mid(refBranchIndex + 1), QDateTime::fromTime_t(timeT).date());
+ m_remoteBranches.insertMulti(ref.left(refBranchIndex), bd);
}
int currIndex = 0;
@@ -165,6 +169,10 @@ QString GerritPushDialog::calculateChangeRange()
void GerritPushDialog::setChangeRange()
{
+ if (m_ui->branchComboBox->itemData(m_ui->branchComboBox->currentIndex()) == 1) {
+ setRemoteBranches(true);
+ return;
+ }
QString remote = selectedRemoteName();
remote += QLatin1Char('/');
remote += selectedRemoteBranchName();
@@ -182,22 +190,31 @@ bool GerritPushDialog::valid() const
return m_valid;
}
-void GerritPushDialog::setRemoteBranches()
+void GerritPushDialog::setRemoteBranches(bool includeOld)
{
bool blocked = m_ui->branchComboBox->blockSignals(true);
m_ui->branchComboBox->clear();
int i = 0;
+ bool excluded = false;
for (RemoteBranchesMap::const_iterator it = m_remoteBranches.constBegin(),
end = m_remoteBranches.constEnd();
it != end; ++it) {
if (it.key() == selectedRemoteName()) {
- m_ui->branchComboBox->addItem(it.value());
- if (it.value() == m_suggestedRemoteBranch)
- m_ui->branchComboBox->setCurrentIndex(i);
- ++i;
+ const BranchDate &bd = it.value();
+ const bool isSuggested = bd.first == m_suggestedRemoteBranch;
+ if (includeOld || bd.second.daysTo(QDate::currentDate()) <= 60 || isSuggested) {
+ m_ui->branchComboBox->addItem(bd.first);
+ if (isSuggested)
+ m_ui->branchComboBox->setCurrentIndex(i);
+ ++i;
+ } else {
+ excluded = true;
+ }
}
}
+ if (excluded)
+ m_ui->branchComboBox->addItem(tr("... Include older branches ..."), 1);
setChangeRange();
m_ui->branchComboBox->blockSignals(blocked);
}