gitoid.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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)) == 0
  25. && m_repository == other.m_repository;
  26. }
  27. GitOid& GitOid::operator=(const GitOid& other)
  28. {
  29. updateOid(&(other.m_oid));
  30. m_repository = other.m_repository;
  31. return *this;
  32. }
  33. void GitOid::updateOid(const git_oid* oid)
  34. {
  35. if(oid != nullptr) {
  36. git_oid_cpy(&m_oid, oid);
  37. m_string = QLatin1String(git_oid_tostr_s(&m_oid));
  38. } else {
  39. memset(&m_oid, 0, sizeof(m_oid));
  40. m_string = QLatin1String("");
  41. }
  42. }
  43. bool GitOid::isValid() const
  44. {
  45. return !git_oid_iszero(&m_oid) && m_repository != nullptr;
  46. }