gitcommit.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "gitcommit.h"
  2. #include <gitoid.h>
  3. #include <QDebug>
  4. #include <git2/commit.h>
  5. GitCommit::GitCommit(git_commit* raw, GitRepository* parent) : GitBase(raw, parent)
  6. ,m_x(0)
  7. ,m_y(0)
  8. ,m_childrenCounter(0)
  9. {
  10. m_oid = GitOid(git_commit_id(m_raw), m_repository);
  11. }
  12. GitCommit::GitCommit() : GitBase(nullptr, nullptr)
  13. {
  14. }
  15. GitCommit* GitCommit::fromOid(const GitOid& oid)
  16. {
  17. if(!oid.isValid()) {
  18. return nullptr;
  19. }
  20. git_commit *commit;
  21. if(git_commit_lookup(&commit, oid.repository()->raw(), oid.raw()) != 0) {
  22. return nullptr;
  23. }
  24. return new GitCommit(commit, oid.repository());
  25. }
  26. GitCommit::~GitCommit()
  27. {
  28. git_commit_free(m_raw);
  29. }
  30. QString GitCommit::author() const
  31. {
  32. return QString(git_commit_author(m_raw)->name);
  33. }
  34. QDateTime GitCommit::time() const
  35. {
  36. return QDateTime::fromMSecsSinceEpoch(git_commit_time(m_raw));
  37. }
  38. QString GitCommit::message() const
  39. {
  40. return QString(git_commit_message(m_raw));
  41. }
  42. QString GitCommit::email() const
  43. {
  44. return QString(git_commit_author(m_raw)->email);
  45. }
  46. QString GitCommit::sha1() const
  47. {
  48. return oid().toString();
  49. }
  50. QString GitCommit::shortSha1() const
  51. {
  52. return oid().toShorten();
  53. }
  54. bool GitCommit::isMerge() const
  55. {
  56. return git_commit_parentcount(m_raw) > 1;
  57. }
  58. void GitCommit::setAuthor(QString author)
  59. {
  60. Q_UNUSED(author)
  61. //TODO
  62. }
  63. void GitCommit::setTime(QDateTime time)
  64. {
  65. Q_UNUSED(time)
  66. //TODO
  67. }
  68. void GitCommit::setMessage(QString message)
  69. {
  70. Q_UNUSED(message)
  71. //TODO
  72. }
  73. void GitCommit::setEmail(QString email)
  74. {
  75. Q_UNUSED(email)
  76. //TODO
  77. }