commitmodel.cpp 912 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "commitmodel.h"
  2. #include <gitbranch.h>
  3. #include <git2/revwalk.h>
  4. CommitModel::CommitModel(const QString &head, QObject* parent) : UniversalListModel(parent)
  5. ,m_head(head)
  6. {
  7. }
  8. CommitModel* CommitModel::fromBranch(GitBranch* branch)
  9. {
  10. qDebug() << branch->name();
  11. CommitModel* tmpModel = new CommitModel(branch->name(), branch);
  12. git_revwalk* walk;
  13. git_revwalk_new(&walk, branch->repository()->raw());
  14. git_revwalk_push(walk, branch->oid().raw());
  15. git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL);
  16. git_oid newOid;
  17. while(git_revwalk_next(&newOid, walk) == 0) {
  18. GitOid commitOid(&newOid, branch->repository());
  19. GitCommit *commit = GitCommit::fromOid(commitOid);
  20. if(commit != nullptr) {
  21. tmpModel->add(commit);
  22. } else {
  23. qDebug() << "Commit is null";
  24. }
  25. }
  26. git_revwalk_free(walk);
  27. return tmpModel;
  28. }