Skip to content

Commit

Permalink
Implement GitCommandItem_push class for handling 'push' operations
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jun 29, 2024
1 parent d6291b1 commit 491d1a0
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 56 deletions.
17 changes: 17 additions & 0 deletions src/GitProcessThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ void GitCommandItem_fetch_tags_f::run()

//

GitCommandItem_push::GitCommandItem_push(const QString &progress_message, bool set_upstream, QString const &remote, QString const &branch, bool force)
: AbstractGitCommandItem(progress_message)
, set_upstream_(set_upstream)
, remote_(remote)
, branch_(branch)
, force_(force)
{
}

void GitCommandItem_push::run()
{
g->push_u(set_upstream_, remote_, branch_, force_, pty);
}

//

GitCommandItem_pull::GitCommandItem_pull(const QString &progress_message)
: AbstractGitCommandItem(progress_message)
{
Expand Down Expand Up @@ -189,3 +205,4 @@ void GitCommandItem_add_tag::run()
{
g->tag(name_, commit_id_);
}

17 changes: 16 additions & 1 deletion src/GitProcessThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AbstractGitCommandItem {
PtyProcess *pty = nullptr;
QString progress_message;
bool update_commit_log = false;
std::function<void ()> done;
std::vector<std::function<void (AbstractGitCommandItem const *)>> done;
bool reopen_repository = true;
AbstractGitCommandItem(QString const &progress_message)
: progress_message(progress_message)
Expand All @@ -38,6 +38,21 @@ class GitCommandItem_fetch_tags_f : public AbstractGitCommandItem {
void run() override;
};

class GitCommandItem_push : public AbstractGitCommandItem {
private:
bool set_upstream_ = false;
QString remote_;
QString branch_;
bool force_ = false;
private:
friend class MainWindow;
int exitcode_ = 0;
QString errormsg_;
public:
GitCommandItem_push(QString const &progress_message, bool set_upstream, QString const &remote, QString const &branch, bool force);
void run() override;
};

class GitCommandItem_pull : public AbstractGitCommandItem {
public:
GitCommandItem_pull(QString const &progress_message);
Expand Down
104 changes: 58 additions & 46 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ void MainWindow::push(bool set_upstream, const QString &remote, const QString &b
if (branch.isEmpty()) return;
}

#if 0
int exitcode = 0;
QString errormsg;

Expand All @@ -2157,6 +2158,59 @@ void MainWindow::push(bool set_upstream, const QString &remote, const QString &b

updateRemoteInfo(git());
updateCommitLog();
#else
std::shared_ptr<GitCommandItem_push> params = std::make_shared<GitCommandItem_push>(tr("Pushing..."), set_upstream, remote, branch, force);
params->done.push_back([&](AbstractGitCommandItem const *p){
ASSERT_MAIN_THREAD();
GitCommandItem_push const *cmd = static_cast<GitCommandItem_push const *>(p);
if (cmd->exitcode_ == 128) {
if (cmd->errormsg_.indexOf("Connection refused") >= 0) {
QMessageBox::critical(this, qApp->applicationName(), tr("Connection refused."));
return;
}
}
updateRemoteInfo(git());
updateCommitLog();
});
runPtyGit(git(), params);

#endif
}

bool MainWindow::fetch(GitPtr g, bool prune)
{
std::shared_ptr<GitCommandItem_fetch> params = std::make_shared<GitCommandItem_fetch>(tr("Fetching..."), prune);
return runPtyGit(g, params);
}

bool MainWindow::fetch_tags_f(GitPtr g)
{
std::shared_ptr<GitCommandItem_fetch_tags_f> params = std::make_shared<GitCommandItem_fetch_tags_f>(tr("Fetching tags..."));
return runPtyGit(g, params);
}

bool MainWindow::pull(GitPtr g)
{
std::shared_ptr<GitCommandItem_pull> params = std::make_shared<GitCommandItem_pull>(tr("Pulling..."));
return runPtyGit(g, params);
}

bool MainWindow::push_tags(GitPtr g)
{
std::shared_ptr<GitCommandItem_push_tags> params = std::make_shared<GitCommandItem_push_tags>(tr("Pushing tags..."));
return runPtyGit(g, params);
}

bool MainWindow::delete_tags(GitPtr g, const QStringList &tagnames)
{
std::shared_ptr<GitCommandItem_delete_tags> params = std::make_shared<GitCommandItem_delete_tags>(tagnames);
return runPtyGit(g, params);
}

bool MainWindow::add_tag(GitPtr g, const QString &name, Git::CommitID const &commit_id)
{
std::shared_ptr<GitCommandItem_add_tag> params = std::make_shared<GitCommandItem_add_tag>(name, commit_id);
return runPtyGit(g, params);
}

/**
Expand Down Expand Up @@ -3344,22 +3398,16 @@ bool MainWindow::runPtyGit(GitPtr g, std::shared_ptr<AbstractGitCommandItem> par
req.done = [this](GitProcessRequest const &req){
ASSERT_MAIN_THREAD();

if (req.params->done) {
req.params->done();
}

getPtyProcessOk();
if (req.params->update_commit_log) {
openRepositoryMain(frame(), git(), false, false, false, true);
for (auto done : req.params->done) {
done(req.params.get());
}

hideProgress();

if (req.params->reopen_repository) {
QElapsedTimer t;
t.start();
internalOpenRepository(git());
qDebug() << "reopen repository:" << t.elapsed() << "ms";
} else if (req.params->update_commit_log) {
openRepositoryMain(frame(), git(), false, false, false, true);
}

QApplication::restoreOverrideCursor();
Expand All @@ -3372,42 +3420,6 @@ bool MainWindow::runPtyGit(GitPtr g, std::shared_ptr<AbstractGitCommandItem> par
return ret;
}

bool MainWindow::fetch(GitPtr g, bool prune)
{
std::shared_ptr<GitCommandItem_fetch> params = std::make_shared<GitCommandItem_fetch>(tr("Fetching..."), prune);
return runPtyGit(g, params);
}

bool MainWindow::fetch_tags_f(GitPtr g)
{
std::shared_ptr<GitCommandItem_fetch_tags_f> params = std::make_shared<GitCommandItem_fetch_tags_f>(tr("Fetching tags..."));
return runPtyGit(g, params);
}

bool MainWindow::pull(GitPtr g)
{
std::shared_ptr<GitCommandItem_pull> params = std::make_shared<GitCommandItem_pull>(tr("Pulling..."));
return runPtyGit(g, params);
}

bool MainWindow::push_tags(GitPtr g)
{
std::shared_ptr<GitCommandItem_push_tags> params = std::make_shared<GitCommandItem_push_tags>(tr("Pushing tags..."));
return runPtyGit(g, params);
}

bool MainWindow::delete_tags(GitPtr g, const QStringList &tagnames)
{
std::shared_ptr<GitCommandItem_delete_tags> params = std::make_shared<GitCommandItem_delete_tags>(tagnames);
return runPtyGit(g, params);
}

bool MainWindow::add_tag(GitPtr g, const QString &name, Git::CommitID const &commit_id)
{
std::shared_ptr<GitCommandItem_add_tag> params = std::make_shared<GitCommandItem_add_tag>(name, commit_id);
return runPtyGit(g, params);
}

bool MainWindow::interactionCanceled() const
{
return m->interaction_canceled;
Expand Down
18 changes: 9 additions & 9 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,17 @@ class MainWindow : public QMainWindow {
Git::CommitItem selectedCommitItem(RepositoryWrapperFrame *frame) const;
void commit(RepositoryWrapperFrame *frame, bool amend = false);
void commitAmend(RepositoryWrapperFrame *frame);

void push(bool set_upstream, const QString &remote, const QString &branch, bool force);
bool fetch(GitPtr g, bool prune);
bool fetch_tags_f(GitPtr g);
bool pull(GitPtr g);
bool push_tags(GitPtr g);
bool delete_tags(GitPtr g, const QStringList &tagnames);
bool add_tag(GitPtr g, const QString &name, Git::CommitID const &commit_id);

bool push();

void deleteBranch(RepositoryWrapperFrame *frame, const Git::CommitItem &commit);
void deleteSelectedBranch(RepositoryWrapperFrame *frame);
void resetFile(const QStringList &paths);
Expand Down Expand Up @@ -333,15 +342,6 @@ class MainWindow : public QMainWindow {
PtyCondition getPtyCondition();
void setPtyUserData(const QVariant &userdata);
void setPtyProcessOk(bool pty_process_ok);

bool fetch(GitPtr g, bool prune);
bool fetch_tags_f(GitPtr g);
bool pull(GitPtr g);
bool push_tags(GitPtr g);
bool delete_tags(GitPtr g, const QStringList &tagnames);
bool add_tag(GitPtr g, const QString &name, Git::CommitID const &commit_id);


void setPtyCondition(const PtyCondition &ptyCondition);
const QList<RepositoryData> &cRepositories() const;
QList<RepositoryData> *pRepositories();
Expand Down

0 comments on commit 491d1a0

Please sign in to comment.