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

@@ -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