From 3d5e58b6ef1a3ee912ffe6ec73a34d9a3871b51f Mon Sep 17 00:00:00 2001 From: Frank Li Date: Fri, 26 Dec 2008 21:26:25 +0800 Subject: [PATCH] Show Tag branch at loglist --- src/Git/Git.cpp | 31 ++++- src/Git/Git.h | 5 + src/TortoiseProc/GitLogList.cpp | 223 +++++++++++++++++++++++------------ src/TortoiseProc/GitLogList.h | 5 +- src/TortoiseProc/TortoiseProc.vcproj | 29 +++-- 5 files changed, 206 insertions(+), 87 deletions(-) diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 094158f..4e28fb1 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -145,7 +145,7 @@ int CGit::GetLog(CString& logOut) cmd += log; log.Format(_T("#<%c>%%n"),LOG_REV_COMMIT_FILE); cmd += log; - cmd += CString(_T("\"")); + cmd += CString(_T("\" HEAD~4..HEAD")); Run(cmd,&logOut); return 0; } @@ -321,4 +321,33 @@ int CGit::GetRemoteList(CStringList &list) } } return ret; +} + +int CGit::GetMapHashToFriendName(MAP_HASH_NAME &map) +{ + int ret; + CString cmd,output; + cmd=_T("git show-ref"); + ret=g_Git.Run(cmd,&output); + if(!ret) + { + int pos=0; + CString one; + while( pos>=0 ) + { + one=output.Tokenize(_T("\n"),pos); + int start=one.Find(_T(" "),0); + if(start>0) + { + CString name; + name=one.Right(one.GetLength()-start-1); + + CString hash; + hash=one.Left(start); + + map[hash].push_back(name); + } + } + } + return ret; } \ No newline at end of file diff --git a/src/Git/Git.h b/src/Git/Git.h index f07687d..be3aa97 100644 --- a/src/Git/Git.h +++ b/src/Git/Git.h @@ -9,6 +9,10 @@ enum GIT_ERROR_CREATE_PROCESS, GIT_ERROR_GET_EXIT_CODE }; + +typedef std::vector STRING_VECTOR; +typedef std::map MAP_HASH_NAME; + class CGit { private: @@ -40,6 +44,7 @@ public: int GetRemoteList(CStringList &list); int GetBranchList(CStringList &list, int *Current,BRANCH_TYPE type=BRANCH_LOCAL); int GetTagList(CStringList &list); + int GetMapHashToFriendName(MAP_HASH_NAME &map); int GetLog(CString& logOut); git_revnum_t GetHash(CString &friendname); diff --git a/src/TortoiseProc/GitLogList.cpp b/src/TortoiseProc/GitLogList.cpp index a00acb2..2fe5c00 100644 --- a/src/TortoiseProc/GitLogList.cpp +++ b/src/TortoiseProc/GitLogList.cpp @@ -66,7 +66,7 @@ CGitLogList::CGitLogList():CHintListCtrl() m_hAddedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONADDED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE); m_hDeletedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONDELETED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE); - + g_Git.GetMapHashToFriendName(m_HashMap); } CGitLogList::~CGitLogList() @@ -243,7 +243,133 @@ void CGitLogList::ResizeAllListCtrlCols() } } +BOOL CGitLogList::GetShortName(CString ref, CString &shortname,CString prefix) +{ + if(ref.Left(prefix.GetLength()) == prefix) + { + shortname = ref.Right(ref.GetLength()-prefix.GetLength()); + return TRUE; + } + return FALSE; +} +void CGitLogList::FillBackGround(HDC hdc, int Index,CRect &rect) +{ + HBRUSH brush; + LVITEM rItem; + SecureZeroMemory(&rItem, sizeof(LVITEM)); + rItem.mask = LVIF_STATE; + rItem.iItem = Index; + rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; + GetItem(&rItem); + + if (m_Theme.IsAppThemed() && m_bVista) + { + m_Theme.Open(m_hWnd, L"Explorer"); + int state = LISS_NORMAL; + if (rItem.state & LVIS_SELECTED) + { + if (::GetFocus() == m_hWnd) + state |= LISS_SELECTED; + else + state |= LISS_SELECTEDNOTFOCUS; + } + else + { +#if 0 + if (pLogEntry->bCopiedSelf) + { + // unfortunately, the pLVCD->nmcd.uItemState does not contain valid + // information at this drawing stage. But we can check the whether the + // previous stage changed the background color of the item + if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU)) + { + HBRUSH brush; + brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU)); + if (brush) + { + ::FillRect(pLVCD->nmcd.hdc, &rect, brush); + ::DeleteObject(brush); + } + } + } +#endif + } + + if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state)) + m_Theme.DrawParentBackground(m_hWnd, hdc, &rect); + + m_Theme.DrawBackground(hdc, LVP_LISTDETAIL, state, &rect, NULL); + } + else + { + HBRUSH brush; + if (rItem.state & LVIS_SELECTED) + { + if (::GetFocus() == m_hWnd) + brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT)); + else + brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE)); + } + else + { + //if (pLogEntry->bCopiedSelf) + // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU)); + //else + brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW)); + } + if (brush == NULL) + return; + + ::FillRect(hdc, &rect, brush); + ::DeleteObject(brush); + + } +} + +void CGitLogList::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index) +{ + GitRev* data = (GitRev*)m_arShownList.GetAt(index); + CRect rt=rect; + for(int i=0;im_CommitHash].size();i++) + { + CString str; + str=m_HashMap[data->m_CommitHash][i]; + + CString shortname; + HBRUSH brush=0; + shortname=_T(""); + if(GetShortName(str,shortname,_T("refs/heads/"))) + { + brush = ::CreateSolidBrush(RGB(0xff, 0, 0)); + }else if(GetShortName(str,shortname,_T("refs/remotes/"))) + { + brush = ::CreateSolidBrush(RGB(0xff, 0xff, 0)); + } + else if(GetShortName(str,shortname,_T("refs/tags/"))) + { + brush = ::CreateSolidBrush(RGB(0, 0, 0xff)); + } + if(!shortname.IsEmpty()) + { + SIZE size; + memset(&size,0,sizeof(SIZE)); + GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size); + + rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom); + + ::FillRect(hdc, &rt, brush); + ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER); + + rt.left=rt.right+3; + } + if(brush) + ::DeleteObject(brush); + } + rt.right=rect.right; + ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT); + +} void CGitLogList::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) { @@ -316,6 +442,25 @@ void CGitLogList::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) { pLVCD->nmcd.uItemState &= ~(CDIS_SELECTED|CDIS_FOCUS); } + if (pLVCD->iSubItem == LOGLIST_MESSAGE) + { + if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec) + { + GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec); + if(m_HashMap[data->m_CommitHash].size()!=0) + { + CRect rect; + GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect); + + FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect); + DrawTagBranch(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec); + + *pResult = CDRF_SKIPDEFAULT; + return; + + } + } + } if (pLVCD->iSubItem == 1) { *pResult = CDRF_DODEFAULT; @@ -328,82 +473,14 @@ void CGitLogList::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) int iconheight = ::GetSystemMetrics(SM_CYSMICON); GitRev* pLogEntry = reinterpret_cast(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec)); - - // Get the selected state of the - // item being drawn. - LVITEM rItem; - SecureZeroMemory(&rItem, sizeof(LVITEM)); - rItem.mask = LVIF_STATE; - rItem.iItem = pLVCD->nmcd.dwItemSpec; - rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; - GetItem(&rItem); - CRect rect; GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect); + // Get the selected state of the + // item being drawn. // Fill the background - if (m_Theme.IsAppThemed() && m_bVista) - { - m_Theme.Open(m_hWnd, L"Explorer"); - int state = LISS_NORMAL; - if (rItem.state & LVIS_SELECTED) - { - if (::GetFocus() == m_hWnd) - state |= LISS_SELECTED; - else - state |= LISS_SELECTEDNOTFOCUS; - } - else - { -#if 0 - if (pLogEntry->bCopiedSelf) - { - // unfortunately, the pLVCD->nmcd.uItemState does not contain valid - // information at this drawing stage. But we can check the whether the - // previous stage changed the background color of the item - if (pLVCD->clrTextBk == GetSysColor(COLOR_MENU)) - { - HBRUSH brush; - brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU)); - if (brush) - { - ::FillRect(pLVCD->nmcd.hdc, &rect, brush); - ::DeleteObject(brush); - } - } - } -#endif - } - - if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state)) - m_Theme.DrawParentBackground(m_hWnd, pLVCD->nmcd.hdc, &rect); - - m_Theme.DrawBackground(pLVCD->nmcd.hdc, LVP_LISTDETAIL, state, &rect, NULL); - } - else - { - HBRUSH brush; - if (rItem.state & LVIS_SELECTED) - { - if (::GetFocus() == m_hWnd) - brush = ::CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT)); - else - brush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE)); - } - else - { - //if (pLogEntry->bCopiedSelf) - // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU)); - //else - brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW)); - } - if (brush == NULL) - return; - - ::FillRect(pLVCD->nmcd.hdc, &rect, brush); - ::DeleteObject(brush); - } - + FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect); + // Draw the icon(s) into the compatible DC if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_MODIFIED) ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL); diff --git a/src/TortoiseProc/GitLogList.h b/src/TortoiseProc/GitLogList.h index 38cedfe..83247a3 100644 --- a/src/TortoiseProc/GitLogList.h +++ b/src/TortoiseProc/GitLogList.h @@ -131,7 +131,9 @@ protected: virtual BOOL PreTranslateMessage(MSG* pMsg); static UINT LogThreadEntry(LPVOID pVoid); UINT LogThread(); - + void FillBackGround(HDC hdc, int Index,CRect &rect); + void DrawTagBranch(HDC,CRect &rect,INT_PTR index); + BOOL GetShortName(CString ref, CString &shortname,CString prefix); CXPTheme m_Theme; BOOL m_bVista; @@ -149,6 +151,7 @@ protected: CALLBACK_PROCESS *m_ProcCallBack; void *m_ProcData; CStoreSelection* m_pStoreSelection; + MAP_HASH_NAME m_HashMap; }; diff --git a/src/TortoiseProc/TortoiseProc.vcproj b/src/TortoiseProc/TortoiseProc.vcproj index 060df3f..6d0fc77 100644 --- a/src/TortoiseProc/TortoiseProc.vcproj +++ b/src/TortoiseProc/TortoiseProc.vcproj @@ -566,11 +566,11 @@ > + + -- 2.11.0