MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / handleParseFileDatas

Method handleParseFileDatas

src/plugins/git/utils/diffutils.cpp:183–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183void GitDiffWorker::handleParseFileDatas(const QList<FileData> &dataList, const QFont &font)
184{
185 isStop = false;
186 const DiffEditorInput input(dataList, font);
187 const SideBySideDiffOutput output = diffOutput(input);
188 if (isStop) {
189 Q_EMIT parseFileDatasFinished(false);
190 return;
191 }
192
193 const SideBySideShowResult leftResult { QSharedPointer<QTextDocument>(new QTextDocument()),
194 output.side[LeftSide].diffData, output.side[LeftSide].selections };
195 const SideBySideShowResult rightResult { QSharedPointer<QTextDocument>(new QTextDocument()),
196 output.side[RightSide].diffData, output.side[RightSide].selections };
197 const SideBySideShowResults result { leftResult, rightResult };
198
199 auto propagateDocument = [&output, this](DiffSide side, const SideBySideShowResult &result) {
200 // No need to store the change history
201 result.textDocument->setUndoRedoEnabled(false);
202
203 // We could do just:
204 // result.textDocument->setPlainText(output.diffText);
205 // but this would freeze the thread for couple of seconds without progress reporting
206 // and without checking for canceled.
207 const int diffSize = output.side[side].diffText.size();
208 const int packageSize = 10000;
209 int currentPos = 0;
210 QTextCursor cursor(result.textDocument.data());
211 while (currentPos < diffSize) {
212 const QString package = output.side[side].diffText.mid(currentPos, packageSize);
213 cursor.insertText(package);
214 currentPos += package.size();
215 if (isStop) {
216 Q_EMIT parseFileDatasFinished(false);
217 return;
218 }
219 }
220
221 // If future was canceled, the destructor runs in this thread, so we can't move it
222 // to caller's thread. We push it to no thread (make object to have no thread affinity),
223 // and later, in the caller's thread, we pull it back to the caller's thread.
224 result.textDocument->moveToThread(nullptr);
225 };
226
227 propagateDocument(LeftSide, leftResult);
228 if (isStop) {
229 Q_EMIT parseFileDatasFinished(false);
230 return;
231 }
232
233 propagateDocument(RightSide, rightResult);
234 if (isStop) {
235 Q_EMIT parseFileDatasFinished(false);
236 return;
237 }
238
239 showResults = result;
240 Q_EMIT parseFileDatasFinished(true);

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.45
dataMethod · 0.45
insertTextMethod · 0.45

Tested by

no test coverage detected