diff --git a/src/plugins/git/gerrit/gerritpushdialog.cpp b/src/plugins/git/gerrit/gerritpushdialog.cpp index 87bc2d235d33d01e466c7f31ec938a7d0d529b36..25bc5a10bcbf98dcb8bb9c1e39e990d278001b17 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); } diff --git a/src/plugins/git/gerrit/gerritpushdialog.h b/src/plugins/git/gerrit/gerritpushdialog.h index 08afdd8a9f3807ca1205864add219b52600510d9..950cbacb297be40c262afc4ae848905fe41fedef 100644 --- a/src/plugins/git/gerrit/gerritpushdialog.h +++ b/src/plugins/git/gerrit/gerritpushdialog.h @@ -32,6 +32,7 @@ #include <QDialog> #include <QMultiMap> +#include <QDate> namespace Gerrit { namespace Internal { @@ -59,10 +60,11 @@ public: private slots: void setChangeRange(); - void setRemoteBranches(); + void setRemoteBranches(bool includeOld = false); private: - typedef QMultiMap<QString, QString> RemoteBranchesMap; + typedef QPair<QString, QDate> BranchDate; + typedef QMultiMap<QString, BranchDate> RemoteBranchesMap; QString calculateChangeRange(); QString m_workingDir; diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index ce0f8512268d34a1be72c56920e43df965f65f3a..2744c9be8fec9587b7dc5935a213a1a347ab27f7 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -1988,8 +1988,12 @@ bool GitClient::synchronousForEachRefCmd(const QString &workingDirectory, QStrin const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText); *output = commandOutputFromLocal8Bit(outputText); if (!rc) { - *errorMessage = msgCannotRun(QLatin1String("git for-each-ref"), workingDirectory, + QString error = msgCannotRun(QLatin1String("git for-each-ref"), workingDirectory, commandOutputFromLocal8Bit(errorText)); + if (errorMessage) + *errorMessage = error; + else + outputWindow()->appendError(error); return false; } diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index b0b1ed291f0f0a91e92a5dffaeb8eb01a687c351..79974b07c41d82c48c529d140e536d872d8ab9f9 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -203,7 +203,7 @@ public: bool synchronousTagCmd(const QString &workingDirectory, QStringList tagArgs, QString *output, QString *errorMessage); bool synchronousForEachRefCmd(const QString &workingDirectory, QStringList args, - QString *output, QString *errorMessage); + QString *output, QString *errorMessage = 0); bool synchronousRemoteCmd(const QString &workingDirectory, QStringList remoteArgs, QString *output, QString *errorMessage);