Git: Aspectify settings

Change-Id: I87dfeba360967cc77cc230811bcd9f67b3ea6e38
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2021-03-16 06:00:25 +01:00
parent f2c34e51e9
commit aa69415ac7
19 changed files with 379 additions and 529 deletions

View File

@@ -35,6 +35,5 @@ add_qtc_plugin(Git
remoteadditiondialog.ui
remotedialog.cpp remotedialog.h remotedialog.ui
remotemodel.cpp remotemodel.h
settingspage.cpp settingspage.h settingspage.ui
stashdialog.cpp stashdialog.h stashdialog.ui
)

View File

@@ -793,7 +793,7 @@ void BranchModel::Private::parseOutputLine(const QString &line, bool force)
const qint64 age = dateTime.daysTo(QDateTime::currentDateTime());
isOld = age > Constants::OBSOLETE_COMMIT_AGE_IN_DAYS;
}
bool showTags = client->settings().boolValue(GitSettings::showTagsKey);
const bool showTags = client->settings().showTags.value();
// insert node into tree:
QStringList nameParts = fullName.split('/');

View File

@@ -121,8 +121,7 @@ BranchView::BranchView() :
connect(m_includeOldEntriesAction, &QAction::toggled,
this, &BranchView::setIncludeOldEntries);
m_includeTagsAction->setCheckable(true);
m_includeTagsAction->setChecked(
GitClient::instance()->settings().boolValue(GitSettings::showTagsKey));
m_includeTagsAction->setChecked(GitClient::settings().showTags.value());
connect(m_includeTagsAction, &QAction::toggled,
this, &BranchView::setIncludeTags);
@@ -309,7 +308,7 @@ void BranchView::setIncludeOldEntries(bool filter)
void BranchView::setIncludeTags(bool includeTags)
{
GitClient::instance()->settings().setValue(GitSettings::showTagsKey, includeTags);
GitClient::settings().showTags.setValue(includeTags);
refreshCurrentRepository();
}

View File

@@ -7,7 +7,6 @@ HEADERS += gitplugin.h \
gitclient.h \
changeselectiondialog.h \
commitdata.h \
settingspage.h \
giteditor.h \
annotationhighlighter.h \
gitsubmiteditorwidget.h \
@@ -30,7 +29,6 @@ SOURCES += gitplugin.cpp \
gitclient.cpp \
changeselectiondialog.cpp \
commitdata.cpp \
settingspage.cpp \
giteditor.cpp \
annotationhighlighter.cpp \
gitsubmiteditorwidget.cpp \
@@ -50,7 +48,6 @@ SOURCES += gitplugin.cpp \
branchview.cpp
FORMS += changeselectiondialog.ui \
settingspage.ui \
gitsubmitpanel.ui \
stashdialog.ui \
remotedialog.ui \

View File

@@ -62,9 +62,6 @@ QtcPlugin {
"remotedialog.ui",
"remotemodel.cpp",
"remotemodel.h",
"settingspage.cpp",
"settingspage.h",
"settingspage.ui",
"stashdialog.cpp",
"stashdialog.h",
"stashdialog.ui",

View File

@@ -493,17 +493,16 @@ class BaseGitDiffArgumentsWidget : public VcsBaseEditorConfig
Q_OBJECT
public:
BaseGitDiffArgumentsWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
BaseGitDiffArgumentsWidget(GitSettings &settings, QToolBar *toolBar) :
VcsBaseEditorConfig(toolBar)
{
m_patienceButton
= addToggleButton("--patience", tr("Patience"),
tr("Use the patience algorithm for calculating the differences."));
mapSetting(m_patienceButton, settings.boolPointer(GitSettings::diffPatienceKey));
mapSetting(m_patienceButton, &settings.diffPatience);
m_ignoreWSButton = addToggleButton("--ignore-space-change", tr("Ignore Whitespace"),
tr("Ignore whitespace only changes."));
mapSetting(m_ignoreWSButton,
settings.boolPointer(GitSettings::ignoreSpaceChangesInDiffKey));
mapSetting(m_ignoreWSButton, &settings.ignoreSpaceChangesInDiff);
}
protected:
@@ -516,15 +515,15 @@ class GitBlameArgumentsWidget : public VcsBaseEditorConfig
Q_OBJECT
public:
GitBlameArgumentsWidget(VcsBaseClientSettings &settings, QToolBar *toolBar) :
GitBlameArgumentsWidget(GitSettings &settings, QToolBar *toolBar) :
VcsBaseEditorConfig(toolBar)
{
mapSetting(addToggleButton(QString(), tr("Omit Date"),
tr("Hide the date of a change from the output.")),
settings.boolPointer(GitSettings::omitAnnotationDateKey));
&settings.omitAnnotationDate);
mapSetting(addToggleButton("-w", tr("Ignore Whitespace"),
tr("Ignore whitespace only changes.")),
settings.boolPointer(GitSettings::ignoreSpaceChangesInBlameKey));
&settings.ignoreSpaceChangesInBlame);
const QList<ChoiceItem> logChoices = {
ChoiceItem(tr("No Move Detection"), ""),
@@ -533,7 +532,7 @@ public:
ChoiceItem(tr("Detect Moves and Copies Between Files"), "-M -C -C")
};
mapSetting(addChoices(tr("Move detection"), {}, logChoices),
settings.intPointer(GitSettings::blameMoveDetection));
&settings.blameMoveDetection);
addReloadButton();
}
@@ -544,13 +543,13 @@ class BaseGitLogArgumentsWidget : public BaseGitDiffArgumentsWidget
Q_OBJECT
public:
BaseGitLogArgumentsWidget(VcsBaseClientSettings &settings, GitEditorWidget *editor) :
BaseGitLogArgumentsWidget(GitSettings &settings, GitEditorWidget *editor) :
BaseGitDiffArgumentsWidget(settings, editor->toolBar())
{
QToolBar *toolBar = editor->toolBar();
QAction *diffButton = addToggleButton(patchOption, tr("Diff"),
tr("Show difference."));
mapSetting(diffButton, settings.boolPointer(GitSettings::logDiffKey));
mapSetting(diffButton, &settings.logDiff);
connect(diffButton, &QAction::toggled, m_patienceButton, &QAction::setVisible);
connect(diffButton, &QAction::toggled, m_ignoreWSButton, &QAction::setVisible);
m_patienceButton->setVisible(diffButton->isChecked());
@@ -585,27 +584,27 @@ class GitLogArgumentsWidget : public BaseGitLogArgumentsWidget
Q_OBJECT
public:
GitLogArgumentsWidget(VcsBaseClientSettings &settings, bool fileRelated, GitEditorWidget *editor) :
GitLogArgumentsWidget(GitSettings &settings, bool fileRelated, GitEditorWidget *editor) :
BaseGitLogArgumentsWidget(settings, editor)
{
QAction *firstParentButton =
addToggleButton({"-m", "--first-parent"},
tr("First Parent"),
tr("Follow only the first parent on merge commits."));
mapSetting(firstParentButton, settings.boolPointer(GitSettings::firstParentKey));
mapSetting(firstParentButton, &settings.firstParent);
QAction *graphButton = addToggleButton(graphArguments(), tr("Graph"),
tr("Show textual graph log."));
mapSetting(graphButton, settings.boolPointer(GitSettings::graphLogKey));
mapSetting(graphButton, &settings.graphLog);
QAction *colorButton = addToggleButton(QStringList{colorOption},
tr("Color"), tr("Use colors in log."));
mapSetting(colorButton, settings.boolPointer(GitSettings::colorLogKey));
mapSetting(colorButton, &settings.colorLog);
if (fileRelated) {
QAction *followButton = addToggleButton(
"--follow", tr("Follow"),
tr("Show log also for previous names of the file."));
mapSetting(followButton, settings.boolPointer(GitSettings::followRenamesKey));
mapSetting(followButton, &settings.followRenames);
}
addReloadButton();
@@ -644,14 +643,14 @@ class GitRefLogArgumentsWidget : public BaseGitLogArgumentsWidget
Q_OBJECT
public:
GitRefLogArgumentsWidget(VcsBaseClientSettings &settings, GitEditorWidget *editor) :
GitRefLogArgumentsWidget(GitSettings &settings, GitEditorWidget *editor) :
BaseGitLogArgumentsWidget(settings, editor)
{
QAction *showDateButton =
addToggleButton("--date=iso",
tr("Show Date"),
tr("Show date instead of sequence."));
mapSetting(showDateButton, settings.boolPointer(GitSettings::refLogShowDateKey));
mapSetting(showDateButton, &settings.refLogShowDate);
addReloadButton();
}
@@ -784,9 +783,8 @@ static inline void msgCannotRun(const QStringList &args, const QString &workingD
// ---------------- GitClient
GitClient::GitClient(GitSettings *settings) : VcsBase::VcsBaseClientImpl(settings),
m_cachedGitVersion(0),
m_disableEditor(false)
GitClient::GitClient(GitSettings *settings)
: VcsBase::VcsBaseClientImpl(nullptr, settings)
{
m_instance = this;
m_gitQtcEditor = QString::fromLatin1("\"%1\" -client -block -pid %2")
@@ -799,6 +797,11 @@ GitClient *GitClient::instance()
return m_instance;
}
GitSettings &GitClient::settings()
{
return static_cast<GitSettings &>(m_instance->baseSettings());
}
QString GitClient::findRepositoryForDirectory(const QString &directory) const
{
if (directory.isEmpty() || directory.endsWith("/.git") || directory.contains("/.git/"))
@@ -977,8 +980,8 @@ void GitClient::requestReload(const QString &documentId, const QString &source,
QTC_ASSERT(document, return);
GitBaseDiffEditorController *controller = factory(document);
QTC_ASSERT(controller, return);
controller->setVcsBinary(settings().binaryPath());
controller->setVcsTimeoutS(settings().vcsTimeoutS());
controller->setVcsBinary(settings().binaryPath.filePath());
controller->setVcsTimeoutS(settings().timeout.value());
controller->setProcessEnvironment(processEnvironment());
controller->setWorkingDirectory(workingDirectory);
controller->initialize();
@@ -1118,7 +1121,7 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
editor->setWorkingDirectory(workingDir);
QStringList arguments = {"log", decorateOption};
int logCount = settings().intValue(GitSettings::logCountKey);
int logCount = settings().logCount.value();
if (logCount > 0)
arguments << "-n" << QString::number(logCount);
@@ -1171,7 +1174,7 @@ void GitClient::reflog(const QString &workingDirectory, const QString &ref)
QStringList arguments = {"reflog", noColorOption, decorateOption};
arguments << argWidget->arguments();
int logCount = settings().intValue(GitSettings::logCountKey);
int logCount = settings().logCount.value();
if (logCount > 0)
arguments << "-n" << QString::number(logCount);
@@ -2194,16 +2197,14 @@ bool GitClient::synchronousApplyPatch(const QString &workingDirectory,
QProcessEnvironment GitClient::processEnvironment() const
{
QProcessEnvironment environment = VcsBaseClientImpl::processEnvironment();
QString gitPath = settings().stringValue(GitSettings::pathKey);
QString gitPath = settings().path.value();
if (!gitPath.isEmpty()) {
gitPath += HostOsInfo::pathListSeparator();
gitPath += environment.value("PATH");
environment.insert("PATH", gitPath);
}
if (HostOsInfo::isWindowsHost()
&& settings().boolValue(GitSettings::winSetHomeEnvironmentKey)) {
if (HostOsInfo::isWindowsHost() && settings().winSetHomeEnvironment.value())
environment.insert("HOME", QDir::toNativeSeparators(QDir::homePath()));
}
environment.insert("GIT_EDITOR", m_disableEditor ? "true" : m_gitQtcEditor);
return environment;
}
@@ -2551,7 +2552,7 @@ void GitClient::launchGitK(const QString &workingDirectory, const QString &fileN
void GitClient::launchRepositoryBrowser(const QString &workingDirectory) const
{
const QString repBrowserBinary = settings().stringValue(GitSettings::repositoryBrowserCmd);
const QString repBrowserBinary = settings().repositoryBrowserCmd.value();
if (!repBrowserBinary.isEmpty())
QProcess::startDetached(repBrowserBinary, {workingDirectory}, workingDirectory);
}
@@ -2571,7 +2572,7 @@ bool GitClient::tryLauchingGitK(const QProcessEnvironment &env,
binary = wish;
}
}
const QString gitkOpts = settings().stringValue(GitSettings::gitkOptionsKey);
const QString gitkOpts = settings().gitkOptions.value();
if (!gitkOpts.isEmpty())
arguments.append(QtcProcess::splitArgs(gitkOpts, HostOsInfo::hostOs()));
if (!fileName.isEmpty())
@@ -2580,7 +2581,7 @@ bool GitClient::tryLauchingGitK(const QProcessEnvironment &env,
// This should always use QProcess::startDetached (as not to kill
// the child), but that does not have an environment parameter.
bool success = false;
if (!settings().stringValue(GitSettings::pathKey).isEmpty()) {
if (!settings().path.value().isEmpty()) {
auto process = new QProcess;
process->setWorkingDirectory(workingDirectory);
process->setProcessEnvironment(env);
@@ -3226,7 +3227,7 @@ void GitClient::synchronousSubversionFetch(const QString &workingDirectory) cons
void GitClient::subversionLog(const QString &workingDirectory) const
{
QStringList arguments = {"svn", "log"};
int logCount = settings().intValue(GitSettings::logCountKey);
int logCount = settings().logCount.value();
if (logCount > 0)
arguments << ("--limit=" + QString::number(logCount));

View File

@@ -140,6 +140,7 @@ public:
explicit GitClient(GitSettings *settings);
static GitClient *instance();
static GitSettings &settings();
Utils::FilePath vcsBinary() const override;
unsigned gitVersion(QString *errorMessage = nullptr) const;
@@ -416,14 +417,14 @@ private:
const QString &gitCommand, ContinueCommandMode continueMode);
mutable Utils::FilePath m_gitVersionForBinary;
mutable unsigned m_cachedGitVersion;
mutable unsigned m_cachedGitVersion = 0;
QString m_gitQtcEditor;
QMap<QString, StashInfo> m_stashInfo;
QString m_pushFallbackCommand;
QString m_diffCommit;
QStringList m_updatedSubmodules;
bool m_disableEditor;
bool m_disableEditor = false;
QFutureSynchronizer<void> m_synchronizer; // for commit updates
};

View File

@@ -152,8 +152,7 @@ static QString sanitizeBlameOutput(const QString &b)
if (b.isEmpty())
return b;
const bool omitDate = GitClient::instance()->settings().boolValue(
GitSettings::omitAnnotationDateKey);
const bool omitDate = GitClient::instance()->settings().omitAnnotationDate.value();
const QChar space(' ');
const int parenPos = b.indexOf(')');
if (parenPos == -1)

View File

@@ -34,7 +34,6 @@
#include "gitsubmiteditor.h"
#include "remotedialog.h"
#include "stashdialog.h"
#include "settingspage.h"
#include "logchangedialog.h"
#include "mergetool.h"
#include "gitutils.h"
@@ -1486,7 +1485,7 @@ void GitPluginPrivate::pull()
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
QString topLevel = state.topLevel();
bool rebase = m_settings.boolValue(GitSettings::pullRebaseKey);
bool rebase = m_settings.pullRebase.value();
if (!rebase) {
QString currentBranch = m_gitClient.synchronousCurrentLocalBranch(topLevel);
@@ -1821,8 +1820,7 @@ QObject *GitPlugin::remoteCommand(const QStringList &options, const QString &wor
void GitPluginPrivate::updateRepositoryBrowserAction()
{
const bool repositoryEnabled = currentState().hasTopLevel();
const bool hasRepositoryBrowserCmd
= !m_settings.stringValue(GitSettings::repositoryBrowserCmd).isEmpty();
const bool hasRepositoryBrowserCmd = !m_settings.repositoryBrowserCmd.value().isEmpty();
m_repositoryBrowserAction->setEnabled(repositoryEnabled && hasRepositoryBrowserCmd);
}

View File

@@ -25,76 +25,214 @@
#include "gitsettings.h"
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <QCoreApplication>
#include <utils/layoutbuilder.h>
#include <vcsbase/vcsbaseconstants.h>
#include <QDir>
using namespace Utils;
using namespace VcsBase;
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");
const QLatin1String GitSettings::blameMoveDetection("BlameDetectMove");
const QLatin1String GitSettings::diffPatienceKey("DiffPatience");
const QLatin1String GitSettings::winSetHomeEnvironmentKey("WinSetHomeEnvironment");
const QLatin1String GitSettings::gitkOptionsKey("GitKOptions");
const QLatin1String GitSettings::logDiffKey("LogDiff");
const QLatin1String GitSettings::repositoryBrowserCmd("RepositoryBrowserCmd");
const QLatin1String GitSettings::graphLogKey("GraphLog");
const QLatin1String GitSettings::colorLogKey("ColorLog");
const QLatin1String GitSettings::firstParentKey("FirstParent");
const QLatin1String GitSettings::followRenamesKey("FollowRenames");
const QLatin1String GitSettings::lastResetIndexKey("LastResetIndex");
const QLatin1String GitSettings::refLogShowDateKey("RefLogShowDate");
GitSettings::GitSettings()
{
setSettingsGroup("Git");
declareKey(binaryPathKey, "git");
declareKey(timeoutKey, Utils::HostOsInfo::isWindowsHost() ? 60 : 30);
declareKey(pullRebaseKey, false);
declareKey(showTagsKey, false);
declareKey(omitAnnotationDateKey, false);
declareKey(ignoreSpaceChangesInDiffKey, true);
declareKey(blameMoveDetection, 0);
declareKey(ignoreSpaceChangesInBlameKey, true);
declareKey(diffPatienceKey, true);
declareKey(winSetHomeEnvironmentKey, true);
declareKey(gitkOptionsKey, QString());
declareKey(logDiffKey, false);
declareKey(repositoryBrowserCmd, QString());
declareKey(graphLogKey, false);
declareKey(colorLogKey, true);
declareKey(firstParentKey, false);
declareKey(followRenamesKey, true);
declareKey(lastResetIndexKey, 0);
declareKey(refLogShowDateKey, false);
path.setDisplayStyle(StringAspect::LineEditDisplay);
path.setLabelText(tr("Prepend to PATH:"));
registerAspect(&binaryPath);
binaryPath.setDefaultValue("git");
registerAspect(&pullRebase);
pullRebase.setSettingsKey("PullRebase");
pullRebase.setLabelText(tr("Pull with rebase"));
registerAspect(&showTags);
showTags.setSettingsKey("ShowTags");
registerAspect(&omitAnnotationDate);
omitAnnotationDate.setSettingsKey("OmitAnnotationDate");
registerAspect(&ignoreSpaceChangesInDiff);
ignoreSpaceChangesInDiff.setSettingsKey("SpaceIgnorantDiff");
ignoreSpaceChangesInDiff.setDefaultValue(true);
registerAspect(&ignoreSpaceChangesInBlame);
ignoreSpaceChangesInBlame.setSettingsKey("SpaceIgnorantBlame");
ignoreSpaceChangesInBlame.setDefaultValue(true);
registerAspect(&blameMoveDetection);
blameMoveDetection.setSettingsKey("BlameDetectMove");
blameMoveDetection.setDefaultValue(0);
registerAspect(&diffPatience);
diffPatience.setSettingsKey("DiffPatience");
diffPatience.setDefaultValue(true);
registerAspect(&winSetHomeEnvironment);
winSetHomeEnvironment.setSettingsKey("WinSetHomeEnvironment");
winSetHomeEnvironment.setDefaultValue(true);
winSetHomeEnvironment.setLabelText(tr("Set \"HOME\" environment variable"));
if (true || HostOsInfo::isWindowsHost()) {
const QByteArray currentHome = qgetenv("HOME");
const QString toolTip
= tr("Set the environment variable HOME to \"%1\"\n(%2).\n"
"This causes Git to look for the SSH-keys in that location\n"
"instead of its installation directory when run outside git bash.").
arg(QDir::homePath(),
currentHome.isEmpty() ? tr("not currently set") :
tr("currently set to \"%1\"").arg(QString::fromLocal8Bit(currentHome)));
winSetHomeEnvironment.setToolTip(toolTip);
} else {
winSetHomeEnvironment.setVisible(false);
}
registerAspect(&gitkOptions);
gitkOptions.setDisplayStyle(StringAspect::LineEditDisplay);
gitkOptions.setSettingsKey("GitKOptions");
gitkOptions.setLabelText(tr("Arguments:"));
registerAspect(&logDiff);
logDiff.setSettingsKey("LogDiff");
logDiff.setToolTip(tr("Note that huge amount of commits might take some time."));
registerAspect(&repositoryBrowserCmd);
repositoryBrowserCmd.setDisplayStyle(StringAspect::PathChooserDisplay);
repositoryBrowserCmd.setSettingsKey("RepositoryBrowserCmd");
repositoryBrowserCmd.setExpectedKind(PathChooser::ExistingCommand);
repositoryBrowserCmd.setHistoryCompleter("Git.RepoCommand.History");
repositoryBrowserCmd.setDisplayName(tr("Git Repository Browser Command"));
repositoryBrowserCmd.setLabelText(tr("Command:"));
registerAspect(&graphLog);
graphLog.setSettingsKey("GraphLog");
registerAspect(&colorLog);
colorLog.setSettingsKey("ColorLog");
colorLog.setDefaultValue(true);
registerAspect(&firstParent);
firstParent.setSettingsKey("FirstParent");
registerAspect(&followRenames);
followRenames.setSettingsKey("FollowRenames");
followRenames.setDefaultValue(true);
registerAspect(&lastResetIndex);
lastResetIndex.setSettingsKey("LastResetIndex");
registerAspect(&refLogShowDate);
refLogShowDate.setSettingsKey("RefLogShowDate");
timeout.setDefaultValue(Utils::HostOsInfo::isWindowsHost() ? 60 : 30);
note.setText(tr("<b>Note:</b>") + tr("Git needs to find Perl in the environment."));
const auto updateNoteField = [this] {
Environment env = Environment::systemEnvironment();
env.prependOrSetPath(path.value());
const bool showNote = env.searchInPath("perl").isEmpty();
note.setVisible(showNote);
};
updateNoteField();
QObject::connect(&path, &BaseAspect::changed, &note, updateNoteField);
}
Utils::FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const
FilePath GitSettings::gitExecutable(bool *ok, QString *errorMessage) const
{
// Locate binary in path if one is specified, otherwise default
// to pathless binary
// Locate binary in path if one is specified, otherwise default to pathless binary.
if (ok)
*ok = true;
if (errorMessage)
errorMessage->clear();
Utils::FilePath binPath = binaryPath();
FilePath binPath = binaryPath.filePath();
if (binPath.isEmpty()) {
if (ok)
*ok = false;
if (errorMessage)
*errorMessage = QCoreApplication::translate("Git::Internal::GitSettings",
"The binary \"%1\" could not be located in the path \"%2\"")
.arg(stringValue(binaryPathKey), stringValue(pathKey));
*errorMessage = tr("The binary \"%1\" could not be located in the path \"%2\"")
.arg(binaryPath.value(), path.value());
}
return binPath;
}
// GitSettingsPageWidget
class GitSettingsPageWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(Git::Internal::SettingsPageWidget)
public:
GitSettingsPageWidget(GitSettings *settings, const std::function<void()> &onChange);
void apply() final;
private:
std::function<void()> m_onChange;
GitSettings *m_settings;
};
GitSettingsPageWidget::GitSettingsPageWidget(GitSettings *settings, const std::function<void()> &onChange)
: m_onChange(onChange), m_settings(settings)
{
GitSettings &s = *m_settings;
using namespace Layouting;
Column {
Group {
Title(tr("Configuration")),
Row { s.path },
s.winSetHomeEnvironment,
},
Group {
Title(tr("Miscellaneous")),
Row { s.logCount, s.timeout, Stretch() },
s.pullRebase
},
Group {
Title(tr("Gitk")),
Row { s.gitkOptions }
},
Group {
Title(tr("Repository Browser")),
Row { s.repositoryBrowserCmd }
},
Stretch()
}.attachTo(this);
}
void GitSettingsPageWidget::apply()
{
if (m_settings->isDirty()) {
m_settings->apply();
m_onChange();
}
}
// GitSettingsPage
GitSettingsPage::GitSettingsPage(GitSettings *settings, const std::function<void()> &onChange)
{
setId(VcsBase::Constants::VCS_ID_GIT);
setDisplayName(GitSettingsPageWidget::tr("Git"));
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
setWidgetCreator([settings, onChange] { return new GitSettingsPageWidget(settings, onChange); });
}
} // namespace Internal
} // namespace Git

View File

@@ -25,6 +25,7 @@
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
#include <vcsbase/vcsbaseclientsettings.h>
namespace Git {
@@ -38,32 +39,39 @@ enum CommitType
};
// Todo: Add user name and password?
class GitSettings : public VcsBase::VcsBaseClientSettings
class GitSettings : public VcsBase::VcsBaseSettings
{
Q_DECLARE_TR_FUNCTIONS(Git::Internal::GitSettings)
public:
GitSettings();
static const QLatin1String pullRebaseKey;
static const QLatin1String showTagsKey;
static const QLatin1String omitAnnotationDateKey;
static const QLatin1String ignoreSpaceChangesInDiffKey;
static const QLatin1String ignoreSpaceChangesInBlameKey;
static const QLatin1String blameMoveDetection;
static const QLatin1String diffPatienceKey;
static const QLatin1String winSetHomeEnvironmentKey;
static const QLatin1String gitkOptionsKey;
static const QLatin1String logDiffKey;
static const QLatin1String repositoryBrowserCmd;
static const QLatin1String graphLogKey;
static const QLatin1String colorLogKey;
static const QLatin1String firstParentKey;
static const QLatin1String followRenamesKey;
static const QLatin1String lastResetIndexKey;
static const QLatin1String refLogShowDateKey;
Utils::BoolAspect pullRebase;
Utils::BoolAspect showTags;
Utils::BoolAspect omitAnnotationDate;
Utils::BoolAspect ignoreSpaceChangesInDiff;
Utils::BoolAspect ignoreSpaceChangesInBlame;
Utils::IntegerAspect blameMoveDetection;
Utils::BoolAspect diffPatience;
Utils::BoolAspect winSetHomeEnvironment;
Utils::StringAspect gitkOptions;
Utils::BoolAspect logDiff;
Utils::StringAspect repositoryBrowserCmd;
Utils::BoolAspect graphLog;
Utils::BoolAspect colorLog;
Utils::BoolAspect firstParent;
Utils::BoolAspect followRenames;
Utils::IntegerAspect lastResetIndex;
Utils::BoolAspect refLogShowDate;
Utils::TextDisplay note;
Utils::FilePath gitExecutable(bool *ok = nullptr, QString *errorMessage = nullptr) const;
};
GitSettings &operator=(const GitSettings &s) = default;
class GitSettingsPage final : public Core::IOptionsPage
{
public:
GitSettingsPage(GitSettings *settings, const std::function<void()> &onChange);
};
} // namespace Internal

View File

@@ -244,8 +244,7 @@ LogChangeDialog::LogChangeDialog(bool isReset, QWidget *parent) :
m_resetTypeComboBox->addItem(tr("Hard"), "--hard");
m_resetTypeComboBox->addItem(tr("Mixed"), "--mixed");
m_resetTypeComboBox->addItem(tr("Soft"), "--soft");
m_resetTypeComboBox->setCurrentIndex(
GitClient::instance()->settings().intValue(GitSettings::lastResetIndexKey));
m_resetTypeComboBox->setCurrentIndex(GitClient::settings().lastResetIndex.value());
popUpLayout->addWidget(m_resetTypeComboBox);
popUpLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));
}
@@ -271,10 +270,8 @@ bool LogChangeDialog::runDialog(const QString &repository,
return false;
if (QDialog::exec() == QDialog::Accepted) {
if (m_resetTypeComboBox) {
GitClient::instance()->settings().setValue(
GitSettings::lastResetIndexKey, m_resetTypeComboBox->currentIndex());
}
if (m_resetTypeComboBox)
GitClient::settings().lastResetIndex.setValue(m_resetTypeComboBox->currentIndex());
return true;
}
return false;

View File

@@ -1,138 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "settingspage.h"
#include "gitsettings.h"
#include "gitplugin.h"
#include "gitclient.h"
#include "ui_settingspage.h"
#include <coreplugin/icore.h>
#include <coreplugin/messagebox.h>
#include <vcsbase/vcsbaseconstants.h>
#include <utils/environment.h>
#include <utils/hostosinfo.h>
#include <QDir>
using namespace VcsBase;
namespace Git {
namespace Internal {
class GitSettingsPageWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(Git::Internal::SettingsPageWidget)
public:
GitSettingsPageWidget(GitSettings *settings, const std::function<void()> &onChange);
void apply() final;
private:
void updateNoteField();
std::function<void()> m_onChange;
GitSettings *m_settings;
Ui::SettingsPage m_ui;
};
GitSettingsPageWidget::GitSettingsPageWidget(GitSettings *settings, const std::function<void()> &onChange)
: m_onChange(onChange), m_settings(settings)
{
m_ui.setupUi(this);
if (Utils::HostOsInfo::isWindowsHost()) {
const QByteArray currentHome = qgetenv("HOME");
const QString toolTip
= tr("Set the environment variable HOME to \"%1\"\n(%2).\n"
"This causes Git to look for the SSH-keys in that location\n"
"instead of its installation directory when run outside git bash.").
arg(QDir::homePath(),
currentHome.isEmpty() ? tr("not currently set") :
tr("currently set to \"%1\"").arg(QString::fromLocal8Bit(currentHome)));
m_ui.winHomeCheckBox->setToolTip(toolTip);
} else {
m_ui.winHomeCheckBox->setVisible(false);
}
updateNoteField();
m_ui.repBrowserCommandPathChooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
m_ui.repBrowserCommandPathChooser->setHistoryCompleter("Git.RepoCommand.History");
m_ui.repBrowserCommandPathChooser->setPromptDialogTitle(tr("Git Repository Browser Command"));
connect(m_ui.pathLineEdit, &QLineEdit::textChanged, this, &GitSettingsPageWidget::updateNoteField);
GitSettings &s = *m_settings;
m_ui.pathLineEdit->setText(s.stringValue(GitSettings::pathKey));
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.winHomeCheckBox->setChecked(s.boolValue(GitSettings::winSetHomeEnvironmentKey));
m_ui.gitkOptionsLineEdit->setText(s.stringValue(GitSettings::gitkOptionsKey));
m_ui.repBrowserCommandPathChooser->setPath(s.stringValue(GitSettings::repositoryBrowserCmd));
}
void GitSettingsPageWidget::apply()
{
GitSettings rc = *m_settings;
rc.setValue(GitSettings::pathKey, m_ui.pathLineEdit->text());
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::winSetHomeEnvironmentKey, m_ui.winHomeCheckBox->isChecked());
rc.setValue(GitSettings::gitkOptionsKey, m_ui.gitkOptionsLineEdit->text().trimmed());
rc.setValue(GitSettings::repositoryBrowserCmd, m_ui.repBrowserCommandPathChooser->path().trimmed());
if (rc != *m_settings) {
*m_settings = rc;
m_onChange();
}
}
void GitSettingsPageWidget::updateNoteField()
{
Utils::Environment env = Utils::Environment::systemEnvironment();
env.prependOrSetPath(m_ui.pathLineEdit->text());
bool showNote = env.searchInPath("perl").isEmpty();
m_ui.noteFieldlabel->setVisible(showNote);
m_ui.noteLabel->setVisible(showNote);
}
// -------- SettingsPage
GitSettingsPage::GitSettingsPage(GitSettings *settings, const std::function<void()> &onChange)
{
setId(VcsBase::Constants::VCS_ID_GIT);
setDisplayName(GitSettingsPageWidget::tr("Git"));
setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY);
setWidgetCreator([settings, onChange] { return new GitSettingsPageWidget(settings, onChange); });
}
} // namespace Internal
} // namespace Git

View File

@@ -1,42 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
namespace Git {
namespace Internal {
class GitSettings;
class GitSettingsPage final : public Core::IOptionsPage
{
public:
GitSettingsPage(GitSettings *settings, const std::function<void()> &onChange);
};
} // namespace Internal
} // namespace Git

View File

@@ -1,214 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Git::Internal::SettingsPage</class>
<widget class="QWidget" name="Git::Internal::SettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>705</width>
<height>403</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="configurationGroupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Configuration</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="pathlabel">
<property name="text">
<string>Prepend to PATH:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="pathLineEdit"/>
</item>
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="winHomeCheckBox">
<property name="text">
<string>Set &quot;HOME&quot; environment variable</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="noteLabel">
<property name="text">
<string>&lt;b&gt;Note:&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLabel" name="noteFieldlabel">
<property name="text">
<string>Git needs to find Perl in the environment.</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Miscellaneous</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="pullRebaseCheckBox">
<property name="text">
<string>Pull with rebase</string>
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>211</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="timeoutSpinBox">
<property name="suffix">
<string>s</string>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>360</number>
</property>
<property name="value">
<number>30</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="logCountLabel">
<property name="text">
<string>Log count:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="timeoutLabel">
<property name="text">
<string>Timeout:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="logCountSpinBox">
<property name="toolTip">
<string>Note that huge amount of commits might take some time.</string>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>1000</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gitkGroupBox">
<property name="title">
<string>Gitk</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="gitkOptionsLabel">
<property name="text">
<string>Arguments:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="gitkOptionsLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="repBrowserGroupBox">
<property name="title">
<string>Repository Browser</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="repBrowserCommandLabel">
<property name="text">
<string>Command:</string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="repBrowserCommandPathChooser" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
<slots>
<signal>editingFinished()</signal>
<signal>browsingFinished()</signal>
</slots>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>pathLineEdit</tabstop>
<tabstop>winHomeCheckBox</tabstop>
<tabstop>logCountSpinBox</tabstop>
<tabstop>timeoutSpinBox</tabstop>
<tabstop>pullRebaseCheckBox</tabstop>
<tabstop>gitkOptionsLineEdit</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@@ -73,11 +73,15 @@ static Core::IEditor *locateEditor(const char *property, const QString &entry)
namespace VcsBase {
VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseClientSettings *settings) :
m_clientSettings(settings)
VcsBaseClientImpl::VcsBaseClientImpl(VcsBaseClientSettings *settings, VcsBaseSettings *baseSettings) :
m_clientSettings(settings), m_baseSettings(baseSettings)
{
if (settings) {
m_defaultSettings = *m_clientSettings;
m_clientSettings->readSettings(Core::ICore::settings());
} else {
m_baseSettings->readSettings(Core::ICore::settings());
}
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
this, &VcsBaseClientImpl::saveSettings);
}
@@ -87,6 +91,11 @@ VcsBaseClientSettings &VcsBaseClientImpl::settings() const
return *m_clientSettings;
}
VcsBaseSettings &VcsBaseClientImpl::baseSettings() const
{
return *m_baseSettings;
}
FilePath VcsBaseClientImpl::vcsBinary() const
{
return settings().binaryPath();
@@ -215,7 +224,9 @@ SynchronousProcessResponse VcsBaseClientImpl::vcsSynchronousExec(const QString &
int VcsBaseClientImpl::vcsTimeoutS() const
{
if (m_clientSettings)
return m_clientSettings->vcsTimeoutS();
return m_baseSettings->timeout.value();
}
VcsBaseEditorWidget *VcsBaseClientImpl::createVcsEditor(Utils::Id kind, QString title,
@@ -250,7 +261,10 @@ VcsBaseEditorWidget *VcsBaseClientImpl::createVcsEditor(Utils::Id kind, QString
void VcsBaseClientImpl::saveSettings()
{
settings().writeSettings(Core::ICore::settings(), m_defaultSettings);
if (m_clientSettings)
m_clientSettings->writeSettings(Core::ICore::settings(), m_defaultSettings);
else
m_baseSettings->writeSettings(Core::ICore::settings());
}
VcsBaseClient::VcsBaseClient(VcsBaseClientSettings *settings) :

View File

@@ -58,10 +58,12 @@ class VCSBASE_EXPORT VcsBaseClientImpl : public QObject
Q_OBJECT
public:
explicit VcsBaseClientImpl(VcsBaseClientSettings *settings);
explicit VcsBaseClientImpl(VcsBaseClientSettings *settings,
VcsBaseSettings *baseSettings = nullptr);
~VcsBaseClientImpl() override = default;
VcsBaseClientSettings &settings() const;
VcsBaseClientSettings &settings() const; // FIXME: Phase out.
VcsBaseSettings &baseSettings() const; // FIXME: Rename into settings() when the original is gone.
virtual Utils::FilePath vcsBinary() const;
int vcsTimeoutS() const;
@@ -128,8 +130,9 @@ protected:
private:
void saveSettings();
VcsBaseClientSettings *m_clientSettings;
VcsBaseClientSettings *m_clientSettings; // "old" style.
VcsBaseClientSettings m_defaultSettings;
VcsBaseSettings *m_baseSettings = nullptr; // Aspect based.
};
class VCSBASE_EXPORT VcsBaseClient : public VcsBaseClientImpl

View File

@@ -397,4 +397,74 @@ QVariant VcsBaseClientSettings::keyDefaultValue(const QString &key) const
return QVariant(valueType(key));
}
// VcsBaseSettings
VcsBaseSettings::VcsBaseSettings()
{
setAutoApply(false);
registerAspect(&binaryPath);
binaryPath.setSettingsKey("BinaryPath");
registerAspect(&userName);
userName.setSettingsKey("Username");
registerAspect(&userEmail);
userEmail.setSettingsKey("UserEmail");
registerAspect(&logCount);
logCount.setSettingsKey("LogCount");
logCount.setRange(0, 1000 * 1000);
logCount.setDefaultValue(100);
logCount.setLabelText(tr("Log count:"));
registerAspect(&path);
path.setSettingsKey("Path");
registerAspect(&promptOnSubmit);
promptOnSubmit.setSettingsKey("PromptOnSubmit");
promptOnSubmit.setDefaultValue(true);
promptOnSubmit.setLabelText(tr("Prompt on submit"));
registerAspect(&timeout);
timeout.setSettingsKey("Timeout");
timeout.setRange(0, 3600 * 24 * 365);
timeout.setDefaultValue(30);
timeout.setLabelText(tr("Timeout:"));
timeout.setSuffix(tr("s"));
}
QStringList VcsBaseSettings::searchPathList() const
{
return path.value().split(HostOsInfo::pathListSeparator(), Qt::SkipEmptyParts);
}
void VcsBaseSettings::setSettingsGroup(const QString &key)
{
m_settingsGroup = key;
}
void VcsBaseSettings::writeSettings(QSettings *settings) const
{
QTC_ASSERT(!m_settingsGroup.isEmpty(), return);
settings->remove(m_settingsGroup);
settings->beginGroup(m_settingsGroup);
forEachAspect([settings](BaseAspect *aspect) {
QtcSettings::setValueWithDefault(settings, aspect->settingsKey(),
aspect->value(), aspect->defaultValue());
});
settings->endGroup();
}
void VcsBaseSettings::readSettings(const QSettings *settings)
{
const QString keyRoot = m_settingsGroup + '/';
forEachAspect([settings, keyRoot](BaseAspect *aspect) {
QString key = aspect->settingsKey();
const QVariant value = settings->value(keyRoot + key, aspect->defaultValue());
aspect->setValue(value);
});
}
} // namespace VcsBase

View File

@@ -27,19 +27,42 @@
#include "vcsbase_global.h"
#include <utils/aspects.h>
#include <QStringList>
#include <QVariant>
#include <QSharedDataPointer>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace Utils { class FilePath; }
namespace VcsBase {
namespace Internal { class VcsBaseClientSettingsPrivate; }
class VCSBASE_EXPORT VcsBaseSettings : public Utils::AspectContainer
{
Q_DECLARE_TR_FUNCTIONS(VcsBase::VcsBaseSettings)
public:
VcsBaseSettings();
Utils::StringAspect binaryPath;
Utils::StringAspect userName;
Utils::StringAspect userEmail;
Utils::IntegerAspect logCount;
Utils::BoolAspect promptOnSubmit;
Utils::IntegerAspect timeout; // Seconds
Utils::StringAspect path;
QStringList searchPathList() const;
void writeSettings(QSettings *settings) const;
void readSettings(const QSettings *settings);
void setSettingsGroup(const QString &key);
private:
QString m_settingsGroup;
};
class VCSBASE_EXPORT VcsBaseClientSettings
{
public: