mirror of
				https://github.com/QRouland/UTPass.git
				synced 2025-11-03 17:56:30 +00:00 
			
		
		
		
	Harmonize naming
This commit is contained in:
		@@ -9,7 +9,7 @@
 | 
			
		||||
#include "utils.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QDir Git::clone_setup()
 | 
			
		||||
QDir Git::cloneSetup()
 | 
			
		||||
{
 | 
			
		||||
    QDir tmp_dir(QStandardPaths::writableLocation( QStandardPaths::CacheLocation).append("/clone"));
 | 
			
		||||
 | 
			
		||||
@@ -20,12 +20,12 @@ QDir Git::clone_setup()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool Git::clone_tear_down(QDir tmp_dir)
 | 
			
		||||
bool Git::cloneTearDown(QDir tmp_dir)
 | 
			
		||||
{
 | 
			
		||||
    return tmp_dir.removeRecursively();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Git::move_to_destination(QString path, QDir tmp_dir)
 | 
			
		||||
bool Git::moveToDestination(QString path, QDir tmp_dir)
 | 
			
		||||
{
 | 
			
		||||
    qDebug() << "Removing password_store " << path;
 | 
			
		||||
    QDir destination_dir(path);
 | 
			
		||||
@@ -37,42 +37,40 @@ bool Git::move_to_destination(QString path, QDir tmp_dir)
 | 
			
		||||
    return dir.rename(tmp_dir.absolutePath(), destination_dir.absolutePath()); // TODO Better error handling
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool Git::clone(QString url, QString path, mode_type mode) //, GitPlugin::RepoType type, QString pass)
 | 
			
		||||
{
 | 
			
		||||
    auto v =  overload {
 | 
			
		||||
        [](const Unset & x)  { return "Unset"; },
 | 
			
		||||
        [](const HTTP & x)   { return "Unset"; },
 | 
			
		||||
        [](const HTTP & x)   { return "HTTP"; },
 | 
			
		||||
        [](const HTTPAuth & x)   { return "HTTPAuth"; },
 | 
			
		||||
        [](const SSHAuth & x)   { return "SSHAuth"; },
 | 
			
		||||
        [](const SSHKey & x)   { return "SSHKey"; },
 | 
			
		||||
    };
 | 
			
		||||
    qInfo() << "Cloning " << url << " to destination " << path << " using " << std::visit(v, mode);
 | 
			
		||||
 | 
			
		||||
    LibGit::instance()->set_mode(mode);
 | 
			
		||||
    auto tmp_dir = this->clone_setup();
 | 
			
		||||
    LibGit::instance()->setMode(mode);
 | 
			
		||||
    auto tmp_dir = this->cloneSetup();
 | 
			
		||||
 | 
			
		||||
    qDebug() << "Cloning " << url << " to tmp dir " << tmp_dir.absolutePath();
 | 
			
		||||
    auto ret = LibGit::instance()->clone(url, tmp_dir.absolutePath()); // TODO Better error handling
 | 
			
		||||
 | 
			
		||||
    if (ret) {
 | 
			
		||||
        this->move_to_destination(path, tmp_dir);
 | 
			
		||||
        this->moveToDestination(path, tmp_dir);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this->clone_tear_down(tmp_dir);
 | 
			
		||||
    LibGit::instance()->set_mode(Unset());
 | 
			
		||||
    this->cloneTearDown(tmp_dir);
 | 
			
		||||
    LibGit::instance()->setMode(Unset());
 | 
			
		||||
 | 
			
		||||
    return ret ;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Git::clone_http(QString url, QString path) //, GitPlugin::RepoType type, QString pass)
 | 
			
		||||
bool Git::cloneHttp(QString url, QString path)
 | 
			
		||||
{
 | 
			
		||||
    HTTP mode = {};
 | 
			
		||||
    return this->clone(url, path, mode);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Git::clone_http_pass(QString url, QString path, QString pass)
 | 
			
		||||
bool Git::cloneHttpPass(QString url, QString path, QString pass)
 | 
			
		||||
{
 | 
			
		||||
    HTTPAuth mode = { pass };
 | 
			
		||||
    return this->clone(url, path, mode);
 | 
			
		||||
 
 | 
			
		||||
@@ -7,14 +7,17 @@
 | 
			
		||||
 | 
			
		||||
#include "libgit.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief The Git class is class that provide Git functionnly to clone and update a repo.
 | 
			
		||||
 */
 | 
			
		||||
class Git : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QDir clone_setup();
 | 
			
		||||
    bool move_to_destination(QString path, QDir tmp_dir);
 | 
			
		||||
    bool clone_tear_down(QDir tmp_dir);
 | 
			
		||||
    QDir cloneSetup();
 | 
			
		||||
    bool moveToDestination(QString path, QDir tmp_dir);
 | 
			
		||||
    bool cloneTearDown(QDir tmp_dir);
 | 
			
		||||
    bool clone(QString url, QString path, mode_type mode);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -22,8 +25,8 @@ public:
 | 
			
		||||
    Git() = default;
 | 
			
		||||
    ~Git() override = default;
 | 
			
		||||
 | 
			
		||||
    Q_INVOKABLE bool clone_http(QString url, QString path);
 | 
			
		||||
    Q_INVOKABLE bool clone_http_pass(QString url, QString path, QString pass);
 | 
			
		||||
    Q_INVOKABLE bool cloneHttp(QString url, QString path);
 | 
			
		||||
    Q_INVOKABLE bool cloneHttpPass(QString url, QString path, QString pass);
 | 
			
		||||
    // Q_INVOKABLE bool clone_ssh_pass(QString url, QString path, QString pass);
 | 
			
		||||
    // Q_INVOKABLE bool clone_ssh_key(QString url, QString path, QString pub_key, QString priv_key, QString passphrase);
 | 
			
		||||
    // Q_INVOKABLE bool update(QUrl url, QString path);
 | 
			
		||||
 
 | 
			
		||||
@@ -21,12 +21,12 @@ LibGit::~LibGit()
 | 
			
		||||
    git_libgit2_shutdown();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LibGit::set_mode(mode_type type)
 | 
			
		||||
void LibGit::setMode(mode_type type)
 | 
			
		||||
{
 | 
			
		||||
    this->mode = type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int LibGit::credentials_cb(git_cred **out, const char *url, const char *username_from_url,
 | 
			
		||||
int LibGit::credentialsCB(git_cred **out, const char *url, const char *username_from_url,
 | 
			
		||||
                           unsigned int allowed_types, void *payload)
 | 
			
		||||
{
 | 
			
		||||
    // TODO : More precise Error Handling for UI
 | 
			
		||||
@@ -73,7 +73,7 @@ bool LibGit::clone(QString url, QString path)
 | 
			
		||||
    git_repository *repo = NULL;
 | 
			
		||||
    git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
 | 
			
		||||
 | 
			
		||||
    opts.fetch_opts.callbacks.credentials = *credentials_cb;
 | 
			
		||||
    opts.fetch_opts.callbacks.credentials = *credentialsCB;
 | 
			
		||||
 | 
			
		||||
    int ret = git_clone(&repo, url.toLocal8Bit().data(), path.toLocal8Bit().data(), &opts);
 | 
			
		||||
    if (ret != 0) {
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ private:
 | 
			
		||||
 | 
			
		||||
    mode_type mode;
 | 
			
		||||
 | 
			
		||||
    static int credentials_cb(git_cred **out, const char *url, const char *username_from_url,
 | 
			
		||||
    static int credentialsCB(git_cred **out, const char *url, const char *username_from_url,
 | 
			
		||||
                              unsigned int allowed_types, void *payload);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
@@ -40,7 +40,7 @@ public:
 | 
			
		||||
    void operator=(LibGit const &) = delete;
 | 
			
		||||
 | 
			
		||||
    bool clone(QString url, QString path);
 | 
			
		||||
    void set_mode(mode_type type);
 | 
			
		||||
    void setMode(mode_type type);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user