forked from qt-creator/qt-creator
Git: Show tracking branch on Branches dialog
Simplify branch model parsing a bit Change-Id: Id9e41c6c2769397d6eee3ab74de4afbb94111e25 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Petar Perisin <petar.perisin@gmail.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
7d300a29bf
commit
e9443ff51f
@@ -50,8 +50,8 @@ public:
|
|||||||
name(QLatin1String("<ROOT>"))
|
name(QLatin1String("<ROOT>"))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
BranchNode(const QString &n, const QString &s = QString()) :
|
BranchNode(const QString &n, const QString &s = QString(), const QString &t = QString()) :
|
||||||
parent(0), name(n), sha(s)
|
parent(0), name(n), sha(s), tracking(t)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~BranchNode()
|
~BranchNode()
|
||||||
@@ -132,15 +132,6 @@ public:
|
|||||||
else
|
else
|
||||||
current = current->append(new BranchNode(path.at(i)));
|
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);
|
current->append(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +164,7 @@ public:
|
|||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
QString sha;
|
QString sha;
|
||||||
|
QString tracking;
|
||||||
mutable QString toolTip;
|
mutable QString toolTip;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -238,7 +230,12 @@ QVariant BranchModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
switch (role) {
|
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:
|
case Qt::EditRole:
|
||||||
return node->name;
|
return node->name;
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
@@ -325,10 +322,11 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage
|
|||||||
if (workingDirectory.isEmpty())
|
if (workingDirectory.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
m_currentSha = m_client->synchronousTopRevision(workingDirectory);
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << QLatin1String("--head") << QLatin1String("--dereference");
|
args << QLatin1String("--format=%(objectname)\t%(refname)\t%(upstream:short)\t%(*objectname)");
|
||||||
QString output;
|
QString output;
|
||||||
if (!m_client->synchronousShowRefCmd(workingDirectory, args, &output, errorMessage))
|
if (!m_client->synchronousForEachRefCmd(workingDirectory, args, &output, errorMessage))
|
||||||
VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage);
|
VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage);
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
@@ -565,17 +563,12 @@ void BranchModel::parseOutputLine(const QString &line)
|
|||||||
if (line.size() < 3)
|
if (line.size() < 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int shaLength = 40;
|
QStringList lineParts = line.split(QLatin1Char('\t'));
|
||||||
const QString sha = line.left(shaLength);
|
const QString shaDeref = lineParts.at(3);
|
||||||
const QString fullName = line.mid(shaLength + 1);
|
const QString sha = shaDeref.isEmpty() ? lineParts.at(0) : shaDeref;
|
||||||
|
const QString fullName = lineParts.at(1);
|
||||||
|
|
||||||
static QString currentSha;
|
bool current = (sha == m_currentSha);
|
||||||
if (fullName == QLatin1String("HEAD")) {
|
|
||||||
currentSha = sha;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool current = (sha == currentSha);
|
|
||||||
bool showTags = m_client->settings()->boolValue(GitSettings::showTagsKey);
|
bool showTags = m_client->settings()->boolValue(GitSettings::showTagsKey);
|
||||||
|
|
||||||
// insert node into tree:
|
// insert node into tree:
|
||||||
@@ -601,7 +594,7 @@ void BranchModel::parseOutputLine(const QString &line)
|
|||||||
const QString name = nameParts.last();
|
const QString name = nameParts.last();
|
||||||
nameParts.removeLast();
|
nameParts.removeLast();
|
||||||
|
|
||||||
BranchNode *newNode = new BranchNode(name, sha);
|
BranchNode *newNode = new BranchNode(name, sha, lineParts.at(2));
|
||||||
m_rootNode->insert(nameParts, newNode);
|
m_rootNode->insert(nameParts, newNode);
|
||||||
if (current)
|
if (current)
|
||||||
m_currentBranch = newNode;
|
m_currentBranch = newNode;
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ private:
|
|||||||
QString m_workingDirectory;
|
QString m_workingDirectory;
|
||||||
BranchNode *m_rootNode;
|
BranchNode *m_rootNode;
|
||||||
BranchNode *m_currentBranch;
|
BranchNode *m_currentBranch;
|
||||||
|
QString m_currentSha;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -1883,16 +1883,17 @@ bool GitClient::synchronousBranchCmd(const QString &workingDirectory, QStringLis
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GitClient::synchronousShowRefCmd(const QString &workingDirectory, QStringList args,
|
bool GitClient::synchronousForEachRefCmd(const QString &workingDirectory, QStringList args,
|
||||||
QString *output, QString *errorMessage)
|
QString *output, QString *errorMessage)
|
||||||
{
|
{
|
||||||
args.push_front(QLatin1String("show-ref"));
|
args.push_front(QLatin1String("for-each-ref"));
|
||||||
QByteArray outputText;
|
QByteArray outputText;
|
||||||
QByteArray errorText;
|
QByteArray errorText;
|
||||||
const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText);
|
const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText);
|
||||||
*output = commandOutputFromLocal8Bit(outputText);
|
*output = commandOutputFromLocal8Bit(outputText);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
*errorMessage = msgCannotRun(QLatin1String("git show-ref"), workingDirectory, commandOutputFromLocal8Bit(errorText));
|
*errorMessage = msgCannotRun(QLatin1String("git for-each-ref"), workingDirectory,
|
||||||
|
commandOutputFromLocal8Bit(errorText));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ public:
|
|||||||
QString *errorMessage = 0);
|
QString *errorMessage = 0);
|
||||||
bool synchronousBranchCmd(const QString &workingDirectory, QStringList branchArgs,
|
bool synchronousBranchCmd(const QString &workingDirectory, QStringList branchArgs,
|
||||||
QString *output, QString *errorMessage);
|
QString *output, QString *errorMessage);
|
||||||
bool synchronousShowRefCmd(const QString &workingDirectory, QStringList args,
|
bool synchronousForEachRefCmd(const QString &workingDirectory, QStringList args,
|
||||||
QString *output, QString *errorMessage);
|
QString *output, QString *errorMessage);
|
||||||
bool synchronousRemoteCmd(const QString &workingDirectory, QStringList remoteArgs,
|
bool synchronousRemoteCmd(const QString &workingDirectory, QStringList remoteArgs,
|
||||||
QString *output, QString *errorMessage);
|
QString *output, QString *errorMessage);
|
||||||
|
|||||||
Reference in New Issue
Block a user