commitmodel.cpp 945 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. CommitModel* tmpModel = new CommitModel(branch->name(), branch);
  11. git_revwalk* walk;
  12. git_revwalk_new(&walk, branch->repository()->raw());
  13. git_revwalk_push(walk, branch->oid().raw());
  14. git_revwalk_sorting(walk, GIT_SORT_TIME);
  15. git_oid newOid;
  16. while(git_revwalk_next(&newOid, walk) == 0)
  17. {
  18. GitOid commitOid(&newOid, branch->repository());
  19. if(!tmpModel->m_container.isEmpty()) {
  20. qDebug() << "Last:" << tmpModel->m_container.last().data()->sha1();
  21. }
  22. GitCommit *commit = GitCommit::fromOid(commitOid);
  23. qDebug() << commit->sha1();
  24. tmpModel->add(commit);
  25. }
  26. git_revwalk_free(walk);
  27. return tmpModel;
  28. }