Commit 7c6bb252 authored by Petar Perisin's avatar Petar Perisin
Browse files

Git: Also show tags in the branches dialog



Change-Id: I74e010af7bff046647ac75e731a87867ff34b0f1
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarOrgad Shaneh <orgads@gmail.com>
parent 2cb6b27d
......@@ -132,6 +132,15 @@ public:
else
current = current->append(new BranchNode(path.at(i)));
}
if (n->name.endsWith(QLatin1String("^{}"))) {
n->name.chop(3);
if (!current->children.isEmpty()) {
BranchNode* lastOne = current->children.last();
current->children.removeLast();
if (lastOne)
delete lastOne;
}
}
current->append(n);
}
......@@ -316,11 +325,10 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage
if (workingDirectory.isEmpty())
return false;
QStringList branchArgs;
branchArgs << QLatin1String(GitClient::noColorOption)
<< QLatin1String("-v") << QLatin1String("-a");
QStringList args;
args << QLatin1String("--head") << QLatin1String("--dereference");
QString output;
if (!m_client->synchronousBranchCmd(workingDirectory, branchArgs, &output, errorMessage))
if (!m_client->synchronousShowRefCmd(workingDirectory, args, &output, errorMessage))
VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage);
beginResetModel();
......@@ -331,11 +339,32 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage
foreach (const QString &l, lines)
parseOutputLine(l);
if (m_currentBranch) {
if (m_currentBranch->parent == m_rootNode->children[0])
m_currentBranch = 0;
setCurrentBranch();
}
endResetModel();
return true;
}
void BranchModel::setCurrentBranch()
{
QString currentBranch = m_client->synchronousCurrentLocalBranch(m_workingDirectory);
if (currentBranch.isEmpty())
return;
BranchNode *local = m_rootNode->children.at(0);
int pos = 0;
for (pos = 0; pos < local->count(); ++pos) {
if (local->children.at(pos)->name == currentBranch) {
m_currentBranch = local->children[pos];
}
}
}
void BranchModel::renameBranch(const QString &oldName, const QString &newName)
{
QString errorMessage;
......@@ -538,33 +567,40 @@ void BranchModel::parseOutputLine(const QString &line)
if (line.size() < 3)
return;
bool current = line.startsWith(QLatin1String("* "));
const int shaLength = 40;
const QString sha = line.left(shaLength);
const QString fullName = line.mid(shaLength + 1);
const QString branchInfo = line.mid(2);
if (current && branchInfo.startsWith(QLatin1String("(no branch)")))
return;
QStringList tokens = branchInfo.split(QLatin1Char(' '), QString::SkipEmptyParts);
if (tokens.size() < 2)
static QString currentSha;
if (fullName == QLatin1String("HEAD")) {
currentSha = sha;
return;
}
QString sha = tokens.at(1);
bool current = (sha == currentSha);
bool showTags = m_client->settings()->boolValue(GitSettings::showTagsKey);
// insert node into tree:
QStringList nameParts = tokens.at(0).split(QLatin1Char('/'));
if (nameParts.count() < 1)
return;
QStringList nameParts = fullName.split(QLatin1Char('/'));
nameParts.removeFirst(); // remove refs...
if (nameParts.isEmpty() || nameParts.at(0) != QLatin1String("remotes"))
nameParts.prepend(m_rootNode->children.at(0)->name); // Insert the local designator
else
if (nameParts.first() == QLatin1String("heads"))
nameParts[0] = m_rootNode->children.at(0)->name; // Insert the local designator
else if (nameParts.first() == QLatin1String("remotes"))
nameParts.removeFirst(); // remove "remotes"
else if (nameParts.first() == QLatin1String("stash"))
return;
else if (!showTags && (nameParts.first() == QLatin1String("tags")))
return;
// limit depth of list. Git basically only ever wants one / and considers the rest as part of
// the name.
while (nameParts.count() > 3) {
nameParts[2] = nameParts.at(2) + QLatin1Char('/') + nameParts.at(3);
nameParts.removeAt(3);
}
QString name = nameParts.last();
const QString name = nameParts.last();
nameParts.removeLast();
BranchNode *newNode = new BranchNode(name, sha);
......
......@@ -82,6 +82,7 @@ public:
private:
void parseOutputLine(const QString &line);
void setCurrentBranch();
BranchNode *indexToNode(const QModelIndex &index) const;
QModelIndex nodeToIndex(BranchNode *node) const;
......
......@@ -1506,6 +1506,23 @@ bool GitClient::synchronousBranchCmd(const QString &workingDirectory, QStringLis
return true;
}
bool GitClient::synchronousShowRefCmd(const QString &workingDirectory, QStringList args,
QString *output, QString *errorMessage)
{
args.push_front(QLatin1String("show-ref"));
QByteArray outputText;
QByteArray errorText;
const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText);
*output = commandOutputFromLocal8Bit(outputText);
if (!rc) {
*errorMessage = tr("Cannot run \"git show-ref\" in \"%1\": %2")
.arg(QDir::toNativeSeparators(workingDirectory), commandOutputFromLocal8Bit(errorText));
return false;
}
return true;
}
bool GitClient::synchronousRemoteCmd(const QString &workingDirectory, QStringList remoteArgs,
QString *output, QString *errorMessage)
{
......
......@@ -180,6 +180,8 @@ public:
QString *errorMessage = 0);
bool synchronousBranchCmd(const QString &workingDirectory, QStringList branchArgs,
QString *output, QString *errorMessage);
bool synchronousShowRefCmd(const QString &workingDirectory, QStringList args,
QString *output, QString *errorMessage);
bool synchronousRemoteCmd(const QString &workingDirectory, QStringList remoteArgs,
QString *output, QString *errorMessage);
......
......@@ -36,6 +36,7 @@ namespace Git {
namespace Internal {
const QLatin1String GitSettings::pullRebaseKey("PullRebase");
const QLatin1String GitSettings::showTagsKey("ShowTags");
const QLatin1String GitSettings::omitAnnotationDateKey("OmitAnnotationDate");
const QLatin1String GitSettings::ignoreSpaceChangesInDiffKey("SpaceIgnorantDiff");
const QLatin1String GitSettings::ignoreSpaceChangesInBlameKey("SpaceIgnorantBlame");
......@@ -53,6 +54,7 @@ GitSettings::GitSettings()
declareKey(binaryPathKey, QLatin1String("git"));
declareKey(timeoutKey, Utils::HostOsInfo::isWindowsHost() ? 60 : 30);
declareKey(pullRebaseKey, false);
declareKey(showTagsKey, false);
declareKey(omitAnnotationDateKey, false);
declareKey(ignoreSpaceChangesInDiffKey, true);
declareKey(ignoreSpaceChangesInBlameKey, true);
......
......@@ -42,6 +42,7 @@ public:
GitSettings();
static const QLatin1String pullRebaseKey;
static const QLatin1String showTagsKey;
static const QLatin1String omitAnnotationDateKey;
static const QLatin1String ignoreSpaceChangesInDiffKey;
static const QLatin1String ignoreSpaceChangesInBlameKey;
......
......@@ -71,6 +71,7 @@ GitSettings SettingsPageWidget::settings() const
rc.setValue(GitSettings::logCountKey, m_ui.logCountSpinBox->value());
rc.setValue(GitSettings::timeoutKey, m_ui.timeoutSpinBox->value());
rc.setValue(GitSettings::pullRebaseKey, m_ui.pullRebaseCheckBox->isChecked());
rc.setValue(GitSettings::showTagsKey, m_ui.showTagsCheckBox->isChecked());
rc.setValue(GitSettings::promptOnSubmitKey, m_ui.promptToSubmitCheckBox->isChecked());
rc.setValue(GitSettings::winSetHomeEnvironmentKey, m_ui.winHomeCheckBox->isChecked());
rc.setValue(GitSettings::gitkOptionsKey, m_ui.gitkOptionsLineEdit->text().trimmed());
......@@ -84,6 +85,7 @@ void SettingsPageWidget::setSettings(const GitSettings &s)
m_ui.logCountSpinBox->setValue(s.intValue(GitSettings::logCountKey));
m_ui.timeoutSpinBox->setValue(s.intValue(GitSettings::timeoutKey));
m_ui.pullRebaseCheckBox->setChecked(s.boolValue(GitSettings::pullRebaseKey));
m_ui.showTagsCheckBox->setChecked(s.boolValue(GitSettings::showTagsKey));
m_ui.promptToSubmitCheckBox->setChecked(s.boolValue(GitSettings::promptOnSubmitKey));
m_ui.winHomeCheckBox->setChecked(s.boolValue(GitSettings::winSetHomeEnvironmentKey));
m_ui.gitkOptionsLineEdit->setText(s.stringValue(GitSettings::gitkOptionsKey));
......
......@@ -130,6 +130,13 @@
</property>
</widget>
</item>
<item row="1" column="3" colspan="2">
<widget class="QCheckBox" name="showTagsCheckBox">
<property name="text">
<string>Show Tags in Branches Dialog</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment