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
KDevelop
KDevelop
Commits
a6390bf3
Commit
a6390bf3
authored
Aug 28, 2022
by
Milian Wolff
Browse files
Make perforce plugin compile with strict string conversions
parent
c441909c
Changes
5
Hide whitespace changes
Inline
Side-by-side
plugins/perforce/CMakeLists.txt
View file @
a6390bf3
# temporary while patch series in work 08/2018
remove_definitions
(
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_BYTEARRAY
)
add_subdirectory
(
p4clientstub
)
declare_qt_logging_category
(
kdevperforce_LOG_PART_SRCS
TYPE PLUGIN
...
...
plugins/perforce/p4clientstub/main.cpp
View file @
a6390bf3
...
...
@@ -218,15 +218,15 @@ int main(int argc, char** argv)
}
else
if
(
qstrcmp
(
argv
[
1
],
"diff"
)
==
0
)
{
return
fakeDiffOutput
();
}
else
if
(
qstrcmp
(
argv
[
1
],
"filelog"
)
==
0
)
{
return
fakeFileLogOutput
(
argv
[
3
]);
return
fakeFileLogOutput
(
QString
::
fromUtf8
(
argv
[
3
])
)
;
}
else
if
(
qstrcmp
(
argv
[
1
],
"annotate"
)
==
0
)
{
return
fakeAnnotateOutput
();
}
else
if
(
qstrcmp
(
argv
[
1
],
"edit"
)
==
0
)
{
return
fakeEditOutput
(
QString
(
argv
[
2
]));
return
fakeEditOutput
(
QString
::
fromUtf8
(
argv
[
2
]));
}
else
if
(
qstrcmp
(
argv
[
1
],
"fstat"
)
==
0
)
{
return
fakeFstatOutput
(
QString
(
argv
[
2
]));
return
fakeFstatOutput
(
QString
::
fromUtf8
(
argv
[
2
]));
}
else
if
(
qstrcmp
(
argv
[
1
],
"add"
)
==
0
)
{
return
fakeAddOutput
(
QString
(
argv
[
2
]));
return
fakeAddOutput
(
QString
::
fromUtf8
(
argv
[
2
]));
}
return
-
1
;
}
plugins/perforce/perforceplugin.cpp
View file @
a6390bf3
...
...
@@ -182,11 +182,7 @@ QString PerforcePlugin::getRepositoryName(const QFileInfo& curFile)
QScopedPointer
<
DVcsJob
>
job
(
p4fstatJob
(
curFile
,
KDevelop
::
OutputJob
::
Silent
));
if
(
job
->
exec
()
&&
job
->
status
()
==
KDevelop
::
VcsJob
::
JobSucceeded
)
{
if
(
!
job
->
output
().
isEmpty
())
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
const
QStringList
outputLines
=
job
->
output
().
split
(
'\n'
,
Qt
::
SkipEmptyParts
);
#else
const
QStringList
outputLines
=
job
->
output
().
split
(
'\n'
,
QString
::
SkipEmptyParts
);
#endif
const
QStringList
outputLines
=
job
->
output
().
split
(
QLatin1Char
(
'\n'
),
Qt
::
SkipEmptyParts
);
for
(
const
QString
&
line
:
outputLines
)
{
int
idx
(
line
.
indexOf
(
DEPOT_FILE_STR
));
if
(
idx
!=
-
1
)
{
...
...
@@ -273,7 +269,7 @@ KDevelop::VcsJob* PerforcePlugin::update(const QList<QUrl>& localLocations, cons
//*job << m_perforceExecutable << "-p" << "127.0.0.1:1666" << "info"; - Let's keep this for now it's very handy for debugging
QString
fileOrDirectory
;
if
(
curFile
.
isDir
())
fileOrDirectory
=
curFile
.
absolutePath
()
+
"/..."
;
fileOrDirectory
=
curFile
.
absolutePath
()
+
QLatin1String
(
"/..."
)
;
else
fileOrDirectory
=
curFile
.
fileName
();
*
job
<<
m_perforceExecutable
<<
"sync"
<<
fileOrDirectory
;
...
...
@@ -342,14 +338,14 @@ KDevelop::VcsJob* PerforcePlugin::log(const QUrl& localLocation, const KDevelop:
*
job
<<
QStringLiteral
(
"-m %1"
).
arg
(
limit
);
if
(
curFile
.
isDir
())
{
localLocationAndRevStr
.
append
(
"/..."
);
localLocationAndRevStr
.
append
(
QLatin1String
(
"/..."
)
)
;
}
QString
revStr
=
toRevisionName
(
rev
,
QString
());
if
(
!
revStr
.
isEmpty
())
{
// This is not too nice, but perforce argument for restricting output from filelog does not Work :-(
// So putting this in so we do not end up in infinite loop calling log,
if
(
revStr
==
lastSeenChangeList
)
{
localLocationAndRevStr
.
append
(
"#none"
);
localLocationAndRevStr
.
append
(
QLatin1String
(
"#none"
)
)
;
lastSeenChangeList
.
clear
();
}
else
{
localLocationAndRevStr
.
append
(
revStr
);
...
...
@@ -506,34 +502,35 @@ QList<QVariant> PerforcePlugin::getQvariantFromLogOutput(QStringList const& outp
int
changeNumber
=
0
;
for
(
const
QString
&
line
:
outputLines
)
{
if
(
!
line
.
startsWith
(
LOGENTRY_START
)
&&
!
line
.
startsWith
(
DEPOTMESSAGE_START
)
&&
!
line
.
startsWith
(
'\t'
))
{
if
(
!
line
.
startsWith
(
LOGENTRY_START
)
&&
!
line
.
startsWith
(
DEPOTMESSAGE_START
)
&&
!
line
.
startsWith
(
QLatin1Char
(
'\t'
)))
{
currentFileName
=
line
;
}
if
(
line
.
indexOf
(
LOGENTRY_START
)
!=
-
1
)
{
// expecting the Logentry line to be of the form:
//... #5 change 10 edit on 2010/12/06 12:07:31 by mvo@testbed (text)
changeNumberStr
=
line
.
section
(
' '
,
3
,
3
);
// We use global change number
changeNumberStr
=
line
.
section
(
QLatin1Char
(
' '
)
,
3
,
3
);
// We use global change number
changeNumber
=
changeNumberStr
.
toInt
();
author
=
line
.
section
(
' '
,
9
,
9
);
changeDescription
=
line
.
section
(
' '
,
4
,
4
);
indexofAt
=
author
.
indexOf
(
'@'
);
author
=
line
.
section
(
QLatin1Char
(
' '
)
,
9
,
9
);
changeDescription
=
line
.
section
(
QLatin1Char
(
' '
)
,
4
,
4
);
indexofAt
=
author
.
indexOf
(
QLatin1Char
(
'@'
)
)
;
author
.
remove
(
indexofAt
,
author
.
size
());
// Only keep the username itself
rev
.
setRevisionValue
(
changeNumberStr
,
KDevelop
::
VcsRevision
::
GlobalNumber
);
changes
[
changeNumber
].
setRevision
(
rev
);
changes
[
changeNumber
].
setAuthor
(
author
);
changes
[
changeNumber
].
setDate
(
QDateTime
::
fromString
(
line
.
section
(
' '
,
6
,
7
),
QStringLiteral
(
"yyyy/MM/dd hh:mm:ss"
)));
changes
[
changeNumber
].
setDate
(
QDateTime
::
fromString
(
line
.
section
(
QLatin1Char
(
' '
),
6
,
7
),
QStringLiteral
(
"yyyy/MM/dd hh:mm:ss"
)));
currentRepoFile
.
setRepositoryLocation
(
currentFileName
);
currentRepoFile
.
setActions
(
actionsFromString
(
changeDescription
)
);
changes
[
changeNumber
].
addItem
(
currentRepoFile
);
commitMessage
.
clear
();
// We have a new entry, clear message
}
if
(
line
.
startsWith
(
'\t'
)
||
line
.
startsWith
(
DEPOTMESSAGE_START
))
{
commitMessage
+=
line
.
trimmed
()
+
'\n'
;
if
(
line
.
startsWith
(
QLatin1Char
(
'\t'
)
)
||
line
.
startsWith
(
DEPOTMESSAGE_START
))
{
commitMessage
+=
line
.
trimmed
()
+
QLatin1Char
(
'\n'
)
;
changes
[
changeNumber
].
setMessage
(
commitMessage
);
}
}
}
for
(
const
auto
&
item
:
qAsConst
(
changes
))
{
...
...
@@ -544,11 +541,7 @@ QList<QVariant> PerforcePlugin::getQvariantFromLogOutput(QStringList const& outp
void
PerforcePlugin
::
parseP4StatusOutput
(
DVcsJob
*
job
)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
const
QStringList
outputLines
=
job
->
output
().
split
(
'\n'
,
Qt
::
SkipEmptyParts
);
#else
const
QStringList
outputLines
=
job
->
output
().
split
(
'\n'
,
QString
::
SkipEmptyParts
);
#endif
const
QStringList
outputLines
=
job
->
output
().
split
(
QLatin1Char
(
'\n'
),
Qt
::
SkipEmptyParts
);
QVariantList
statuses
;
const
QString
ACTION_STR
(
QStringLiteral
(
"... action "
));
const
QString
CLIENT_FILE_STR
(
QStringLiteral
(
"... clientFile "
));
...
...
@@ -584,11 +577,7 @@ void PerforcePlugin::parseP4StatusOutput(DVcsJob* job)
void
PerforcePlugin
::
parseP4LogOutput
(
KDevelop
::
DVcsJob
*
job
)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QList
<
QVariant
>
commits
(
getQvariantFromLogOutput
(
job
->
output
().
split
(
'\n'
,
Qt
::
SkipEmptyParts
)));
#else
QList
<
QVariant
>
commits
(
getQvariantFromLogOutput
(
job
->
output
().
split
(
'\n'
,
QString
::
SkipEmptyParts
)));
#endif
QList
<
QVariant
>
commits
(
getQvariantFromLogOutput
(
job
->
output
().
split
(
QLatin1Char
(
'\n'
),
Qt
::
SkipEmptyParts
)));
job
->
setResults
(
commits
);
}
...
...
@@ -625,11 +614,7 @@ void PerforcePlugin::parseP4AnnotateOutput(DVcsJob *job)
QList
<
QVariant
>
commits
;
if
(
logJob
->
exec
()
&&
logJob
->
status
()
==
KDevelop
::
VcsJob
::
JobSucceeded
)
{
if
(
!
job
->
output
().
isEmpty
())
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
commits
=
getQvariantFromLogOutput
(
logJob
->
output
().
split
(
'\n'
,
Qt
::
SkipEmptyParts
));
#else
commits
=
getQvariantFromLogOutput
(
logJob
->
output
().
split
(
'\n'
,
QString
::
SkipEmptyParts
));
#endif
commits
=
getQvariantFromLogOutput
(
logJob
->
output
().
split
(
QLatin1Char
(
'\n'
),
Qt
::
SkipEmptyParts
));
}
}
...
...
@@ -643,7 +628,7 @@ void PerforcePlugin::parseP4AnnotateOutput(DVcsJob *job)
globalCommits
.
insert
(
item
.
revision
().
revisionValue
().
toLongLong
(),
item
);
}
const
QStringList
lines
=
job
->
output
().
split
(
'\n'
);
const
QStringList
lines
=
job
->
output
().
split
(
QLatin1Char
(
'\n'
)
)
;
int
lineNumber
=
0
;
QMap
<
qlonglong
,
VcsEvent
>::
iterator
currentEvent
;
...
...
@@ -655,7 +640,7 @@ void PerforcePlugin::parseP4AnnotateOutput(DVcsJob *job)
continue
;
}
globalRevision
=
line
.
left
(
line
.
indexOf
(
':'
));
globalRevision
=
line
.
left
(
line
.
indexOf
(
QLatin1Char
(
':'
))
)
;
VcsAnnotationLine
annotation
;
annotation
.
setLineNumber
(
lineNumber
);
...
...
plugins/perforce/tests/test_perforce.cpp
View file @
a6390bf3
...
...
@@ -47,13 +47,14 @@ void PerforcePluginTest::initTestCase()
m_plugin
=
new
PerforcePlugin
(
TestCore
::
self
());
/// During test we are setting the executable the plugin uses to our own stub
QDirIterator
it
(
P4_BINARY_DIR
,
QStringList
()
<<
QStringLiteral
(
"*"
),
QDir
::
Dirs
|
QDir
::
NoDotAndDotDot
,
QDirIterator
::
Subdirectories
);
QDirIterator
it
(
QString
::
fromUtf8
(
P4_BINARY_DIR
),
QStringList
()
<<
QStringLiteral
(
"*"
),
QDir
::
Dirs
|
QDir
::
NoDotAndDotDot
,
QDirIterator
::
Subdirectories
);
QStringList
pathsToSearch
;
while
(
it
.
hasNext
())
{
it
.
next
();
pathsToSearch
<<
it
.
filePath
();
}
QString
p4stubPath
=
QStandardPaths
::
findExecutable
(
"p4clientstub"
,
pathsToSearch
);
QString
p4stubPath
=
QStandardPaths
::
findExecutable
(
QStringLiteral
(
"p4clientstub"
)
,
pathsToSearch
);
qDebug
()
<<
"found p4stub executable :"
<<
p4stubPath
;
QVERIFY
(
!
p4stubPath
.
isEmpty
());
...
...
plugins/perforce/ui/perforceimportmetadatawidget.cpp
View file @
a6390bf3
...
...
@@ -21,15 +21,18 @@ PerforceImportMetadataWidget::PerforceImportMetadataWidget(QWidget* parent)
{
m_ui
->
setupUi
(
this
);
m_ui
->
executableLoc
->
setText
(
"/usr/bin/p4"
);
m_ui
->
p4portEdit
->
setText
(
"perforce:1666"
);
m_ui
->
executableLoc
->
setText
(
QStringLiteral
(
"/usr/bin/p4"
)
)
;
m_ui
->
p4portEdit
->
setText
(
QStringLiteral
(
"perforce:1666"
)
)
;
QProcessEnvironment
curEnv
=
QProcessEnvironment
::
systemEnvironment
();
m_ui
->
p4configEdit
->
setText
(
curEnv
.
contains
(
"P4CONFIG"
)
?
curEnv
.
value
(
"P4CONFIG"
)
:
""
);
m_ui
->
p4portEdit
->
setText
(
curEnv
.
contains
(
"P4PORT"
)
?
curEnv
.
value
(
"P4PORT"
)
:
""
);
m_ui
->
p4userEdit
->
setText
(
curEnv
.
contains
(
"P4USER"
)
?
curEnv
.
value
(
"P4USER"
)
:
""
);
curEnv
.
contains
(
"P4CONFIG"
)
?
m_ui
->
radioButtonConfig
->
setChecked
(
true
)
:
m_ui
->
radioButtonVariables
->
setChecked
(
true
);
curEnv
.
contains
(
"P4CONFIG"
)
?
m_ui
->
p4configEdit
->
setEnabled
(
true
)
:
m_ui
->
p4configEdit
->
setEnabled
(
false
);
m_ui
->
p4configEdit
->
setText
(
curEnv
.
value
(
QStringLiteral
(
"P4CONFIG"
)));
m_ui
->
p4portEdit
->
setText
(
curEnv
.
value
(
QStringLiteral
(
"P4PORT"
)));
m_ui
->
p4userEdit
->
setText
(
curEnv
.
value
(
QStringLiteral
(
"P4USER"
)));
const
auto
hasP4Config
=
curEnv
.
contains
(
QStringLiteral
(
"P4CONFIG"
));
m_ui
->
radioButtonConfig
->
setChecked
(
hasP4Config
);
m_ui
->
radioButtonVariables
->
setChecked
(
!
hasP4Config
);
m_ui
->
p4configEdit
->
setEnabled
(
hasP4Config
);
m_ui
->
sourceLoc
->
setEnabled
(
false
);
m_ui
->
sourceLoc
->
setMode
(
KFile
::
Directory
);
...
...
@@ -117,7 +120,8 @@ void PerforceImportMetadataWidget::testP4setup()
bool
PerforceImportMetadataWidget
::
validateP4executable
()
{
if
(
QStandardPaths
::
findExecutable
(
m_ui
->
executableLoc
->
url
().
toLocalFile
()).
isEmpty
())
{
m_ui
->
errorMsg
->
setText
(
"Unable to find perforce executable. Is it installed on the system? Is it in your PATH?"
);
m_ui
->
errorMsg
->
setText
(
i18n
(
"Unable to find perforce executable. Is it installed on the system? Is it in your PATH?"
));
return
false
;
}
return
true
;
...
...
@@ -127,7 +131,7 @@ bool PerforceImportMetadataWidget::validateP4user(const QString& projectDir) co
{
QProcess
exec
;
QProcessEnvironment
p4execEnvironment
;
p4execEnvironment
.
insert
(
QString
(
"P4PORT"
),
m_ui
->
p4portEdit
->
displayText
());
p4execEnvironment
.
insert
(
QString
Literal
(
"P4PORT"
),
m_ui
->
p4portEdit
->
displayText
());
exec
.
setWorkingDirectory
(
projectDir
);
exec
.
setProcessEnvironment
(
p4execEnvironment
);
exec
.
start
(
m_ui
->
executableLoc
->
url
().
toLocalFile
(),
QStringList
{
QStringLiteral
(
"workspaces"
),
...
...
@@ -135,19 +139,17 @@ bool PerforceImportMetadataWidget::validateP4user(const QString& projectDir) co
);
exec
.
waitForFinished
();
QString
processStdout
(
exec
.
readAllStandardOutput
());
QString
processStderr
(
exec
.
readAllStandardError
());
const
auto
processStdout
=
QString
::
fromUtf8
(
exec
.
readAllStandardOutput
());
const
auto
processStderr
=
QString
::
fromUtf8
(
exec
.
readAllStandardError
());
// std::cout << "Exited with code: " << exec.exitCode() << std::endl;
// std::cout << "Exited with stdout" << processStdout.toStdString() << std::endl;
// std::cout << "Exited with stderr" << processStderr.toStdString() << std::endl;
// std::cout << "Exited with code: " << exec.exitCode() << std::endl;
// std::cout << "Exited with stdout" << processStdout.toStdString() << std::endl;
// std::cout << "Exited with stderr" << processStderr.toStdString() << std::endl;
if
(
exec
.
exitCode
()
!=
0
)
{
if
(
!
processStderr
.
isEmpty
())
{
m_ui
->
errorMsg
->
setText
(
processStderr
);
}
else
{
QString
msg
(
"P4 Client failed with exit code: "
);
msg
+=
QString
::
number
(
exec
.
exitCode
());
m_ui
->
errorMsg
->
setText
(
msg
);
m_ui
->
errorMsg
->
setText
(
i18n
(
"P4 Client failed with exit code: %1"
,
exec
.
exitCode
()));
}
return
false
;
}
...
...
@@ -173,7 +175,7 @@ bool PerforceImportMetadataWidget::validateP4port(const QString& projectDir) co
{
QProcess
exec
;
QProcessEnvironment
p4execEnvironment
;
p4execEnvironment
.
insert
(
QString
(
"P4PORT"
),
m_ui
->
p4portEdit
->
displayText
());
p4execEnvironment
.
insert
(
QString
Literal
(
"P4PORT"
),
m_ui
->
p4portEdit
->
displayText
());
QTextStream
out
(
stdout
);
const
auto
&
env
=
p4execEnvironment
.
toStringList
();
for
(
const
QString
&
x
:
env
)
{
...
...
@@ -186,7 +188,7 @@ bool PerforceImportMetadataWidget::validateP4port(const QString& projectDir) co
exec
.
start
(
m_ui
->
executableLoc
->
url
().
toLocalFile
(),
QStringList
()
<<
QStringLiteral
(
"info"
));
exec
.
waitForFinished
();
//QString processStdout(exec.readAllStandardOutput());
QString
processStderr
(
exec
.
readAllStandardError
());
const
auto
processStderr
=
QString
::
fromUtf8
(
exec
.
readAllStandardError
());
//std::cout << "Exited with code: " << exec.exitCode() << std::endl;
//std::cout << "Exited with stdout" << processStdout.toStdString() << std::endl;
...
...
@@ -195,9 +197,7 @@ bool PerforceImportMetadataWidget::validateP4port(const QString& projectDir) co
if
(
!
processStderr
.
isEmpty
())
{
m_ui
->
errorMsg
->
setText
(
processStderr
);
}
else
{
QString
msg
(
"P4 Client failed with error code: "
);
msg
+=
QString
::
number
(
exec
.
exitCode
());
m_ui
->
errorMsg
->
setText
(
msg
);
m_ui
->
errorMsg
->
setText
(
i18n
(
"P4 Client failed with error code: %1"
,
exec
.
exitCode
()));
}
return
false
;
}
...
...
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