From 28b82f0ad376dea3abdac11b10335ab97ef0336d Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 14 Feb 2016 14:51:19 +0100 Subject: [PATCH] Improve type safety Signed-off-by: Sven Strickroth --- src/TortoiseProc/GitLogListAction.cpp | 66 +++++++++++++------------- src/TortoiseProc/GitLogListBase.cpp | 89 +++++++++++++++++------------------ src/TortoiseProc/GitLogListBase.h | 29 +++++------- src/TortoiseProc/LogDlg.cpp | 54 ++++++++++----------- src/TortoiseProc/RebaseDlg.cpp | 32 ++++++------- src/TortoiseProc/RefLogDlg.cpp | 30 ++++++------ src/TortoiseProc/RefLogDlg.h | 2 +- src/TortoiseProc/StatGraphDlg.cpp | 8 ++-- src/TortoiseProc/refloglist.cpp | 7 +-- 9 files changed, 153 insertions(+), 164 deletions(-) diff --git a/src/TortoiseProc/GitLogListAction.cpp b/src/TortoiseProc/GitLogListAction.cpp index 79d33c273..4dd6ad212 100644 --- a/src/TortoiseProc/GitLogListAction.cpp +++ b/src/TortoiseProc/GitLogListAction.cpp @@ -79,7 +79,7 @@ int CGitLogList::RevertSelectedCommits(int parent) while(pos) { int index = GetNextSelectedItem(pos); - GitRev * r1 = reinterpret_cast(m_arShownList.GetAt(index)); + GitRev* r1 = m_arShownList.SafeGetAt(index); if (progress.IsVisible()) { @@ -239,7 +239,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe if (indexNext < 0) return; - GitRevLoglist* pSelLogEntry = reinterpret_cast(m_arShownList.GetAt(indexNext)); + GitRevLoglist* pSelLogEntry = m_arShownList.SafeGetAt(indexNext); theApp.DoWaitCursor(1); switch (cmd&0xFFFF) @@ -265,7 +265,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe break; case ID_GNUDIFF1: // compare with WC, unified { - GitRev * r1 = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); + GitRev* r1 = m_arShownList.SafeGetAt(FirstSelect); bool bMerge = false, bCombine = false; CString hash2; if(!r1->m_CommitHash.IsEmpty()) @@ -331,16 +331,16 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe case ID_GNUDIFF2: // compare two revisions, unified { - GitRev * r1 = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); - GitRev * r2 = reinterpret_cast(m_arShownList.GetAt(LastSelect)); + GitRev* r1 = m_arShownList.SafeGetAt(FirstSelect); + GitRev* r2 = m_arShownList.SafeGetAt(LastSelect); CAppUtils::StartShowUnifiedDiff(nullptr, CTGitPath(), r2->m_CommitHash.ToString(), CTGitPath(), r1->m_CommitHash.ToString()); } break; case ID_COMPARETWO: // compare two revisions { - GitRev * r1 = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); - GitRev * r2 = reinterpret_cast(m_arShownList.GetAt(LastSelect)); + GitRev* r1 = m_arShownList.SafeGetAt(FirstSelect); + GitRev* r2 = m_arShownList.SafeGetAt(LastSelect); if (m_Path.IsDirectory() || !(m_ShowMask & CGit::LOG_INFO_FOLLOW)) CGitDiff::DiffCommit(this->m_Path, r1,r2); else @@ -349,7 +349,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe // start with 1 (0 = working copy changes) for (int i = 1; i < FirstSelect; ++i) { - GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(i)); + GitRevLoglist* first = m_arShownList.SafeGetAt(i); CTGitPathList list = first->GetFiles(NULL); const CTGitPath* file = list.LookForGitPath(path1); if (file && !file->GetGitOldPathString().IsEmpty()) @@ -358,7 +358,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe CString path2 = path1; for (int i = FirstSelect; i < LastSelect; ++i) { - GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(i)); + GitRevLoglist* first = m_arShownList.SafeGetAt(i); CTGitPathList list = first->GetFiles(NULL); const CTGitPath* file = list.LookForGitPath(path2); if (file && !file->GetGitOldPathString().IsEmpty()) @@ -383,7 +383,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe // start with 1 (0 = working copy changes) for (int i = 1; i < FirstSelect; ++i) { - GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(i)); + GitRevLoglist* first = m_arShownList.SafeGetAt(i); CTGitPathList list = first->GetFiles(NULL); const CTGitPath* file = list.LookForGitPath(path1); if (file && !file->GetGitOldPathString().IsEmpty()) @@ -432,14 +432,14 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe // start with 1 (0 = working copy changes) for (int i = 1; i < indexNext; ++i) { - GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(i)); + GitRevLoglist* first = m_arShownList.SafeGetAt(i); CTGitPathList list = first->GetFiles(NULL); const CTGitPath* file = list.LookForGitPath(path1); if (file && !file->GetGitOldPathString().IsEmpty()) path1 = file->GetGitOldPathString(); } CString path2 = path1; - GitRevLoglist* first = reinterpret_cast(m_arShownList.GetAt(indexNext)); + GitRevLoglist* first = m_arShownList.SafeGetAt(indexNext); CTGitPathList list = first->GetFiles(NULL); const CTGitPath* file = list.LookForGitPath(path2); if (file && !file->GetGitOldPathString().IsEmpty()) @@ -466,7 +466,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe case ID_LOG_VIEWRANGE: case ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE: { - GitRev* pLastEntry = reinterpret_cast(m_arShownList.SafeGetAt(LastSelect)); + GitRev* pLastEntry = m_arShownList.SafeGetAt(LastSelect); CString sep = _T(".."); if ((cmd & 0xFFFF) == ID_LOG_VIEWRANGE_REACHABLEFROMONLYONE) @@ -599,8 +599,8 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe } } - GitRev* pFirstEntry = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); - GitRev* pLastEntry = reinterpret_cast(m_arShownList.GetAt(LastSelect)); + GitRev* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect); + GitRev* pLastEntry = m_arShownList.SafeGetAt(LastSelect); if(pFirstEntry->m_CommitHash != hashFirst || pLastEntry->m_CommitHash != hashLast) { CMessageBox::Show(NULL, IDS_PROC_CANNOTCOMBINE, IDS_APPNAME, MB_OK); @@ -678,7 +678,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe CCommitDlg dlg; for (int i = FirstSelect; i <= LastSelect; ++i) { - GitRev* pRev = reinterpret_cast(m_arShownList.GetAt(i)); + GitRev* pRev = m_arShownList.SafeGetAt(i); dlg.m_sLogMessage+=pRev->GetSubject()+_T("\n")+pRev->GetBody(); dlg.m_sLogMessage+=_T("\n"); } @@ -741,8 +741,8 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe while(pos2) { int indexNext2 = GetNextSelectedItem(pos2); - dlg.m_CommitList.m_logEntries.push_back(((GitRevLoglist*)m_arShownList[indexNext2])->m_CommitHash); - dlg.m_CommitList.m_LogCache.m_HashMap[((GitRevLoglist*)m_arShownList[indexNext2])->m_CommitHash] = *(GitRevLoglist*)m_arShownList[indexNext2]; + dlg.m_CommitList.m_logEntries.push_back(m_arShownList.SafeGetAt(indexNext2)->m_CommitHash); + dlg.m_CommitList.m_LogCache.m_HashMap[m_arShownList.SafeGetAt(indexNext2)->m_CommitHash] = *m_arShownList.SafeGetAt(indexNext2); dlg.m_CommitList.m_logEntries.GetGitRevAt(dlg.m_CommitList.m_logEntries.size() - 1).GetRebaseAction() |= LOGACTIONS_REBASE_PICK; } @@ -807,7 +807,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe POSITION pos2 = GetFirstSelectedItemPosition(); while (pos2) { - CString ref = ((GitRevLoglist*)m_arShownList[GetNextSelectedItem(pos2)])->m_Ref; + CString ref = m_arShownList.SafeGetAt(GetNextSelectedItem(pos2))->m_Ref; if (ref.Find(_T("refs/")) == 0) ref = ref.Mid(5); int refpos = ref.ReverseFind('{'); @@ -836,7 +836,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe { CString sCmd = _T("/command:log"); sCmd += _T(" /path:\"") + g_Git.m_CurrentDir + _T("\" "); - GitRev * r1 = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); + GitRev* r1 = m_arShownList.SafeGetAt(FirstSelect); sCmd += _T(" /endrev:") + r1->m_CommitHash.ToString(); CAppUtils::RunTortoiseGitProc(sCmd); } @@ -847,7 +847,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe CString sCmd = _T("/command:formatpatch"); sCmd += _T(" /path:\"") + g_Git.m_CurrentDir + _T("\" "); - GitRev * r1 = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); + GitRev* r1 = m_arShownList.SafeGetAt(FirstSelect); GitRev * r2 = NULL; if(select == 1) { @@ -855,7 +855,7 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe } else { - r2 = reinterpret_cast(m_arShownList.GetAt(LastSelect)); + r2 = m_arShownList.SafeGetAt(LastSelect); if( this->m_IsOldFirst ) { sCmd += _T(" /startrev:") + r1->m_CommitHash.ToString() + _T("~1"); @@ -875,8 +875,8 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe break; case ID_BISECTSTART: { - GitRev * first = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); - GitRev * last = reinterpret_cast(m_arShownList.GetAt(LastSelect)); + GitRev* first = m_arShownList.SafeGetAt(FirstSelect); + GitRev* last = m_arShownList.SafeGetAt(LastSelect); ASSERT(first != NULL && last != NULL); CString firstBad = first->m_CommitHash.ToString(); @@ -892,14 +892,14 @@ void CGitLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect, CMe break; case ID_BISECTGOOD: { - GitRev *first = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); + GitRev* first = m_arShownList.SafeGetAt(FirstSelect); if (CAppUtils::BisectOperation(_T("good"), !first->m_CommitHash.IsEmpty() ? first->m_CommitHash.ToString() : _T(""))) Refresh(); } break; case ID_BISECTBAD: { - GitRev *first = reinterpret_cast(m_arShownList.GetAt(FirstSelect)); + GitRev* first = m_arShownList.SafeGetAt(FirstSelect); if (CAppUtils::BisectOperation(_T("bad"), !first->m_CommitHash.IsEmpty() ? first->m_CommitHash.ToString() : _T(""))) Refresh(); } @@ -1221,11 +1221,11 @@ void CGitLogList::SetSelectedRebaseAction(int action) while(pos) { index = GetNextSelectedItem(pos); - if (((GitRevLoglist*)m_arShownList[index])->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE) || (index == GetItemCount() - 1 && action == LOGACTIONS_REBASE_SQUASH)) + if (m_arShownList.SafeGetAt(index)->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE) || (index == GetItemCount() - 1 && action == LOGACTIONS_REBASE_SQUASH)) continue; - if (!m_bIsCherryPick && ((GitRevLoglist*)m_arShownList[index])->ParentsCount() > 1 && action == LOGACTIONS_REBASE_SQUASH) + if (!m_bIsCherryPick && m_arShownList.SafeGetAt(index)->ParentsCount() > 1 && action == LOGACTIONS_REBASE_SQUASH) continue; - ((GitRevLoglist*)m_arShownList[index])->GetRebaseAction() = action; + m_arShownList.SafeGetAt(index)->GetRebaseAction() = action; CRect rect; this->GetItemRect(index,&rect,LVIR_BOUNDS); this->InvalidateRect(rect); @@ -1246,9 +1246,9 @@ void CGitLogList::SetUnselectedRebaseAction(int action) continue; } - if (((GitRevLoglist*)m_arShownList[i])->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE) || (i == GetItemCount() - 1 && action == LOGACTIONS_REBASE_SQUASH) || (!m_bIsCherryPick && action == LOGACTIONS_REBASE_SQUASH && ((GitRevLoglist*)m_arShownList[i])->ParentsCount() != 1)) + if (m_arShownList.SafeGetAt(index)->GetRebaseAction() & (LOGACTIONS_REBASE_CURRENT | LOGACTIONS_REBASE_DONE) || (i == GetItemCount() - 1 && action == LOGACTIONS_REBASE_SQUASH) || (!m_bIsCherryPick && action == LOGACTIONS_REBASE_SQUASH && m_arShownList.SafeGetAt(index)->ParentsCount() != 1)) continue; - ((GitRevLoglist*)m_arShownList[i])->GetRebaseAction() = action; + m_arShownList.SafeGetAt(i)->GetRebaseAction() = action; CRect rect; this->GetItemRect(i, &rect, LVIR_BOUNDS); this->InvalidateRect(rect); @@ -1264,7 +1264,7 @@ void CGitLogList::ShiftSelectedRebaseAction() while(pos) { index = GetNextSelectedItem(pos); - int *action = &((GitRevLoglist*)m_arShownList[index])->GetRebaseAction(); + int* action = &(m_arShownList.SafeGetAt(index))->GetRebaseAction(); switch (*action) { case LOGACTIONS_REBASE_PICK: @@ -1275,7 +1275,7 @@ void CGitLogList::ShiftSelectedRebaseAction() break; case LOGACTIONS_REBASE_EDIT: *action = LOGACTIONS_REBASE_SQUASH; - if (index == GetItemCount() - 1 && (m_bIsCherryPick || ((GitRevLoglist*)m_arShownList[index])->m_ParentHash.size() == 1)) + if (index == GetItemCount() - 1 && (m_bIsCherryPick || m_arShownList.SafeGetAt(index)->m_ParentHash.size() == 1)) *action = LOGACTIONS_REBASE_PICK; break; case LOGACTIONS_REBASE_SQUASH: diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index d9fd4d146..0019d3f11 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -224,9 +224,9 @@ int CGitLogListBase::AsyncDiffThread() { // fetch change file list for (int i = GetTopIndex(); !m_AsyncThreadExit && i <= GetTopIndex() + GetCountPerPage(); ++i) { - if(i < m_arShownList.GetCount()) + if (i < (int)m_arShownList.size()) { - GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(i); + GitRevLoglist* data = m_arShownList.SafeGetAt(i); if(data->m_CommitHash == pRev->m_CommitHash) { ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)i,0); @@ -242,7 +242,7 @@ int CGitLogListBase::AsyncDiffThread() if(nItem>=0) { - GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem); + GitRevLoglist* data = m_arShownList.SafeGetAt(nItem); if(data) if(data->m_CommitHash == pRev->m_CommitHash) { @@ -495,7 +495,7 @@ void CGitLogListBase::FillBackGround(HDC hdc, DWORD_PTR Index, CRect &rect) rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; GetItem(&rItem); - GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(Index); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(Index); HBRUSH brush = NULL; if (!(rItem.state & LVIS_SELECTED)) @@ -571,7 +571,7 @@ void DrawUpTriangle(HDC hdc, CRect rect, COLORREF color, int bold) void CGitLogListBase::DrawTagBranchMessage(HDC hdc, CRect &rect, INT_PTR index, std::vector &refList) { - GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index); + GitRevLoglist* data = m_arShownList.SafeGetAt(index); CRect rt=rect; LVITEM rItem = { 0 }; rItem.mask = LVIF_STATE; @@ -1077,7 +1077,7 @@ void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index) { // TODO: unfinished // return; - GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(index); + GitRevLoglist* data = m_arShownList.SafeGetAt(index); if(data->m_CommitHash.IsEmpty()) return; @@ -1177,9 +1177,9 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) COLORREF crText = GetSysColor(COLOR_WINDOWTEXT); - if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec) + if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec) { - GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec); + GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec); if (data) { HGDIOBJ hGdiObj = nullptr; @@ -1225,7 +1225,7 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) } } } - if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec) + if (m_arShownList.size() == pLVCD->nmcd.dwItemSpec) { if (m_bStrictStopped) crText = GetSysColor(COLOR_GRAYTEXT); @@ -1237,14 +1237,14 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) break; case CDDS_ITEMPREPAINT|CDDS_ITEM|CDDS_SUBITEM: { - if ((m_bStrictStopped)&&(m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec)) + if (m_bStrictStopped && m_arShownList.size() == pLVCD->nmcd.dwItemSpec) { pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS); } if (pLVCD->iSubItem == LOGLIST_GRAPH && !HasFilterText() && (m_ShowFilter & FILTERSHOW_MERGEPOINTS)) { - if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) ) + if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec && !this->m_IsRebaseReplaceGraph) { CRect rect; GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_LABEL, rect); @@ -1252,7 +1252,7 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) //TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right); FillBackGround(pLVCD->nmcd.hdc, pLVCD->nmcd.dwItemSpec,rect); - GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec); + GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec); if( !data ->m_CommitHash.IsEmpty()) DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec); @@ -1270,9 +1270,9 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) m_RefLabelPosMap.clear(); } - if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec) + if (m_arShownList.size() > pLVCD->nmcd.dwItemSpec) { - GitRevLoglist* data = (GitRevLoglist*)m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec); + GitRevLoglist* data = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec); if (!m_HashMap[data->m_CommitHash].empty() && !(data->GetRebaseAction() & LOGACTIONS_REBASE_DONE)) { @@ -1479,14 +1479,14 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) } *pResult = CDRF_DODEFAULT; - if (m_arShownList.GetCount() <= (INT_PTR)pLVCD->nmcd.dwItemSpec) + if (m_arShownList.size() <= pLVCD->nmcd.dwItemSpec) return; int nIcons = 0; int iconwidth = ::GetSystemMetrics(SM_CXSMICON); int iconheight = ::GetSystemMetrics(SM_CYSMICON); - GitRevLoglist* pLogEntry = reinterpret_cast(m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec)); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pLVCD->nmcd.dwItemSpec); CRect rect; GetSubItemRect((int)pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect); //TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right); @@ -1605,10 +1605,7 @@ void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) return; // Which item number? - int itemid = pItem->iItem; - GitRevLoglist* pLogEntry = nullptr; - if (itemid < m_arShownList.GetCount()) - pLogEntry = reinterpret_cast(m_arShownList.SafeGetAt(pItem->iItem)); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pItem->iItem); CString temp; if(m_IsOldFirst) @@ -1618,7 +1615,7 @@ void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) } else { - temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem); + temp.Format(_T("%d"), m_arShownList.size() - pItem->iItem); } // Which column? @@ -1694,12 +1691,12 @@ void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) bool CGitLogListBase::IsOnStash(int index) { - GitRevLoglist* rev = reinterpret_cast(m_arShownList.SafeGetAt(index)); + GitRevLoglist* rev = m_arShownList.SafeGetAt(index); if (IsStash(rev)) return true; if (index > 0) { - GitRevLoglist* preRev = reinterpret_cast(m_arShownList.SafeGetAt(index - 1)); + GitRevLoglist* preRev = m_arShownList.SafeGetAt(index - 1); if (IsStash(preRev)) return preRev->m_ParentHash.size() == 2 && preRev->m_ParentHash[1] == rev->m_CommitHash; } @@ -1750,7 +1747,7 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) // if the user selected the info text telling about not all revisions shown due to // the "stop on copy/rename" option, we also don't show the context menu - if ((m_bStrictStopped)&&(selIndex == m_arShownList.GetCount())) + if (m_bStrictStopped && selIndex == (int)m_arShownList.size()) return; // if the context menu is invoked through the keyboard, we have to use @@ -1773,7 +1770,7 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) if (indexNext < 0) return; - GitRevLoglist* pSelLogEntry = reinterpret_cast(m_arShownList.SafeGetAt(indexNext)); + GitRevLoglist* pSelLogEntry = m_arShownList.SafeGetAt(indexNext); if (pSelLogEntry == nullptr) return; #if 0 @@ -2003,7 +2000,7 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) if (CTGitPath(g_Git.m_CurrentDir).IsBisectActive()) { - GitRevLoglist* pFirstEntry = reinterpret_cast(m_arShownList.SafeGetAt(FirstSelect)); + GitRevLoglist* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect); if (m_ContextMenuMask&GetContextMenuBit(ID_BISECTGOOD) && !IsBisect(pFirstEntry)) { popup.AppendMenuIcon(ID_BISECTGOOD, IDS_MENUBISECTGOOD, IDI_THUMB_UP); @@ -2228,7 +2225,7 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) if (!pSelLogEntry->m_CommitHash.IsEmpty()) { CString firstSelHash = pSelLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()); - GitRevLoglist* pLastEntry = reinterpret_cast(m_arShownList.SafeGetAt(LastSelect)); + GitRevLoglist* pLastEntry = m_arShownList.SafeGetAt(LastSelect); CString lastSelHash = pLastEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()); CString menu; menu.Format(IDS_SHOWLOG_OF, (LPCTSTR)(lastSelHash + _T("..") + firstSelHash)); @@ -2272,8 +2269,8 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) CGitHash hash; if (g_Git.GetHash(hash, head)) MessageBox(g_Git.GetGitLastErr(_T("Could not get hash of ") + head + _T(".")), _T("TortoiseGit"), MB_ICONERROR); - GitRevLoglist* pFirstEntry = reinterpret_cast(m_arShownList.SafeGetAt(FirstSelect)); - GitRevLoglist* pLastEntry = reinterpret_cast(m_arShownList.SafeGetAt(LastSelect)); + GitRevLoglist* pFirstEntry = m_arShownList.SafeGetAt(FirstSelect); + GitRevLoglist* pLastEntry = m_arShownList.SafeGetAt(LastSelect); if (pFirstEntry->m_CommitHash == hashFirst && pLastEntry->m_CommitHash == hash) { popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE); bAddSeparator = true; @@ -2299,7 +2296,7 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) popup.AppendMenu(MF_SEPARATOR, NULL); } - if (m_hasWC && !isMergeActive && !isStash && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !reinterpret_cast(m_arShownList.SafeGetAt(FirstSelect))->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive()) + if (m_hasWC && !isMergeActive && !isStash && (m_ContextMenuMask & GetContextMenuBit(ID_BISECTSTART)) && GetSelectedCount() == 2 && !m_arShownList.SafeGetAt(FirstSelect)->m_CommitHash.IsEmpty() && !CTGitPath(g_Git.m_CurrentDir).IsBisectActive()) { popup.AppendMenuIcon(ID_BISECTSTART, IDS_MENUBISECTSTART, IDI_BISECT); popup.AppendMenu(MF_SEPARATOR, NULL); @@ -2424,7 +2421,7 @@ bool CGitLogListBase::IsSelectionContinuous() } POSITION pos = GetFirstSelectedItemPosition(); - bool bContinuous = (m_arShownList.GetCount() == (INT_PTR)m_logEntries.size()); + bool bContinuous = (m_arShownList.size() == m_logEntries.size()); if (bContinuous) { int itemindex = GetNextSelectedItem(pos); @@ -2462,7 +2459,7 @@ void CGitLogListBase::CopySelectionToClipBoard(int toCopy) { CString sLogCopyText; CString sPaths; - GitRevLoglist* pLogEntry = reinterpret_cast(m_arShownList.SafeGetAt(GetNextSelectedItem(pos))); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(GetNextSelectedItem(pos)); if (toCopy == ID_COPY_ALL) { @@ -2543,7 +2540,7 @@ void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult) if (pFindInfo->lvfi.flags & LVFI_PARAM) return; - if ((pFindInfo->iStart < 0)||(pFindInfo->iStart >= m_arShownList.GetCount())) + if (pFindInfo->iStart < 0 || pFindInfo->iStart >= (int)m_arShownList.size()) return; if (pFindInfo->lvfi.psz == 0) return; @@ -3042,7 +3039,7 @@ UINT CGitLogListBase::LogThread() continue; if (lastSelectedHashNItem == -1 && hash == m_lastSelectedHash) - lastSelectedHashNItem = (int)m_arShownList.GetCount() - 1; + lastSelectedHashNItem = (int)m_arShownList.size() - 1; t2 = GetTickCount64(); @@ -3970,13 +3967,13 @@ int CGitLogListBase::GetHeadIndex() if(m_HeadHash.IsEmpty()) return -1; - for (int i = 0; i < m_arShownList.GetCount(); ++i) + for (size_t i = 0; i < m_arShownList.size(); ++i) { - GitRev *pRev = (GitRev*)m_arShownList.SafeGetAt(i); + GitRev* pRev = m_arShownList.SafeGetAt(i); if(pRev) { if(pRev->m_CommitHash.ToString() == m_HeadHash ) - return i; + return (int)i; } } return -1; @@ -4027,7 +4024,7 @@ LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam* return 0; } - INT_PTR cnt = m_arShownList.GetCount(); + int cnt = (int)m_arShownList.size(); if(m_pFindDialog->IsRef()) { @@ -4046,7 +4043,7 @@ LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam* { for (i = 0; i < cnt; ++i) { - GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i); + GitRev* pLogEntry = m_arShownList.SafeGetAt(i); if(pLogEntry && pLogEntry->m_CommitHash == hash) { bFound = true; @@ -4091,7 +4088,7 @@ LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam* } } - GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(i); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(i); CString str; str+=pLogEntry->m_CommitHash.ToString(); @@ -4199,7 +4196,7 @@ LRESULT CGitLogListBase::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam* } else { - GitRev* pLogEntry = (GitRev*)m_arShownList.SafeGetAt(i); + GitRev* pLogEntry = m_arShownList.SafeGetAt(i); if (pLogEntry) m_highlight = pLogEntry->m_CommitHash; } @@ -4295,7 +4292,7 @@ BOOL CGitLogListBase::OnToolTipText(UINT /*id*/, NMHDR* pNMHDR, LRESULT* pResult { CString branch; CGit::REF_TYPE type = CGit::REF_TYPE::LOCAL_BRANCH; - if (IsMouseOnRefLabel((GitRevLoglist*)m_arShownList.SafeGetAt(nItem), lvhitTestInfo.pt, type, &branch)) + if (IsMouseOnRefLabel(m_arShownList.SafeGetAt(nItem), lvhitTestInfo.pt, type, &branch)) { MAP_STRING_STRING descriptions; g_Git.GetBranchDescriptions(descriptions); @@ -4352,7 +4349,7 @@ CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem) { if (nSubItem == LOGLIST_MESSAGE && !m_bTagsBranchesOnRightSide) { - GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem); if (pLogEntry == nullptr) return CString(); if (m_HashMap[pLogEntry->m_CommitHash].empty()) @@ -4361,21 +4358,21 @@ CString CGitLogListBase::GetToolTipText(int nItem, int nSubItem) } else if (nSubItem == LOGLIST_DATE && m_bRelativeTimes) { - GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem); if (pLogEntry == nullptr) return CString(); return CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, false); } else if (nSubItem == LOGLIST_COMMIT_DATE && m_bRelativeTimes) { - GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem); if (pLogEntry == nullptr) return CString(); return CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, false); } else if (nSubItem == LOGLIST_ACTION) { - GitRevLoglist* pLogEntry = (GitRevLoglist*)m_arShownList.SafeGetAt(nItem); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(nItem); if (pLogEntry == nullptr) return CString(); diff --git a/src/TortoiseProc/GitLogListBase.h b/src/TortoiseProc/GitLogListBase.h index 2f0f4cccd..ccd3fefce 100644 --- a/src/TortoiseProc/GitLogListBase.h +++ b/src/TortoiseProc/GitLogListBase.h @@ -141,45 +141,42 @@ private: size_t location; }; -class CThreadSafePtrArray: public CPtrArray +class CThreadSafePtrArray : public std::vector { CComCriticalSection *m_critSec; public: CThreadSafePtrArray(CComCriticalSection *section){ m_critSec = section ;} - void * SafeGetAt(INT_PTR i) + GitRevLoglist* SafeGetAt(size_t i) { if(m_critSec) m_critSec->Lock(); - if( i<0 || i>=GetCount()) + SCOPE_EXIT { - if(m_critSec) + if (m_critSec) m_critSec->Unlock(); + }; - return NULL; - } + if (i >= size()) + return nullptr; - if(m_critSec) - m_critSec->Unlock(); - - return GetAt(i); + return (*this)[i]; } - INT_PTR SafeAdd(void *newElement) + + void SafeAdd(GitRevLoglist* newElement) { - INT_PTR ret; if(m_critSec) m_critSec->Lock(); - ret = Add(newElement); + push_back(newElement); if(m_critSec) m_critSec->Unlock(); - return ret; } void SafeRemoveAll() { if(m_critSec) m_critSec->Lock(); - RemoveAll(); + clear(); if(m_critSec) m_critSec->Unlock(); } @@ -389,7 +386,7 @@ public: static const UINT m_ScrollToMessage; static const UINT m_RebaseActionMessage; - inline int ShownCountWithStopped() const { return (int)m_arShownList.GetCount() + (m_bStrictStopped ? 1 : 0); } + inline int ShownCountWithStopped() const { return (int)m_arShownList.size() + (m_bStrictStopped ? 1 : 0); } void FetchLogAsync(void* data = nullptr); CThreadSafePtrArray m_arShownList; void Refresh(BOOL IsCleanFilter=TRUE); diff --git a/src/TortoiseProc/LogDlg.cpp b/src/TortoiseProc/LogDlg.cpp index fd2e3d9b5..8e8ada9d8 100644 --- a/src/TortoiseProc/LogDlg.cpp +++ b/src/TortoiseProc/LogDlg.cpp @@ -538,7 +538,7 @@ LRESULT CLogDlg::OnLogListLoading(WPARAM wParam, LPARAM /*lParam*/) DialogEnableWindow(IDC_WHOLE_PROJECT, !m_bFollowRenames && !m_path.IsEmpty()); - DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC)); + DialogEnableWindow(IDC_STATBUTTON, !(m_LogList.m_arShownList.empty() || m_LogList.m_arShownList.size() == 1 && m_LogList.m_bShowWC)); DialogEnableWindow(IDC_REFRESH, TRUE); DialogEnableWindow(IDC_VIEW, TRUE); DialogEnableWindow(IDC_WALKBEHAVIOUR, TRUE); @@ -776,14 +776,14 @@ void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/) // with the corresponding log message, and also fill the changed files // list fully. POSITION pos = m_LogList.GetFirstSelectedItemPosition(); - int selIndex = m_LogList.GetNextSelectedItem(pos); - if (selIndex >= m_LogList.m_arShownList.GetCount()) + size_t selIndex = m_LogList.GetNextSelectedItem(pos); + if (selIndex >= m_LogList.m_arShownList.size()) { // InterlockedExchange(&m_bNoDispUpdates, FALSE); m_ChangedFileListCtrl.SetRedraw(TRUE); return; } - GitRevLoglist* pLogEntry = reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(selIndex)); + GitRevLoglist* pLogEntry = m_LogList.m_arShownList.SafeGetAt(selIndex); { m_gravatar.LoadGravatar(pLogEntry->GetAuthorEmail()); @@ -981,7 +981,7 @@ void CLogDlg::FillPatchView(bool onlySetTimer) return; // nothing is selected, get out of here } - GitRev * pLogEntry = reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(posLogList))); + GitRev* pLogEntry = m_LogList.m_arShownList.SafeGetAt(m_LogList.GetNextSelectedItem(posLogList)); if (pLogEntry == nullptr || m_LogList.GetNextSelectedItem(posLogList) != -1) { m_patchViewdlg.ClearView(); @@ -1130,9 +1130,9 @@ void CLogDlg::GoBackForward(bool select, bool bForward) if (bForward ? m_LogList.m_selectionHistory.GoForward(gotoHash) : m_LogList.m_selectionHistory.GoBack(gotoHash)) { int i; - for (i = 0; i < m_LogList.m_arShownList.GetCount(); ++i) + for (i = 0; i < (int)m_LogList.m_arShownList.size(); ++i) { - GitRev *rev = (GitRev *)m_LogList.m_arShownList.SafeGetAt(i); + GitRev* rev = m_LogList.m_arShownList.SafeGetAt(i); if (!rev) continue; if (rev->m_CommitHash == gotoHash) { @@ -1159,7 +1159,7 @@ void CLogDlg::GoBackForward(bool select, bool bForward) return; } } - if (i == m_LogList.m_arShownList.GetCount()) + if (i == (int)m_LogList.m_arShownList.size()) { CString msg; msg.Format(IDS_LOG_NOT_VISIBLE, (LPCTSTR)gotoHash.ToString()); @@ -1440,7 +1440,7 @@ void CLogDlg::OnContextMenu(CWnd* pWnd, CPoint point) if (pos) selIndex = m_LogList.GetNextSelectedItem(pos); - GitRevLoglist* pRev = ((GitRevLoglist*)m_LogList.m_arShownList[selIndex]); + GitRevLoglist* pRev = m_LogList.m_arShownList.SafeGetAt(selIndex); if ((point.x == -1) && (point.y == -1)) { @@ -1516,10 +1516,10 @@ void CLogDlg::OnOK() // get the selected row POSITION pos = m_LogList.GetFirstSelectedItemPosition(); int selIndex = m_LogList.GetNextSelectedItem(pos); - if (selIndex < m_LogList.m_arShownList.GetCount()) + if (selIndex < m_LogList.m_arShownList.size()) { // all ok, pick up the revision - GitRev* pLogEntry = reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(selIndex)); + GitRev* pLogEntry = m_LogList.m_arShownList.SafeGetAt(selIndex); // extract the hash m_sSelectedHash = pLogEntry->m_CommitHash; } @@ -1642,9 +1642,9 @@ void CLogDlg::OnPasteGitHash() void CLogDlg::JumpToGitHash(CString& hash) { - for (int i = 0; i < m_LogList.m_arShownList.GetCount(); ++i) + for (int i = 0; i < (int)m_LogList.m_arShownList.size(); ++i) { - GitRev* rev = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i); + GitRev* rev = m_LogList.m_arShownList.SafeGetAt(i); if (!rev) continue; if (rev->m_CommitHash.ToString().Left(hash.GetLength()) != hash) continue; @@ -1763,13 +1763,13 @@ void CLogDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult) m_LogList.Invalidate(); } this->m_LogList.m_nSearchIndex = pNMLV->iItem; - GitRev* pLogEntry = reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem)); + GitRev* pLogEntry = m_LogList.m_arShownList.SafeGetAt(pNMLV->iItem); if (pLogEntry == nullptr) return; m_LogList.m_lastSelectedHash = pLogEntry->m_CommitHash; if (pNMLV->iSubItem != 0) return; - if ((pNMLV->iItem == m_LogList.m_arShownList.GetCount())) + if (pNMLV->iItem == (int)m_LogList.m_arShownList.size()) { // remove the selected state if (pNMLV->uChanged & LVIF_STATE) @@ -1869,7 +1869,7 @@ void CLogDlg::OnBnClickedStatbutton() { if (this->IsThreadRunning()) return; - if (m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC) + if (m_LogList.m_arShownList.empty() || m_LogList.m_arShownList.size() == 1 && m_LogList.m_bShowWC) return; // nothing or just the working copy changes are shown, so no statistics. // the statistics dialog expects the log entries to be sorted by date SortByColumn(3, false); @@ -2384,7 +2384,7 @@ void CLogDlg::OnTimer(UINT_PTR nIDEvent) KillTimer(FILEFILTER_TIMER); FillLogMessageCtrl(); } - DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty() || m_LogList.m_arShownList.GetCount() == 1 && m_LogList.m_bShowWC)))); + DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.empty() || m_LogList.m_arShownList.size() == 1 && m_LogList.m_bShowWC)))); __super::OnTimer(nIDEvent); } @@ -2480,7 +2480,7 @@ void CLogDlg::OnBnClickedJumpUp() index = m_LogList.GetNextSelectedItem(pos); if (index == 0) return; - GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index); + GitRev* data = m_LogList.m_arShownList.SafeGetAt(index); if (jumpType == JumpType_AuthorEmail) strValue = data->GetAuthorEmail(); else if (jumpType == JumpType_CommitterEmail) @@ -2509,7 +2509,7 @@ void CLogDlg::OnBnClickedJumpUp() for (int i = index - 1; i >= 0; i--) { bool found = false; - GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i); + GitRev* data = m_LogList.m_arShownList.SafeGetAt(i); if (jumpType == JumpType_AuthorEmail) found = strValue == data->GetAuthorEmail(); else if (jumpType == JumpType_CommitterEmail) @@ -2589,7 +2589,7 @@ void CLogDlg::OnBnClickedJumpDown() index = m_LogList.GetNextSelectedItem(pos); if (index == 0) return; - GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(index); + GitRev* data = m_LogList.m_arShownList.SafeGetAt(index); if (jumpType == JumpType_AuthorEmail) strValue = data->GetAuthorEmail(); else if (jumpType == JumpType_CommitterEmail) @@ -2628,7 +2628,7 @@ void CLogDlg::OnBnClickedJumpDown() for (int i = index + 1; i < m_LogList.GetItemCount(); ++i) { bool found = false; - GitRev* data = (GitRev*)m_LogList.m_arShownList.SafeGetAt(i); + GitRev* data = m_LogList.m_arShownList.SafeGetAt(i); if (jumpType == JumpType_AuthorEmail) found = strValue == data->GetAuthorEmail(); else if (jumpType == JumpType_CommitterEmail) @@ -2817,16 +2817,16 @@ void CLogDlg::UpdateLogInfoLabel() CGitHash rev2 ; long selectedrevs = 0; long selectedfiles = 0; - int count = (int)m_LogList.m_arShownList.GetCount(); + int count = (int)m_LogList.m_arShownList.size(); int start = 0; if (count) { - rev1 = (reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(0)))->m_CommitHash; + rev1 = m_LogList.m_arShownList.SafeGetAt(0)->m_CommitHash; if(this->m_LogList.m_bShowWC && rev1.IsEmpty()&&(count>1)) start = 1; - rev1 = (reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(start)))->m_CommitHash; + rev1 = m_LogList.m_arShownList.SafeGetAt(start)->m_CommitHash; //pLogEntry = reinterpret_cast(m_arShownList.SafeGetAt(m_arShownList.GetCount()-1)); - rev2 = (reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(count-1)))->m_CommitHash; + rev2 = m_LogList.m_arShownList.SafeGetAt(count - 1)->m_CommitHash; selectedrevs = m_LogList.GetSelectedCount(); if (selectedrevs) selectedfiles = m_ChangedFileListCtrl.GetSelectedCount(); @@ -2980,7 +2980,7 @@ void CLogDlg::OnEnChangeSearchedit() GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_HIDE); GetDlgItem(IDC_SEARCHEDIT)->ShowWindow(SW_SHOW); GetDlgItem(IDC_SEARCHEDIT)->SetFocus(); - DialogEnableWindow(IDC_STATBUTTON, !(((this->IsThreadRunning())||(m_LogList.m_arShownList.IsEmpty())))); + DialogEnableWindow(IDC_STATBUTTON, !(this->IsThreadRunning() || m_LogList.m_arShownList.empty())); return; } if (Validate(m_LogList.m_sFilterText)) @@ -3288,7 +3288,7 @@ void CLogDlg::OnBnClickedView() int moreSel = m_LogList.GetNextSelectedItem(pos); if (moreSel < 0) { - GitRev* pLogEntry = reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(selIndex)); + GitRev* pLogEntry = m_LogList.m_arShownList.SafeGetAt(selIndex); if (pLogEntry) email = pLogEntry->GetAuthorEmail(); } diff --git a/src/TortoiseProc/RebaseDlg.cpp b/src/TortoiseProc/RebaseDlg.cpp index ce4ff9a66..7ed2e00d4 100644 --- a/src/TortoiseProc/RebaseDlg.cpp +++ b/src/TortoiseProc/RebaseDlg.cpp @@ -919,7 +919,7 @@ int CRebaseDlg::StartRebase() this->AddLogString(log); for (int i = 0; i < m_CommitList.GetItemCount(); ++i) { - m_rewrittenCommitsMap[((GitRevLoglist*)m_CommitList.m_arShownList[i])->m_CommitHash] = CGitHash(); + m_rewrittenCommitsMap[m_CommitList.m_arShownList.SafeGetAt(i)->m_CommitHash] = CGitHash(); } if (m_bPreserveMerges) { @@ -1133,7 +1133,7 @@ void CRebaseDlg::OnBnClickedContinue() { if(VerifyNoConflict()) return; - GitRevLoglist* curRev = (GitRevLoglist*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; + GitRevLoglist* curRev = m_CommitList.m_arShownList.SafeGetAt(m_CurrentRebaseIndex); if(this->CheckNextCommitIsSquash()) {//next commit is not squash; m_RebaseStage = REBASE_SQUASH_EDIT; @@ -1154,7 +1154,7 @@ void CRebaseDlg::OnBnClickedContinue() if(VerifyNoConflict()) return; - GitRevLoglist* curRev = (GitRevLoglist*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; + GitRevLoglist* curRev = m_CommitList.m_arShownList.SafeGetAt(m_CurrentRebaseIndex); // *************************************************** // ATTENTION: Similar code in CommitDlg.cpp!!! // *************************************************** @@ -1341,7 +1341,7 @@ void CRebaseDlg::OnBnClickedContinue() this->m_ctrlTabCtrl.SetActiveTab(REBASE_TAB_LOG); m_RebaseStage = REBASE_CONTINUE; - GitRevLoglist* curRev = (GitRevLoglist*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; + GitRevLoglist* curRev = m_CommitList.m_arShownList.SafeGetAt(m_CurrentRebaseIndex); CGitHash head; if (g_Git.GetHash(head, _T("HEAD"))) { @@ -1359,7 +1359,7 @@ void CRebaseDlg::OnBnClickedContinue() if( m_RebaseStage == REBASE_EDIT || m_RebaseStage == REBASE_SQUASH_EDIT ) { CString str; - GitRevLoglist* curRev = (GitRevLoglist*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; + GitRevLoglist* curRev = m_CommitList.m_arShownList.SafeGetAt(m_CurrentRebaseIndex); str=this->m_LogMessageCtrl.GetText(); if(str.Trim().IsEmpty()) @@ -1459,7 +1459,7 @@ int CRebaseDlg::CheckNextCommitIsSquash() if(index>= m_CommitList.GetItemCount()) return -1; - curRev = (GitRevLoglist*)m_CommitList.m_arShownList[index]; + curRev = m_CommitList.m_arShownList.SafeGetAt(index); if (curRev->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_SQUASH) return 0; @@ -1647,14 +1647,12 @@ void CRebaseDlg::UpdateProgress() GitRevLoglist* prevRev = nullptr, *curRev = nullptr; - if( m_CurrentRebaseIndex >= 0 && m_CurrentRebaseIndex< m_CommitList.m_arShownList.GetSize()) - { - curRev = (GitRevLoglist*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; - } + if (m_CurrentRebaseIndex >= 0 && m_CurrentRebaseIndex < (int)m_CommitList.m_arShownList.size()) + curRev = m_CommitList.m_arShownList.SafeGetAt(m_CurrentRebaseIndex); - for (int i = 0; i < m_CommitList.m_arShownList.GetSize(); ++i) + for (int i = 0; i < (int)m_CommitList.m_arShownList.size(); ++i) { - prevRev = (GitRevLoglist*)m_CommitList.m_arShownList[i]; + prevRev = m_CommitList.m_arShownList.SafeGetAt(i); if (prevRev->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_CURRENT) { prevRev->GetRebaseAction() &= ~CGitLogListBase::LOGACTIONS_REBASE_CURRENT; @@ -1728,7 +1726,7 @@ int CRebaseDlg::DoRebase() if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() ) return 0; - GitRevLoglist* pRev = (GitRevLoglist*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; + GitRevLoglist* pRev = m_CommitList.m_arShownList.SafeGetAt(m_CurrentRebaseIndex); int mode = pRev->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_MODE_MASK; CString nocommit; @@ -2164,7 +2162,7 @@ LRESULT CRebaseDlg::OnRebaseUpdateUI(WPARAM,LPARAM) return 0; if(m_CurrentRebaseIndex >= m_CommitList.GetItemCount() ) return 0; - GitRev *curRev=(GitRev*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; + GitRev* curRev = m_CommitList.m_arShownList.SafeGetAt(m_CurrentRebaseIndex); switch(m_RebaseStage) { @@ -2477,7 +2475,7 @@ void CRebaseDlg::OnLvnItemchangedLoglist(NMHDR *pNMHDR, LRESULT *pResult) this->m_CommitList.m_nSearchIndex = pNMLV->iItem; if (pNMLV->iSubItem != 0) return; - if ((pNMLV->iItem == m_CommitList.m_arShownList.GetCount())) + if (pNMLV->iItem == (int)m_CommitList.m_arShownList.size()) { // remove the selected state if (pNMLV->uChanged & LVIF_STATE) @@ -2505,7 +2503,7 @@ void CRebaseDlg::FillLogMessageCtrl() { POSITION pos = m_CommitList.GetFirstSelectedItemPosition(); int selIndex = m_CommitList.GetNextSelectedItem(pos); - GitRevLoglist* pLogEntry = reinterpret_cast(m_CommitList.m_arShownList.SafeGetAt(selIndex)); + GitRevLoglist* pLogEntry = m_CommitList.m_arShownList.SafeGetAt(selIndex); m_FileListCtrl.UpdateWithGitPathList(pLogEntry->GetFiles(&m_CommitList)); m_FileListCtrl.m_CurrentVersion = pLogEntry->m_CommitHash; m_FileListCtrl.Show(GITSLC_SHOWVERSIONED); @@ -2523,7 +2521,7 @@ LRESULT CRebaseDlg::OnRebaseActionMessage(WPARAM, LPARAM) { if (m_RebaseStage == REBASE_ERROR || m_RebaseStage == REBASE_CONFLICT) { - GitRevLoglist* pRev = (GitRevLoglist*)m_CommitList.m_arShownList[m_CurrentRebaseIndex]; + GitRevLoglist* pRev = m_CommitList.m_arShownList.SafeGetAt(m_CurrentRebaseIndex); int mode = pRev->GetRebaseAction() & CGitLogListBase::LOGACTIONS_REBASE_MODE_MASK; if (mode == CGitLogListBase::LOGACTIONS_REBASE_SKIP) { diff --git a/src/TortoiseProc/RefLogDlg.cpp b/src/TortoiseProc/RefLogDlg.cpp index c1056aeb9..22b8a74d3 100644 --- a/src/TortoiseProc/RefLogDlg.cpp +++ b/src/TortoiseProc/RefLogDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2009-2015 - TortoiseGit +// Copyright (C) 2009-2016 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -105,11 +105,11 @@ void CRefLogDlg::OnBnClickedOk() { // get the selected row POSITION pos = m_RefList.GetFirstSelectedItemPosition(); - int selIndex = m_RefList.GetNextSelectedItem(pos); - if (selIndex < m_RefList.m_arShownList.GetCount()) + size_t selIndex = m_RefList.GetNextSelectedItem(pos); + if (selIndex < m_RefList.m_arShownList.size()) { // all ok, pick up the revision - GitRev* pLogEntry = reinterpret_cast(m_RefList.m_arShownList.GetAt(selIndex)); + GitRev* pLogEntry = m_RefList.m_arShownList.SafeGetAt(selIndex); // extract the hash m_SelectedHash = pLogEntry->m_CommitHash; } @@ -119,7 +119,7 @@ void CRefLogDlg::OnBnClickedOk() } void CRefLogDlg::OnBnClickedClearStash() { - size_t count = m_RefList.m_arShownList.GetCount(); + size_t count = m_RefList.m_arShownList.size(); CString msg; msg.Format(IDS_PROC_DELETEALLSTASH, count); if (CMessageBox::Show(this->GetSafeHwnd(), msg, _T("TortoiseGit"), 2, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 1) @@ -150,13 +150,13 @@ void CRefLogDlg::OnCbnSelchangeRef() m_RefList.SetItemCountEx((int)m_RefList.m_RevCache.size()); - this->m_RefList.m_arShownList.RemoveAll(); + this->m_RefList.m_arShownList.clear(); for (unsigned int i = 0; i < m_RefList.m_RevCache.size(); ++i) { GitRevLoglist* rev = &m_RefList.m_RevCache[i]; rev->m_IsFull = TRUE; - this->m_RefList.m_arShownList.Add(rev); + this->m_RefList.m_arShownList.SafeAdd(rev); } m_RefList.SetRedraw(true); @@ -166,7 +166,7 @@ void CRefLogDlg::OnCbnSelchangeRef() if (ref == _T("refs/stash")) { GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH)->ShowWindow(SW_SHOW); - BOOL enabled = m_RefList.m_arShownList.GetSize() > 0; + BOOL enabled = !m_RefList.m_arShownList.empty(); GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH)->EnableWindow(enabled); if (!enabled) GetDlgItem(IDOK)->SetFocus(); @@ -231,7 +231,7 @@ LRESULT CRefLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/) { ASSERT(m_pFindDialog != NULL); - if (m_RefList.m_arShownList.IsEmpty()) + if (m_RefList.m_arShownList.empty()) return 0; // If the FR_DIALOGTERM flag is set, @@ -256,13 +256,13 @@ LRESULT CRefLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/) if (!bCaseSensitive) findString.MakeLower(); - int i = m_nSearchLine; - if (i < 0 || i >= m_RefList.m_arShownList.GetCount()) + size_t i = m_nSearchLine; + if (i >= m_RefList.m_arShownList.size()) i = 0; do { - GitRevLoglist* data = (GitRevLoglist*)m_RefList.m_arShownList.SafeGetAt(i); + GitRevLoglist* data = m_RefList.m_arShownList.SafeGetAt(i); CString str; str += data->m_Ref; @@ -283,14 +283,14 @@ LRESULT CRefLogDlg::OnFindDialogMessage(WPARAM /*wParam*/, LPARAM /*lParam*/) bFound = true; ++i; - if(!bFound && i >= m_RefList.m_arShownList.GetCount()) + if(!bFound && i >= m_RefList.m_arShownList.size()) i=0; } while (i != m_nSearchLine && (!bFound)); if (bFound) { - m_RefList.SetHotItem(i - 1); - m_RefList.EnsureVisible(i - 1, FALSE); + m_RefList.SetHotItem((int)i - 1); + m_RefList.EnsureVisible((int)i - 1, FALSE); m_nSearchLine = i; } else diff --git a/src/TortoiseProc/RefLogDlg.h b/src/TortoiseProc/RefLogDlg.h index 14258343b..e0b78b4e4 100644 --- a/src/TortoiseProc/RefLogDlg.h +++ b/src/TortoiseProc/RefLogDlg.h @@ -54,7 +54,7 @@ protected: void OnFind(); CFindReplaceDialog *m_pFindDialog; static UINT m_FindDialogMessage; - int m_nSearchLine; + size_t m_nSearchLine; public: CString m_CurrentBranch; diff --git a/src/TortoiseProc/StatGraphDlg.cpp b/src/TortoiseProc/StatGraphDlg.cpp index 3123d8f62..47dd35d29 100644 --- a/src/TortoiseProc/StatGraphDlg.cpp +++ b/src/TortoiseProc/StatGraphDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2015 - TortoiseGit +// Copyright (C) 2008-2016 - TortoiseGit // Copyright (C) 2003-2011,2014-2015 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -743,9 +743,9 @@ int CStatGraphDlg::GatherData(BOOL fetchdiff, BOOL keepFetchedData) GIT_MAILMAP mailmap = nullptr; git_read_mailmap(&mailmap); - for (INT_PTR i = 0; i < m_ShowList.GetCount(); ++i) + for (size_t i = 0; i < m_ShowList.size(); ++i) { - GitRevLoglist* pLogEntry = reinterpret_cast(m_ShowList.SafeGetAt(i)); + GitRevLoglist* pLogEntry = m_ShowList.SafeGetAt(i); int inc, dec, incnewfile, decdeletedfile, files; inc = dec = incnewfile = decdeletedfile = files= 0; @@ -809,7 +809,7 @@ int CStatGraphDlg::GatherData(BOOL fetchdiff, BOOL keepFetchedData) if (progress.IsVisible() && (GetTickCount64() - starttime > 100UL)) { progress.FormatNonPathLine(2, _T("%s: %s"), (LPCTSTR)pLogEntry->m_CommitHash.ToString().Left(g_Git.GetShortHASHLength()), (LPCTSTR)pLogEntry->GetSubject()); - progress.SetProgress64(i, m_ShowList.GetCount()); + progress.SetProgress64(i, m_ShowList.size()); starttime = GetTickCount64(); } diff --git a/src/TortoiseProc/refloglist.cpp b/src/TortoiseProc/refloglist.cpp index eaf7f5cfa..6eb39df84 100644 --- a/src/TortoiseProc/refloglist.cpp +++ b/src/TortoiseProc/refloglist.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2009-2011,2013,2015 TortoiseGit +// Copyright (C) 2009-2011,2013,2015-2016 TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -90,10 +90,7 @@ void CRefLogList::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) return; // Which item number? - int itemid = pItem->iItem; - GitRevLoglist* pLogEntry = nullptr; - if (itemid < m_arShownList.GetCount()) - pLogEntry = reinterpret_cast(m_arShownList.GetAt(pItem->iItem)); + GitRevLoglist* pLogEntry = m_arShownList.SafeGetAt(pItem->iItem); CString temp; -- 2.11.4.GIT