123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "githandler.h"
- #include <QDebug>
- #include <QUrl>
- #include <qqml.h>
- #include <gitrepository.h>
- #include <git2.h>
- 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();
- }
|