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>
This commit is contained in:
Petar Perisin
2013-04-08 13:04:27 +03:00
parent 2cb6b27de2
commit 7c6bb25248
8 changed files with 87 additions and 19 deletions

View File

@@ -132,6 +132,15 @@ 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);
} }
@@ -316,11 +325,10 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage
if (workingDirectory.isEmpty()) if (workingDirectory.isEmpty())
return false; return false;
QStringList branchArgs; QStringList args;
branchArgs << QLatin1String(GitClient::noColorOption) args << QLatin1String("--head") << QLatin1String("--dereference");
<< QLatin1String("-v") << QLatin1String("-a");
QString output; QString output;
if (!m_client->synchronousBranchCmd(workingDirectory, branchArgs, &output, errorMessage)) if (!m_client->synchronousShowRefCmd(workingDirectory, args, &output, errorMessage))
VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage); VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage);
beginResetModel(); beginResetModel();
@@ -331,11 +339,32 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage
foreach (const QString &l, lines) foreach (const QString &l, lines)
parseOutputLine(l); parseOutputLine(l);
if (m_currentBranch) {
if (m_currentBranch->parent == m_rootNode->children[0])
m_currentBranch = 0;
setCurrentBranch();
}
endResetModel(); endResetModel();
return true; 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) void BranchModel::renameBranch(const QString &oldName, const QString &newName)
{ {
QString errorMessage; QString errorMessage;
@@ -538,33 +567,40 @@ void BranchModel::parseOutputLine(const QString &line)
if (line.size() < 3) if (line.size() < 3)
return; 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); static QString currentSha;
if (current && branchInfo.startsWith(QLatin1String("(no branch)"))) if (fullName == QLatin1String("HEAD")) {
currentSha = sha;
return; return;
}
QStringList tokens = branchInfo.split(QLatin1Char(' '), QString::SkipEmptyParts); bool current = (sha == currentSha);
if (tokens.size() < 2) bool showTags = m_client->settings()->boolValue(GitSettings::showTagsKey);
return;
QString sha = tokens.at(1);
// insert node into tree: // insert node into tree:
QStringList nameParts = tokens.at(0).split(QLatin1Char('/')); QStringList nameParts = fullName.split(QLatin1Char('/'));
if (nameParts.count() < 1) nameParts.removeFirst(); // remove refs...
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; return;
if (nameParts.isEmpty() || nameParts.at(0) != QLatin1String("remotes")) // limit depth of list. Git basically only ever wants one / and considers the rest as part of
nameParts.prepend(m_rootNode->children.at(0)->name); // Insert the local designator // the name.
else
nameParts.removeFirst(); // remove "remotes"
while (nameParts.count() > 3) { while (nameParts.count() > 3) {
nameParts[2] = nameParts.at(2) + QLatin1Char('/') + nameParts.at(3); nameParts[2] = nameParts.at(2) + QLatin1Char('/') + nameParts.at(3);
nameParts.removeAt(3); nameParts.removeAt(3);
} }
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);

View File

@@ -82,6 +82,7 @@ public:
private: private:
void parseOutputLine(const QString &line); void parseOutputLine(const QString &line);
void setCurrentBranch();
BranchNode *indexToNode(const QModelIndex &index) const; BranchNode *indexToNode(const QModelIndex &index) const;
QModelIndex nodeToIndex(BranchNode *node) const; QModelIndex nodeToIndex(BranchNode *node) const;

View File

@@ -1506,6 +1506,23 @@ bool GitClient::synchronousBranchCmd(const QString &workingDirectory, QStringLis
return true; 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, bool GitClient::synchronousRemoteCmd(const QString &workingDirectory, QStringList remoteArgs,
QString *output, QString *errorMessage) QString *output, QString *errorMessage)
{ {

View File

@@ -180,6 +180,8 @@ 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,
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);

View File

@@ -36,6 +36,7 @@ namespace Git {
namespace Internal { namespace Internal {
const QLatin1String GitSettings::pullRebaseKey("PullRebase"); const QLatin1String GitSettings::pullRebaseKey("PullRebase");
const QLatin1String GitSettings::showTagsKey("ShowTags");
const QLatin1String GitSettings::omitAnnotationDateKey("OmitAnnotationDate"); const QLatin1String GitSettings::omitAnnotationDateKey("OmitAnnotationDate");
const QLatin1String GitSettings::ignoreSpaceChangesInDiffKey("SpaceIgnorantDiff"); const QLatin1String GitSettings::ignoreSpaceChangesInDiffKey("SpaceIgnorantDiff");
const QLatin1String GitSettings::ignoreSpaceChangesInBlameKey("SpaceIgnorantBlame"); const QLatin1String GitSettings::ignoreSpaceChangesInBlameKey("SpaceIgnorantBlame");
@@ -53,6 +54,7 @@ GitSettings::GitSettings()
declareKey(binaryPathKey, QLatin1String("git")); declareKey(binaryPathKey, QLatin1String("git"));
declareKey(timeoutKey, Utils::HostOsInfo::isWindowsHost() ? 60 : 30); declareKey(timeoutKey, Utils::HostOsInfo::isWindowsHost() ? 60 : 30);
declareKey(pullRebaseKey, false); declareKey(pullRebaseKey, false);
declareKey(showTagsKey, false);
declareKey(omitAnnotationDateKey, false); declareKey(omitAnnotationDateKey, false);
declareKey(ignoreSpaceChangesInDiffKey, true); declareKey(ignoreSpaceChangesInDiffKey, true);
declareKey(ignoreSpaceChangesInBlameKey, true); declareKey(ignoreSpaceChangesInBlameKey, true);

View File

@@ -42,6 +42,7 @@ public:
GitSettings(); GitSettings();
static const QLatin1String pullRebaseKey; static const QLatin1String pullRebaseKey;
static const QLatin1String showTagsKey;
static const QLatin1String omitAnnotationDateKey; static const QLatin1String omitAnnotationDateKey;
static const QLatin1String ignoreSpaceChangesInDiffKey; static const QLatin1String ignoreSpaceChangesInDiffKey;
static const QLatin1String ignoreSpaceChangesInBlameKey; static const QLatin1String ignoreSpaceChangesInBlameKey;

View File

@@ -71,6 +71,7 @@ GitSettings SettingsPageWidget::settings() const
rc.setValue(GitSettings::logCountKey, m_ui.logCountSpinBox->value()); rc.setValue(GitSettings::logCountKey, m_ui.logCountSpinBox->value());
rc.setValue(GitSettings::timeoutKey, m_ui.timeoutSpinBox->value()); rc.setValue(GitSettings::timeoutKey, m_ui.timeoutSpinBox->value());
rc.setValue(GitSettings::pullRebaseKey, m_ui.pullRebaseCheckBox->isChecked()); 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::promptOnSubmitKey, m_ui.promptToSubmitCheckBox->isChecked());
rc.setValue(GitSettings::winSetHomeEnvironmentKey, m_ui.winHomeCheckBox->isChecked()); rc.setValue(GitSettings::winSetHomeEnvironmentKey, m_ui.winHomeCheckBox->isChecked());
rc.setValue(GitSettings::gitkOptionsKey, m_ui.gitkOptionsLineEdit->text().trimmed()); 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.logCountSpinBox->setValue(s.intValue(GitSettings::logCountKey));
m_ui.timeoutSpinBox->setValue(s.intValue(GitSettings::timeoutKey)); m_ui.timeoutSpinBox->setValue(s.intValue(GitSettings::timeoutKey));
m_ui.pullRebaseCheckBox->setChecked(s.boolValue(GitSettings::pullRebaseKey)); 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.promptToSubmitCheckBox->setChecked(s.boolValue(GitSettings::promptOnSubmitKey));
m_ui.winHomeCheckBox->setChecked(s.boolValue(GitSettings::winSetHomeEnvironmentKey)); m_ui.winHomeCheckBox->setChecked(s.boolValue(GitSettings::winSetHomeEnvironmentKey));
m_ui.gitkOptionsLineEdit->setText(s.stringValue(GitSettings::gitkOptionsKey)); m_ui.gitkOptionsLineEdit->setText(s.stringValue(GitSettings::gitkOptionsKey));

View File

@@ -130,6 +130,13 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
</item> </item>