X-Git-Url: http://git.sourceforge.jp/view?p=tortoisegit%2FTortoiseGitJp.git;a=blobdiff_plain;f=src%2FTortoiseProc%2FGitLogListBase.cpp;h=f4e23143ff2f404ee1ac6acaca4a1a84101a4c05;hp=500c9cffbb0605abb1f7b25813b3e314cae1a762;hb=bde4c52c53f390bd9f1672916e5bba47cf55db95;hpb=c0e4916c9c73c9dbaa338c4f7c3d179045ac538f diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index 500c9cf..f4e2314 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -57,6 +57,8 @@ CGitLogListBase::CGitLogListBase():CHintListCtrl() , m_bStrictStopped(false) , m_pStoreSelection(NULL) , m_nSelectedFilter(LOGFILTER_ALL) + , m_bVista(false) + , m_bShowWC(false) { // use the default GUI font, create a copy of it and // change the copy to BOLD (leave the rest of the font @@ -72,7 +74,11 @@ CGitLogListBase::CGitLogListBase():CHintListCtrl() m_IsIDReplaceAction=FALSE; m_wcRev.m_CommitHash=GIT_REV_ZERO; - m_wcRev.m_Subject=_T("Working Copy"); + m_wcRev.m_Subject=_T("Working dir changes"); + m_wcRev.m_ParentHash.clear(); + m_wcRev.m_Mark=_T('-'); + m_wcRev.m_IsUpdateing=FALSE; + m_wcRev.m_IsFull = TRUE; m_hModifiedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONMODIFIED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE); m_hReplacedIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ACTIONREPLACED), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE); @@ -83,13 +89,17 @@ CGitLogListBase::CGitLogListBase():CHintListCtrl() g_Git.GetMapHashToFriendName(m_HashMap); m_CurrentBranch=g_Git.GetCurrentBranch(); + this->m_HeadHash=g_Git.GetHash(CString(_T("HEAD"))).Left(40); m_From=CTime(1970,1,2,0,0,0); m_To=CTime::GetCurrentTime(); - m_bAllBranch = FALSE; + m_ShowMask = 0; m_LoadingThread = NULL; m_bExitThread=FALSE; + m_IsOldFirst = FALSE; + m_IsRebaseReplaceGraph = FALSE; + for(int i=0;i= 0x0600); + + m_ColumnRegKey=_T("log"); } CGitLogListBase::~CGitLogListBase() @@ -144,8 +172,25 @@ BEGIN_MESSAGE_MAP(CGitLogListBase, CHintListCtrl) ON_WM_CREATE() ON_WM_DESTROY() ON_MESSAGE(MSG_LOADED,OnLoad) + ON_WM_MEASUREITEM() + ON_WM_MEASUREITEM_REFLECT() END_MESSAGE_MAP() +void CGitLogListBase::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) +{ + // TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ + + CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct); +} + +void CGitLogListBase::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) +{ + //if (m_nRowHeight>0) + { + lpMeasureItemStruct->itemHeight = 50; + } +} + int CGitLogListBase:: OnCreate(LPCREATESTRUCT lpCreateStruct) { PreSubclassWindow(); @@ -156,7 +201,9 @@ void CGitLogListBase::PreSubclassWindow() { SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES); // load the icons for the action columns - m_Theme.SetWindowTheme(GetSafeHwnd(), L"Explorer", NULL); +// m_Theme.Open(m_hWnd, L"ListView"); + m_Theme.Open(m_hWnd, L"Explorer::ListView;ListView"); + m_Theme.SetWindowTheme(m_hWnd, L"Explorer", NULL); CHintListCtrl::PreSubclassWindow(); } @@ -164,12 +211,20 @@ void CGitLogListBase::InsertGitColumn() { CString temp; - int c = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1; + int c = GetHeaderCtrl()->GetItemCount()-1; while (c>=0) DeleteColumn(c--); temp.LoadString(IDS_LOG_GRAPH); + if(m_IsRebaseReplaceGraph) + { + temp=_T("Rebase"); + } + else + { + temp.LoadString(IDS_LOG_GRAPH); + } InsertColumn(this->LOGLIST_GRAPH, temp); #if 0 @@ -217,83 +272,43 @@ void CGitLogListBase::InsertGitColumn() } +/** + * Resizes all columns in a list control to values in registry. + */ void CGitLogListBase::ResizeAllListCtrlCols() { - - const int nMinimumWidth = ICONITEMBORDER+16*4; - int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount()-1; - int nItemCount = GetItemCount(); - TCHAR textbuf[MAX_PATH]; - CHeaderCtrl * pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0)); + // column max and min widths to allow + static const int nMinimumWidth = 10; + static const int nMaximumWidth = 1000; + CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0)); if (pHdrCtrl) { - for (int col = 0; col <= maxcol; col++) + int numcols = pHdrCtrl->GetItemCount(); + for (int col = 0; col < numcols; col++) { - HDITEM hdi = {0}; - hdi.mask = HDI_TEXT; - hdi.pszText = textbuf; - hdi.cchTextMax = sizeof(textbuf); - pHdrCtrl->GetItem(col, &hdi); - int cx = GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin - for (int index = 0; indexLOGLIST_MESSAGE) { - GitRev * pCurLogEntry = reinterpret_cast(m_arShownList.GetAt(index)); - if ((pCurLogEntry)&&(pCurLogEntry->m_CommitHash == m_wcRev.m_CommitHash)) - { - // set the bold font and ask for the string width again - SendMessage(WM_SETFONT, (WPARAM)m_boldFont, NULL); - linewidth = GetStringWidth(GetItemText(index, col)) + 14; - // restore the system font - SendMessage(WM_SETFONT, NULL, NULL); - } - } - if (index == 0) - { - // add the image size - CImageList * pImgList = GetImageList(LVSIL_SMALL); - if ((pImgList)&&(pImgList->GetImageCount())) - { - IMAGEINFO imginfo; - pImgList->GetImageInfo(0, &imginfo); - linewidth += (imginfo.rcImage.right - imginfo.rcImage.left); - linewidth += 3; // 3 pixels between icon and text - } + cx = LOGLIST_MESSAGE_MIN; } - if (cx < linewidth) - cx = linewidth; - } - // Adjust columns "Actions" containing icons - if (col == this->LOGLIST_ACTION) - { - if (cx < nMinimumWidth) + else { - cx = nMinimumWidth; + cx = ICONITEMBORDER+16*4; } } - - if (col == this->LOGLIST_MESSAGE) + if (cx < nMinimumWidth) { - if (cx > LOGLIST_MESSAGE_MAX) - { - cx = LOGLIST_MESSAGE_MAX; - } - if (cx < LOGLIST_MESSAGE_MIN) - { - cx = LOGLIST_MESSAGE_MIN; - } - - } - // keep the bug id column small - if ((col == 4)&&(m_bShowBugtraqColumn)) + cx = nMinimumWidth; + } else if (cx > nMaximumWidth) { - if (cx > (int)(DWORD)m_regMaxBugIDColWidth) - { - cx = (int)(DWORD)m_regMaxBugIDColWidth; - } + cx = nMaximumWidth; } SetColumnWidth(col, cx); @@ -315,6 +330,7 @@ BOOL CGitLogListBase::GetShortName(CString ref, CString &shortname,CString prefi } return FALSE; } + void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect) { // HBRUSH brush; @@ -325,9 +341,12 @@ void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect) rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED; GetItem(&rItem); + GitRev* pLogEntry = (GitRev*)m_arShownList.GetAt(Index); + HBRUSH brush = NULL; + + if (m_Theme.IsAppThemed() && m_bVista) { - m_Theme.Open(m_hWnd, L"Explorer"); int state = LISS_NORMAL; if (rItem.state & LVIS_SELECTED) { @@ -338,34 +357,34 @@ void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect) } 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(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH) + brush = ::CreateSolidBrush(RGB(156,156,156)); + else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT) + brush = ::CreateSolidBrush(RGB(200,200,128)); } - if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTDETAIL, state)) - m_Theme.DrawParentBackground(m_hWnd, hdc, &rect); + if (brush != NULL) + { + ::FillRect(hdc, &rect, brush); + ::DeleteObject(brush); + } + else + { + if (m_Theme.IsBackgroundPartiallyTransparent(LVP_LISTITEM, state)) + m_Theme.DrawParentBackground(m_hWnd, hdc, &rect); + + CRect rectDraw = rect; + if(rItem.state & LVIS_SELECTED) + rectDraw.InflateRect(1,0); + else + rectDraw.InflateRect(1,1); - m_Theme.DrawBackground(hdc, LVP_LISTDETAIL, state, &rect, NULL); + m_Theme.DrawBackground(hdc, LVP_LISTITEM, state, rectDraw, &rect); + } } else { - HBRUSH brush; + if (rItem.state & LVIS_SELECTED) { if (::GetFocus() == m_hWnd) @@ -378,6 +397,11 @@ void CGitLogListBase::FillBackGround(HDC hdc, int Index,CRect &rect) //if (pLogEntry->bCopiedSelf) // brush = ::CreateSolidBrush(::GetSysColor(COLOR_MENU)); //else + if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH) + brush = ::CreateSolidBrush(RGB(156,156,156)); + else if(pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT) + brush = ::CreateSolidBrush(RGB(200,200,128)); + else brush = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW)); } if (brush == NULL) @@ -406,23 +430,39 @@ void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index) str=m_HashMap[data->m_CommitHash][i]; CString shortname; - HBRUSH brush=0; - shortname=_T(""); + HBRUSH brush = 0; + shortname = _T(""); + COLORREF colRef = 0; + + //Determine label color if(GetShortName(str,shortname,_T("refs/heads/"))) { if( shortname == m_CurrentBranch ) - brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::CurrentBranch)); + colRef = m_Colors.GetColor(CColors::CurrentBranch); else - brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::LocalBranch)); + colRef = m_Colors.GetColor(CColors::LocalBranch); }else if(GetShortName(str,shortname,_T("refs/remotes/"))) { - brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::RemoteBranch)); + colRef = m_Colors.GetColor(CColors::RemoteBranch); } else if(GetShortName(str,shortname,_T("refs/tags/"))) { - brush = ::CreateSolidBrush(m_Colors.GetColor(CColors::Tag)); + colRef = m_Colors.GetColor(CColors::Tag); } + else if(GetShortName(str,shortname,_T("refs/stash"))) + { + colRef = m_Colors.GetColor(CColors::Stash); + shortname=_T("stash"); + } + + //When row selected, ajust label color + if (!(m_Theme.IsAppThemed() && m_bVista)) + if (rItem.state & LVIS_SELECTED) + colRef = CColors::MixColors(colRef, ::GetSysColor(COLOR_HIGHLIGHT), 150); + + brush = ::CreateSolidBrush(colRef); + if(!shortname.IsEmpty()) { @@ -431,46 +471,97 @@ void CGitLogListBase::DrawTagBranch(HDC hdc,CRect &rect,INT_PTR index) GetTextExtentPoint32(hdc, shortname,shortname.GetLength(),&size); rt.SetRect(rt.left,rt.top,rt.left+size.cx,rt.bottom); - rt.right+=4; + rt.right+=8; + + //Fill interior of ref label ::FillRect(hdc, &rt, brush); - if (rItem.state & LVIS_SELECTED) + + //Draw edge of label + CDC W_Dc; + W_Dc.Attach(hdc); + + CRect rectEdge = rt; + + W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,100), m_Colors.Darken(colRef,100)); + rectEdge.DeflateRect(1,1); + W_Dc.Draw3dRect(rectEdge, m_Colors.Lighten(colRef,50), m_Colors.Darken(colRef,50)); + + W_Dc.Detach(); + + //Draw text inside label + if (m_Theme.IsAppThemed() && m_bVista) { - COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT)); - ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER); - ::SetTextColor(hdc,clrOld); - }else + int txtState = LISS_NORMAL; + if (rItem.state & LVIS_SELECTED) + txtState = LISS_SELECTED; + + m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, shortname, -1, DT_CENTER | DT_SINGLELINE | DT_VCENTER, 0, &rt); + } + else { - ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER); + if (rItem.state & LVIS_SELECTED) + { + COLORREF clrNew = ::GetSysColor(COLOR_HIGHLIGHTTEXT); + COLORREF clrOld = ::SetTextColor(hdc,clrNew); + ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER); + ::SetTextColor(hdc,clrOld); + }else + { + ::DrawText(hdc,shortname,shortname.GetLength(),&rt,DT_CENTER | DT_SINGLELINE | DT_VCENTER); + } } - ::MoveToEx(hdc,rt.left,rt.top,NULL); - ::LineTo(hdc,rt.right,rt.top); - ::LineTo(hdc,rt.right,rt.bottom); - ::LineTo(hdc,rt.left,rt.bottom); - ::LineTo(hdc,rt.left,rt.top); + //::MoveToEx(hdc,rt.left,rt.top,NULL); + //::LineTo(hdc,rt.right,rt.top); + //::LineTo(hdc,rt.right,rt.bottom); + //::LineTo(hdc,rt.left,rt.bottom); + //::LineTo(hdc,rt.left,rt.top); + - rt.left=rt.right+3; + rt.left=rt.right+1; } if(brush) ::DeleteObject(brush); } rt.right=rect.right; - if (rItem.state & LVIS_SELECTED) + if (m_Theme.IsAppThemed() && m_bVista) { - COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT)); - ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT); - ::SetTextColor(hdc,clrOld); - }else + int txtState = LISS_NORMAL; + if (rItem.state & LVIS_SELECTED) + txtState = LISS_SELECTED; + + m_Theme.DrawText(hdc, LVP_LISTITEM, txtState, data->m_Subject, -1, DT_LEFT | DT_SINGLELINE | DT_VCENTER, 0, &rt); + } + else { - ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT); + if (rItem.state & LVIS_SELECTED) + { + COLORREF clrOld = ::SetTextColor(hdc,::GetSysColor(COLOR_HIGHLIGHTTEXT)); + ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER); + ::SetTextColor(hdc,clrOld); + }else + { + ::DrawText(hdc,data->m_Subject,data->m_Subject.GetLength(),&rt,DT_LEFT | DT_SINGLELINE | DT_VCENTER); + } } - } +static COLORREF blend(const COLORREF& col1, const COLORREF& col2, int amount = 128) { + + // Returns ((256 - amount)*col1 + amount*col2) / 256; + return RGB(((256 - amount)*GetRValue(col1) + amount*GetRValue(col2) ) / 256, + ((256 - amount)*GetGValue(col1) + amount*GetGValue(col2) ) / 256, + ((256 - amount)*GetBValue(col1) + amount*GetBValue(col2) ) / 256); +} + +Gdiplus::Color GetGdiColor(COLORREF col) +{ + return Gdiplus::Color(GetRValue(col),GetGValue(col),GetBValue(col)); +} void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, int x2, - const COLORREF& col,int top + const COLORREF& col,const COLORREF& activeColor, int top ) { int h = laneHeight / 2; @@ -485,12 +576,97 @@ void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, i #define P_270 m , 2 * h+top #define R_CENTER m - r, h - r+top, m - r+d, h - r+top+d + + #define DELTA_UR_B 2*(x1 - m), 2*h +top + #define DELTA_UR_E 0*16, 90*16 +top // -, + + #define DELTA_DR_B 2*(x1 - m), 2*-h +top + #define DELTA_DR_E 270*16, 90*16 +top // -' + + #define DELTA_UL_B 2*(x2 - m), 2*h +top + #define DELTA_UL_E 90*16, 90*16 +top // ,- + + #define DELTA_DL_B 2*(x2 - m),2*-h +top + #define DELTA_DL_E 180*16, 90*16 // '- + + #define CENTER_UR x1, 2*h, 225 + #define CENTER_DR x1, 0 , 135 + #define CENTER_UL x2, 2*h, 315 + #define CENTER_DL x2, 0 , 45 + + + Gdiplus::Graphics graphics( hdc ); + + // arc + switch (type) { + case Lanes::JOIN: + case Lanes::JOIN_R: + case Lanes::HEAD: + case Lanes::HEAD_R: + { + Gdiplus::LinearGradientBrush gradient( + Gdiplus::Point(x1-2, h+top-2), + Gdiplus::Point(P_270), + GetGdiColor(activeColor),GetGdiColor(col)); + + + Gdiplus::Pen mypen(&gradient,2); + //Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2); + + //graphics.DrawRectangle(&mypen,x1-(x2-x1)/2,top+h, x2-x1,laneHeight); + graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top+h-1, x2-x1+1,laneHeight+1,270,90); + //graphics.DrawLine(&mypen,x1-1,h+top,P_270); + + break; + } + case Lanes::JOIN_L: + { + + Gdiplus::Pen mypen(Gdiplus::Color(0,0,0),2); + + + graphics.DrawArc(&mypen,x1,top+h, x2-x1,laneHeight,270,90); + + break; + } + case Lanes::TAIL: + case Lanes::TAIL_R: + { + + Gdiplus::LinearGradientBrush gradient( + Gdiplus::Point(x1-2, h+top-2), + Gdiplus::Point(P_90), + GetGdiColor(activeColor),GetGdiColor(col)); + + + Gdiplus::Pen mypen(&gradient,2); + + graphics.DrawArc(&mypen,x1-(x2-x1)/2-1,top-h-1, x2-x1+1,laneHeight+1,0,90); + + +#if 0 + QConicalGradient gradient(CENTER_DR); + gradient.setColorAt(0.375, activeCol); + gradient.setColorAt(0.625, col); + myPen.setBrush(gradient); + p->setPen(myPen); + p->drawArc(P_CENTER, DELTA_DR); +#endif + break; + } + default: + break; + } + + //static QPen myPen(Qt::black, 2); // fast path here CPen pen; pen.CreatePen(PS_SOLID,2,col); //myPen.setColor(col); HPEN oldpen=(HPEN)::SelectObject(hdc,(HPEN)pen); + Gdiplus::Pen myPen(GetGdiColor(col),2); + //p->setPen(myPen); // vertical line @@ -503,31 +679,33 @@ void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, i case Lanes::JOIN: case Lanes::JOIN_R: case Lanes::JOIN_L: - DrawLine(hdc,P_90,P_270); + case Lanes::CROSS: + //DrawLine(hdc,P_90,P_270); + graphics.DrawLine(&myPen,P_90,P_270); //p->drawLine(P_90, P_270); break; - case Lanes::HEAD: - case Lanes::HEAD_R: case Lanes::HEAD_L: case Lanes::BRANCH: - DrawLine(hdc,P_CENTER,P_270); + //DrawLine(hdc,P_CENTER,P_270); + graphics.DrawLine(&myPen,P_CENTER,P_270); //p->drawLine(P_CENTER, P_270); break; - case Lanes::TAIL: - case Lanes::TAIL_R: case Lanes::TAIL_L: case Lanes::INITIAL: case Lanes::BOUNDARY: case Lanes::BOUNDARY_C: case Lanes::BOUNDARY_R: case Lanes::BOUNDARY_L: - DrawLine(hdc,P_90, P_CENTER); + //DrawLine(hdc,P_90, P_CENTER); + graphics.DrawLine(&myPen,P_90,P_CENTER); //p->drawLine(P_90, P_CENTER); break; default: break; } + myPen.SetColor(GetGdiColor(activeColor)); + // horizontal line switch (type) { case Lanes::MERGE_FORK: @@ -537,23 +715,22 @@ void CGitLogListBase::paintGraphLane(HDC hdc, int laneHeight,int type, int x1, i case Lanes::CROSS: case Lanes::CROSS_EMPTY: case Lanes::BOUNDARY_C: - DrawLine(hdc,P_180,P_0); + //DrawLine(hdc,P_180,P_0); + graphics.DrawLine(&myPen,P_180,P_0); //p->drawLine(P_180, P_0); break; case Lanes::MERGE_FORK_R: - case Lanes::JOIN_R: - case Lanes::HEAD_R: - case Lanes::TAIL_R: case Lanes::BOUNDARY_R: - DrawLine(hdc,P_180,P_CENTER); + //DrawLine(hdc,P_180,P_CENTER); + graphics.DrawLine(&myPen,P_180,P_CENTER); //p->drawLine(P_180, P_CENTER); break; case Lanes::MERGE_FORK_L: - case Lanes::JOIN_L: case Lanes::HEAD_L: case Lanes::TAIL_L: case Lanes::BOUNDARY_L: - DrawLine(hdc,P_CENTER,P_0); + //DrawLine(hdc,P_CENTER,P_0); + graphics.DrawLine(&myPen,P_CENTER,P_0); //p->drawLine(P_CENTER, P_0); break; default: @@ -629,6 +806,9 @@ void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index) //todo unfinished // return; GitRev* data = (GitRev*)m_arShownList.GetAt(index); + if(data->m_CommitHash.IsEmpty()) + return; + CRect rt=rect; LVITEM rItem; SecureZeroMemory(&rItem, sizeof(LVITEM)); @@ -647,16 +827,37 @@ void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index) std::vector& lanes=data->m_Lanes; UINT laneNum = lanes.size(); - UINT mergeLane = 0; + UINT activeLane = 0; for (UINT i = 0; i < laneNum; i++) if (Lanes::isMerge(lanes[i])) { - mergeLane = i; + activeLane = i; break; } int x1 = 0, x2 = 0; int maxWidth = rect.Width(); int lw = 3 * rect.Height() / 4; //laneWidth() + + COLORREF activeColor = m_LineColors[activeLane % Lanes::COLORS_NUM]; + //if (opt.state & QStyle::State_Selected) + // activeColor = blend(activeColor, opt.palette.highlightedText().color(), 208); + + + for (unsigned int i = 0; i < laneNum && x2 < maxWidth; i++) + { + + x1 = x2; + x2 += lw; + + int ln = lanes[i]; + if (ln == Lanes::EMPTY) + continue; + + COLORREF color = i == activeLane ? activeColor : m_LineColors[i % Lanes::COLORS_NUM]; + paintGraphLane(hdc, rect.Height(),ln, x1+rect.left, x2+rect.left, color,activeColor, rect.top); + } + +#if 0 for (UINT i = 0; i < laneNum && x2 < maxWidth; i++) { x1 = x2; @@ -667,16 +868,16 @@ void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index) continue; UINT col = ( Lanes:: isHead(ln) ||Lanes:: isTail(ln) || Lanes::isJoin(ln) - || ln ==Lanes:: CROSS_EMPTY) ? mergeLane : i; + || ln ==Lanes:: CROSS_EMPTY) ? activeLane : i; if (ln == Lanes::CROSS) { paintGraphLane(hdc, rect.Height(),Lanes::NOT_ACTIVE, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top); - paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[mergeLane % Lanes::COLORS_NUM],rect.top); + paintGraphLane(hdc, rect.Height(),Lanes::CROSS, x1, x2, m_LineColors[activeLane % Lanes::COLORS_NUM],rect.top); } else paintGraphLane(hdc, rect.Height(),ln, x1, x2, m_LineColors[col % Lanes::COLORS_NUM],rect.top); } +#endif - TRACE(_T("index %d %d\r\n"),index,data->m_Lanes.size()); } void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) @@ -725,15 +926,39 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) if (data->bCopies) crText = m_Colors.GetColor(CColors::Modified); #endif + if (data->m_Action& (CTGitPath::LOGACTIONS_REBASE_DONE| CTGitPath::LOGACTIONS_REBASE_SKIP) ) + crText = RGB(128,128,128); + + if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_SQUASH) + pLVCD->clrTextBk = RGB(156,156,156); + else if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_EDIT) + pLVCD->clrTextBk = RGB(200,200,128); + else + pLVCD->clrTextBk = ::GetSysColor(COLOR_WINDOW); + + if(data->m_Action&CTGitPath::LOGACTIONS_REBASE_CURRENT) + { + SelectObject(pLVCD->nmcd.hdc, m_boldFont); + *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT; + } + + if(data->m_CommitHash == m_HeadHash) + { + SelectObject(pLVCD->nmcd.hdc, m_boldFont); + *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT; + } + // if ((data->childStackDepth)||(m_mergedRevs.find(data->Rev) != m_mergedRevs.end())) // crText = GetSysColor(COLOR_GRAYTEXT); -// if (data->Rev == m_wcRev) -// { -// SelectObject(pLVCD->nmcd.hdc, m_boldFont); +// + if (data->m_CommitHash == GIT_REV_ZERO) + { + //crText = GetSysColor(RGB(200,200,0)); + //SelectObject(pLVCD->nmcd.hdc, m_boldFont); // We changed the font, so we're returning CDRF_NEWFONT. This // tells the control to recalculate the extent of the text. -// *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT; -// } + *pResult = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT; + } } } if (m_arShownList.GetCount() == (INT_PTR)pLVCD->nmcd.dwItemSpec) @@ -755,13 +980,23 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) if (pLVCD->iSubItem == LOGLIST_GRAPH) { - if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec) + if (m_arShownList.GetCount() > (INT_PTR)pLVCD->nmcd.dwItemSpec && (!this->m_IsRebaseReplaceGraph) ) { CRect rect; GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect); + if(pLVCD->iSubItem == 0) + { + CRect second; + GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem+1, LVIR_BOUNDS, second); + rect.right=second.left; + } + TRACE(_T("A Graphic left %d right %d\r\n"),rect.left,rect.right); FillBackGround(pLVCD->nmcd.hdc, (INT_PTR)pLVCD->nmcd.dwItemSpec,rect); - DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec); + + GitRev* data = (GitRev*)m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec); + if( data ->m_CommitHash != GIT_REV_ZERO) + DrawGraph(pLVCD->nmcd.hdc,rect,pLVCD->nmcd.dwItemSpec); *pResult = CDRF_SKIPDEFAULT; return; @@ -794,7 +1029,8 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) return; } - } + + } } if (pLVCD->iSubItem == 1) @@ -816,6 +1052,7 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) GitRev* pLogEntry = reinterpret_cast(m_arShownList.GetAt(pLVCD->nmcd.dwItemSpec)); CRect rect; GetSubItemRect(pLVCD->nmcd.dwItemSpec, pLVCD->iSubItem, LVIR_BOUNDS, rect); + TRACE(_T("Action left %d right %d\r\n"),rect.left,rect.right); // Get the selected state of the // item being drawn. @@ -827,7 +1064,7 @@ void CGitLogListBase::OnNMCustomdrawLoglist(NMHDR *pNMHDR, LRESULT *pResult) ::DrawIconEx(pLVCD->nmcd.hdc, rect.left + ICONITEMBORDER, rect.top, m_hModifiedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL); nIcons++; - if (pLogEntry->m_Action & CTGitPath::LOGACTIONS_ADDED) + if (pLogEntry->m_Action & (CTGitPath::LOGACTIONS_ADDED|CTGitPath::LOGACTIONS_COPY) ) ::DrawIconEx(pLVCD->nmcd.hdc, rect.left+nIcons*iconwidth + ICONITEMBORDER, rect.top, m_hAddedIcon, iconwidth, iconheight, 0, NULL, DI_NORMAL); nIcons++; @@ -877,7 +1114,14 @@ void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) pLogEntry = reinterpret_cast(m_arShownList.GetAt(pItem->iItem)); CString temp; - temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem); + if(m_IsOldFirst) + { + temp.Format(_T("%d"),pItem->iItem+1); + + }else + { + temp.Format(_T("%d"),m_arShownList.GetCount()-pItem->iItem); + } // Which column? switch (pItem->iSubItem) @@ -885,6 +1129,13 @@ void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) case this->LOGLIST_GRAPH: //Graphic if (pLogEntry) { + if(this->m_IsRebaseReplaceGraph) + { + CTGitPath path; + path.m_Action=pLogEntry->m_Action&CTGitPath::LOGACTIONS_REBASE_MODE_MASK; + + lstrcpyn(pItem->pszText,path.GetActionName(), pItem->cchTextMax); + } } break; case this->LOGLIST_ACTION: //action -- no text in the column @@ -900,9 +1151,9 @@ void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) lstrcpyn(pItem->pszText, (LPCTSTR)pLogEntry->m_AuthorName, pItem->cchTextMax); break; case this->LOGLIST_DATE: //Date - if (pLogEntry) + if (pLogEntry && pLogEntry->m_CommitHash != GIT_REV_ZERO) lstrcpyn(pItem->pszText, - CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat ), + CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ), pItem->cchTextMax); break; @@ -1001,33 +1252,34 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) } //entry is selected, now show the popup menu CIconMenu popup; + CIconMenu submenu; if (popup.CreatePopupMenu()) { + + if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_PICK)) + popup.AppendMenuIcon(ID_REBASE_PICK, IDS_REBASE_PICK, IDI_PICK); + + if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SQUASH)) + popup.AppendMenuIcon(ID_REBASE_SQUASH,IDS_REBASE_SQUASH, IDI_SQUASH); + + if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_EDIT)) + popup.AppendMenuIcon(ID_REBASE_EDIT, IDS_REBASE_EDIT, IDI_EDIT); + + if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_SKIP)) + popup.AppendMenuIcon(ID_REBASE_SKIP, IDS_REBASE_SKIP, IDI_SKIP); + + if(m_ContextMenuMask&(GetContextMenuBit(ID_REBASE_SKIP)|GetContextMenuBit(ID_REBASE_EDIT)| + GetContextMenuBit(ID_REBASE_SQUASH)|GetContextMenuBit(ID_REBASE_PICK))) + popup.AppendMenu(MF_SEPARATOR, NULL); + if (GetSelectedCount() == 1) { -#if 0 - if (!m_path.IsDirectory()) - { - if (m_hasWC) - { - popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF); - popup.AppendMenuIcon(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME); - } - popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF); - popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF); - popup.AppendMenu(MF_SEPARATOR, NULL); - popup.AppendMenuIcon(ID_SAVEAS, IDS_LOG_POPUP_SAVE, IDI_SAVEAS); - popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN); - popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN); - popup.AppendMenuIcon(ID_BLAME, IDS_LOG_POPUP_BLAME, IDI_BLAME); - popup.AppendMenu(MF_SEPARATOR, NULL); - } - else -#endif + { - if (m_hasWC) + if(pSelLogEntry->m_CommitHash != GIT_REV_ZERO) { - popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF); + if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARE)) + popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF); // TODO: // TortoiseMerge could be improved to take a /blame switch // and then not 'cat' the files from a unified diff but @@ -1035,9 +1287,16 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) // But until that's implemented, the context menu entry for // this feature is commented out. //popup.AppendMenu(ID_BLAMECOMPARE, IDS_LOG_POPUP_BLAMECOMPARE, IDI_BLAME); + }else + { + if(m_ContextMenuMask&GetContextMenuBit(ID_COMMIT)) + popup.AppendMenuIcon(ID_COMMIT, IDS_LOG_POPUP_COMMIT, IDI_COMMIT); } - popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF); - popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF); + if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF1)) + popup.AppendMenuIcon(ID_GNUDIFF1, IDS_LOG_POPUP_GNUDIFF_CH, IDI_DIFF); + + if(m_ContextMenuMask&GetContextMenuBit(ID_COMPAREWITHPREVIOUS)) + popup.AppendMenuIcon(ID_COMPAREWITHPREVIOUS, IDS_LOG_POPUP_COMPAREWITHPREVIOUS, IDI_DIFF); //popup.AppendMenuIcon(ID_BLAMEWITHPREVIOUS, IDS_LOG_POPUP_BLAMEWITHPREVIOUS, IDI_BLAME); popup.AppendMenu(MF_SEPARATOR, NULL); } @@ -1063,31 +1322,64 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) //if (m_hasWC) // popup.AppendMenuIcon(ID_MERGEREV, IDS_LOG_POPUP_MERGEREV, IDI_MERGE); - CString str; - str.Format(_T("Reset %s to this"),g_Git.GetCurrentBranch()); - popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT); - popup.AppendMenuIcon(ID_SWITCHTOREV, _T("Switch/Checkout to this") , IDI_SWITCH); - popup.AppendMenuIcon(ID_CREATE_BRANCH, _T("Create Branch at this version") , IDI_COPY); - popup.AppendMenuIcon(ID_CREATE_TAG, _T("Create Tag at this version"), IDI_COPY); - popup.AppendMenuIcon(ID_CHERRY_PICK, _T("Cherry Pick this version"), IDI_EXPORT); - popup.AppendMenuIcon(ID_EXPORT, _T("Export this version"), IDI_EXPORT); + CString str,format; + format.LoadString(IDS_RESET_TO_THIS_FORMAT); + str.Format(format,g_Git.GetCurrentBranch()); + + if(pSelLogEntry->m_CommitHash != GIT_REV_ZERO) + { + if(m_ContextMenuMask&GetContextMenuBit(ID_RESET)) + popup.AppendMenuIcon(ID_RESET,str,IDI_REVERT); + + if(m_ContextMenuMask&GetContextMenuBit(ID_SWITCHTOREV)) + popup.AppendMenuIcon(ID_SWITCHTOREV, IDS_SWITCH_TO_THIS , IDI_SWITCH); + + if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_BRANCH)) + popup.AppendMenuIcon(ID_CREATE_BRANCH, IDS_CREATE_BRANCH_AT_THIS , IDI_COPY); + + if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_TAG)) + popup.AppendMenuIcon(ID_CREATE_TAG,IDS_CREATE_TAG_AT_THIS , IDI_COPY); + + format.LoadString(IDS_REBASE_THIS_FORMAT); + str.Format(format,g_Git.GetCurrentBranch()); + + if(pSelLogEntry->m_CommitHash != m_HeadHash) + if(m_ContextMenuMask&GetContextMenuBit(ID_REBASE_TO_VERSION)) + popup.AppendMenuIcon(ID_REBASE_TO_VERSION, str , IDI_REBASE); + + if(m_ContextMenuMask&GetContextMenuBit(ID_EXPORT)) + popup.AppendMenuIcon(ID_EXPORT,IDS_EXPORT_TO_THIS, IDI_EXPORT); + popup.AppendMenu(MF_SEPARATOR, NULL); + } + + } + + if(!pSelLogEntry->m_Ref.IsEmpty() && GetSelectedCount() == 1) + { + popup.AppendMenuIcon(ID_REFLOG_DEL, IDS_REFLOG_DEL, IDI_DELETE); + popup.AppendMenuIcon(ID_STASH_APPLY,IDS_MENUSTASHAPPLY, IDI_RELOCATE); popup.AppendMenu(MF_SEPARATOR, NULL); } - else if (GetSelectedCount() >= 2) + + if (GetSelectedCount() >= 2) { bool bAddSeparator = false; if (IsSelectionContinuous() || (GetSelectedCount() == 2)) { - popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF); + if(m_ContextMenuMask&GetContextMenuBit(ID_COMPARETWO)) + popup.AppendMenuIcon(ID_COMPARETWO, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF); } + if (GetSelectedCount() == 2) { //popup.AppendMenuIcon(ID_BLAMETWO, IDS_LOG_POPUP_BLAMEREVS, IDI_BLAME); - popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF); + if(m_ContextMenuMask&GetContextMenuBit(ID_GNUDIFF2)) + popup.AppendMenuIcon(ID_GNUDIFF2, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF); bAddSeparator = true; } + if (m_hasWC) { //popup.AppendMenuIcon(ID_REVERTREV, IDS_LOG_POPUP_REVERTREVS, IDI_REVERT); @@ -1098,6 +1390,39 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) if (bAddSeparator) popup.AppendMenu(MF_SEPARATOR, NULL); } + + if ( GetSelectedCount() >0 && pSelLogEntry->m_CommitHash != GIT_REV_ZERO) + { + if ( IsSelectionContinuous() && GetSelectedCount() >= 2 ) + { + if(m_ContextMenuMask&GetContextMenuBit(ID_COMBINE_COMMIT)) + { + CString head; + int headindex; + headindex = this->GetHeadIndex(); + if(headindex>=0) + { + head.Format(_T("HEAD~%d"),LastSelect-headindex); + CString hash=g_Git.GetHash(head); + hash=hash.Left(40); + GitRev* pLastEntry = reinterpret_cast(m_arShownList.GetAt(LastSelect)); + if(pLastEntry->m_CommitHash == hash) + popup.AppendMenuIcon(ID_COMBINE_COMMIT,IDS_COMBINE_TO_ONE,IDI_COMBINE); + } + } + } + if(m_ContextMenuMask&GetContextMenuBit(ID_CHERRY_PICK)) + popup.AppendMenuIcon(ID_CHERRY_PICK, IDS_CHERRY_PICK_VERSION, IDI_EXPORT); + + if(GetSelectedCount()<=2 || (IsSelectionContinuous() && GetSelectedCount() > 0)) + if(m_ContextMenuMask&GetContextMenuBit(ID_CREATE_PATCH)) + popup.AppendMenuIcon(ID_CREATE_PATCH, IDS_CREATE_PATCH, IDI_PATCH); + + popup.AppendMenu(MF_SEPARATOR, NULL); + + } + + #if 0 // if ((selEntries.size() > 0)&&(bAllFromTheSameAuthor)) // { @@ -1114,13 +1439,49 @@ void CGitLogListBase::OnContextMenu(CWnd* pWnd, CPoint point) if (GetSelectedCount() == 1) { - popup.AppendMenuIcon(ID_COPYHASH, _T("Copy Commit Hash")); + if(m_ContextMenuMask&GetContextMenuBit(ID_COPYHASH)) + popup.AppendMenuIcon(ID_COPYHASH, IDS_COPY_COMMIT_HASH); } if (GetSelectedCount() != 0) { - popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD); + if(m_ContextMenuMask&GetContextMenuBit(ID_COPYCLIPBOARD)) + popup.AppendMenuIcon(ID_COPYCLIPBOARD, IDS_LOG_POPUP_COPYTOCLIPBOARD); + } + + if(m_ContextMenuMask&GetContextMenuBit(ID_FINDENTRY)) + popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND); + + + if (GetSelectedCount() == 1) + { + if(m_ContextMenuMask &GetContextMenuBit(ID_DELETE)) + { + if( this->m_HashMap.find(pSelLogEntry->m_CommitHash) != m_HashMap.end() ) + { + CString str; + str.LoadString(IDS_DELETE_BRANCHTAG); + if( m_HashMap[pSelLogEntry->m_CommitHash].size() == 1 ) + { + str+=_T(" "); + str+=m_HashMap[pSelLogEntry->m_CommitHash].at(0); + popup.AppendMenuIcon(ID_DELETE,str+_T("..."),IDI_DELETE); + } + else if( m_HashMap[pSelLogEntry->m_CommitHash].size() > 1 ) + { + + submenu.CreatePopupMenu(); + for(int i=0;im_CommitHash].size();i++) + { + submenu.AppendMenuIcon(ID_DELETE+(i<<16),m_HashMap[pSelLogEntry->m_CommitHash][i]+_T("...")); + } + + popup.AppendMenu(MF_BYPOSITION|MF_POPUP|MF_STRING,(UINT) submenu.m_hMenu,str); + + } + + } + } } - popup.AppendMenuIcon(ID_FINDENTRY, IDS_LOG_POPUP_FIND); int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0); // DialogEnableWindow(IDOK, FALSE); @@ -1196,7 +1557,8 @@ void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly) sLogCopyText.Format(_T("%s: %s\r\n%s: %s\r\n%s: %s\r\n%s:\r\n%s\r\n----\r\n%s\r\n\r\n"), (LPCTSTR)sRev, pLogEntry->m_CommitHash, (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->m_AuthorName, - (LPCTSTR)sDate, (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat ), + (LPCTSTR)sDate, + (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->m_AuthorDate, m_DateFormat, true, m_bRelativeTimes ), (LPCTSTR)sMessage, pLogEntry->m_Subject+_T("\r\n")+pLogEntry->m_Body, (LPCTSTR)sPaths); sClipdata += sLogCopyText; @@ -1214,9 +1576,20 @@ void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly) void CGitLogListBase::DiffSelectedRevWithPrevious() { -#if 0 if (m_bThreadRunning) return; + + int FirstSelect=-1, LastSelect=-1; + POSITION pos = GetFirstSelectedItemPosition(); + FirstSelect = GetNextSelectedItem(pos); + while(pos) + { + LastSelect = GetNextSelectedItem(pos); + } + + ContextMenuAction(ID_COMPAREWITHPREVIOUS,FirstSelect,LastSelect); + +#if 0 UpdateLogInfoLabel(); int selIndex = m_LogList.GetSelectionMark(); if (selIndex < 0) @@ -1337,12 +1710,12 @@ void CGitLogListBase::OnLvnOdfinditemLoglist(NMHDR *pNMHDR, LRESULT *pResult) *pResult = -1; } -int CGitLogListBase::FillGitLog(CTGitPath *path,int info) +int CGitLogListBase::FillGitLog(CTGitPath *path,int info,CString *from,CString *to) { ClearText(); this->m_logEntries.ClearAll(); - this->m_logEntries.ParserFromLog(path,-1,info); + this->m_logEntries.ParserFromLog(path,-1,info,from,to); //this->m_logEntries.ParserFromLog(); SetItemCountEx(this->m_logEntries.size()); @@ -1351,8 +1724,16 @@ int CGitLogListBase::FillGitLog(CTGitPath *path,int info) for(unsigned int i=0;im_arShownList.Add(&m_logEntries[i]); + if(m_IsOldFirst) + { + m_logEntries[m_logEntries.size()-i-1].m_IsFull=TRUE; + this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]); + + }else + { + m_logEntries[i].m_IsFull=TRUE; + this->m_arShownList.Add(&m_logEntries[i]); + } } if(path) @@ -1378,23 +1759,40 @@ int CGitLogListBase::FillGitShortLog() CString hash; int mask; mask = CGit::LOG_INFO_ONLY_HASH | CGit::LOG_INFO_BOUNDARY; - if(this->m_bAllBranch) - mask |= CGit::LOG_INFO_ALL_BRANCH; - - this->m_logEntries.ParserShortLog(path,hash,-1,mask); +// if(this->m_bAllBranch) + mask |= m_ShowMask; + if(m_bShowWC) + this->m_logEntries.insert(m_logEntries.begin(),this->m_wcRev); + + this->m_logEntries.FetchShortLog(path,m_StartRef,-1,mask,m_bShowWC?1:0); //this->m_logEntries.ParserFromLog(); if(IsInWorkingThread()) + { PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL); + } else + { SetItemCountEx(this->m_logEntries.size()); + } this->m_arShownList.RemoveAll(); for(unsigned int i=0;im_arShownList.Add(&m_logEntries[i]); + { + if(i>0 || m_logEntries[i].m_CommitHash != GIT_REV_ZERO) + m_logEntries[i].m_Subject=_T("parser..."); + + if(this->m_IsOldFirst) + { + this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-1-i]); + }else + { + this->m_arShownList.Add(&m_logEntries[i]); + } + } return 0; } @@ -1439,8 +1837,8 @@ void CGitLogListBase::OnNMDblclkLoglist(NMHDR * /*pNMHDR*/, LRESULT *pResult) // a double click on an entry in the revision list has happened *pResult = 0; - if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE)) - DiffSelectedRevWithPrevious(); + if (CRegDWORD(_T("Software\\TortoiseGit\\DiffByDoubleClickInLog"), FALSE)) + DiffSelectedRevWithPrevious(); } int CGitLogListBase::FetchLogAsync(void * data) @@ -1482,6 +1880,171 @@ void CGitLogListBase::GetTimeRange(CTime &oldest, CTime &latest) } } +//Helper class for FetchFullLogInfo() +class CGitCall_FetchFullLogInfo : public CGitCall +{ +public: + CGitCall_FetchFullLogInfo(CGitLogListBase* ploglist):m_ploglist(ploglist),m_CollectedCount(0){} + virtual bool OnOutputData(const BYTE* data, size_t size) + { + if(size==0) + return m_ploglist->m_bExitThread; + //Add received data to byte collector + m_ByteCollector.append(data,size); + + //Find loginfo endmarker + static const BYTE dataToFind[]={0,0,'#','<'}; + int found=m_ByteCollector.findData(dataToFind,4); + if(found<0) + return m_ploglist->m_bExitThread;//Not found + found+=2;//Position after loginfo end-marker + + //Prepare data for OnLogInfo and call it + BYTE_VECTOR logInfo; + logInfo.append(&*m_ByteCollector.begin(),found); + OnLogInfo(logInfo); + + //Remove loginfo from bytecollector + m_ByteCollector.erase(m_ByteCollector.begin(),m_ByteCollector.begin()+found); + + return m_ploglist->m_bExitThread; + } + virtual void OnEnd() + { + //Rest should be a complete log line. + if(!m_ByteCollector.empty()) + OnLogInfo(m_ByteCollector); + } + + + void OnLogInfo(BYTE_VECTOR& logInfo) + { + GitRev fullRev; + fullRev.ParserFromLog(logInfo); + MAP_HASH_REV::iterator itRev=m_ploglist->m_logEntries.m_HashMap.find(fullRev.m_CommitHash); + if(itRev==m_ploglist->m_logEntries.m_HashMap.end()) + { + //Should not occur, only when Git-tree updated in the mean time. (Race condition) + return;//Ignore + } + //Set updating + int rev=itRev->second; + GitRev* revInVector=&m_ploglist->m_logEntries[rev]; + + + if(revInVector->m_IsFull) + return; + + if(!m_ploglist->m_LogCache.GetCacheData(m_ploglist->m_logEntries[rev])) + { + ++m_CollectedCount; + InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsUpdateing,FALSE); + InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsFull,TRUE); + ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0); + return; + } + +// fullRev.m_IsUpdateing=TRUE; +// fullRev.m_IsFull=TRUE; + + + if(InterlockedExchange(&revInVector->m_IsUpdateing,TRUE)) + return;//Cannot update this row now. Ignore. + TCHAR oldmark=revInVector->m_Mark; + GIT_REV_LIST oldlist=revInVector->m_ParentHash; +// CString oldhash=m_CommitHash; + + //Parse new rev info + revInVector->ParserFromLog(logInfo); + + if(oldmark!=0) + revInVector->m_Mark=oldmark; //parser full log will cause old mark overwrited. + //So we need keep old bound mark. + revInVector->m_ParentHash=oldlist; + + //update cache + m_ploglist->m_LogCache.AddCacheEntry(*revInVector); + + //Reset updating + InterlockedExchange(&revInVector->m_IsFull,TRUE); + InterlockedExchange(&revInVector->m_IsUpdateing,FALSE); + + //Notify listcontrol and update progress bar + ++m_CollectedCount; + + ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0); + + DWORD percent=m_CollectedCount*68/m_ploglist->m_logEntries.size() + GITLOG_START+1+30; + if(percent == GITLOG_END) + percent = GITLOG_END -1; + + ::PostMessage(m_ploglist->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0); + } + + CGitLogListBase* m_ploglist; + BYTE_VECTOR m_ByteCollector; + int m_CollectedCount; + +}; + +void CGitLogListBase::FetchFullLogInfo(CString &from, CString &to) +{ + CGitCall_FetchFullLogInfo fetcher(this); + int mask= + CGit::LOG_INFO_FULL_DIFF| + CGit::LOG_INFO_STAT| + CGit::LOG_INFO_FILESTATE| + CGit::LOG_INFO_DETECT_COPYRENAME| + CGit::LOG_INFO_SHOW_MERGEDFILE | + m_ShowMask; + + CTGitPath *path; + if(this->m_Path.IsEmpty()) + path=NULL; + else + path=&this->m_Path; + + g_Git.GetLog(&fetcher,CString(),path,-1,mask,&from,&to); +} + +void CGitLogListBase::FetchLastLogInfo() +{ + unsigned int updated=0; + int percent=0; + CRect rect; + { + for(unsigned int i=0;im_bExitThread) + { + InterlockedExchange(&m_bThreadRunning, FALSE); + InterlockedExchange(&m_bNoDispUpdates, FALSE); return 0; + } + InterlockedExchange(&m_bNoDispUpdates, FALSE); + ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START_ALL, 0); + + int start=0; CString firstcommit,lastcommit; + int update=0; + for(int i=0;im_HeadHash,m_logEntries[i].m_Files); + m_logEntries[i].m_Action =0; + for(int j=0;j< m_logEntries[i].m_Files.GetCount();j++) + m_logEntries[i].m_Action |= m_logEntries[i].m_Files[j].m_Action; + + m_logEntries[i].m_Body.Format(_T("%d files changed"),m_logEntries[i].m_Files.GetCount()); + ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM)0,0); + continue; + } + + start=this->m_logEntries[i].ParserFromLog(m_logEntries.m_RawlogData,start); + m_logEntries.m_HashMap[m_logEntries[i].m_CommitHash]=i; + + if(m_LogCache.GetCacheData(m_logEntries[i])) + { + if(firstcommit.IsEmpty()) + firstcommit=m_logEntries[i].m_CommitHash; + lastcommit=m_logEntries[i].m_CommitHash; + + }else + { + InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE); + InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE); + update++; + } + ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM) i, 0); + + if(start<0) + break; + if(start>=m_logEntries.m_RawlogData.size()) + break; + + int percent=i*30/m_logEntries.size() + GITLOG_START+1; + + ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent, 0); + + if(this->m_bExitThread) + { + InterlockedExchange(&m_bThreadRunning, FALSE); + InterlockedExchange(&m_bNoDispUpdates, FALSE); + return 0; + } + } + if(!lastcommit.IsEmpty()) + FetchFullLogInfo(lastcommit,firstcommit); + + this->FetchLastLogInfo(); + #if 0 RedrawItems(0, m_arShownList.GetCount()); - SetRedraw(false); - ResizeAllListCtrlCols(); - SetRedraw(true); +// SetRedraw(false); +// ResizeAllListCtrlCols(); +// SetRedraw(true); if ( m_pStoreSelection ) { @@ -1531,48 +2154,11 @@ UINT CGitLogListBase::LogThread() } } #endif - InterlockedExchange(&m_bNoDispUpdates, FALSE); - - int index=0; - unsigned int updated=0; - int percent=0; - CRect rect; - while(1) - { - for(unsigned int i=0;iGetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0); - - - } - if(updated==m_logEntries.size()) - break; - } + //FetchFullLogInfo(); + //FetchFullLogInfoOrig(); //RefreshCursor(); // make sure the filter is applied (if any) now, after we refreshed/fetched // the log messages @@ -1585,11 +2171,26 @@ UINT CGitLogListBase::LogThread() } void CGitLogListBase::Refresh() -{ - if(!m_bThreadRunning) +{ + m_bExitThread=TRUE; + if(m_LoadingThread!=NULL) + { + DWORD ret =::WaitForSingleObject(m_LoadingThread->m_hThread,20000); + if(ret == WAIT_TIMEOUT) + TerminateThread(); + } + + this->SetItemCountEx(0); + this->Clear(); + + //Update branch and Tag info + ReloadHashMap(); + //Assume Thread have exited + //if(!m_bThreadRunning) { - this->SetItemCountEx(0); + m_logEntries.clear(); + m_bExitThread=FALSE; InterlockedExchange(&m_bThreadRunning, TRUE); InterlockedExchange(&m_bNoDispUpdates, TRUE); if (AfxBeginThread(LogThreadEntry, this)==NULL) @@ -1701,7 +2302,7 @@ void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist) } if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS)) { - sRev.Format(_T("%ld"), m_logEntries[i].m_CommitHash); + sRev.Format(_T("%s"), m_logEntries[i].m_CommitHash); if (regex_search(wstring((LPCTSTR)sRev), pat, flags)&&IsEntryInDateRange(i)) { pShownlist->Add(&m_logEntries[i]); @@ -1793,7 +2394,7 @@ void CGitLogListBase::RecalculateShownList(CPtrArray * pShownlist) } if ((m_nSelectedFilter == LOGFILTER_ALL)||(m_nSelectedFilter == LOGFILTER_REVS)) { - sRev.Format(_T("%ld"), m_logEntries[i].m_CommitHash); + sRev.Format(_T("%s"), m_logEntries[i].m_CommitHash); if ((sRev.Find(find) >= 0)&&(IsEntryInDateRange(i))) { pShownlist->Add(&m_logEntries[i]); @@ -1850,15 +2451,21 @@ void CGitLogListBase::RemoveFilter() for (DWORD i=0; im_IsOldFirst) + { + m_arShownList.Add(&m_logEntries[m_logEntries.size()-i-1]); + }else + { + m_arShownList.Add(&m_logEntries[i]); + } } // InterlockedExchange(&m_bNoDispUpdates, FALSE); DeleteAllItems(); SetItemCountEx(ShownCountWithStopped()); RedrawItems(0, ShownCountWithStopped()); - SetRedraw(false); - ResizeAllListCtrlCols(); - SetRedraw(true); +// SetRedraw(false); +// ResizeAllListCtrlCols(); +// SetRedraw(true); InterlockedExchange(&m_bNoDispUpdates, FALSE); } @@ -1866,18 +2473,17 @@ void CGitLogListBase::RemoveFilter() void CGitLogListBase::Clear() { m_arShownList.RemoveAll(); - m_logEntries.clear(); - m_logEntries.m_HashMap.clear(); DeleteAllItems(); - m_logEntries.m_Lns.clear(); - m_logEntries.m_FirstFreeLane=0; - m_logEntries.m_Lns.clear(); + m_logEntries.ClearAll(); } void CGitLogListBase::OnDestroy() { + // save the column widths to the registry + SaveColumnWidths(); + if(this->m_bThreadRunning) { this->m_bExitThread=true; @@ -1887,7 +2493,7 @@ void CGitLogListBase::OnDestroy() } while(m_LogCache.SaveCache()) { - if(CMessageBox::Show(NULL,_T("Can Save Log Cache to Disk,click yes for retry, click no for give up"),_T("TortoiseGit"), + if(CMessageBox::Show(NULL,_T("Cannot Save Log Cache to Disk. To retry click yes. To give up click no."),_T("TortoiseGit"), MB_YESNO) == IDNO) break; } @@ -1900,5 +2506,47 @@ LRESULT CGitLogListBase::OnLoad(WPARAM wParam,LPARAM lParam) int i=(int)wParam; this->GetItemRect(i,&rect,LVIR_BOUNDS); this->InvalidateRect(rect); + + if(this->GetItemState(i,LVIF_STATE) & LVIS_SELECTED) + { + int i=0; + } return 0; } + +/** + * Save column widths to the registry + */ +void CGitLogListBase::SaveColumnWidths() +{ + CHeaderCtrl* pHdrCtrl = (CHeaderCtrl*)(GetDlgItem(0)); + if (pHdrCtrl) + { + int numcols = pHdrCtrl->GetItemCount(); + for (int col = 0; col < numcols; col++) + { + int width = GetColumnWidth( col ); + CString regentry; + regentry.Format( _T("Software\\TortoiseGit\\%s\\ColWidth%d"),m_ColumnRegKey, col); + CRegDWORD regwidth(regentry, 0); + regwidth = width; // this writes it to reg + } + } +} + +int CGitLogListBase::GetHeadIndex() +{ + if(m_HeadHash.IsEmpty()) + return -1; + + for(int i=0;im_CommitHash == m_HeadHash ) + return i; + } + } + return -1; +} \ No newline at end of file