forked from qt-creator/qt-creator
Git: Allow colorful logs
Requires Git 2.3 or higher for RGB colors. Can be enabled for the normal or graph log with the "Color" tool button. For the diff log, the old behavior is kept (highlighter is used for the "normal" log, no colors at all for the graph log) Fixes: QTCREATORBUG-19624 Change-Id: I8a42a7ad0ebf99ceb459355310311d702dcf9977 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
committed by
André Hartmann
parent
3ddf93ba64
commit
cbb70513bf
@@ -223,6 +223,12 @@ VcsBase_FileDeleted_TextColor=ffff6c6c
|
|||||||
VcsBase_FileRenamed_TextColor=ffffa500
|
VcsBase_FileRenamed_TextColor=ffffa500
|
||||||
VcsBase_FileUnmerged_TextColor=ffff4040
|
VcsBase_FileUnmerged_TextColor=ffff4040
|
||||||
|
|
||||||
|
Git_AuthorName_TextColor=ceffe5
|
||||||
|
Git_CommitDate_TextColor=00ff00
|
||||||
|
Git_CommitHash_TextColor=ff0000
|
||||||
|
Git_CommitSubject_TextColor=text
|
||||||
|
Git_Decoration_TextColor=ff00ff
|
||||||
|
|
||||||
Bookmarks_TextMarkColor=ff8080ff
|
Bookmarks_TextMarkColor=ff8080ff
|
||||||
|
|
||||||
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
||||||
|
|||||||
@@ -214,6 +214,12 @@ VcsBase_FileDeleted_TextColor=ff800000
|
|||||||
VcsBase_FileRenamed_TextColor=ffd77d00
|
VcsBase_FileRenamed_TextColor=ffd77d00
|
||||||
VcsBase_FileUnmerged_TextColor=ffee0000
|
VcsBase_FileUnmerged_TextColor=ffee0000
|
||||||
|
|
||||||
|
Git_AuthorName_TextColor=007af4
|
||||||
|
Git_CommitDate_TextColor=006600
|
||||||
|
Git_CommitHash_TextColor=ff0000
|
||||||
|
Git_CommitSubject_TextColor=text
|
||||||
|
Git_Decoration_TextColor=ff00ff
|
||||||
|
|
||||||
Bookmarks_TextMarkColor=ffa0a0ff
|
Bookmarks_TextMarkColor=ffa0a0ff
|
||||||
|
|
||||||
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
||||||
|
|||||||
@@ -227,6 +227,12 @@ VcsBase_FileDeleted_TextColor=fffff6c6c
|
|||||||
VcsBase_FileRenamed_TextColor=ffffa500
|
VcsBase_FileRenamed_TextColor=ffffa500
|
||||||
VcsBase_FileUnmerged_TextColor=ffff4040
|
VcsBase_FileUnmerged_TextColor=ffff4040
|
||||||
|
|
||||||
|
Git_AuthorName_TextColor=ceffe5
|
||||||
|
Git_CommitDate_TextColor=00ff00
|
||||||
|
Git_CommitHash_TextColor=ff4343
|
||||||
|
Git_CommitSubject_TextColor=text
|
||||||
|
Git_Decoration_TextColor=ff00ff
|
||||||
|
|
||||||
Bookmarks_TextMarkColor=ff8080ff
|
Bookmarks_TextMarkColor=ff8080ff
|
||||||
|
|
||||||
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
||||||
|
|||||||
@@ -227,6 +227,12 @@ VcsBase_FileDeleted_TextColor=fffff6c6c
|
|||||||
VcsBase_FileRenamed_TextColor=ffffa500
|
VcsBase_FileRenamed_TextColor=ffffa500
|
||||||
VcsBase_FileUnmerged_TextColor=ffff4040
|
VcsBase_FileUnmerged_TextColor=ffff4040
|
||||||
|
|
||||||
|
Git_AuthorName_TextColor=ceffe5
|
||||||
|
Git_CommitDate_TextColor=00ff00
|
||||||
|
Git_CommitHash_TextColor=ff4343
|
||||||
|
Git_CommitSubject_TextColor=text
|
||||||
|
Git_Decoration_TextColor=ff00ff
|
||||||
|
|
||||||
Bookmarks_TextMarkColor=ff8080ff
|
Bookmarks_TextMarkColor=ff8080ff
|
||||||
|
|
||||||
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
||||||
|
|||||||
@@ -223,6 +223,12 @@ VcsBase_FileDeleted_TextColor=ff800000
|
|||||||
VcsBase_FileRenamed_TextColor=ffd77d00
|
VcsBase_FileRenamed_TextColor=ffd77d00
|
||||||
VcsBase_FileUnmerged_TextColor=ffee0000
|
VcsBase_FileUnmerged_TextColor=ffee0000
|
||||||
|
|
||||||
|
Git_AuthorName_TextColor=007af4
|
||||||
|
Git_CommitDate_TextColor=006600
|
||||||
|
Git_CommitHash_TextColor=ff0000
|
||||||
|
Git_CommitSubject_TextColor=text
|
||||||
|
Git_Decoration_TextColor=ff00ff
|
||||||
|
|
||||||
Bookmarks_TextMarkColor=ffa0a0ff
|
Bookmarks_TextMarkColor=ffa0a0ff
|
||||||
|
|
||||||
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
||||||
|
|||||||
@@ -221,6 +221,12 @@ VcsBase_FileDeleted_TextColor=ff800000
|
|||||||
VcsBase_FileRenamed_TextColor=ffd77d00
|
VcsBase_FileRenamed_TextColor=ffd77d00
|
||||||
VcsBase_FileUnmerged_TextColor=ffee0000
|
VcsBase_FileUnmerged_TextColor=ffee0000
|
||||||
|
|
||||||
|
Git_AuthorName_TextColor=007af4
|
||||||
|
Git_CommitDate_TextColor=006600
|
||||||
|
Git_CommitHash_TextColor=ff0000
|
||||||
|
Git_CommitSubject_TextColor=text
|
||||||
|
Git_Decoration_TextColor=ff00ff
|
||||||
|
|
||||||
Bookmarks_TextMarkColor=ffa0a0ff
|
Bookmarks_TextMarkColor=ffa0a0ff
|
||||||
|
|
||||||
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
TextEditor_SearchResult_ScrollBarColor=ff00c000
|
||||||
|
|||||||
@@ -279,6 +279,13 @@ public:
|
|||||||
VcsBase_FileRenamed_TextColor,
|
VcsBase_FileRenamed_TextColor,
|
||||||
VcsBase_FileUnmerged_TextColor,
|
VcsBase_FileUnmerged_TextColor,
|
||||||
|
|
||||||
|
/* Git Plugin */
|
||||||
|
Git_AuthorName_TextColor,
|
||||||
|
Git_CommitDate_TextColor,
|
||||||
|
Git_CommitHash_TextColor,
|
||||||
|
Git_CommitSubject_TextColor,
|
||||||
|
Git_Decoration_TextColor,
|
||||||
|
|
||||||
/* Bookmarks Plugin */
|
/* Bookmarks Plugin */
|
||||||
Bookmarks_TextMarkColor,
|
Bookmarks_TextMarkColor,
|
||||||
|
|
||||||
|
|||||||
@@ -84,12 +84,14 @@
|
|||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
const char GIT_DIRECTORY[] = ".git";
|
const char GIT_DIRECTORY[] = ".git";
|
||||||
const char graphLogFormatC[] = "%h %d %an %s %ci";
|
|
||||||
const char HEAD[] = "HEAD";
|
const char HEAD[] = "HEAD";
|
||||||
const char CHERRY_PICK_HEAD[] = "CHERRY_PICK_HEAD";
|
const char CHERRY_PICK_HEAD[] = "CHERRY_PICK_HEAD";
|
||||||
const char BRANCHES_PREFIX[] = "Branches: ";
|
const char BRANCHES_PREFIX[] = "Branches: ";
|
||||||
const char stashNamePrefix[] = "stash@{";
|
const char stashNamePrefix[] = "stash@{";
|
||||||
const char noColorOption[] = "--no-color";
|
const char noColorOption[] = "--no-color";
|
||||||
|
const char colorOption[] = "--color=always";
|
||||||
|
const char patchOption[] = "--patch";
|
||||||
|
const char graphOption[] = "--graph";
|
||||||
const char decorateOption[] = "--decorate";
|
const char decorateOption[] = "--decorate";
|
||||||
const char showFormatC[] =
|
const char showFormatC[] =
|
||||||
"--pretty=format:commit %H%d%n"
|
"--pretty=format:commit %H%d%n"
|
||||||
@@ -540,7 +542,7 @@ public:
|
|||||||
BaseGitDiffArgumentsWidget(settings, editor->toolBar())
|
BaseGitDiffArgumentsWidget(settings, editor->toolBar())
|
||||||
{
|
{
|
||||||
QToolBar *toolBar = editor->toolBar();
|
QToolBar *toolBar = editor->toolBar();
|
||||||
QAction *diffButton = addToggleButton("--patch", tr("Diff"),
|
QAction *diffButton = addToggleButton(patchOption, tr("Diff"),
|
||||||
tr("Show difference."));
|
tr("Show difference."));
|
||||||
mapSetting(diffButton, settings.boolPointer(GitSettings::logDiffKey));
|
mapSetting(diffButton, settings.boolPointer(GitSettings::logDiffKey));
|
||||||
connect(diffButton, &QAction::toggled, m_patienceButton, &QAction::setVisible);
|
connect(diffButton, &QAction::toggled, m_patienceButton, &QAction::setVisible);
|
||||||
@@ -568,14 +570,14 @@ public:
|
|||||||
tr("First Parent"),
|
tr("First Parent"),
|
||||||
tr("Follow only the first parent on merge commits."));
|
tr("Follow only the first parent on merge commits."));
|
||||||
mapSetting(firstParentButton, settings.boolPointer(GitSettings::firstParentKey));
|
mapSetting(firstParentButton, settings.boolPointer(GitSettings::firstParentKey));
|
||||||
const QStringList graphArguments = {
|
QAction *graphButton = addToggleButton(graphArguments(), tr("Graph"),
|
||||||
"--graph", "--oneline", "--topo-order",
|
|
||||||
QLatin1String("--pretty=format:") + graphLogFormatC
|
|
||||||
};
|
|
||||||
QAction *graphButton = addToggleButton(graphArguments, tr("Graph"),
|
|
||||||
tr("Show textual graph log."));
|
tr("Show textual graph log."));
|
||||||
mapSetting(graphButton, settings.boolPointer(GitSettings::graphLogKey));
|
mapSetting(graphButton, settings.boolPointer(GitSettings::graphLogKey));
|
||||||
|
|
||||||
|
QAction *colorButton = addToggleButton(QStringList{colorOption},
|
||||||
|
tr("Color"), tr("Use colors in log."));
|
||||||
|
mapSetting(colorButton, settings.boolPointer(GitSettings::colorLogKey));
|
||||||
|
|
||||||
if (fileRelated) {
|
if (fileRelated) {
|
||||||
QAction *followButton = addToggleButton(
|
QAction *followButton = addToggleButton(
|
||||||
"--follow", tr("Follow"),
|
"--follow", tr("Follow"),
|
||||||
@@ -585,6 +587,35 @@ public:
|
|||||||
|
|
||||||
addReloadButton();
|
addReloadButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList graphArguments() const
|
||||||
|
{
|
||||||
|
auto colorName = [](Theme::Color color) { return creatorTheme()->color(color).name(); };
|
||||||
|
const QString authorName = colorName(Theme::Git_AuthorName_TextColor);
|
||||||
|
const QString commitDate = colorName(Theme::Git_CommitDate_TextColor);
|
||||||
|
const QString commitHash = colorName(Theme::Git_CommitHash_TextColor);
|
||||||
|
const QString commitSubject = colorName(Theme::Git_CommitSubject_TextColor);
|
||||||
|
const QString decoration = colorName(Theme::Git_Decoration_TextColor);
|
||||||
|
|
||||||
|
const QString formatArg = QStringLiteral(
|
||||||
|
"--pretty=format:"
|
||||||
|
"%C(%1)%h%Creset "
|
||||||
|
"%C(%2)%d%Creset "
|
||||||
|
"%C(%3)%an%Creset "
|
||||||
|
"%C(%4)%s%Creset "
|
||||||
|
"%C(%5)%ci%Creset"
|
||||||
|
).arg(commitHash, decoration, authorName, commitSubject, commitDate);
|
||||||
|
|
||||||
|
QStringList graphArgs = {graphOption, "--oneline", "--topo-order"};
|
||||||
|
|
||||||
|
const unsigned gitVersion = GitClient::instance()->gitVersion();
|
||||||
|
if (gitVersion >= 0x020300U)
|
||||||
|
graphArgs << formatArg;
|
||||||
|
else
|
||||||
|
graphArgs << "--pretty=format:%h %d %an %s %ci";
|
||||||
|
|
||||||
|
return graphArgs;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class GitRefLogArgumentsWidget : public BaseGitLogArgumentsWidget
|
class GitRefLogArgumentsWidget : public BaseGitLogArgumentsWidget
|
||||||
@@ -1002,6 +1033,30 @@ void GitClient::status(const QString &workingDirectory) const
|
|||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QStringList normalLogArguments()
|
||||||
|
{
|
||||||
|
const unsigned gitVersion = GitClient::instance()->gitVersion();
|
||||||
|
if (gitVersion < 0x020300U)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
auto colorName = [](Theme::Color color) { return creatorTheme()->color(color).name(); };
|
||||||
|
const QString authorName = colorName(Theme::Git_AuthorName_TextColor);
|
||||||
|
const QString commitDate = colorName(Theme::Git_CommitDate_TextColor);
|
||||||
|
const QString commitHash = colorName(Theme::Git_CommitHash_TextColor);
|
||||||
|
const QString commitSubject = colorName(Theme::Git_CommitSubject_TextColor);
|
||||||
|
const QString decoration = colorName(Theme::Git_Decoration_TextColor);
|
||||||
|
|
||||||
|
const QString logArgs = QStringLiteral(
|
||||||
|
"--pretty=format:"
|
||||||
|
"Commit: %C(%1)%H%Creset %C(%2)%d%Creset%n"
|
||||||
|
"Author: %C(%3)%an <%ae>%Creset%n"
|
||||||
|
"Date: %C(%4)%cD%Creset%n%n"
|
||||||
|
"%C(%5)%s%Creset%n%n%b%n"
|
||||||
|
).arg(commitHash, decoration, authorName, commitDate, commitSubject);
|
||||||
|
|
||||||
|
return {logArgs};
|
||||||
|
}
|
||||||
|
|
||||||
void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
||||||
bool enableAnnotationContextMenu, const QStringList &args)
|
bool enableAnnotationContextMenu, const QStringList &args)
|
||||||
{
|
{
|
||||||
@@ -1031,12 +1086,17 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName,
|
|||||||
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
|
editor->setFileLogAnnotateEnabled(enableAnnotationContextMenu);
|
||||||
editor->setWorkingDirectory(workingDir);
|
editor->setWorkingDirectory(workingDir);
|
||||||
|
|
||||||
QStringList arguments = {"log", noColorOption, decorateOption};
|
QStringList arguments = {"log", decorateOption};
|
||||||
int logCount = settings().intValue(GitSettings::logCountKey);
|
int logCount = settings().intValue(GitSettings::logCountKey);
|
||||||
if (logCount > 0)
|
if (logCount > 0)
|
||||||
arguments << "-n" << QString::number(logCount);
|
arguments << "-n" << QString::number(logCount);
|
||||||
|
|
||||||
arguments << argWidget->arguments();
|
arguments << argWidget->arguments();
|
||||||
|
if (arguments.contains(patchOption))
|
||||||
|
arguments.removeAll(colorOption);
|
||||||
|
if (!arguments.contains(graphOption) && !arguments.contains(patchOption))
|
||||||
|
arguments << normalLogArguments();
|
||||||
|
|
||||||
const QString grepValue = editor->grepValue();
|
const QString grepValue = editor->grepValue();
|
||||||
if (!grepValue.isEmpty())
|
if (!grepValue.isEmpty())
|
||||||
arguments << "--grep=" + grepValue;
|
arguments << "--grep=" + grepValue;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include <vcsbase/vcsbaseeditorconfig.h>
|
#include <vcsbase/vcsbaseeditorconfig.h>
|
||||||
#include <vcsbase/vcsoutputwindow.h>
|
#include <vcsbase/vcsoutputwindow.h>
|
||||||
|
|
||||||
|
#include <utils/ansiescapecodehandler.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/temporaryfile.h>
|
#include <utils/temporaryfile.h>
|
||||||
|
|
||||||
@@ -205,6 +206,20 @@ void GitEditorWidget::setPlainText(const QString &text)
|
|||||||
// If desired, filter out the date from annotation
|
// If desired, filter out the date from annotation
|
||||||
switch (contentType())
|
switch (contentType())
|
||||||
{
|
{
|
||||||
|
case LogOutput: {
|
||||||
|
Utils::AnsiEscapeCodeHandler handler;
|
||||||
|
const QList<Utils::FormattedText> formattedTextList
|
||||||
|
= handler.parseText(Utils::FormattedText(text));
|
||||||
|
|
||||||
|
clear();
|
||||||
|
QTextCursor cursor = textCursor();
|
||||||
|
cursor.beginEditBlock();
|
||||||
|
for (auto formattedChunk : formattedTextList)
|
||||||
|
cursor.insertText(formattedChunk.text, formattedChunk.format);
|
||||||
|
cursor.endEditBlock();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
case AnnotateOutput:
|
case AnnotateOutput:
|
||||||
modText = sanitizeBlameOutput(text);
|
modText = sanitizeBlameOutput(text);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ const QLatin1String GitSettings::gitkOptionsKey("GitKOptions");
|
|||||||
const QLatin1String GitSettings::logDiffKey("LogDiff");
|
const QLatin1String GitSettings::logDiffKey("LogDiff");
|
||||||
const QLatin1String GitSettings::repositoryBrowserCmd("RepositoryBrowserCmd");
|
const QLatin1String GitSettings::repositoryBrowserCmd("RepositoryBrowserCmd");
|
||||||
const QLatin1String GitSettings::graphLogKey("GraphLog");
|
const QLatin1String GitSettings::graphLogKey("GraphLog");
|
||||||
|
const QLatin1String GitSettings::colorLogKey("ColorLog");
|
||||||
const QLatin1String GitSettings::firstParentKey("FirstParent");
|
const QLatin1String GitSettings::firstParentKey("FirstParent");
|
||||||
const QLatin1String GitSettings::followRenamesKey("FollowRenames");
|
const QLatin1String GitSettings::followRenamesKey("FollowRenames");
|
||||||
const QLatin1String GitSettings::lastResetIndexKey("LastResetIndex");
|
const QLatin1String GitSettings::lastResetIndexKey("LastResetIndex");
|
||||||
@@ -67,6 +68,7 @@ GitSettings::GitSettings()
|
|||||||
declareKey(logDiffKey, false);
|
declareKey(logDiffKey, false);
|
||||||
declareKey(repositoryBrowserCmd, QString());
|
declareKey(repositoryBrowserCmd, QString());
|
||||||
declareKey(graphLogKey, false);
|
declareKey(graphLogKey, false);
|
||||||
|
declareKey(colorLogKey, true);
|
||||||
declareKey(firstParentKey, false);
|
declareKey(firstParentKey, false);
|
||||||
declareKey(followRenamesKey, true);
|
declareKey(followRenamesKey, true);
|
||||||
declareKey(lastResetIndexKey, 0);
|
declareKey(lastResetIndexKey, 0);
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public:
|
|||||||
static const QLatin1String logDiffKey;
|
static const QLatin1String logDiffKey;
|
||||||
static const QLatin1String repositoryBrowserCmd;
|
static const QLatin1String repositoryBrowserCmd;
|
||||||
static const QLatin1String graphLogKey;
|
static const QLatin1String graphLogKey;
|
||||||
|
static const QLatin1String colorLogKey;
|
||||||
static const QLatin1String firstParentKey;
|
static const QLatin1String firstParentKey;
|
||||||
static const QLatin1String followRenamesKey;
|
static const QLatin1String followRenamesKey;
|
||||||
static const QLatin1String lastResetIndexKey;
|
static const QLatin1String lastResetIndexKey;
|
||||||
|
|||||||
Reference in New Issue
Block a user