gitoid.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. const QLatin1String& GitOid::toString() const
  15. {
  16. return m_string;
  17. }
  18. bool GitOid::operator ==(const GitOid& other) const
  19. {
  20. return git_oid_equal(&m_oid, &(other.m_oid)) == 0
  21. && m_repository == other.m_repository;
  22. }
  23. GitOid& GitOid::operator=(const GitOid& other)
  24. {
  25. updateOid(&(other.m_oid));
  26. m_repository = other.m_repository;
  27. return *this;
  28. }
  29. void GitOid::updateOid(const git_oid* oid)
  30. {
  31. if(oid != nullptr) {
  32. git_oid_cpy(&m_oid, oid);
  33. m_string = QLatin1String(git_oid_tostr_s(&m_oid));
  34. } else {
  35. memset(&m_oid, 0, sizeof(m_oid));
  36. m_string = QLatin1String("");
  37. }
  38. }
  39. bool GitOid::isValid() const
  40. {
  41. return !git_oid_iszero(&m_oid) && m_repository != nullptr;
  42. }