#include "githandler.h" #include #include #include #include #include GitHandler::GitHandler() : QObject() ,m_repositories(new RepositoryModel(this)) { git_libgit2_init(); } GitHandler::~GitHandler() { git_libgit2_shutdown(); } void GitHandler::open(const QUrl &url) { if(url.isLocalFile()) { open(url.toLocalFile()); } } void GitHandler::open(const QString &path) { git_buf root = {0,0,0}; if(git_repository_discover(&root, path.toUtf8().data(), 0, NULL) != 0) { qDebug() << lastError(); return; } GitRepository* repo = new GitRepository(QString::fromUtf8(root.ptr, root.size)); if(!repo->isValid()) { qDebug() << lastError(); return; } m_repositories->addRepository(repo); } QString GitHandler::lastError() const { const git_error *e = giterr_last(); if(e) { return QString("(%1): %2").arg(e->klass).arg(e->message); giterr_clear(); } giterr_clear(); return QString(); }