gitoid.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "gitoid.h"
  2. #include <gitrepository.h>
  3. GitOid::GitOid() : QObject()
  4. ,m_oid({0})
  5. ,m_repository()
  6. {
  7. }
  8. GitOid::GitOid(const git_oid *oid, GitRepository *parent) : QObject()
  9. ,m_oid({0})
  10. ,m_repository(parent)
  11. {
  12. updateOid(oid);
  13. }
  14. GitOid::GitOid(const GitOid& other) : QObject()
  15. {
  16. updateOid(&(other.m_oid));
  17. m_repository = other.m_repository;
  18. }
  19. QString GitOid::toString() const
  20. {
  21. return m_string;
  22. }
  23. QString GitOid::toShorten() const
  24. {
  25. return m_string.mid(0,9);
  26. }
  27. bool GitOid::operator ==(const GitOid& other) const
  28. {
  29. return git_oid_equal(&m_oid, &(other.m_oid)) == true
  30. && m_repository == other.m_repository;
  31. }
  32. bool GitOid::operator <(const GitOid& other) const
  33. {
  34. return git_oid_cmp(raw(), other.raw()) < 0;
  35. }
  36. GitOid& GitOid::operator=(const GitOid& other)
  37. {
  38. updateOid(&(other.m_oid));
  39. m_repository = other.m_repository;
  40. return *this;
  41. }
  42. void GitOid::updateOid(const git_oid* oid)
  43. {
  44. if(oid != nullptr) {
  45. git_oid_cpy(&m_oid, oid);
  46. m_string = QLatin1String(git_oid_tostr_s(&m_oid));
  47. } else {
  48. memset(&m_oid, 0, sizeof(m_oid));
  49. m_string = QLatin1String("");
  50. }
  51. }
  52. bool GitOid::isValid() const
  53. {
  54. return !git_oid_iszero(&m_oid) && m_repository != nullptr;
  55. }