Wrapped "clone" "diff" "commit"

FossilOrigin-Name: 1207f87a560c9d077c00367a4270c693f7cceee0
This commit is contained in:
kostas
2015-04-26 18:55:05 +00:00
parent 895770b14b
commit a7e759e6a6
6 changed files with 117 additions and 13 deletions

View File

@ -121,6 +121,81 @@ bool Bridge::pullRepository()
return runFossil(QStringList() << "pull");
}
//------------------------------------------------------------------------------
bool Bridge::cloneRepository(const QString& repository, const QUrl& url, const QUrl& proxyUrl)
{
// Actual command
QStringList cmd = QStringList() << "clone";
// Log Command
QStringList logcmd = QStringList() << "fossil" << "clone";
QString source = url.toString();
QString logsource = url.toString(QUrl::RemovePassword);
if(url.isLocalFile())
{
source = url.toLocalFile();
logsource = source;
}
cmd << source << repository;
logcmd << logsource << repository;
if(!proxyUrl.isEmpty())
{
cmd << "--proxy" << proxyUrl.toString();
logcmd << "--proxy" << proxyUrl.toString(QUrl::RemovePassword);
}
log("<b>&gt;"+logcmd.join(" ")+"</b><br>", true);
// Clone Repo
if(!runFossil(cmd, 0, RUNFLAGS_SILENT_INPUT))
return false;
return true;
}
//------------------------------------------------------------------------------
bool Bridge::diffFile(const QString &repoFile)
{
// Run the diff detached
return runFossil(QStringList() << "gdiff" << QuotePath(repoFile), 0, RUNFLAGS_DETACHED);
}
//------------------------------------------------------------------------------
bool Bridge::commitFiles(const QStringList& fileList, const QString& comment)
{
// Do commit
QString comment_fname;
{
QTemporaryFile temp_file;
if(!temp_file.open())
return false;
comment_fname = temp_file.fileName();
}
QFile comment_file(comment_fname);
if(!comment_file.open(QIODevice::WriteOnly))
return false;
// Write BOM
comment_file.write(reinterpret_cast<const char *>(UTF8_BOM), sizeof(UTF8_BOM));
// Write Comment
comment_file.write(comment.toUtf8());
comment_file.close();
// Generate fossil parameters.
QStringList params;
params << "commit" << "--message-file" << QuotePath(comment_fname);
params << QuotePaths(fileList);
runFossil(params);
QFile::remove(comment_fname);
return true;
}
//------------------------------------------------------------------------------
bool Bridge::stashList(stashmap_t& stashes)
{

View File

@ -88,13 +88,18 @@ public:
bool closeRepository();
bool pushRepository();
bool pullRepository();
bool cloneRepository(const QString &repository, const QUrl &url, const QUrl &proxyUrl);
bool uiRunning() const;
bool startUI(const QString &httpPort);
void stopUI();
bool listFiles(QStringList& files);
bool listFiles(QStringList &files);
bool stashList(stashmap_t &stashes);
bool diffFile(const QString &repoFile);
bool commitFiles(const QStringList &fileList, const QString &comment);
private:
void log(const QString &text, bool isHTML=false)

View File

@ -524,6 +524,7 @@ void MainWindow::on_actionCloneRepository_triggered()
stopUI();
#ifndef BRIDGE_ENABLED
// Actual command
QStringList cmd = QStringList() << "clone";
@ -550,6 +551,9 @@ void MainWindow::on_actionCloneRepository_triggered()
// Clone Repo
if(!runFossil(cmd, 0, RUNFLAGS_SILENT_INPUT))
#else
if(!bridge.cloneRepository(repository, url, url_proxy))
#endif
{
QMessageBox::critical(this, tr("Error"), tr("Could not clone the repository"), QMessageBox::Ok);
return;
@ -1736,10 +1740,14 @@ void MainWindow::getStashViewSelection(QStringList &stashNames, bool allIfEmpty)
}
//------------------------------------------------------------------------------
bool MainWindow::diffFile(QString repoFile)
bool MainWindow::diffFile(const QString &repoFile)
{
#ifndef BRIDGE_ENABLED
// Run the diff detached
return runFossil(QStringList() << "gdiff" << QuotePath(repoFile), 0, RUNFLAGS_DETACHED);
#else
return bridge.diffFile(repoFile);
#endif
}
//------------------------------------------------------------------------------
@ -1956,6 +1964,7 @@ void MainWindow::on_actionCommit_triggered()
return;
// Do commit
#ifndef BRIDGE_ENABLED
QString comment_fname;
{
QTemporaryFile temp_file;
@ -1997,6 +2006,21 @@ void MainWindow::on_actionCommit_triggered()
runFossil(params);
QFile::remove(comment_fname);
#else
QStringList files;
// When a subset of files has been selected, explicitely specify each file.
// Otherwise all files will be implicitly committed by fossil. This is necessary
// when committing after a merge where fossil thinks that we are trying to do
// a partial commit which is not permitted.
QStringList all_modified_files;
getAllFilenames(all_modified_files, RepoFile::TYPE_MODIFIED);
if(commit_files.size() != all_modified_files.size())
files = commit_files;
bridge.commitFiles(files, msg);
#endif
refresh();
}

View File

@ -122,7 +122,7 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(Settings &_settings, QWidget *parent = 0, QString *workspacePath = 0);
~MainWindow();
bool diffFile(QString repoFile);
bool diffFile(const QString& repoFile);
void fullRefresh();
private: