commitmodel.cpp 814 B

12345678910111213141516171819202122232425262728293031
  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. GitOid commitOid(&newOid, branch->repository());
  18. GitCommit *commit = GitCommit::fromOid(commitOid);
  19. if(commit != nullptr) {
  20. tmpModel->add(commit);
  21. }
  22. }
  23. git_revwalk_free(walk);
  24. return tmpModel;
  25. }