1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-01-23 23:26:40 +00:00

Some cleanup

This commit is contained in:
Quentin Rouland 2025-01-13 18:11:16 +01:00
parent 6ac11e2da7
commit 063f66e99a
12 changed files with 64 additions and 57 deletions

View File

@ -4,7 +4,7 @@ kill: UTPass
scripts:
style: >-
echo 'Running Astyle :' && astyle --options=.astylerc main.cpp && astyle --options=.astylerc --recursive 'plugins/*.cpp,*.h' && echo 'Running QmlFormat' && find . -name "*.qml" -exec qmlformat -i {} \; && echo 'Success'
echo 'Running Astyle :' && astyle --options=.astylerc --recursive '*.cpp,*.h' --exclude=build && echo 'Running QmlFormat' && find . -name "*.qml" -exec qmlformat -i {} \; && echo 'Success'

View File

@ -6,7 +6,7 @@ set(
plugin.cpp
libgit.cpp
git.cpp
templates.h
)
set(CMAKE_AUTOMOC ON)

View File

@ -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);
}

View File

@ -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

View File

@ -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
View 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

View File

@ -19,10 +19,10 @@ MainView {
//TODO use parameters to impove passphrase dialog
var passphraseDialog = PopupUtils.open(Qt.resolvedUrl("dialogs/PassphraseDialog.qml"));
passphraseDialog.activateFocus();
var validated = function (passphrase) {
var validated = function validated(passphrase) {
responsePassphraseDialog(false, passphrase);
};
var canceled = function () {
var canceled = function canceled() {
responsePassphraseDialog(true, "");
};
passphraseDialog.validated.connect(validated);

View File

@ -69,12 +69,10 @@ Page {
text: i18n.tr('Clone')
onClicked: {
var ret = false;
if(repoPasswordInput.text === "") {
if (repoPasswordInput.text === "")
ret = Git.clone_http(repoUrlInput.text, Pass.password_store);
} else {
else
ret = Git.clone_http_pass(repoUrlInput.text, Pass.password_store, repoPasswordInput.text);
}
if (ret)
PopupUtils.open(dialogImportGitCloneSuccess);
else

View File

@ -8,7 +8,8 @@
#include "utils.h"
QString TestsUtils::getTempPath() {
QString TestsUtils::getTempPath()
{
qFatal("yp");
// Get the system's temporary directory
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);

View File

@ -1,12 +1,11 @@
import Git 1.0
import QtQuick 2.9
import QtTest 1.2
import Git 1.0
TestCase {
name: "git"
function test_git_clone() {
verify(Git.clone("",""));
verify(Git.clone("", ""));
}
name: "git"
}

View File

@ -1,12 +1,11 @@
import Git 1.0
import QtQuick 2.9
import QtTest 1.2
import Git 1.0
TestCase {
name: "git"
function test_git_clone() {
verify(Git.clone("",""));
verify(Git.clone("", ""));
}
name: "git"
}

View File

@ -4,12 +4,12 @@ import TestUtils 1.0
import Utils 1.0
TestCase {
name: "utils"
function test_unzip() {
var tempPath = TestUtils.getTempPath() + "/password-store";
var zipUrl = Qt.resolvedUrl("../assets/archive.zip");
var r = Utils.unzip(zipUrl, tempPath)
verify(r, "Unzip return an error %1".arg(zipUrl))
var r = Utils.unzip(zipUrl, tempPath);
verify(r, "Unzip return an error %1".arg(zipUrl));
}
name: "utils"
}