gitbranch.cpp 990 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "gitbranch.h"
  2. #include <QDebug>
  3. #include <gitrepository.h>
  4. #include <git2.h>
  5. namespace {
  6. const char remoteAddtion = '/';
  7. }
  8. GitBranch::GitBranch(git_reference *ref, git_branch_t type, GitRepository *parent) : GitReference(ref, parent)
  9. ,m_commit(nullptr)
  10. ,m_type(static_cast<BranchType>(type))
  11. {
  12. const char* tmpName;
  13. git_branch_name(&tmpName, m_raw);
  14. m_fullName = tmpName;
  15. m_name = m_fullName;
  16. git_annotated_commit_from_ref(&m_commit, repository()->raw(), m_raw);
  17. m_oid = GitOid(git_annotated_commit_id(m_commit), m_repository);
  18. git_buf buf = GIT_BUF_INIT_CONST("",0);
  19. if(git_branch_remote_name(&buf, repository()->raw(), refName().toUtf8().data()) == 0) {
  20. m_remote = QString::fromUtf8(buf.ptr);
  21. m_name.remove(m_remote + remoteAddtion);
  22. }
  23. }
  24. GitBranch::~GitBranch()
  25. {
  26. if(m_commit != nullptr) {
  27. git_annotated_commit_free(m_commit);
  28. }
  29. }
  30. GitBranch::BranchType GitBranch::type() const
  31. {
  32. return m_type;
  33. }