gitoid.cpp 1.2 KB

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