diff --git a/plugins/fossil/fossilclient.cpp b/plugins/fossil/fossilclient.cpp index 16385c56360..a2817d0047a 100644 --- a/plugins/fossil/fossilclient.cpp +++ b/plugins/fossil/fossilclient.cpp @@ -711,11 +711,15 @@ bool FossilClient::synchronousMove(const QString &workingDir, bool FossilClient::synchronousPull(const QString &workingDir, const QString &srcLocation, const QStringList &extraOptions) { - const QString remoteLocation = (!srcLocation.isEmpty() ? srcLocation : synchronousGetRepositoryURL(workingDir)); - if (remoteLocation.isEmpty()) - return false; + QStringList args(vcsCommandString(PullCommand)); + if (srcLocation.isEmpty()) { + const QString defaultURL(synchronousGetRepositoryURL(workingDir)); + if (defaultURL.isEmpty()) + return false; + } else { + args << srcLocation; + } - QStringList args({vcsCommandString(PullCommand), remoteLocation}); args << extraOptions; // Disable UNIX terminals to suppress SSH prompting const unsigned flags = @@ -731,11 +735,15 @@ bool FossilClient::synchronousPull(const QString &workingDir, const QString &src bool FossilClient::synchronousPush(const QString &workingDir, const QString &dstLocation, const QStringList &extraOptions) { - const QString remoteLocation = (!dstLocation.isEmpty() ? dstLocation : synchronousGetRepositoryURL(workingDir)); - if (remoteLocation.isEmpty()) - return false; + QStringList args(vcsCommandString(PushCommand)); + if (dstLocation.isEmpty()) { + const QString defaultURL(synchronousGetRepositoryURL(workingDir)); + if (defaultURL.isEmpty()) + return false; + } else { + args << dstLocation; + } - QStringList args({vcsCommandString(PushCommand), remoteLocation}); args << extraOptions; // Disable UNIX terminals to suppress SSH prompting const unsigned flags = diff --git a/plugins/fossil/fossilplugin.cpp b/plugins/fossil/fossilplugin.cpp index 88d93ca898b..a83d547f713 100644 --- a/plugins/fossil/fossilplugin.cpp +++ b/plugins/fossil/fossilplugin.cpp @@ -139,6 +139,11 @@ class FossilPluginPrivate final : public VcsBase::VcsBasePluginPrivate Q_DECLARE_TR_FUNCTIONS(Fossil::Internal::FossilPlugin) public: + enum SyncMode { + SyncPull, + SyncPush + }; + FossilPluginPrivate(); // IVersionControl @@ -184,8 +189,8 @@ public: void statusMulti(); // Repository menu action slots - void pull(); - void push(); + void pull() { pullOrPush(SyncPull); } + void push() { pullOrPush(SyncPush); } void update(); void configureRepository(); void commit(); @@ -201,6 +206,7 @@ public: void createRepositoryActions(const Core::Context &context); void describe(const QString &source, const QString &id) { m_client.view(source, id); }; + bool pullOrPush(SyncMode mode); // Variables FossilSettings m_fossilSettings; @@ -591,60 +597,51 @@ void FossilPluginPrivate::createRepositoryActions(const Core::Context &context) m_fossilContainer->addAction(command); } -void FossilPluginPrivate::pull() +bool FossilPluginPrivate::pullOrPush(FossilPluginPrivate::SyncMode mode) { - const VcsBase::VcsBasePluginState state = currentState(); - QTC_ASSERT(state.hasTopLevel(), return); + PullOrPushDialog::Mode pullOrPushMode; + switch (mode) { + case SyncPull: + pullOrPushMode = PullOrPushDialog::PullMode; + break; + case SyncPush: + pullOrPushMode = PullOrPushDialog::PushMode; + break; + default: + return false; + } - PullOrPushDialog dialog(PullOrPushDialog::PullMode, Core::ICore::dialogParent()); + const VcsBase::VcsBasePluginState state = currentState(); + QTC_ASSERT(state.hasTopLevel(), return false); + + PullOrPushDialog dialog(pullOrPushMode, Core::ICore::dialogParent()); dialog.setLocalBaseDirectory(m_client.settings().stringValue(FossilSettings::defaultRepoPathKey)); - dialog.setDefaultRemoteLocation(m_client.synchronousGetRepositoryURL(state.topLevel())); + const QString defaultURL(m_client.synchronousGetRepositoryURL(state.topLevel())); + dialog.setDefaultRemoteLocation(defaultURL); if (dialog.exec() != QDialog::Accepted) - return; + return true; QString remoteLocation(dialog.remoteLocation()); - if (remoteLocation.isEmpty()) - remoteLocation = m_client.synchronousGetRepositoryURL(state.topLevel()); - - if (remoteLocation.isEmpty()) { + if (remoteLocation.isEmpty() && defaultURL.isEmpty()) { VcsBase::VcsOutputWindow::appendError(tr("Remote repository is not defined.")); - return; + return false; + } else if (remoteLocation == defaultURL) { + remoteLocation.clear(); } QStringList extraOptions; - if (!dialog.isRememberOptionEnabled()) + if (!remoteLocation.isEmpty() && !dialog.isRememberOptionEnabled()) extraOptions << "--once"; if (dialog.isPrivateOptionEnabled()) extraOptions << "--private"; - m_client.synchronousPull(state.topLevel(), remoteLocation, extraOptions); -} - -void FossilPluginPrivate::push() -{ - const VcsBase::VcsBasePluginState state = currentState(); - QTC_ASSERT(state.hasTopLevel(), return); - - PullOrPushDialog dialog(PullOrPushDialog::PushMode, Core::ICore::dialogParent()); - dialog.setLocalBaseDirectory(m_client.settings().stringValue(FossilSettings::defaultRepoPathKey)); - dialog.setDefaultRemoteLocation(m_client.synchronousGetRepositoryURL(state.topLevel())); - if (dialog.exec() != QDialog::Accepted) - return; - - QString remoteLocation(dialog.remoteLocation()); - if (remoteLocation.isEmpty()) - remoteLocation = m_client.synchronousGetRepositoryURL(state.topLevel()); - - if (remoteLocation.isEmpty()) { - VcsBase::VcsOutputWindow::appendError(tr("Remote repository is not defined.")); - return; + switch (mode) { + case SyncPull: + return m_client.synchronousPull(state.topLevel(), remoteLocation, extraOptions); + case SyncPush: + return m_client.synchronousPush(state.topLevel(), remoteLocation, extraOptions); + default: + return false; } - - QStringList extraOptions; - if (!dialog.isRememberOptionEnabled()) - extraOptions << "--once"; - if (dialog.isPrivateOptionEnabled()) - extraOptions << "--private"; - m_client.synchronousPush(state.topLevel(), remoteLocation, extraOptions); } void FossilPluginPrivate::update()