Git: Hide obsolete branches by default in branches dialog

Task-number: QTCREATORBUG-15544
Change-Id: I411c7eacd2c154cad08234c0bd22e16dfecb961c
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2016-03-09 23:21:57 +02:00
committed by Orgad Shaneh
parent de127b1f5c
commit 5834769cbf
6 changed files with 80 additions and 49 deletions

View File

@@ -30,6 +30,7 @@
#include "gitclient.h"
#include "gitplugin.h"
#include "gitutils.h"
#include "gitconstants.h"
#include "ui_branchdialog.h"
#include "stashdialog.h" // Label helpers
@@ -61,6 +62,9 @@ BranchDialog::BranchDialog(QWidget *parent) :
setAttribute(Qt::WA_DeleteOnClose, true); // Do not update unnecessarily
m_ui->setupUi(this);
m_ui->includeOldCheckBox->setToolTip(
tr("Include branches and tags that have not been active for %1 days.")
.arg(Constants::OBSOLETE_COMMIT_AGE_IN_DAYS));
connect(m_ui->refreshButton, &QAbstractButton::clicked, this, &BranchDialog::refreshCurrentRepository);
connect(m_ui->addButton, &QAbstractButton::clicked, this, &BranchDialog::add);
@@ -74,8 +78,13 @@ BranchDialog::BranchDialog(QWidget *parent) :
connect(m_ui->rebaseButton, &QAbstractButton::clicked, this, &BranchDialog::rebase);
connect(m_ui->cherryPickButton, &QAbstractButton::clicked, this, &BranchDialog::cherryPick);
connect(m_ui->trackButton, &QAbstractButton::clicked, this, &BranchDialog::setRemoteTracking);
connect(m_ui->includeOldCheckBox, &QCheckBox::toggled, this, [this](bool value) {
m_model->setOldBranchesIncluded(value);
refreshCurrentRepository();
});
m_ui->branchView->setModel(m_model);
m_ui->branchView->setFocus();
connect(m_ui->branchView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &BranchDialog::enableButtons);

View File

@@ -15,36 +15,28 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="infoGroupBox">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QLabel" name="repositoryLabel">
<property name="text">
<string notr="true">Repository: Dummy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refreshButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Re&amp;fresh</string>
</property>
</widget>
</item>
</layout>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="repositoryLabel">
<property name="text">
<string notr="true">Repository: Dummy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refreshButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Re&amp;fresh</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="localBranchGroupBox">
@@ -59,17 +51,28 @@
<number>4</number>
</property>
<item>
<widget class="QTreeView" name="branchView">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QTreeView" name="branchView">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<widget class="QCheckBox" name="includeOldCheckBox">
<property name="text">
<string>&amp;Include old entries</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -210,11 +213,6 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>branchView</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>refreshButton</tabstop>
</tabstops>
<resources/>
<connections>
<connection>

View File

@@ -25,11 +25,13 @@
#include "branchmodel.h"
#include "gitclient.h"
#include "gitconstants.h"
#include <utils/qtcassert.h>
#include <vcsbase/vcsoutputwindow.h>
#include <vcsbase/vcscommand.h>
#include <QDateTime>
#include <QFont>
using namespace VcsBase;
@@ -348,7 +350,8 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage
m_currentSha = m_client->synchronousTopRevision(workingDirectory);
QStringList args;
args << QLatin1String("--format=%(objectname)\t%(refname)\t%(upstream:short)\t%(*objectname)");
args << QLatin1String("--format=%(objectname)\t%(refname)\t%(upstream:short)\t"
"%(*objectname)\t%(committerdate:raw)\t%(*committerdate:raw)");
QString output;
if (!m_client->synchronousForEachRefCmd(workingDirectory, args, &output, errorMessage))
VcsOutputWindow::appendError(*errorMessage);
@@ -629,18 +632,34 @@ void BranchModel::setRemoteTracking(const QModelIndex &trackingIndex)
emit dataChanged(current, current);
}
void BranchModel::setOldBranchesIncluded(bool value)
{
m_oldBranchesIncluded = value;
}
void BranchModel::parseOutputLine(const QString &line)
{
if (line.size() < 3)
return;
// objectname, refname, upstream:short, *objectname
// objectname, refname, upstream:short, *objectname, committerdate:raw, *committerdate:raw
QStringList lineParts = line.split(QLatin1Char('\t'));
const QString shaDeref = lineParts.at(3);
const QString sha = shaDeref.isEmpty() ? lineParts.at(0) : shaDeref;
const QString fullName = lineParts.at(1);
const QString upstream = lineParts.at(2);
if (!m_oldBranchesIncluded) {
QString strDateTime = lineParts.at(5);
if (strDateTime.isEmpty())
strDateTime = lineParts.at(4);
if (!strDateTime.isEmpty()) {
const uint timeT = strDateTime.leftRef(strDateTime.indexOf(QLatin1Char(' '))).toUInt();
const int age = QDateTime::fromTime_t(timeT).daysTo(QDateTime::currentDateTime());
if (age > Constants::OBSOLETE_COMMIT_AGE_IN_DAYS)
return;
}
}
bool current = (sha == m_currentSha);
bool showTags = m_client->settings().boolValue(GitSettings::showTagsKey);

View File

@@ -79,6 +79,7 @@ public:
bool branchIsMerged(const QModelIndex &idx);
QModelIndex addBranch(const QString &name, bool track, const QModelIndex &trackedBranch);
void setRemoteTracking(const QModelIndex &trackingIndex);
void setOldBranchesIncluded(bool value);
private:
void parseOutputLine(const QString &line);
@@ -94,6 +95,7 @@ private:
BranchNode *m_rootNode;
BranchNode *m_currentBranch = nullptr;
QString m_currentSha;
bool m_oldBranchesIncluded = false;
};
} // namespace Internal

View File

@@ -29,6 +29,7 @@
#include "../gitplugin.h"
#include "../gitclient.h"
#include "../gitconstants.h"
#include <QDateTime>
#include <QDir>
@@ -235,7 +236,7 @@ void GerritPushDialog::setRemoteBranches(bool includeOld)
foreach (const BranchDate &bd, m_remoteBranches.values(remoteName)) {
const bool isSuggested = bd.first == m_suggestedRemoteBranch;
if (includeOld || isSuggested || !bd.second.isValid()
|| bd.second.daysTo(QDate::currentDate()) <= 60) {
|| bd.second.daysTo(QDate::currentDate()) <= Git::Constants::OBSOLETE_COMMIT_AGE_IN_DAYS) {
m_ui->targetBranchComboBox->addItem(bd.first);
if (isSuggested)
m_ui->targetBranchComboBox->setCurrentIndex(i);

View File

@@ -49,5 +49,7 @@ const char DIFF_SELECTED[] = "Git.DiffSelectedFilesInLog";
const char SUBMIT_MIMETYPE[] = "text/vnd.qtcreator.git.submit";
const char C_GITEDITORID[] = "Git Editor";
const int OBSOLETE_COMMIT_AGE_IN_DAYS = 90;
} // namespace Constants
} // namespace Git