From 443da3377f3dcf8ac13bbcbb854719e9c833603a Mon Sep 17 00:00:00 2001 From: Sup Yut Sum Date: Thu, 28 Mar 2013 19:03:02 +0800 Subject: [PATCH] Add try-catch blocks and critical sections to wrap libgit functions in CLogDataVector::ParserFromLog() Signed-off-by: Sup Yut Sum --- src/TortoiseProc/LogDataVector.cpp | 46 +++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/TortoiseProc/LogDataVector.cpp b/src/TortoiseProc/LogDataVector.cpp index 14d2f8d50..1bc73ee49 100644 --- a/src/TortoiseProc/LogDataVector.cpp +++ b/src/TortoiseProc/LogDataVector.cpp @@ -82,6 +82,7 @@ int CLogDataVector::ParserFromLog(CTGitPath *path, int count, int infomask, CStr git_init(); GIT_LOG handle; + g_Git.m_critGitDllSec.Lock(); try { if (git_open_log(&handle,CUnicodeUtils::GetMulti(cmd, CP_UTF8).GetBuffer())) @@ -89,18 +90,47 @@ int CLogDataVector::ParserFromLog(CTGitPath *path, int count, int infomask, CStr return -1; } } - catch (char * g_last_error) + catch (char* msg) { - MessageBox(NULL, CString(g_last_error), _T("TortoiseGit"), MB_ICONERROR); + g_Git.m_critGitDllSec.Unlock(); + MessageBox(NULL, _T("Could not open log.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); return -1; } + g_Git.m_critGitDllSec.Unlock(); - git_get_log_firstcommit(handle); - - GIT_COMMIT commit; + g_Git.m_critGitDllSec.Lock(); + try + { + [&]{ git_get_log_firstcommit(handle); }(); + } + catch (char* msg) + { + g_Git.m_critGitDllSec.Unlock(); + MessageBox(NULL, _T("Could not get first commit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); + return -1; + } + g_Git.m_critGitDllSec.Unlock(); - while (git_get_log_nextcommit(handle, &commit, infomask & CGit::LOG_INFO_FOLLOW) == 0) + int ret = 0; + while (ret == 0) { + GIT_COMMIT commit; + g_Git.m_critGitDllSec.Lock(); + try + { + [&]{ ret = git_get_log_nextcommit(handle, &commit, infomask & CGit::LOG_INFO_FOLLOW); }(); + } + catch (char* msg) + { + g_Git.m_critGitDllSec.Unlock(); + MessageBox(NULL, _T("Could not get next commit.\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR); + break; + } + g_Git.m_critGitDllSec.Unlock(); + + if (ret) + break; + if (commit.m_ignore == 1) { git_free_commit(&commit); @@ -112,7 +142,9 @@ int CLogDataVector::ParserFromLog(CTGitPath *path, int count, int infomask, CStr GitRev *pRev = this->m_pLogCache->GetCacheData(hash); char *note=NULL; + g_Git.m_critGitDllSec.Lock(); git_get_notes(commit.m_hash,¬e); + g_Git.m_critGitDllSec.Unlock(); if(note) { pRev->m_Notes.Empty(); @@ -150,7 +182,9 @@ int CLogDataVector::ParserFromLog(CTGitPath *path, int count, int infomask, CStr } + g_Git.m_critGitDllSec.Lock(); git_close_log(handle); + g_Git.m_critGitDllSec.Unlock(); return 0; } -- 2.11.4.GIT