Skip to content

Commit

Permalink
Improves fetch process by utilizing a dedicated function object for t…
Browse files Browse the repository at this point in the history
…hread parameters
  • Loading branch information
soramimi committed Jun 22, 2024
1 parent 8564b14 commit 6ebf823
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ MainWindow::MainWindow(QWidget *parent)
, m(new Private)
{
ui->setupUi(this);
ui->frame_progress->setVisible(false);

setupShowFileListHandler();
setupProgressHandler();
setupAddFileObjectData();

setUnknownRepositoryInfo();
hideProgress();

ui->frame_repository_wrapper->bind(this
, ui->tableWidget_log
Expand Down Expand Up @@ -3228,23 +3228,32 @@ bool MainWindow::fetch(GitPtr g, bool prune)
{
bool ret = false;

std::thread th([&](GitPtr g, bool prune){
struct FetchParams {
PtyProcess *pty = nullptr;
GitPtr g;
bool prune;
};
FetchParams params;
params.g = g;
params.prune = prune;

auto Func = [&](FetchParams params){
params.g->fetch(params.pty, params.prune);
};

std::thread th([&](FetchParams params){
setProgress(-1.0f);
showProgress(tr("Fetching..."), false);
setPtyCondition(PtyCondition::Fetch);
setPtyProcessOk(true);
PtyProcess *pty = getPtyProcess();
// std::thread th2([this, g, prune, pty](){
g->fetch(pty, prune);
// });
while (1) {
if (pty->wait(1)) break;
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
// th2.join();
params.pty = getPtyProcess();

Func(params);

while (!params.pty->wait(1));
ret = getPtyProcessOk();
hideProgress();
}, g, prune);
}, params);

th.join();
return ret;
Expand Down
3 changes: 2 additions & 1 deletion src/win32/Win32PtyProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ void Win32PtyProcess::start(QString const &cmdline, QString const &env, QVariant

bool Win32PtyProcess::wait(unsigned long time)
{
return QThread::wait(time) && m->th_output_reader.wait(time);
std::this_thread::sleep_for(std::chrono::milliseconds(time));
return m->th_output_reader.wait(time);
}

void Win32PtyProcess::stop()
Expand Down

0 comments on commit 6ebf823

Please sign in to comment.