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
d3245cfd
Commit
d3245cfd
authored
Dec 01, 2021
by
Waqar Ahmed
Browse files
Fix git blame for git submodules
(cherry picked from commit
67cd535d
)
parent
5f955baa
Pipeline
#103722
passed with stage
in 3 minutes and 12 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
addons/git-blame/commitfilesview.cpp
View file @
d3245cfd
...
...
@@ -8,6 +8,7 @@
#include
<gitprocess.h>
#include
<QDebug>
#include
<QDir>
#include
<QMimeDatabase>
#include
<QPainter>
...
...
@@ -259,24 +260,47 @@ static void createFileTree(QStandardItem *parent, const QString &basePath, const
}
}
static
std
::
optional
<
QString
>
get
DotGitPath
(
const
QString
&
repo
)
static
std
::
optional
<
QString
>
get
GitCmdOutput
(
const
QString
&
workDir
,
const
QStringList
&
args
)
{
/* This call is intentionally blocking because we need git path for everything else */
QProcess
git
;
setupGitProcess
(
git
,
repo
,
{
QStringLiteral
(
"rev-parse"
),
QStringLiteral
(
"--absolute-git-dir"
)}
);
setupGitProcess
(
git
,
workDir
,
args
);
git
.
start
(
QProcess
::
ReadOnly
);
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
if
(
git
.
exitStatus
()
!=
QProcess
::
NormalExit
||
git
.
exitCode
()
!=
0
)
{
return
std
::
nullopt
;
}
QString
dotGitPath
=
QString
::
fromUtf8
(
git
.
readAllStandardOutput
());
if
(
dotGitPath
.
endsWith
(
QLatin1String
(
"
\n
"
)))
{
dotGitPath
.
remove
(
QLatin1String
(
".git
\n
"
));
}
else
{
dotGitPath
.
remove
(
QLatin1String
(
".git"
));
return
{
QString
::
fromUtf8
(
git
.
readAllStandardOutput
().
trimmed
())};
}
return
{};
}
static
std
::
optional
<
QString
>
getDotGitPath
(
const
QString
&
repo
)
{
/* This call is intentionally blocking because we need git path for everything else */
auto
dotGitPathRes
=
getGitCmdOutput
(
repo
,
{
QStringLiteral
(
"rev-parse"
),
QStringLiteral
(
"--absolute-git-dir"
)});
if
(
!
dotGitPathRes
.
has_value
())
{
return
{};
}
QString
dotGitPath
=
dotGitPathRes
.
value
();
if
(
dotGitPath
.
endsWith
(
QLatin1String
(
".git"
)))
{
dotGitPath
.
remove
(
QLatin1String
(
".git"
));
}
else
if
(
dotGitPath
.
contains
(
QLatin1String
(
".git/modules"
)))
{
// maybe this is some submodule
auto
topLevelRes
=
getGitCmdOutput
(
repo
,
{
QStringLiteral
(
"rev-parse"
),
QStringLiteral
(
"--show-toplevel"
)});
if
(
!
topLevelRes
.
has_value
())
{
return
{};
}
QString
topLevel
=
QDir
::
cleanPath
(
topLevelRes
.
value
());
if
(
!
topLevel
.
endsWith
(
QLatin1Char
(
'/'
)))
{
topLevel
+=
QStringLiteral
(
"/"
);
}
return
dotGitPath
;
return
topLevel
;
}
else
{
qWarning
()
<<
"[blame] Got invalid dot git path: "
<<
dotGitPath
;
return
{};
}
return
dotGitPath
;
return
std
::
nullopt
;
}
...
...
@@ -414,7 +438,7 @@ void CommitDiffTreeView::createFileTreeForCommit(const QString &filePath, const
void
CommitDiffTreeView
::
showDiff
(
const
QModelIndex
&
idx
)
{
auto
file
=
idx
.
data
(
FileItem
::
Path
).
toString
()
.
remove
(
m_gitDir
+
QLatin1Char
(
'/'
))
;
const
QString
file
=
idx
.
data
(
FileItem
::
Path
).
toString
();
QProcess
git
;
setupGitProcess
(
git
,
m_gitDir
,
{
QStringLiteral
(
"show"
),
m_commitHash
,
QStringLiteral
(
"--"
),
file
});
git
.
start
(
QProcess
::
ReadOnly
);
...
...
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