diff --git a/src/plugins/git/branchmodel.cpp b/src/plugins/git/branchmodel.cpp index 034c93e72ad982c326c26df6a26967c12600d2d7..324ba1743444267efc9cd3653b5b38f054884816 100644 --- a/src/plugins/git/branchmodel.cpp +++ b/src/plugins/git/branchmodel.cpp @@ -50,8 +50,8 @@ public: name(QLatin1String("<ROOT>")) { } - BranchNode(const QString &n, const QString &s = QString()) : - parent(0), name(n), sha(s) + BranchNode(const QString &n, const QString &s = QString(), const QString &t = QString()) : + parent(0), name(n), sha(s), tracking(t) { } ~BranchNode() @@ -132,15 +132,6 @@ 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); } @@ -173,6 +164,7 @@ public: QString name; QString sha; + QString tracking; mutable QString toolTip; }; @@ -238,7 +230,12 @@ QVariant BranchModel::data(const QModelIndex &index, int role) const return QVariant(); switch (role) { - case Qt::DisplayRole: + case Qt::DisplayRole: { + QString res = node->name; + if (!node->tracking.isEmpty()) + res += QLatin1String(" [") + node->tracking + QLatin1Char(']'); + return res; + } case Qt::EditRole: return node->name; case Qt::ToolTipRole: @@ -325,10 +322,11 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage if (workingDirectory.isEmpty()) return false; + m_currentSha = m_client->synchronousTopRevision(workingDirectory); QStringList args; - args << QLatin1String("--head") << QLatin1String("--dereference"); + args << QLatin1String("--format=%(objectname)\t%(refname)\t%(upstream:short)\t%(*objectname)"); QString output; - if (!m_client->synchronousShowRefCmd(workingDirectory, args, &output, errorMessage)) + if (!m_client->synchronousForEachRefCmd(workingDirectory, args, &output, errorMessage)) VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage); beginResetModel(); @@ -565,17 +563,12 @@ void BranchModel::parseOutputLine(const QString &line) if (line.size() < 3) return; - const int shaLength = 40; - const QString sha = line.left(shaLength); - const QString fullName = line.mid(shaLength + 1); - - static QString currentSha; - if (fullName == QLatin1String("HEAD")) { - currentSha = sha; - return; - } + 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); - bool current = (sha == currentSha); + bool current = (sha == m_currentSha); bool showTags = m_client->settings()->boolValue(GitSettings::showTagsKey); // insert node into tree: @@ -601,7 +594,7 @@ void BranchModel::parseOutputLine(const QString &line) const QString name = nameParts.last(); nameParts.removeLast(); - BranchNode *newNode = new BranchNode(name, sha); + BranchNode *newNode = new BranchNode(name, sha, lineParts.at(2)); m_rootNode->insert(nameParts, newNode); if (current) m_currentBranch = newNode; diff --git a/src/plugins/git/branchmodel.h b/src/plugins/git/branchmodel.h index 5eda99d9d3603e529a4bb509e17e7f024808a09b..c386e258f364c6d8d390de4f8388c99e8414e4b9 100644 --- a/src/plugins/git/branchmodel.h +++ b/src/plugins/git/branchmodel.h @@ -92,6 +92,7 @@ private: QString m_workingDirectory; BranchNode *m_rootNode; BranchNode *m_currentBranch; + QString m_currentSha; }; } // namespace Internal diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index b6c8fe36e648d30cde09dade67120ef80c86a3a2..af34f190fd338a2089ba11aa91cf7dbdef4a1155 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -1883,16 +1883,17 @@ bool GitClient::synchronousBranchCmd(const QString &workingDirectory, QStringLis return true; } -bool GitClient::synchronousShowRefCmd(const QString &workingDirectory, QStringList args, +bool GitClient::synchronousForEachRefCmd(const QString &workingDirectory, QStringList args, QString *output, QString *errorMessage) { - args.push_front(QLatin1String("show-ref")); + args.push_front(QLatin1String("for-each-ref")); QByteArray outputText; QByteArray errorText; const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText); *output = commandOutputFromLocal8Bit(outputText); if (!rc) { - *errorMessage = msgCannotRun(QLatin1String("git show-ref"), workingDirectory, commandOutputFromLocal8Bit(errorText)); + *errorMessage = msgCannotRun(QLatin1String("git for-each-ref"), workingDirectory, + commandOutputFromLocal8Bit(errorText)); return false; } diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index 3c8cc28a2f9e47fba4f58ecc80b77382352fc516..7eb42ebb1793ce62b514682a7e7e903bd92dd126 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -201,7 +201,7 @@ public: QString *errorMessage = 0); bool synchronousBranchCmd(const QString &workingDirectory, QStringList branchArgs, QString *output, QString *errorMessage); - bool synchronousShowRefCmd(const QString &workingDirectory, QStringList args, + bool synchronousForEachRefCmd(const QString &workingDirectory, QStringList args, QString *output, QString *errorMessage); bool synchronousRemoteCmd(const QString &workingDirectory, QStringList remoteArgs, QString *output, QString *errorMessage);