gitrepository.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef GITREPOSITORY_H
  2. #define GITREPOSITORY_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <QMap>
  6. #include <QPointer>
  7. #include <gitoid.h>
  8. struct git_repository;
  9. class GitBranch;
  10. class GitTag;
  11. class GitDiff;
  12. class GitCommit;
  13. class GitRemote;
  14. struct git_oid;
  15. using BranchContainer = QMap<QString, QPointer<GitBranch> >;
  16. using TagContainer = QMap<GitOid, QPointer<GitTag> >;
  17. using RemoteContainer = QMap<QString, QPointer<GitRemote> >;
  18. class GitRepository : public QObject
  19. {
  20. Q_OBJECT
  21. Q_PROPERTY(QString root READ root WRITE setRoot NOTIFY rootChanged)
  22. Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
  23. Q_PROPERTY(QString path READ path NOTIFY rootChanged)
  24. Q_PROPERTY(GitOid head READ head WRITE setHead NOTIFY headChanged)
  25. Q_PROPERTY(QString id READ id NOTIFY rootChanged)
  26. public:
  27. GitRepository(const QString &root);
  28. ~GitRepository();
  29. QString root() const {
  30. return m_root;
  31. }
  32. QString name() const {
  33. return m_name;
  34. }
  35. QString path() const {
  36. return m_path;
  37. }
  38. git_repository* raw() const {
  39. return m_raw;
  40. }
  41. bool isValid() const {
  42. return m_raw != nullptr;
  43. }
  44. BranchContainer& branches() {
  45. return m_branches;
  46. }
  47. TagContainer& tags() {
  48. return m_tags;
  49. }
  50. RemoteContainer& remotes() {
  51. return m_remotes;
  52. }
  53. GitOid head() const
  54. {
  55. return m_head;
  56. }
  57. QString id() const;
  58. Q_INVOKABLE bool isHead(const GitOid& oid) const {
  59. return m_head == oid;
  60. }
  61. Q_INVOKABLE void checkout(QObject* object);
  62. public slots:
  63. void setRoot(QString root) {
  64. if (m_root == root)
  65. return;
  66. m_root = root;
  67. emit rootChanged(root);
  68. }
  69. void setName(QString name) {
  70. if (m_name == name)
  71. return;
  72. m_name = name;
  73. emit nameChanged(name);
  74. }
  75. void setHead(GitOid head)
  76. {
  77. if (m_head == head)
  78. return;
  79. m_head = head;
  80. emit headChanged(head);
  81. }
  82. void updateHead();
  83. void readBranches();
  84. void readTags();
  85. void readRemotes();
  86. signals:
  87. void rootChanged(QString root);
  88. void nameChanged(QString name);
  89. void headChanged(GitOid head);
  90. void branchesChanged();
  91. private:
  92. void close();
  93. QString m_root;
  94. QString m_name;
  95. QString m_path;
  96. git_repository* m_raw;
  97. BranchContainer m_branches;
  98. TagContainer m_tags;
  99. RemoteContainer m_remotes;
  100. GitOid m_head;
  101. #if 0 //Test functionality
  102. public:
  103. void testReadBranches();
  104. #endif
  105. };
  106. #endif // GITREPOSITORY_H