Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
b2b33af7
Commit
b2b33af7
authored
Sep 27, 2022
by
Waqar Ahmed
Browse files
Diff: Show commit info
parent
b3e4bd60
Pipeline
#237415
failed with stage
in 6 minutes and 58 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
addons/git-blame/kategitblameplugin.cpp
View file @
b2b33af7
...
...
@@ -591,6 +591,7 @@ void KateGitBlamePluginView::showDiffForFile(const QByteArray &diffContents, con
{
DiffParams
d
;
d
.
srcFile
=
file
;
d
.
flags
.
setFlag
(
DiffParams
::
ShowCommitInfo
);
Utils
::
showDiff
(
diffContents
,
d
,
m_mainWindow
);
}
...
...
apps/lib/diff/diffparams.h
View file @
b2b33af7
...
...
@@ -18,6 +18,8 @@ struct DiffParams {
ShowDiscard
=
4
,
/** show filename with diff. Appears right before hunk heading **/
ShowFileName
=
8
,
/** show commit info with diff **/
ShowCommitInfo
=
16
,
};
Q_DECLARE_FLAGS
(
Flags
,
Flag
)
Q_FLAGS
(
Flags
)
...
...
apps/lib/diff/diffwidget.cpp
View file @
b2b33af7
...
...
@@ -9,6 +9,7 @@
#include
<QApplication>
#include
<QHBoxLayout>
#include
<QLabel>
#include
<QMimeDatabase>
#include
<QPainter>
#include
<QPainterPath>
...
...
@@ -29,11 +30,17 @@ DiffWidget::DiffWidget(DiffParams p, QWidget *parent)
:
QWidget
(
parent
)
,
m_left
(
new
DiffEditor
(
p
.
flags
,
this
))
,
m_right
(
new
DiffEditor
(
p
.
flags
,
this
))
,
m_commitInfo
(
new
QLabel
(
this
))
,
m_params
(
p
)
{
auto
layout
=
new
QHBoxLayout
(
this
);
layout
->
addWidget
(
m_left
);
layout
->
addWidget
(
m_right
);
auto
layout
=
new
QVBoxLayout
(
this
);
layout
->
setContentsMargins
({});
layout
->
addWidget
(
m_commitInfo
);
auto
diffLayout
=
new
QHBoxLayout
;
diffLayout
->
setContentsMargins
({});
diffLayout
->
addWidget
(
m_left
);
diffLayout
->
addWidget
(
m_right
);
layout
->
addLayout
(
diffLayout
);
leftHl
=
new
DiffSyntaxHighlighter
(
m_left
->
document
(),
this
);
rightHl
=
new
DiffSyntaxHighlighter
(
m_right
->
document
(),
this
);
...
...
@@ -54,6 +61,12 @@ DiffWidget::DiffWidget(DiffParams p, QWidget *parent)
connect
(
e
,
&
DiffEditor
::
actionTriggered
,
this
,
&
DiffWidget
::
handleStageUnstage
);
}
m_commitInfo
->
hide
();
m_commitInfo
->
setWordWrap
(
true
);
m_commitInfo
->
setFont
(
Utils
::
editorFont
());
m_commitInfo
->
setTextInteractionFlags
(
Qt
::
TextSelectableByMouse
);
m_commitInfo
->
setFrameStyle
(
QFrame
::
StyledPanel
|
QFrame
::
Sunken
);
KSharedConfig
::
Ptr
config
=
KSharedConfig
::
openConfig
();
KConfigGroup
cgGeneral
=
KConfigGroup
(
config
,
"General"
);
handleStyleChange
(
cgGeneral
.
readEntry
(
"Diff Show Style"
,
(
int
)
SideBySide
));
...
...
@@ -234,6 +247,8 @@ void DiffWidget::clearData()
m_lineToDiffHunkLine
.
clear
();
m_params
.
clear
();
m_linesWithFileName
.
clear
();
m_commitInfo
->
clear
();
m_commitInfo
->
hide
();
}
void
DiffWidget
::
diffDocs
(
KTextEditor
::
Document
*
l
,
KTextEditor
::
Document
*
r
)
...
...
@@ -765,8 +780,27 @@ void DiffWidget::parseAndShowDiffUnified(const QByteArray &raw)
leftHl
->
setDefinition
(
defs
.
constFirst
());
}
static
QString
commitInfoFromDiff
(
const
QByteArray
&
raw
)
{
if
(
!
raw
.
startsWith
(
"commit "
))
{
return
{};
}
int
commitEnd
=
raw
.
indexOf
(
"diff --git"
);
if
(
commitEnd
==
-
1
)
{
return
{};
}
return
QString
::
fromUtf8
(
raw
.
mid
(
0
,
commitEnd
).
trimmed
());
}
void
DiffWidget
::
openDiff
(
const
QByteArray
&
raw
)
{
if
(
m_params
.
flags
&
DiffParams
::
ShowCommitInfo
)
{
m_commitInfo
->
setText
(
commitInfoFromDiff
(
raw
));
m_commitInfo
->
show
();
}
else
{
m_commitInfo
->
hide
();
}
if
(
m_style
==
SideBySide
)
{
parseAndShowDiff
(
raw
);
}
else
if
(
m_style
==
Unified
)
{
...
...
apps/lib/diff/diffwidget.h
View file @
b2b33af7
...
...
@@ -63,6 +63,7 @@ private:
class
DiffEditor
*
m_left
;
class
DiffEditor
*
m_right
;
class
QLabel
*
const
m_commitInfo
;
KSyntaxHighlighting
::
AbstractHighlighter
*
leftHl
;
KSyntaxHighlighting
::
AbstractHighlighter
*
rightHl
;
DiffStyle
m_style
=
SideBySide
;
...
...
apps/lib/filehistorywidget.cpp
View file @
b2b33af7
...
...
@@ -328,6 +328,7 @@ void FileHistoryWidget::itemClicked(const QModelIndex &idx)
DiffParams
d
;
const
QString
shortCommit
=
QString
::
fromUtf8
(
commit
.
hash
.
mid
(
0
,
7
));
d
.
tabTitle
=
QStringLiteral
(
"%1[%2]"
).
arg
(
Utils
::
fileNameFromPath
(
m_file
),
shortCommit
);
d
.
flags
.
setFlag
(
DiffParams
::
ShowCommitInfo
);
Utils
::
showDiff
(
contents
,
d
,
m_mainWindow
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment