int CLogDataVector::ParserFromRefLog(CString ref) { if(g_Git.m_IsUseGitDLL) { git_for_each_reflog_ent(CUnicodeUtils::GetUTF8(ref),AddTolist,this); for(int i=0;i<size();i++) { m_pLogCache->m_HashMap[at(i)].m_Ref.Format(_T("%s{%d}"), ref,i); } } else { CString cmd, out; GitRev rev; cmd.Format(_T("git.exe reflog show %s"),ref); if (g_Git.Run(cmd, &out, NULL, CP_UTF8)) return -1; int pos=0; while(pos>=0) { CString one=out.Tokenize(_T("\n"),pos); int ref=one.Find(_T(' '),0); if(ref<0) continue; rev.Clear(); rev.m_CommitHash=g_Git.GetHash(one.Left(ref)); int action=one.Find(_T(' '),ref+1); int message; if(action>0) { rev.m_Ref=one.Mid(ref+1,action-ref-2); message=one.Find(_T(":"),action); if(message>0) { rev.m_RefAction=one.Mid(action+1,message-action-1); rev.GetSubject()=one.Right(one.GetLength()-message-1); } } this->m_pLogCache->m_HashMap[rev.m_CommitHash]=rev; this->push_back(rev.m_CommitHash); } } return 0; }
int ParserFromRefLog(CString ref, std::vector<GitRev> &refloglist) { refloglist.clear(); if (g_Git.m_IsUseLibGit2) { CAutoRepository repo(g_Git.GetGitRepository()); if (!repo) { MessageBox(nullptr, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_ICONERROR); return -1; } CAutoReflog reflog; if (git_reflog_read(reflog.GetPointer(), repo, CUnicodeUtils::GetUTF8(ref)) < 0) { MessageBox(nullptr, CGit::GetLibGit2LastErr(_T("Could not read reflog.")), _T("TortoiseGit"), MB_ICONERROR); return -1; } for (size_t i = 0; i < git_reflog_entrycount(reflog); ++i) { const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, i); if (!entry) continue; GitRev rev; rev.m_CommitHash = (char *)git_reflog_entry_id_new(entry)->id; rev.m_Ref.Format(_T("%s@{%d}"), ref, i); rev.GetCommitterDate() = CTime(git_reflog_entry_committer(entry)->when.time); if (git_reflog_entry_message(entry) != nullptr) { CString one; g_Git.StringAppend(&one, (BYTE *)git_reflog_entry_message(entry)); int message = one.Find(_T(":"), 0); if (message > 0) { rev.m_RefAction = one.Left(message); rev.GetSubject() = one.Mid(message + 1); } } refloglist.push_back(rev); } } else if (g_Git.m_IsUseGitDLL) { git_for_each_reflog_ent(CUnicodeUtils::GetUTF8(ref), AddToRefLoglist, &refloglist); for (size_t i = 0; i < refloglist.size(); ++i) refloglist[i].m_Ref.Format(_T("%s@{%d}"), ref, i); } else { CString cmd, out; GitRev rev; cmd.Format(_T("git.exe reflog show --pretty=\"%%H %%gD: %%gs\" --date=raw %s"), ref); if (g_Git.Run(cmd, &out, NULL, CP_UTF8)) return -1; int i = 0; CString prefix = ref + _T("@{"); int pos = 0; while (pos >= 0) { CString one = out.Tokenize(_T("\n"), pos); int refPos = one.Find(_T(' '), 0); if (refPos < 0) continue; rev.Clear(); CString hashStr = one.Left(refPos); rev.m_CommitHash = hashStr; rev.m_Ref.Format(_T("%s@{%d}"), ref, i++); int prefixPos = one.Find(prefix, refPos + 1); if (prefixPos != refPos + 1) continue; int spacePos = one.Find(_T(' '), prefixPos + prefix.GetLength() + 1); if (spacePos < 0) continue; CString timeStr = one.Mid(prefixPos + prefix.GetLength(), spacePos - prefixPos - prefix.GetLength()); rev.GetCommitterDate() = CTime(_ttoi(timeStr)); int action = one.Find(_T("}: "), spacePos + 1); if (action > 0) { action += 2; int message = one.Find(_T(":"), action); if (message > 0) { rev.m_RefAction = one.Mid(action + 1, message - action - 1); rev.GetSubject() = one.Right(one.GetLength() - message - 1); } } refloglist.push_back(rev); } } return 0; }