From 23713ac21c00031f5ab28e59df3f26959071808b Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Thu, 12 Mar 2015 16:32:46 +0100 Subject: [PATCH] Improve error handling in GitRev Signed-off-by: Sven Strickroth --- src/Git/GitRev.cpp | 30 +++++++++-- src/Git/GitRev.h | 3 ++ src/Git/GitRevLoglist.h | 7 +-- src/TortoiseGitBlame/LogListBlameAction.cpp | 10 +--- src/TortoiseGitBlame/PropertiesWnd.cpp | 10 +--- src/TortoiseGitBlame/TortoiseGitBlameData.cpp | 21 ++++---- src/TortoiseGitBlame/TortoiseGitBlameData.h | 2 +- src/TortoiseGitBlame/TortoiseGitBlameView.cpp | 12 ++--- src/TortoiseProc/BranchCombox.h | 13 +---- src/TortoiseProc/CommitDlg.cpp | 47 +++++----------- src/TortoiseProc/FileDiffDlg.cpp | 78 +++++++-------------------- src/TortoiseProc/FileDiffDlg.h | 17 +----- src/TortoiseProc/GitLogListAction.cpp | 19 ++----- src/TortoiseProc/GitLogListBase.cpp | 28 ++++------ src/TortoiseProc/GitLogListBase.h | 16 ------ src/TortoiseProc/LogDataVector.cpp | 8 +-- src/TortoiseProc/RebaseDlg.cpp | 14 ++--- 17 files changed, 106 insertions(+), 229 deletions(-) diff --git a/src/Git/GitRev.cpp b/src/Git/GitRev.cpp index d91950027..214910779 100644 --- a/src/Git/GitRev.cpp +++ b/src/Git/GitRev.cpp @@ -59,6 +59,7 @@ void GitRev::Clear() m_Body.Empty(); m_Subject.Empty(); m_CommitHash.Empty(); + m_sErr.Empty(); } int GitRev::CopyFrom(GitRev &rev,bool OmitParentAndMark) @@ -146,8 +147,19 @@ int GitRev::GetParentFromHash(CGitHash &hash) g_Git.CheckAndInitDll(); GIT_COMMIT commit; - if(git_get_commit_from_hash( &commit, hash.m_hash)) + try + { + if (git_get_commit_from_hash(&commit, hash.m_hash)) + { + m_sErr = _T("git_get_commit_from_hash failed for ") + hash.ToString(); + return -1; + } + } + catch (char* msg) + { + m_sErr = _T("Could not get parents of commit \"") + hash.ToString() + _T("\".\nlibgit reports:\n") + CString(msg); return -1; + } this->ParserParentFromCommit(&commit); git_free_commit(&commit); @@ -171,17 +183,22 @@ int GitRev::GetCommitFromHash_withoutLock(CGitHash &hash) try { if (git_get_commit_from_hash(&commit, hash.m_hash)) + { + m_sErr = _T("git_get_commit_from_hash failed for ") + hash.ToString(); return -1; + } } catch (char * msg) { - MessageBox(NULL, _T("Could not get commit \"") + hash.ToString() + _T("\".\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); + m_sErr = _T("Could not get commit \"") + hash.ToString() + _T("\".\nlibgit reports:\n") + CString(msg); return -1; } this->ParserFromCommit(&commit); git_free_commit(&commit); + m_sErr.Empty(); + return 0; } @@ -197,6 +214,7 @@ int GitRev::GetCommit(CString refname) { this->m_CommitHash.Empty(); this->m_Subject=_T("Working Copy"); + m_sErr.Empty(); return 0; } CStringA rev; @@ -206,15 +224,17 @@ int GitRev::GetCommit(CString refname) try { if (git_get_sha1(rev.GetBuffer(), sha)) + { + m_sErr = _T("Could not get SHA-1 of ref \"") + g_Git.FixBranchName(refname); return -1; + } } catch (char * msg) { - MessageBox(NULL, _T("Could not get SHA-1 of ref \"") + g_Git.FixBranchName(refname) + _T("\".\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); + m_sErr = _T("Could not get SHA-1 of ref \"") + g_Git.FixBranchName(refname) + _T("\".\nlibgit reports:\n") + CString(msg); return -1; } CGitHash hash((char*)sha); - GetCommitFromHash_withoutLock(hash); - return 0; + return GetCommitFromHash_withoutLock(hash); } diff --git a/src/Git/GitRev.h b/src/Git/GitRev.h index 653e3d899..e47b7b296 100644 --- a/src/Git/GitRev.h +++ b/src/Git/GitRev.h @@ -57,6 +57,8 @@ protected: CString m_Subject; CString m_Body; + CString m_sErr; + public: GitRev(void); CString GetAuthorName() @@ -127,6 +129,7 @@ public: int GetCommitFromHash(CGitHash &hash); int GetCommit(CString Rev); + CString GetLastErr() { return m_sErr; } public: void DbgPrint(); private: diff --git a/src/Git/GitRevLoglist.h b/src/Git/GitRevLoglist.h index c17e09933..e992cf8f3 100644 --- a/src/Git/GitRevLoglist.h +++ b/src/Git/GitRevLoglist.h @@ -64,13 +64,14 @@ public: { if (!m_IsDiffFiles && !m_CommitHash.IsEmpty()) { - SafeFetchFullInfo(&g_Git); + int ret = 0; + ret = SafeFetchFullInfo(&g_Git); InterlockedExchange(&m_IsDiffFiles, TRUE); if (m_IsDiffFiles && m_IsCommitParsed) InterlockedExchange(&m_IsFull, TRUE); - return 0; + return ret; } - return -1; + return 1; } public: diff --git a/src/TortoiseGitBlame/LogListBlameAction.cpp b/src/TortoiseGitBlame/LogListBlameAction.cpp index c7f441710..02e399199 100644 --- a/src/TortoiseGitBlame/LogListBlameAction.cpp +++ b/src/TortoiseGitBlame/LogListBlameAction.cpp @@ -189,14 +189,8 @@ void CGitBlameLogList::GetParentNumbers(GitRevLoglist* pRev, const std::vectorm_ParentHash.empty()) { - try - { - pRev->GetParentFromHash(pRev->m_CommitHash); - } - catch (const char* msg) - { - MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (pRev->GetParentFromHash(pRev->m_CommitHash)) + MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); } GIT_REV_LIST allParentHash; diff --git a/src/TortoiseGitBlame/PropertiesWnd.cpp b/src/TortoiseGitBlame/PropertiesWnd.cpp index d5f1fe457..4b382b6da 100644 --- a/src/TortoiseGitBlame/PropertiesWnd.cpp +++ b/src/TortoiseGitBlame/PropertiesWnd.cpp @@ -243,14 +243,8 @@ void CPropertiesWnd::UpdateProperties(GitRevLoglist* pRev) { if (pRev->m_ParentHash.empty()) { - try - { - pRev->GetParentFromHash(pRev->m_CommitHash); - } - catch (const char* msg) - { - MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (pRev->GetParentFromHash(pRev->m_CommitHash)) + MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); } CString hash = pRev->m_CommitHash.ToString(); m_CommitHash->SetValue(hash); diff --git a/src/TortoiseGitBlame/TortoiseGitBlameData.cpp b/src/TortoiseGitBlame/TortoiseGitBlameData.cpp index e5ad6bf90..2fe2ba893 100644 --- a/src/TortoiseGitBlame/TortoiseGitBlameData.cpp +++ b/src/TortoiseGitBlame/TortoiseGitBlameData.cpp @@ -216,16 +216,8 @@ void CTortoiseGitBlameData::ParseBlameOutput(BYTE_VECTOR &data, CGitHashMap & Ha for (auto it = hashes.begin(), it_end = hashes.end(); it != it_end; ++it) { CGitHash hash = *it; - GitRev *pRev; - try - { - pRev = GetRevForHash(HashToRev, hash); - } - catch (char* e) - { - MessageBox(nullptr, _T("Could not get revision by hash \"") + hash.ToString() + _T("\".\nlibgit reported:\n") + CString(e), _T("TortoiseGit"), MB_OK); - return; - } + CString err; + GitRev* pRev = GetRevForHash(HashToRev, hash, &err); if (pRev) { authors.push_back(pRev->GetAuthorName()); @@ -233,6 +225,7 @@ void CTortoiseGitBlameData::ParseBlameOutput(BYTE_VECTOR &data, CGitHashMap & Ha } else { + MessageBox(nullptr, err, _T("TortoiseGit"), MB_ICONERROR); authors.push_back(CString()); dates.push_back(CString()); } @@ -472,13 +465,17 @@ bool CTortoiseGitBlameData::ContainsOnlyFilename(const CString &filename) const return true; } -GitRevLoglist* CTortoiseGitBlameData::GetRevForHash(CGitHashMap& HashToRev, CGitHash& hash) +GitRevLoglist* CTortoiseGitBlameData::GetRevForHash(CGitHashMap& HashToRev, CGitHash& hash, CString* err) { auto it = HashToRev.find(hash); if (it == HashToRev.end()) { GitRevLoglist rev; - rev.GetCommitFromHash(hash); + if (rev.GetCommitFromHash(hash)) + { + *err = rev.GetLastErr(); + return nullptr; + } it = HashToRev.insert(std::make_pair(hash, rev)).first; } return &(it->second); diff --git a/src/TortoiseGitBlame/TortoiseGitBlameData.h b/src/TortoiseGitBlame/TortoiseGitBlameData.h index bd9bd79b7..cc4ac494b 100644 --- a/src/TortoiseGitBlame/TortoiseGitBlameData.h +++ b/src/TortoiseGitBlame/TortoiseGitBlameData.h @@ -119,7 +119,7 @@ public: } private: - static GitRevLoglist* GetRevForHash(CGitHashMap& HashToRev, CGitHash& hash); + static GitRevLoglist* GetRevForHash(CGitHashMap& HashToRev, CGitHash& hash, CString* err = nullptr); static CString UnquoteFilename(CStringA& s); std::vector m_Hash; diff --git a/src/TortoiseGitBlame/TortoiseGitBlameView.cpp b/src/TortoiseGitBlame/TortoiseGitBlameView.cpp index 35cc32dfb..2a89da6e1 100644 --- a/src/TortoiseGitBlame/TortoiseGitBlameView.cpp +++ b/src/TortoiseGitBlame/TortoiseGitBlameView.cpp @@ -371,16 +371,10 @@ void CTortoiseGitBlameView::OnRButtonUp(UINT /*nFlags*/, CPoint point) else { pRev = m_data.GetRev(line, GetLogData()->m_pLogCache->m_HashMap); - if (pRev->m_ParentHash.empty()) + if (pRev && pRev->m_ParentHash.empty()) { - try - { - pRev->GetParentFromHash(pRev->m_CommitHash); - } - catch (const char* msg) - { - MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (pRev->GetParentFromHash(pRev->m_CommitHash)) + MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); } } diff --git a/src/TortoiseProc/BranchCombox.h b/src/TortoiseProc/BranchCombox.h index 202cacb47..18b4333d4 100644 --- a/src/TortoiseProc/BranchCombox.h +++ b/src/TortoiseProc/BranchCombox.h @@ -139,18 +139,9 @@ protected: CString tooltip; GitRev rev; - try + if (rev.GetCommit(text)) { - if (rev.GetCommit(text)) - { - ASSERT(FALSE); - return; - } - } - catch (char* msg) - { - CString err(msg); - MessageBox(NULL, _T("Could not get commit \"") + text + _T("\".\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR); + MessageBox(nullptr, rev.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); return; } diff --git a/src/TortoiseProc/CommitDlg.cpp b/src/TortoiseProc/CommitDlg.cpp index e4946fe86..0b9aa2431 100644 --- a/src/TortoiseProc/CommitDlg.cpp +++ b/src/TortoiseProc/CommitDlg.cpp @@ -1286,15 +1286,8 @@ UINT CCommitDlg::StatusThread() if (!hash.IsEmpty()) { GitRev headRevision; - try - { - headRevision.GetParentFromHash(hash); - } - catch (char* msg) - { - CString err(msg); - MessageBox(_T("Could not get parent from HEAD.\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR); - } + if (headRevision.GetParentFromHash(hash)) + MessageBox(headRevision.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); // do not allow to show diff to "last" revision if it has more that one parent if (headRevision.ParentsCount() != 1) { @@ -1860,7 +1853,11 @@ bool CCommitDlg::HandleMenuItemClick(int cmd, CSciEdit * pSciEdit) // get selected hash if any CString selectedHash = dlg.GetSelectedHash(); GitRev rev; - rev.GetCommit(selectedHash); + if (rev.GetCommit(selectedHash)) + { + MessageBox(rev.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); + return false; + } CString message = rev.GetSubject() + _T("\r\n") + rev.GetBody(); pSciEdit->InsertText(message); } @@ -2336,14 +2333,8 @@ void CCommitDlg::OnBnClickedCommitAmend() if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty()) { GitRev rev; - try - { - rev.GetCommit(CString(_T("HEAD"))); - } - catch (const char *msg) - { - CMessageBox::Show(m_hWnd, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (rev.GetCommit(CString(_T("HEAD")))) + MessageBox(rev.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); m_AmendStr=rev.GetSubject()+_T("\n")+rev.GetBody(); } @@ -2557,14 +2548,8 @@ void CCommitDlg::OnBnClickedCommitSetDateTime() if (m_bCommitAmend) { GitRev headRevision; - try - { - headRevision.GetCommit(_T("HEAD")); - } - catch (const char *msg) - { - CMessageBox::Show(m_hWnd, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (headRevision.GetCommit(_T("HEAD"))) + MessageBox(headRevision.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); authordate = headRevision.GetAuthorDate(); } @@ -2629,14 +2614,8 @@ void CCommitDlg::OnBnClickedCommitSetauthor() if (m_bCommitAmend) { GitRev headRevision; - try - { - headRevision.GetCommit(_T("HEAD")); - } - catch (const char *msg) - { - CMessageBox::Show(m_hWnd, _T("Could not get HEAD commit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (headRevision.GetCommit(_T("HEAD"))) + MessageBox(headRevision.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); m_sAuthor.Format(_T("%s <%s>"), headRevision.GetAuthorName(), headRevision.GetAuthorEmail()); } diff --git a/src/TortoiseProc/FileDiffDlg.cpp b/src/TortoiseProc/FileDiffDlg.cpp index 83bd09992..9e8962868 100644 --- a/src/TortoiseProc/FileDiffDlg.cpp +++ b/src/TortoiseProc/FileDiffDlg.cpp @@ -142,14 +142,8 @@ void CFileDiffDlg::SetDiff(const CTGitPath * path, const CString &hash1, const C } else { - try - { - m_rev1.GetCommit(hash1); - } - catch (const char *msg) - { - MessageBox(_T("Could not get commit ") + hash1 + _T("\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (m_rev1.GetCommit(hash1)) + MessageBox(m_rev1.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); } logout.clear(); @@ -161,14 +155,8 @@ void CFileDiffDlg::SetDiff(const CTGitPath * path, const CString &hash1, const C } else { - try - { - m_rev2.GetCommit(hash2); - } - catch (const char *msg) - { - MessageBox(_T("Could not get commit ") + hash2 + _T("\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (m_rev2.GetCommit(hash2)) + MessageBox(m_rev2.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); } } @@ -274,21 +262,11 @@ BOOL CFileDiffDlg::OnInitDialog() this->m_ctrRev1Edit.SetWindowText(this->m_rev1.m_CommitHash.ToString()); else { - bool rev1fail = false; - try - { - rev1fail = !!m_rev1.GetCommit(m_strRev1); - } - catch (const char *msg) - { - rev1fail = true; - MessageBox(_T("Could not get commit ") + m_strRev1 + _T("\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } - if (rev1fail) + if (m_rev1.GetCommit(m_strRev1)) { CString msg; msg.Format(IDS_PROC_REFINVALID, m_strRev1); - this->m_FileListText += msg; + this->m_FileListText += msg + _T("\n") + m_rev1.GetLastErr(); } this->m_ctrRev1Edit.SetWindowText(m_strRev1); @@ -298,21 +276,11 @@ BOOL CFileDiffDlg::OnInitDialog() this->m_ctrRev2Edit.SetWindowText(this->m_rev2.m_CommitHash.ToString()); else { - bool rev2fail = false; - try - { - rev2fail = !!m_rev2.GetCommit(m_strRev2); - } - catch (const char *msg) - { - rev2fail = true; - MessageBox(_T("Could not get commit ") + m_strRev2 + _T("\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } - if (rev2fail) + if (m_rev2.GetCommit(m_strRev2)) { CString msg; msg.Format(IDS_PROC_REFINVALID, m_strRev2); - this->m_FileListText += msg; + this->m_FileListText += msg + _T("\n") + m_rev1.GetLastErr(); } this->m_ctrRev2Edit.SetWindowText(m_strRev2); @@ -1171,33 +1139,23 @@ void CFileDiffDlg::OnTimer(UINT_PTR nIDEvent) CString str; int mask = 0; this->m_ctrRev1Edit.GetWindowText(str); - try - { - if (!gitrev.GetCommit(str)) - { - m_rev1 = gitrev; - mask |= 0x1; - } - } - catch (const char *msg) + if (!gitrev.GetCommit(str)) { - CMessageBox::Show(m_hWnd, _T("Could not get commit ") + str + _T("\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); + m_rev1 = gitrev; + mask |= 0x1; } + else + MessageBox(gitrev.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); this->m_ctrRev2Edit.GetWindowText(str); - try - { - if (!gitrev.GetCommit(str)) - { - m_rev2 = gitrev; - mask |= 0x2; - } - } - catch (const char *msg) + if (!gitrev.GetCommit(str)) { - CMessageBox::Show(m_hWnd, _T("Could not get commit ") + str + _T("\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); + m_rev2 = gitrev; + mask |= 0x2; } + else + MessageBox(gitrev.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); this->SetURLLabels(mask); diff --git a/src/TortoiseProc/FileDiffDlg.h b/src/TortoiseProc/FileDiffDlg.h index 92256bddd..094736e14 100644 --- a/src/TortoiseProc/FileDiffDlg.h +++ b/src/TortoiseProc/FileDiffDlg.h @@ -102,22 +102,9 @@ protected: int FillRevFromString(GitRev *rev, CString str) { GitRev gitrev; - bool revfail = false; - try + if (gitrev.GetCommit(str)) { - revfail = !!gitrev.GetCommit(str); - } - catch (const char *msg) - { - CMessageBox::Show(m_hWnd, _T("Could not get commit ") + str + _T("\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - return -1; - } - - if (revfail) - { - CString msg; - msg.Format(_T("Reference %s is wrong"), str); - CMessageBox::Show(NULL, msg, _T("TortoiseGit"), MB_OK | MB_ICONERROR); + MessageBox(gitrev.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); return -1; } *rev=gitrev; diff --git a/src/TortoiseProc/GitLogListAction.cpp b/src/TortoiseProc/GitLogListAction.cpp index 238b82c03..0a82c7f4e 100644 --- a/src/TortoiseProc/GitLogListAction.cpp +++ b/src/TortoiseProc/GitLogListAction.cpp @@ -302,14 +302,8 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe if (pSelLogEntry->m_ParentHash.empty()) { - try - { - pSelLogEntry->GetParentFromHash(pSelLogEntry->m_CommitHash); - } - catch (const char* msg) - { - MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (pSelLogEntry->GetParentFromHash(pSelLogEntry->m_CommitHash)) + MessageBox(pSelLogEntry->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); } if (!pSelLogEntry->m_ParentHash.empty()) @@ -522,14 +516,9 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe } GitRev lastRevision; - try - { - lastRevision.GetParentFromHash(hashLast); - } - catch (char* msg) + if (lastRevision.GetParentFromHash(hashLast)) { - CString err(msg); - MessageBox(_T("Could not get parent(s) of ") + hashLast.ToString() + _T(".\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR); + MessageBox(lastRevision.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); break; } diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index dcac548de..c5d79b216 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -198,13 +198,11 @@ int CGitLogListBase::AsyncDiffThread() { g_Git.GetCommitDiffList(pRev->m_CommitHash.ToString(),this->m_HeadHash.ToString(), pRev->GetFiles(this)); } - int dummyAction = 0; - int *action = &dummyAction; - SafeGetAction(pRev, &action); - *action = 0; - - for (int j = 0; j < pRev->GetFiles(this).GetCount(); ++j) - *action |= pRev->GetFiles(this)[j].m_Action; + int& action = pRev->GetAction(this); + action = 0; + const CTGitPathList& files = pRev->GetFiles(this); + for (int j = 0; j < files.GetCount(); ++j) + action |= files[j].m_Action; CString err; if (pRev->GetUnRevFiles().FillUnRev(CTGitPath::LOGACTIONS_UNVER, nullptr, &err)) @@ -1517,8 +1515,7 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec, rect); // Draw the icon(s) into the compatible DC - int action = SafeGetAction(pLogEntry); - + int action = pLogEntry->GetAction(this); if (!pLogEntry->m_IsDiffFiles) { ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hFetchIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL); @@ -1718,14 +1715,8 @@ void CGitLogListBase::GetParentHashes(GitRev *pRev, GIT_REV_LIST &parentHash) { if (pRev->m_ParentHash.empty()) { - try - { - pRev->GetParentFromHash(pRev->m_CommitHash); - } - catch (const char* msg) - { - MessageBox(_T("Could not get parent.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - } + if (pRev->GetParentFromHash(pRev->m_CommitHash)) + MessageBox(pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); } parentHash = pRev->m_ParentHash; } @@ -4275,10 +4266,9 @@ CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem) if (!pLogEntry->m_IsDiffFiles) return CString(MAKEINTRESOURCE(IDS_PROC_LOG_FETCHINGFILES)); + int actions = pLogEntry->GetAction(this); CString sToolTipText; - DWORD actions = SafeGetAction(pLogEntry); - CString actionText; if (actions & CTGitPath::LOGACTIONS_MODIFIED) actionText += CTGitPath::GetActionName(CTGitPath::LOGACTIONS_MODIFIED); diff --git a/src/TortoiseProc/GitLogListBase.h b/src/TortoiseProc/GitLogListBase.h index 4cbb57bf4..280111935 100644 --- a/src/TortoiseProc/GitLogListBase.h +++ b/src/TortoiseProc/GitLogListBase.h @@ -575,22 +575,6 @@ protected: int AsyncDiffThread(); bool m_AsyncThreadExited; - int SafeGetAction(GitRevLoglist* rev, int** ptr = nullptr) - { - try - { - int *p = &rev->GetAction(this); - if (ptr) - *ptr = p; - return *p; - } - catch (const char* msg) - { - MessageBox(_T("Could not get action of commit ") + rev->m_CommitHash.ToString() + _T(".\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); - return 0; - } - } - public: void SafeTerminateAsyncDiffThread() { diff --git a/src/TortoiseProc/LogDataVector.cpp b/src/TortoiseProc/LogDataVector.cpp index 76a89d3ab..203b56b7c 100644 --- a/src/TortoiseProc/LogDataVector.cpp +++ b/src/TortoiseProc/LogDataVector.cpp @@ -156,13 +156,9 @@ int CLogDataVector::ParserFromLog(CTGitPath *path, int count, int infomask, CStr if (!pRev->m_IsFull && (infomask & CGit::LOG_INFO_FULL_DIFF)) { - try + if (pRev->SafeFetchFullInfo(&g_Git)) { - pRev->SafeFetchFullInfo(&g_Git); - } - catch (char * g_last_error) - { - MessageBox(NULL, _T("Could not fetch full info of a commit.\nlibgit reports:\n") + CString(g_last_error), _T("TortoiseGit"), MB_ICONERROR); + MessageBox(nullptr, pRev->GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); return -1; } } diff --git a/src/TortoiseProc/RebaseDlg.cpp b/src/TortoiseProc/RebaseDlg.cpp index 561097f89..c7f7381e8 100644 --- a/src/TortoiseProc/RebaseDlg.cpp +++ b/src/TortoiseProc/RebaseDlg.cpp @@ -638,13 +638,11 @@ void CRebaseDlg::AddBranchToolTips(CHistoryCombo *pBranch) CString tooltip; GitRev rev; - try + if (rev.GetCommit(text)) { - rev.GetCommit(text); - } - catch (const char *msg) - { - CMessageBox::Show(m_hWnd, _T("Could not get commit ") + text + _T("\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); + MessageBox(rev.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); + pBranch->DisableTooltip(); + return; } tooltip.Format(_T("%s: %s\n%s: %s <%s>\n%s: %s\n%s:\n%s\n%s"), @@ -1987,7 +1985,9 @@ LRESULT CRebaseDlg::OnRebaseUpdateUI(WPARAM,LPARAM) // Since the new commit is done and the HEAD points to it, // just using the new body modified by git self. GitRev headRevision; - headRevision.GetCommit(_T("HEAD")); + if (headRevision.GetCommit(_T("HEAD"))) + MessageBox(headRevision.GetLastErr(), _T("TortoiseGit"), MB_ICONERROR); + m_LogMessageCtrl.SetText(headRevision.GetSubject() + _T("\n") + headRevision.GetBody()); } else -- 2.11.4.GIT