Skip to content

Commit

Permalink
Remove AsyncExecGitThread_ class and simplify submodule_add process
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jun 30, 2024
1 parent b828324 commit 913be40
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 104 deletions.
12 changes: 12 additions & 0 deletions src/GitProcessThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,15 @@ void GitCommandItem_add_tag::run()
g->tag(name_, commit_id_);
}


GitCommandItem_submodule_add::GitCommandItem_submodule_add(const QString &progress_message, Git::CloneData data, bool force)
: AbstractGitCommandItem(progress_message)
, data_(data)
, force_(force)
{
}

void GitCommandItem_submodule_add::run()
{
g->submodule_add(data_, force_, pty);
}
10 changes: 10 additions & 0 deletions src/GitProcessThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ class GitCommandItem_add_tag : public AbstractGitCommandItem {
void run() override;
};

class GitCommandItem_submodule_add : public AbstractGitCommandItem {
private:
Git::CloneData data_;
bool force_ = false;
public:
GitCommandItem_submodule_add(QString const &progress_message, Git::CloneData data, bool force);
void run() override;
};


class GitProcessRequest {
public:
typedef unsigned int request_id_t;
Expand Down
123 changes: 21 additions & 102 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,8 @@ struct EventItem {
}
};

class AsyncExecGitThread_ : public QThread {
private:
GitPtr g;
std::function<void(GitPtr g)> callback;
public:
AsyncExecGitThread_(GitPtr g, std::function<void(GitPtr g)> const &callback)
: g(g)
, callback(callback)
{
}
virtual ~AsyncExecGitThread_() override
{
}
protected:
void run() override
{
global->mainwindow->setLogEnabled(g, true);

callback(g);

global->mainwindow->setLogEnabled(g, false);
}
};

struct MainWindow::Private {

// MainWindowHelperThread helper;
// QThread helper_thread;

QIcon repository_icon;
QIcon folder_icon;
QIcon signature_good_icon;
Expand Down Expand Up @@ -323,8 +296,6 @@ MainWindow::MainWindow(QWidget *parent)

connect(ui->treeWidget_repos, &RepositoriesTreeWidget::dropped, this, &MainWindow::onRepositoriesTreeDropped);

// connect((AbstractPtyProcess *)getPtyProcess(), &AbstractPtyProcess::completed, this, &MainWindow::onPtyProcessCompleted);

connectPtyProcessCompleted();

// 右上のアイコンがクリックされたとき、ConfigUserダイアログを表示
Expand Down Expand Up @@ -761,11 +732,6 @@ void MainWindow::toggleMaximized()
setWindowState(state);
}

// void MainWindow::onGitProcessThreadDone(GitProcessRequest const &req)
// {
// req.done(req);
// }

void MainWindow::setStatusBarText(QString const &text)
{
m->status_bar_label->setText(text);
Expand Down Expand Up @@ -1949,48 +1915,28 @@ void MainWindow::submodule_add(QString url, QString const &local_dir)
if (local_dir.isEmpty()) return;

QString dir = local_dir;

while (1) {
SubmoduleAddDialog dlg(this, url, dir, &m->gcx);
if (dlg.exec() != QDialog::Accepted) {
return;
}
url = dlg.url();
dir = dlg.dir();
const QString ssh_key = dlg.overridedSshKey();

RepositoryData repos_item_data;
repos_item_data.local_dir = dir;
repos_item_data.local_dir.replace('\\', '/');
repos_item_data.name = makeRepositoryName(dir);
repos_item_data.ssh_key = ssh_key;

Git::CloneData data = Git::preclone(url, dir);
bool force = dlg.isForce();

GitPtr g = git(local_dir, {}, repos_item_data.ssh_key);

auto callback = [&](GitPtr g){
g->submodule_add(data, force, getPtyProcess());
};

{
OverrideWaitCursor;
{
setLogEnabled(g, true);
AsyncExecGitThread_ th(g, callback);
th.start();
while (1) {
if (th.wait(1)) break;
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
setLogEnabled(g, false);
}
internalOpenRepository(g, false, false);
}

return; // done

SubmoduleAddDialog dlg(this, url, dir, &m->gcx);
if (dlg.exec() != QDialog::Accepted) {
return;
}
url = dlg.url();
dir = dlg.dir();
const QString ssh_key = dlg.overridedSshKey();

RepositoryData repos_item_data;
repos_item_data.local_dir = dir;
repos_item_data.local_dir.replace('\\', '/');
repos_item_data.name = makeRepositoryName(dir);
repos_item_data.ssh_key = ssh_key;

Git::CloneData data = Git::preclone(url, dir);
bool force = dlg.isForce();

GitPtr g = git(local_dir, {}, repos_item_data.ssh_key);

std::shared_ptr<GitCommandItem_submodule_add> params = std::make_shared<GitCommandItem_submodule_add>(tr("Submodule..."), data, force);
runPtyGit(g, params, nullptr, {});
}

/**
Expand Down Expand Up @@ -2142,11 +2088,7 @@ void MainWindow::push(bool set_upstream, const QString &remote, const QString &b
}
}
updateRemoteInfo(git());
// updateCommitLog();
reopenRepository();

// fetch(git(), false);

}, {});
}

Expand Down Expand Up @@ -2828,13 +2770,6 @@ void MainWindow::clearDiffView()
clearDiffView(ui->frame_repository_wrapper);
}

// /**
// * @brief リポジトリ情報を消去
// */
// void MainWindow::clearRepositoryInfo()
// {
// }

void MainWindow::setRepositoryInfo(QString const &reponame, QString const &brname)
{
ui->label_repo_name->setText(reponame);
Expand Down Expand Up @@ -3324,21 +3259,6 @@ Git::CommitItemList *MainWindow::getCommitLogPtr(RepositoryWrapperFrame *frame)
return &frame->commit_log;
}

// const Git::CommitItemList &MainWindow::getCommitLog(RepositoryWrapperFrame const *frame) const
// {
// return frame->commit_log;
// }

// void MainWindow::setCommitLog(RepositoryWrapperFrame *frame, const Git::CommitItemList &logs)
// {
// frame->commit_log = logs;
// }

// void MainWindow::clearCommitLog(RepositoryWrapperFrame *frame)
// {
// frame->commit_log.clear();
// }

PtyProcess *MainWindow::getPtyProcess()
{
return &m->pty_process;
Expand Down Expand Up @@ -7436,7 +7356,6 @@ Terminal=false
#endif
}


void MainWindow::test()
{
}
Expand Down
1 change: 0 additions & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class MainWindow : public QMainWindow {
friend class FileDiffWidget;
friend class AboutDialog;
friend class RepositoriesTreeWidget; // TODO:
friend class AsyncExecGitThread_; //TODO:
friend class ExchangeData;
public:
enum {
Expand Down
1 change: 0 additions & 1 deletion src/RepositoriesTreeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ void RepositoriesTreeWidget::dropEvent(QDropEvent *event)
if (j > i) {
QString username = path.mid(i, j - i);
QString reponame = path.mid(j + 1);
// mainwindow()->postOpenRepositoryFromGitHub(username, reponame);
}
}
}
Expand Down

0 comments on commit 913be40

Please sign in to comment.