gitcommit.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. {
  7. m_oid = GitOid(git_commit_id(m_raw), m_repository);
  8. }
  9. GitCommit::GitCommit() : GitBase(nullptr, nullptr)
  10. {
  11. }
  12. GitCommit* GitCommit::fromOid(const GitOid& oid)
  13. {
  14. if(!oid.isValid()) {
  15. return nullptr;
  16. }
  17. git_commit *commit;
  18. if(git_commit_lookup(&commit, oid.repository()->raw(), oid.raw()) != 0) {
  19. return nullptr;
  20. }
  21. return new GitCommit(commit, oid.repository());
  22. }
  23. GitCommit::~GitCommit()
  24. {
  25. git_commit_free(m_raw);
  26. }
  27. QString GitCommit::author() const
  28. {
  29. return QString(git_commit_author(m_raw)->name);
  30. }
  31. QDateTime GitCommit::time() const
  32. {
  33. return QDateTime::fromMSecsSinceEpoch(git_commit_time(m_raw));
  34. }
  35. QString GitCommit::message() const
  36. {
  37. return QString(git_commit_message(m_raw));
  38. }
  39. QString GitCommit::email() const
  40. {
  41. return QString(git_commit_author(m_raw)->email);
  42. }
  43. QString GitCommit::sha1() const
  44. {
  45. return oid().toString();
  46. }
  47. QString GitCommit::shortSha1() const
  48. {
  49. return oid().toShorten();
  50. }
  51. void GitCommit::setAuthor(QString author)
  52. {
  53. Q_UNUSED(author)
  54. //TODO
  55. }
  56. void GitCommit::setTime(QDateTime time)
  57. {
  58. Q_UNUSED(time)
  59. //TODO
  60. }
  61. void GitCommit::setMessage(QString message)
  62. {
  63. Q_UNUSED(message)
  64. //TODO
  65. }
  66. void GitCommit::setEmail(QString email)
  67. {
  68. Q_UNUSED(email)
  69. //TODO
  70. }