summaryrefslogtreecommitdiff
path: root/src/plugins/git/branchmodel.cpp
diff options
context:
space:
mode:
authorPetar Perisin <petar.perisin@gmail.com>2013-04-08 13:04:27 +0300
committerPetar Perisin <petar.perisin@gmail.com>2013-04-11 17:06:24 +0200
commit7c6bb2524890b6260aa6de376b6411eef3b452f8 (patch)
tree771b5e3ab9aa19088813fb1764b742c5100566cb /src/plugins/git/branchmodel.cpp
parent2cb6b27de281a3bd1f2b38499b3bad07a0087140 (diff)
downloadqt-creator-7c6bb2524890b6260aa6de376b6411eef3b452f8.tar.gz
Git: Also show tags in the branches dialog
Change-Id: I74e010af7bff046647ac75e731a87867ff34b0f1 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/git/branchmodel.cpp')
-rw-r--r--src/plugins/git/branchmodel.cpp74
1 files changed, 55 insertions, 19 deletions
diff --git a/src/plugins/git/branchmodel.cpp b/src/plugins/git/branchmodel.cpp
index 4cb59ae8af..c3321c533a 100644
--- a/src/plugins/git/branchmodel.cpp
+++ b/src/plugins/git/branchmodel.cpp
@@ -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);