Working Fuel-managed remote-url

No more FOSSIL_SETTING_REMOTE_URL uglyness


FossilOrigin-Name: 54518e5519ad4d5d478c815cc78859c9120997fe
This commit is contained in:
kostas
2015-05-25 19:59:37 +00:00
parent e6fa4062d0
commit b1276a7cd1
11 changed files with 272 additions and 133 deletions

View File

@@ -70,6 +70,10 @@ RepoStatus Fossil::getRepoStatus()
}
}
defaultRemoteUrl.clear();
if(run_ok)
getRemoteUrl(defaultRemoteUrl);
return run_ok ? REPO_OK : REPO_NOT_FOUND;
}
@@ -128,15 +132,51 @@ bool Fossil::status(QStringList &result)
}
//------------------------------------------------------------------------------
bool Fossil::pushRepository()
bool Fossil::pushRepository(const QUrl &url)
{
return runFossil(QStringList() << "push");
QStringList params;
params << "push";
int runFlags=RUNFLAGS_NONE;
if(!url.isEmpty())
{
params << url.toString();
params << "--once";
QStringList log_params = params;
log_params[1] = url.toDisplayString();
log_params.push_front("fossil");
runFlags = RUNFLAGS_SILENT_INPUT;
log("<b>&gt;"+log_params.join(" ")+"</b><br>", true);
}
return runFossil(params, 0, runFlags);
}
//------------------------------------------------------------------------------
bool Fossil::pullRepository()
bool Fossil::pullRepository(const QUrl &url)
{
return runFossil(QStringList() << "pull");
QStringList params;
params << "pull";
int runFlags=RUNFLAGS_NONE;
if(!url.isEmpty())
{
params << url.toString();
params << "--once";
QStringList log_params = params;
log_params[1] = url.toDisplayString();
log_params.push_front("fossil");
runFlags = RUNFLAGS_SILENT_INPUT;
log("<b>&gt;"+log_params.join(" ")+"</b><br>", true);
}
return runFossil(params, 0, runFlags);
}
//------------------------------------------------------------------------------
@@ -361,20 +401,25 @@ bool Fossil::setFossilSetting(const QString& name, const QString& value, bool gl
}
//------------------------------------------------------------------------------
bool Fossil::setRemoteUrl(const QString& url)
bool Fossil::setRemoteUrl(const QUrl& url)
{
QString u = url;
QString u = url.toString(QUrl::FullyEncoded);
if(url.isEmpty())
u = "off";
// Run as silent to avoid displaying credentials in the log
// FIXME: maybe use a QUrl instead
return runFossil(QStringList() << "remote-url" << u, 0, RUNFLAGS_SILENT_INPUT);
bool ok = runFossil(QStringList() << "remote-url" << u, 0, RUNFLAGS_SILENT_INPUT);
// Retrieve default url
if(ok)
getRemoteUrl(defaultRemoteUrl);
return ok;
}
//------------------------------------------------------------------------------
bool Fossil::getRemoteUrl(QString& url)
bool Fossil::getRemoteUrl(QUrl& url)
{
url.clear();
@@ -382,8 +427,15 @@ bool Fossil::getRemoteUrl(QString& url)
if(!runFossil(QStringList() << "remote-url", &out, RUNFLAGS_SILENT_ALL))
return false;
QString url_str;
if(out.length()>0)
url = out[0].trimmed();
url_str = out[0].trimmed();
if(url_str == "off")
url.clear();
else
url.setUrl(url_str);
return true;
}

View File

@@ -4,7 +4,7 @@
class QStringList;
#include <QString>
#include <QStringList>
#include <QObject>
#include <QUrl>
#include "LoggedProcess.h"
#include "Utils.h"
@@ -81,8 +81,8 @@ public:
bool openRepository(const QString &repositoryPath, const QString& workspacePath);
bool newRepository(const QString &repositoryPath);
bool closeRepository();
bool pushRepository();
bool pullRepository();
bool pushRepository(const QUrl& url);
bool pullRepository(const QUrl& url);
bool cloneRepository(const QString &repository, const QUrl &url, const QUrl &proxyUrl);
bool undoRepository(QStringList& result, bool explainOnly);
bool updateRepository(QStringList& result, const QString& revision, bool explainOnly);
@@ -103,8 +103,8 @@ public:
bool renameFile(const QString& beforePath, const QString& afterPath, bool renameLocal);
bool getFossilSettings(QStringList& result);
bool setFossilSetting(const QString &name, const QString &value, bool global);
bool setRemoteUrl(const QString &url);
bool getRemoteUrl(QString &url);
bool setRemoteUrl(const QUrl& url);
bool getRemoteUrl(QUrl &url);
bool stashNew(const QStringList& fileList, const QString& name, bool revert);
bool stashList(stashmap_t &stashes);
@@ -128,6 +128,8 @@ public:
const QString &getUIHttpPort() const { return fossilUIPort; }
QString getUIHttpAddress() const;
const QUrl &getDefaultRemoteUrl() const { return defaultRemoteUrl; }
private:
void log(const QString &text, bool isHTML=false)
{
@@ -144,6 +146,7 @@ private:
QString repositoryFile;
QString projectName;
QString currentRevision;
QUrl defaultRemoteUrl;
QStringList currentTags;
LoggedProcess fossilUI;
QString fossilUIPort;

View File

@@ -20,7 +20,6 @@ FslSettingsDialog::FslSettingsDialog(QWidget *parent, Settings &_settings) :
ui->lineProxy->setText(settings->GetFossilValue(FOSSIL_SETTING_PROXY_URL).toString());
// Repository Settings
ui->lineRemoteURL->setText(settings->GetFossilValue(FOSSIL_SETTING_REMOTE_URL).toString());
ui->lineIgnore->setText(settings->GetFossilValue(FOSSIL_SETTING_IGNORE_GLOB).toString());
ui->lineIgnoreCRNL->setText(settings->GetFossilValue(FOSSIL_SETTING_CRNL_GLOB).toString());
}
@@ -47,7 +46,6 @@ void FslSettingsDialog::on_buttonBox_accepted()
settings->SetFossilValue(FOSSIL_SETTING_GMERGE_CMD, ui->lineGMergeCommand->text());
settings->SetFossilValue(FOSSIL_SETTING_PROXY_URL, ui->lineProxy->text());
settings->SetFossilValue(FOSSIL_SETTING_REMOTE_URL, ui->lineRemoteURL->text());
settings->SetFossilValue(FOSSIL_SETTING_IGNORE_GLOB, ui->lineIgnore->text());
settings->SetFossilValue(FOSSIL_SETTING_CRNL_GLOB, ui->lineIgnoreCRNL->text());

View File

@@ -177,7 +177,12 @@ MainWindow::MainWindow(Settings &_settings, QWidget *parent, QString *workspaceP
// RemotesMenu
menuRemotes = new QMenu(this);
menuRemotes->addAction(ui->actionPushRemote);
menuRemotes->addAction(ui->actionPullRemote);
menuRemotes->addAction(separator);
menuRemotes->addAction(ui->actionAddRemote);
menuRemotes->addAction(ui->actionEditRemote);
menuRemotes->addAction(ui->actionSetDefaultRemote);
// Recent Workspaces
// Locate a sequence of two separator actions in file menu
@@ -212,7 +217,6 @@ MainWindow::MainWindow(Settings &_settings, QWidget *parent, QString *workspaceP
ui->statusBar->insertPermanentWidget(1, lblTags);
lblTags->setVisible(true);
// Construct ProgressBar
progressBar = new QProgressBar();
progressBar->setMinimum(0);
@@ -249,7 +253,6 @@ MainWindow::MainWindow(Settings &_settings, QWidget *parent, QString *workspaceP
searchShortcut->setEnabled(true);
connect(searchShortcut, SIGNAL(activated()), this, SLOT(onSearch()));
// Create SearchBox
searchBox = new SearchBox(this);
searchBox->setPlaceholderText(tr("Find (%0)").arg(searchShortcut->key().toString()));
@@ -778,7 +781,6 @@ void MainWindow::updateWorkspaceView()
{
const QString &tag_name = it.key();
QStandardItem *tag = new QStandardItem(getInternalIcon(":icons/icon-item-tag"), tag_name);
tag->setData(WorkspaceItem(WorkspaceItem::TYPE_TAG, tag_name), ROLE_WORKSPACE_ITEM);
@@ -805,21 +807,22 @@ void MainWindow::updateWorkspaceView()
stashes->appendRow(stash);
}
#if 1
// Remotes
QStandardItem *remotes = new QStandardItem(getInternalIcon(":icons/icon-item-remote"), tr("Remotes"));
remotes->setData(WorkspaceItem(WorkspaceItem::TYPE_REMOTES, ""), ROLE_WORKSPACE_ITEM);
remotes->setEditable(false);
getWorkspace().getTreeModel().appendRow(remotes);
{
QStandardItem *default_url = new QStandardItem(getInternalIcon(":icons/icon-item-remote"), tr("Default"));
QString url = settings.GetFossilValue(FOSSIL_SETTING_REMOTE_URL).toString();
default_url->setData(WorkspaceItem(WorkspaceItem::TYPE_REMOTE, url), ROLE_WORKSPACE_ITEM);
remotes->appendRow(default_url);
QUrl default_url = fossil().getDefaultRemoteUrl();
if(!default_url.isEmpty())
{
QUrl url = default_url;
QStandardItem *remote_item = new QStandardItem(getInternalIcon(":icons/icon-item-remote"), url.toDisplayString());
remote_item->setData(WorkspaceItem(WorkspaceItem::TYPE_REMOTE, default_url.toString()), ROLE_WORKSPACE_ITEM);
remotes->appendRow(remote_item);
}
}
#endif
// Expand previously selected nodes
name_map.clear();
BuildNameToModelIndex(name_map, getWorkspace().getTreeModel());
@@ -1353,34 +1356,6 @@ void MainWindow::on_actionOpenFile_triggered()
}
}
//------------------------------------------------------------------------------
void MainWindow::on_actionPush_triggered()
{
QString remote_url = settings.GetFossilValue(FOSSIL_SETTING_REMOTE_URL).toString();
if(remote_url.isEmpty() || remote_url == "off")
{
QMessageBox::critical(this, tr("Error"), tr("A remote repository has not been specified.\nUse the preferences window to set the remote repostory location"), QMessageBox::Ok );
return;
}
fossil().pushRepository();
}
//------------------------------------------------------------------------------
void MainWindow::on_actionPull_triggered()
{
QString remote_url = settings.GetFossilValue(FOSSIL_SETTING_REMOTE_URL).toString();
if(remote_url.isEmpty() || remote_url == "off")
{
QMessageBox::critical(this, tr("Error"), tr("A remote repository has not been specified.\nUse the preferences window to set the remote repostory location"), QMessageBox::Ok );
return;
}
fossil().pullRepository();
}
//------------------------------------------------------------------------------
void MainWindow::on_actionCommit_triggered()
{
@@ -1629,17 +1604,6 @@ void MainWindow::loadFossilSettings()
const QString &name = it.key();
Settings::Setting::SettingType type = it->Type;
// Command types we issue directly on fossil
if(name == FOSSIL_SETTING_REMOTE_URL)
{
// Retrieve existing url
QString url;
if(fossil().getRemoteUrl(url))
it.value().Value = url;
continue;
}
Q_ASSERT(type == Settings::Setting::TYPE_FOSSIL_GLOBAL || type == Settings::Setting::TYPE_FOSSIL_LOCAL);
// Otherwise it must be a fossil setting
@@ -1685,15 +1649,6 @@ void MainWindow::on_actionFossilSettings_triggered()
const QString &name = it.key();
Settings::Setting::SettingType type = it.value().Type;
// Command types we issue directly on fossil
// FIXME: major uglyness with settings management
if(name == FOSSIL_SETTING_REMOTE_URL)
{
// Run as silent to avoid displaying credentials in the log
fossil().setRemoteUrl(it.value().Value.toString());
continue;
}
Q_ASSERT(type == Settings::Setting::TYPE_FOSSIL_GLOBAL || type == Settings::Setting::TYPE_FOSSIL_LOCAL);
QString value = it.value().Value.toString();
@@ -2208,7 +2163,7 @@ void MainWindow::on_workspaceTreeView_customContextMenuRequested(const QPoint &)
menu = menuTags;
else if (tv.Type == WorkspaceItem::TYPE_BRANCH || tv.Type == WorkspaceItem::TYPE_BRANCHES)
menu = menuBranches;
else if (tv.Type == WorkspaceItem::TYPE_REMOTE)
else if (tv.Type == WorkspaceItem::TYPE_REMOTE || tv.Type == WorkspaceItem::TYPE_REMOTES)
menu = menuRemotes;
if(menu)
@@ -2514,9 +2469,120 @@ void MainWindow::on_actionEditRemote_triggered()
if(!RemoteDialog::run(this, url))
return;
if(exists)
if(!url.isLocalFile())
{
if(exists)
KeychainDelete(this, url);
if(!KeychainSet(this, url))
QMessageBox::critical(this, tr("Error"), tr("Could not store information to keychain."), QMessageBox::Ok );
}
}
//------------------------------------------------------------------------------
void MainWindow::on_actionPushRemote_triggered()
{
QStringList remotes;
getSelectionRemotes(remotes);
if(remotes.empty())
return;
QUrl url(remotes.first());
// Retrieve password from keychain
if(!url.isLocalFile())
KeychainGet(this, url);
fossil().pushRepository(url);
}
//------------------------------------------------------------------------------
void MainWindow::on_actionPullRemote_triggered()
{
QStringList remotes;
getSelectionRemotes(remotes);
if(remotes.empty())
return;
QUrl url(remotes.first());
// Retrieve password from keychain
if(!url.isLocalFile())
KeychainGet(this, url);
fossil().pullRepository(url);
}
//------------------------------------------------------------------------------
void MainWindow::on_actionPush_triggered()
{
QUrl url = fossil().getDefaultRemoteUrl();
if(url.isEmpty())
{
QMessageBox::critical(this, tr("Error"), tr("A default remote repository has not been specified."), QMessageBox::Ok );
return;
}
// Retrieve password from keychain
if(!url.isLocalFile())
KeychainGet(this, url);
fossil().pushRepository(url);
}
//------------------------------------------------------------------------------
void MainWindow::on_actionPull_triggered()
{
QUrl url = fossil().getDefaultRemoteUrl();
if(url.isEmpty())
{
QMessageBox::critical(this, tr("Error"), tr("A default remote repository has not been specified."), QMessageBox::Ok );
return;
}
// Retrieve password from keychain
if(!url.isLocalFile())
KeychainGet(this, url);
fossil().pullRepository(url);
}
//------------------------------------------------------------------------------
void MainWindow::on_actionSetDefaultRemote_triggered()
{
QStringList remotes;
getSelectionRemotes(remotes);
if(remotes.empty())
return;
QUrl url(remotes.first());
// Retrieve password from keychain
if(!url.isLocalFile())
KeychainGet(this, url);
fossil().setRemoteUrl(url);
updateWorkspaceView();
}
//------------------------------------------------------------------------------
void MainWindow::on_actionAddRemote_triggered()
{
QUrl url;
if(!RemoteDialog::run(this, url))
return;
if(!url.isLocalFile())
{
KeychainDelete(this, url);
if(!KeychainSet(this, url))
QMessageBox::critical(this, tr("Error"), tr("Could not store information to keychain."), QMessageBox::Ok );
if(!KeychainSet(this, url))
QMessageBox::critical(this, tr("Error"), tr("Could not store information to keychain."), QMessageBox::Ok );
}
fossil().setRemoteUrl(url);
updateWorkspaceView();
}

View File

@@ -90,6 +90,8 @@ private slots:
void on_actionOpenFile_triggered();
void on_actionPush_triggered();
void on_actionPull_triggered();
void on_actionPushRemote_triggered();
void on_actionPullRemote_triggered();
void on_actionCommit_triggered();
void on_actionAdd_triggered();
void on_actionDelete_triggered();
@@ -126,6 +128,8 @@ private slots:
void on_actionCreateBranch_triggered();
void on_actionMergeBranch_triggered();
void on_actionEditRemote_triggered();
void on_actionSetDefaultRemote_triggered();
void on_actionAddRemote_triggered();
private:
class MainWinUICallback : public UICallback

View File

@@ -17,7 +17,6 @@ Settings::Settings(bool portableMode) : store(0)
Mappings.insert(FOSSIL_SETTING_IGNORE_GLOB, Setting("", Setting::TYPE_FOSSIL_LOCAL));
Mappings.insert(FOSSIL_SETTING_CRNL_GLOB, Setting("", Setting::TYPE_FOSSIL_LOCAL));
Mappings.insert(FOSSIL_SETTING_REMOTE_URL, Setting("off", Setting::TYPE_FOSSIL_COMMAND));
// Go into portable mode when explicitly requested or if a config file exists next to the executable
QString ini_path = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QDir::separator() + QCoreApplication::applicationName() + ".ini");

View File

@@ -16,7 +16,6 @@
#define FOSSIL_SETTING_PROXY_URL "proxy"
#define FOSSIL_SETTING_IGNORE_GLOB "ignore-glob"
#define FOSSIL_SETTING_CRNL_GLOB "crnl-glob"
#define FOSSIL_SETTING_REMOTE_URL "remote-url"
#define FOSSIL_SETTING_HTTP_PORT "http-port"