gitreference.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "gitreference.h"
  2. #include <QDebug>
  3. #include <git2.h>
  4. GitReference::GitReference(git_reference *ref, GitRepository *parent) : GitBase(nullptr, parent)
  5. ,m_namespace(Invalid)
  6. {
  7. if(ref == nullptr) {
  8. qDebug() << "Null reference ptr";
  9. return;
  10. }
  11. m_raw = ref;
  12. detectNamespace();
  13. if(m_namespace == Invalid) {
  14. qDebug() << "Namespace for reference is invalid";
  15. free();
  16. return;
  17. }
  18. }
  19. void GitReference::detectNamespace()
  20. {
  21. if(m_raw == nullptr) {
  22. return;
  23. }
  24. if(git_reference_is_branch(m_raw)) {
  25. m_namespace = Branch;
  26. qDebug() << "Reference namespace Branch";
  27. return;
  28. }
  29. if(git_reference_is_tag(m_raw)) {
  30. m_namespace = Tag;
  31. qDebug() << "Reference namespace Tag";
  32. return;
  33. }
  34. if(git_reference_is_note(m_raw)) {
  35. m_namespace = Note;
  36. qDebug() << "Reference namespace Note";
  37. return;
  38. }
  39. if(git_reference_is_remote(m_raw)) {
  40. m_namespace = Remote;
  41. qDebug() << "Reference namespace Remote";
  42. return;
  43. }
  44. }
  45. GitReference::~GitReference()
  46. {
  47. free();
  48. }
  49. void GitReference::free()
  50. {
  51. if(m_raw != nullptr) {
  52. git_reference_free(m_raw);
  53. }
  54. m_raw = nullptr;
  55. }