File indexing completed on 2024-05-19 04:47:12
0001 #include "commithistorymodel.h" 0002 #include <QDebug> 0003 #include "libGitWrap/ObjectId.hpp" 0004 #include "libGitWrap/BranchRef.hpp" 0005 0006 #include "controllers/project.h" 0007 0008 CommitHistoryModel::CommitHistoryModel(Project *parent) : MauiList(parent) 0009 ,m_project(parent) 0010 { 0011 connect(m_project, &Project::currentBranchChanged, [this](QString) 0012 { 0013 this->setData(); 0014 }); 0015 0016 } 0017 0018 void CommitHistoryModel::setRepo(Git::Repository &repo) 0019 { 0020 m_repo = repo; 0021 this->setData(); 0022 } 0023 0024 const FMH::MODEL_LIST &CommitHistoryModel::items() const 0025 { 0026 return m_list; 0027 } 0028 0029 void CommitHistoryModel::setData() 0030 { 0031 if(!m_repo.isValid()) 0032 return; 0033 0034 Git::Result r; 0035 0036 auto walker = Git::RevisionWalker::create(r, m_repo); 0037 0038 if(r) 0039 { 0040 walker.setSorting(r, true, true); 0041 if(r) 0042 { 0043 auto ref = m_repo.branchRef(r, m_project->currentBranch()); 0044 if(!r) 0045 { 0046 return; 0047 } 0048 0049 walker.pushRef(r, ref.name()); 0050 0051 if(r) 0052 { 0053 auto ids = walker.all(r); 0054 0055 if(r) 0056 { 0057 this->m_list.clear(); 0058 emit this->preListChanged(); 0059 for(const auto &id : ids) 0060 { 0061 auto commit = m_repo.lookupCommit(r, id); 0062 0063 if(r) 0064 { 0065 this->m_list << FMH::MODEL {{FMH::MODEL_KEY::ID, id.toString()}, {FMH::MODEL_KEY::MESSAGE, commit.message()}, {FMH::MODEL_KEY::AUTHOR, commit.author().name()}, {FMH::MODEL_KEY::EMAIL, commit.author().email()}, {FMH::MODEL_KEY::DATE, commit.author().when().toString()}}; 0066 0067 } 0068 } 0069 0070 emit this->postListChanged(); 0071 } 0072 } 0073 } 0074 } 0075 }