commitmodel.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "commitmodel.h"
  2. #include <gitbranch.h>
  3. #include <git2/revwalk.h>
  4. #include <commitgraph.h>
  5. #include <graphpoint.h>
  6. #include <graphlistmodel.h>
  7. CommitModel::CommitModel(const QString &head, QObject* parent) : UniversalListModel(parent)
  8. ,m_head(head)
  9. {
  10. }
  11. CommitModel* CommitModel::fromBranch(GitBranch* branch)
  12. {
  13. qDebug() << branch->name();
  14. CommitModel* tmpModel = new CommitModel(branch->name(), branch);
  15. git_revwalk* walk;
  16. git_revwalk_new(&walk, branch->repository()->raw());
  17. git_revwalk_push(walk, branch->oid().raw());
  18. git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL);
  19. git_oid newOid;
  20. while(git_revwalk_next(&newOid, walk) == 0) {
  21. GitOid commitOid(&newOid, branch->repository());
  22. GitCommit *commit = GitCommit::fromOid(commitOid);
  23. if(commit != nullptr) {
  24. tmpModel->add(commit);
  25. } else {
  26. qDebug() << "Commit is null";
  27. }
  28. }
  29. git_revwalk_free(walk);
  30. return tmpModel;
  31. }
  32. CommitModel* CommitModel::fromGraph(CommitGraph *graph)
  33. {
  34. CommitModel* model = new CommitModel("HEAD");
  35. QList<QPointer<GraphPoint> > points = graph->points()->container();
  36. for(int i = 0; i < points.count(); i++) {
  37. GraphPoint* point = points.at(i).data();
  38. model->m_container.prepend(GitCommit::fromOid(point->oid()));
  39. // QPointer<GitTag> tag = commit->repository()->tags().value(commit->oid());
  40. // if(!tag.isNull()) {
  41. // point->setTag(tag.data()->name());
  42. // }
  43. }
  44. return model;
  45. }