#include "gitrepository.h" #include #include #include #include #include #include #include #include #include GitRepository::GitRepository(const QString& root) : QObject(nullptr) { if(git_repository_open(&m_raw, root.toUtf8().data()) != 0) { qDebug() << "Cannot open repository"; close(); return; } m_root = root; m_path = git_repository_workdir(m_raw); m_name = m_path;//TODO: replace with Human readable name qDebug() << "New repo:" << m_name << m_root << m_path; readBranches(); readTags(); readRemotes(); } GitRepository::~GitRepository() { close(); } void GitRepository::close() { if(m_raw) { git_repository_free(m_raw); } m_raw = nullptr; } void GitRepository::readBranches() { git_reference *branchRef; git_branch_t branchType; git_branch_iterator* iter; git_branch_iterator_new(&iter, m_raw, GIT_BRANCH_ALL); while(git_branch_next(&branchRef, &branchType, iter) == 0) { GitBranch* branch = new GitBranch(branchRef, branchType, this); m_branches.insert(branch->name(), QPointer(branch)); qDebug() << branch->name(); qDebug() << branch->type(); } } void GitRepository::readTags() { git_tag_foreach(raw(), [](const char *name, git_oid *oid, void *payload) -> int { Q_UNUSED(payload) Q_UNUSED(name) GitRepository* repo = static_cast(payload); git_tag* tagraw = 0; if(git_tag_lookup(&tagraw, repo->raw(), oid) != 0) { qCritical() << "Invalid tag found. Broken repository"; return 1; } GitTag* tag = new GitTag(tagraw, repo); if(tag->isValid()) { repo->m_tags.insert(tag->targetId(), tag); } qDebug() << "Tag found: " << tag->name() << tag->sha1(); return 0; }, this); } void GitRepository::readRemotes() { git_reference_foreach(raw(),[](git_reference *reference, void *payload) -> int { if(git_reference_is_remote(reference)) { GitRemote* remote = GitRemote::fromName(QString::fromLatin1(git_reference_name(reference)), static_cast(payload)); } }, this); // git_remote* remoteRaw; // git_reference_is_remote() }