mirror of
https://github.com/QRouland/UTPass.git
synced 2025-06-24 22:42:28 +00:00
Some cleanup
This commit is contained in:
@ -6,7 +6,7 @@ set(
|
||||
plugin.cpp
|
||||
libgit.cpp
|
||||
git.cpp
|
||||
|
||||
templates.h
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
@ -6,14 +6,7 @@
|
||||
|
||||
#include "git.h"
|
||||
#include "libgit.h"
|
||||
|
||||
|
||||
template<class... Ts>
|
||||
struct overload : Ts... {
|
||||
using Ts::operator()...;
|
||||
};
|
||||
template<class... Ts>
|
||||
overload(Ts...) -> overload<Ts...>;
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
QDir Git::clone_setup()
|
||||
@ -29,7 +22,7 @@ QDir Git::clone_setup()
|
||||
|
||||
bool Git::clone_tear_down(QDir tmp_dir)
|
||||
{
|
||||
tmp_dir.removeRecursively();
|
||||
return tmp_dir.removeRecursively();
|
||||
}
|
||||
|
||||
bool Git::move_to_destination(QString path, QDir tmp_dir)
|
||||
@ -49,11 +42,11 @@ bool Git::move_to_destination(QString path, QDir tmp_dir)
|
||||
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 HTTPAuth& x) { return "HTTPAuth"; },
|
||||
[](const SSHAuth& x) { return "SSHAuth"; },
|
||||
[](const SSHKey& x) { return "SSHKey"; },
|
||||
[](const Unset & x) { return "Unset"; },
|
||||
[](const HTTP & x) { return "Unset"; },
|
||||
[](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);
|
||||
|
||||
@ -63,9 +56,11 @@ bool Git::clone(QString url, QString path, mode_type mode) //, GitPlugin::RepoTy
|
||||
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);}
|
||||
if (ret) {
|
||||
this->move_to_destination(path, tmp_dir);
|
||||
}
|
||||
|
||||
tmp_dir.removeRecursively();
|
||||
this->clone_tear_down(tmp_dir);
|
||||
LibGit::instance()->set_mode(Unset());
|
||||
|
||||
return ret ;
|
||||
@ -77,7 +72,8 @@ bool Git::clone_http(QString url, QString path) //, GitPlugin::RepoType type, QS
|
||||
return this->clone(url, path, mode);
|
||||
}
|
||||
|
||||
bool Git::clone_http_pass(QString url, QString path, QString pass) {
|
||||
bool Git::clone_http_pass(QString url, QString path, QString pass)
|
||||
{
|
||||
HTTPAuth mode = { pass };
|
||||
return this->clone(url, path, mode);
|
||||
}
|
||||
|
@ -7,14 +7,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
#include "libgit.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
template<class... Ts>
|
||||
struct overload : Ts... {
|
||||
using Ts::operator()...;
|
||||
};
|
||||
template<class... Ts>
|
||||
overload(Ts...) -> overload<Ts...>;
|
||||
|
||||
LibGit::LibGit()
|
||||
{
|
||||
@ -26,7 +21,8 @@ LibGit::~LibGit()
|
||||
git_libgit2_shutdown();
|
||||
}
|
||||
|
||||
void LibGit::set_mode(mode_type type) {
|
||||
void LibGit::set_mode(mode_type type)
|
||||
{
|
||||
this->mode = type;
|
||||
}
|
||||
|
||||
@ -36,30 +32,35 @@ int LibGit::credentials_cb(git_cred **out, const char *url, const char *username
|
||||
// TODO : More precise Error Handling for UI
|
||||
auto instance = LibGit::instance();
|
||||
auto v = overload {
|
||||
[](const Unset& x) {
|
||||
[](const Unset & x)
|
||||
{
|
||||
qDebug() << "credentials_cb : Unset ";
|
||||
qWarning() << "credentials_cb : callback should never be call for Unset ";
|
||||
return (int) GIT_EUSER;
|
||||
},
|
||||
[](const HTTP& x) {
|
||||
[](const HTTP & x)
|
||||
{
|
||||
qDebug() << "credentials_cb : HTTP ";
|
||||
qWarning() << "credentials_cb : callback should never be call for HTTP ";
|
||||
return (int) GIT_EUSER;
|
||||
},
|
||||
[&out, &username_from_url](const HTTPAuth& x) {
|
||||
[&out, &username_from_url](const HTTPAuth & x)
|
||||
{
|
||||
qDebug() << "credentials_cb : HTTPAuth ";
|
||||
if(!username_from_url) {
|
||||
if (!username_from_url) {
|
||||
qWarning() << "credentials_cb : no username provided ";
|
||||
return (int) GIT_EUSER;
|
||||
}
|
||||
return git_cred_userpass_plaintext_new(out, username_from_url, x.pass.toLocal8Bit().constData());
|
||||
},
|
||||
[&](const SSHAuth& x) {
|
||||
[&](const SSHAuth & x)
|
||||
{
|
||||
qWarning() << "credentials_cb : SSHAuth to be implemented ";
|
||||
return (int) GIT_EUSER;
|
||||
}, // TODO
|
||||
[&](const SSHKey& x) {
|
||||
qWarning() << "credentials_cb : SSHKey to be implemented ";
|
||||
[&](const SSHKey & x)
|
||||
{
|
||||
qWarning() << "credentials_cb : SSHKey to be implemented ";
|
||||
return (int) GIT_EUSER;
|
||||
} // TODO
|
||||
};
|
||||
@ -76,10 +77,10 @@ bool LibGit::clone(QString url, QString path)
|
||||
|
||||
int ret = git_clone(&repo, url.toLocal8Bit().data(), path.toLocal8Bit().data(), &opts);
|
||||
if (ret != 0) {
|
||||
qDebug() << git_error_last()->message;
|
||||
qDebug() << git_error_last()->message;
|
||||
}
|
||||
if (repo) {
|
||||
git_repository_free(repo);
|
||||
git_repository_free(repo);
|
||||
}
|
||||
return ret == 0; // TODO Clean error handling to return specifics errors for the ui
|
||||
|
||||
|
@ -12,7 +12,9 @@ extern "C" {
|
||||
|
||||
struct Unset { };
|
||||
struct HTTP { };
|
||||
struct HTTPAuth { QString pass; };
|
||||
struct HTTPAuth {
|
||||
QString pass;
|
||||
};
|
||||
struct SSHAuth { };
|
||||
struct SSHKey { };
|
||||
typedef std::variant<Unset, HTTP, HTTPAuth, SSHAuth, SSHKey> mode_type;
|
||||
|
11
plugins/Git/utils.h
Normal file
11
plugins/Git/utils.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
template<class... Ts>
|
||||
struct overload : Ts... {
|
||||
using Ts::operator()...;
|
||||
};
|
||||
template<class... Ts>
|
||||
overload(Ts...) -> overload<Ts...>;
|
||||
|
||||
#endif // UTILS_H
|
Reference in New Issue
Block a user