OSDN Git Service

Improve log speed.
authorFrank Li <lznuaa@gmail.com>
Tue, 24 Mar 2009 14:52:40 +0000 (22:52 +0800)
committerFrank Li <lznuaa@gmail.com>
Tue, 24 Mar 2009 14:52:40 +0000 (22:52 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseProc/GitLogListBase.cpp
src/TortoiseProc/GitLogListBase.h
src/TortoiseProc/LogDataVector.cpp
src/TortoiseProc/LogDlgHelper.h

index 6ed7eea..7dedd88 100644 (file)
@@ -625,6 +625,9 @@ void CGitLogListBase::DrawGraph(HDC hdc,CRect &rect,INT_PTR index)
        //todo unfinished\r
 //     return;\r
        GitRev* data = (GitRev*)m_arShownList.GetAt(index);\r
+       if(data->m_CommitHash.IsEmpty())\r
+               return;\r
+\r
        CRect rt=rect;\r
        LVITEM   rItem;\r
        SecureZeroMemory(&rItem, sizeof(LVITEM));\r
@@ -1497,9 +1500,8 @@ int CGitLogListBase::FillGitShortLog()
 //     if(this->m_bAllBranch)\r
        mask |= m_ShowMask;\r
 \r
-       this->m_logEntries.ParserShortLog(path,hash,-1,mask);\r
+       this->m_logEntries.FetchShortLog(path,hash,-1,mask);\r
        \r
-\r
        //this->m_logEntries.ParserFromLog();\r
        if(IsInWorkingThread())\r
                PostMessage(LVM_SETITEMCOUNT, (WPARAM) this->m_logEntries.size(),(LPARAM) LVSICF_NOINVALIDATEALL);\r
@@ -1510,6 +1512,7 @@ int CGitLogListBase::FillGitShortLog()
 \r
        for(unsigned int i=0;i<m_logEntries.size();i++)\r
        {\r
+               m_logEntries[i].m_Subject=_T("parser...");\r
                if(this->m_IsOldFirst)\r
                {\r
                        this->m_arShownList.Add(&m_logEntries[m_logEntries.size()-1-i]);\r
@@ -1658,9 +1661,21 @@ public:
                GitRev* revInVector=&m_ploglist->m_logEntries[rev];\r
 \r
 \r
+               if(revInVector->m_IsFull)\r
+                       return;\r
+\r
+               if(!m_ploglist->m_LogCache.GetCacheData(m_ploglist->m_logEntries[rev]))\r
+               {\r
+                       ++m_CollectedCount;\r
+                       InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsUpdateing,FALSE);\r
+                       InterlockedExchange(&m_ploglist->m_logEntries[rev].m_IsFull,TRUE);\r
+                       ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);\r
+                       return;\r
+               }\r
+\r
 //             fullRev.m_IsUpdateing=TRUE;\r
 //             fullRev.m_IsFull=TRUE;\r
-\r
+       \r
 \r
                if(InterlockedExchange(&revInVector->m_IsUpdateing,TRUE))\r
                        return;//Cannot update this row now. Ignore.\r
@@ -1676,6 +1691,9 @@ public:
                                                               //So we need keep old bound mark.\r
                revInVector->m_ParentHash=oldlist;\r
 \r
+               //update cache\r
+               m_ploglist->m_LogCache.AddCacheEntry(*revInVector);\r
+\r
                //Reset updating\r
                InterlockedExchange(&revInVector->m_IsFull,TRUE);\r
                InterlockedExchange(&revInVector->m_IsUpdateing,FALSE);\r
@@ -1685,7 +1703,7 @@ public:
 \r
                ::PostMessage(m_ploglist->m_hWnd,MSG_LOADED,(WPARAM)rev,0);\r
 \r
-               DWORD percent=m_CollectedCount*98/m_ploglist->m_logEntries.size() + GITLOG_START+1;\r
+               DWORD percent=m_CollectedCount*68/m_ploglist->m_logEntries.size() + GITLOG_START+1+30;\r
                if(percent == GITLOG_END)\r
                        percent = GITLOG_END -1;\r
                \r
@@ -1698,7 +1716,7 @@ public:
 \r
 };\r
 \r
-void CGitLogListBase::FetchFullLogInfo()\r
+void CGitLogListBase::FetchFullLogInfo(CString &from, CString &to)\r
 {\r
        CGitCall_FetchFullLogInfo fetcher(this);\r
        int mask=\r
@@ -1706,18 +1724,27 @@ void CGitLogListBase::FetchFullLogInfo()
                CGit::LOG_INFO_FILESTATE|\r
                CGit::LOG_INFO_DETECT_COPYRENAME|\r
                m_ShowMask;\r
-       g_Git.GetLog(&fetcher,CString(),NULL,-1,mask);\r
+\r
+       CTGitPath *path;\r
+    if(this->m_Path.IsEmpty())\r
+        path=NULL;\r
+    else\r
+        path=&this->m_Path;\r
+\r
+       g_Git.GetLog(&fetcher,CString(),path,-1,mask,&from,&to);\r
 }\r
 \r
-void CGitLogListBase::FetchFullLogInfoOrig()\r
+void CGitLogListBase::FetchLastLogInfo()\r
 {\r
        unsigned int updated=0;\r
        int percent=0;\r
        CRect rect;\r
-       while(1)\r
        {\r
                for(unsigned int i=0;i<m_logEntries.size();i++)\r
                {\r
+                       if(m_logEntries[i].m_IsFull)\r
+                               continue;\r
+\r
                        if(m_LogCache.GetCacheData(m_logEntries[i]))\r
                        {\r
                                if(!m_logEntries.FetchFullInfo(i))\r
@@ -1740,18 +1767,8 @@ void CGitLogListBase::FetchFullLogInfoOrig()
                                InterlockedExchange(&m_bThreadRunning, FALSE);\r
                                InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
                                return;\r
-                       }\r
-\r
-                       percent=updated*98/m_logEntries.size() + GITLOG_START+1;\r
-                       if(percent == GITLOG_END)\r
-                               percent = GITLOG_END -1;\r
-                       \r
-                       ::PostMessage(this->GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent,0);\r
-\r
-                       \r
+                       }                       \r
                }\r
-               if(updated==m_logEntries.size())\r
-                       break;\r
        }\r
 }\r
 \r
@@ -1780,6 +1797,50 @@ UINT CGitLogListBase::LogThread()
                InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
                return 0;\r
        }\r
+       InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
+       ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) GITLOG_START_ALL, 0);\r
+\r
+       int start=0; CString firstcommit,lastcommit;\r
+       int update=0;\r
+       for(int i=0;i<this->GetItemCount();i++)\r
+       {\r
+               start=this->m_logEntries[i].ParserFromLog(m_logEntries.m_RawlogData,start);\r
+               m_logEntries.m_HashMap[m_logEntries[i].m_CommitHash]=i;\r
+\r
+               if(m_LogCache.GetCacheData(m_logEntries[i]))\r
+               {\r
+                       if(firstcommit.IsEmpty())\r
+                               firstcommit=m_logEntries[i].m_CommitHash;\r
+                       lastcommit=m_logEntries[i].m_CommitHash;\r
+\r
+               }else\r
+               {\r
+                       InterlockedExchange(&m_logEntries[i].m_IsUpdateing,FALSE);\r
+                       InterlockedExchange(&m_logEntries[i].m_IsFull,TRUE);\r
+                       update++;\r
+               }\r
+               if(start<0)\r
+                       break;\r
+               if(start>=m_logEntries.m_RawlogData.size())\r
+                       break;\r
+\r
+               int percent=i*30/m_logEntries.size() + GITLOG_START+1;\r
+\r
+               ::PostMessage(GetParent()->m_hWnd,MSG_LOAD_PERCENTAGE,(WPARAM) percent, 0);\r
+               ::PostMessage(m_hWnd,MSG_LOADED,(WPARAM) i, 0);\r
+\r
+               if(this->m_bExitThread)\r
+               {       \r
+                       InterlockedExchange(&m_bThreadRunning, FALSE);\r
+                       InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
+                       return 0;\r
+               }\r
+       }\r
+       if(!lastcommit.IsEmpty())\r
+               FetchFullLogInfo(lastcommit,firstcommit);\r
+       \r
+       this->FetchLastLogInfo();\r
+       \r
 #if 0\r
        RedrawItems(0, m_arShownList.GetCount());\r
 //     SetRedraw(false);\r
@@ -1804,7 +1865,7 @@ UINT CGitLogListBase::LogThread()
                }\r
        }\r
 #endif\r
-       InterlockedExchange(&m_bNoDispUpdates, FALSE);\r
+\r
 \r
 \r
        //FetchFullLogInfo();\r
index 4f1b6f7..94be5ba 100644 (file)
@@ -208,8 +208,8 @@ protected:
        virtual BOOL PreTranslateMessage(MSG* pMsg);\r
        static UINT LogThreadEntry(LPVOID pVoid);\r
        UINT LogThread();\r
-       void FetchFullLogInfoOrig();\r
-       void FetchFullLogInfo();\r
+       void FetchLastLogInfo();\r
+       void FetchFullLogInfo(CString &from, CString &to);\r
        void FillBackGround(HDC hdc, int Index,CRect &rect);\r
        void DrawTagBranch(HDC,CRect &rect,INT_PTR index);\r
        void DrawGraph(HDC,CRect &rect,INT_PTR index);\r
index 9ae5fb7..d0281b7 100644 (file)
@@ -79,6 +79,41 @@ void CLogDataVector::ClearAll()
 
 int CLogDataVector::ParserShortLog(CTGitPath *path ,CString &hash,int count ,int mask )
 {
+       BYTE_VECTOR log;
+       GitRev rev;
+
+       if(g_Git.IsInitRepos())
+               return 0;
+
+       CString begin;
+       begin.Format(_T("#<%c>"),LOG_REV_ITEM_BEGIN);
+
+       //g_Git.GetShortLog(log,path,count);
+
+       g_Git.GetLog(log,hash,path,count,mask);
+
+       if(log.size()==0)
+               return 0;
+       
+       int start=4;
+       int length;
+       int next =0;
+       while( next>=0 && next<log.size())
+       {
+               next=rev.ParserFromLog(log,next);
+
+               rev.m_Subject=_T("Load .................................");
+               this->push_back(rev);
+               m_HashMap[rev.m_CommitHash]=size()-1;
+
+               //next=log.find(0,next);
+       }
+
+       return 0;
+
+}
+int CLogDataVector::FetchShortLog(CTGitPath *path ,CString &hash,int count ,int mask )
+{
        //BYTE_VECTOR log;
        m_RawlogData.clear();\r
        m_RawLogStart.clear();
@@ -115,14 +150,13 @@ int CLogDataVector::ParserShortLog(CTGitPath *path ,CString &hash,int count ,int
                //this->at(i).m_Subject=_T("parser...");
                next=m_RawlogData.findData(dataToFind,2,next+1);
                //next=log.find(0,next);
-
        }
-       t2=GetTickCount();
 
-       TRACE(_T("Parser Log Time %ld\r\n"),t2-t1);
+       resize(m_RawLogStart.size());
 
-       return 0;
+       t2=GetTickCount();
 
+       return 0;
 }
 int CLogDataVector::FetchFullInfo(int i)
 {
index f823ad6..945f8d4 100644 (file)
@@ -60,6 +60,8 @@ public:
        void ClearAll();\r
        int  ParserFromLog(CTGitPath *path =NULL,int count = -1,int infomask=CGit::LOG_INFO_STAT|CGit::LOG_INFO_FILESTATE,\r
                                                                                         CString *from=NULL,CString *to=NULL);\r
+\r
+       int  FetchShortLog(CTGitPath *path , CString &hash,int count=-1 ,int mask=CGit::LOG_INFO_ONLY_HASH );\r
        int  ParserShortLog(CTGitPath *path ,CString &hash,int count=-1 ,int mask=CGit::LOG_INFO_ONLY_HASH );\r
 \r
        int  ParserFromRefLog(CString ref);\r