Skip to content
GitLab
Menu
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
67cd535d
Commit
67cd535d
authored
Dec 01, 2021
by
Waqar Ahmed
Browse files
Fix git blame for git submodules
parent
22dda3b1
Pipeline
#103721
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 @
67cd535d
...
...
@@ -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
);
...
...
Waqar Ahmed
@waqar
mentioned in commit
d3245cfd
·
Dec 01, 2021
mentioned in commit
d3245cfd
mentioned in commit d3245cfdb896915b3f3dd23c26036c53e1c7fee5
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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