X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=src%2FTortoiseProc%2FGitLogCache.cpp;h=0ba88b94a745b9a7428bc53ea52813ef091d1caa;hb=7cd2af98958cd63ad34eb6c6528bf2c8638c1041;hp=36eff941b325574086f568bc86a0ef780cff7f7c;hpb=7ccde0bdfee1371a9bcd2da4459c9b73ea16ba61;p=tortoisegit%2FTortoiseGitJp.git diff --git a/src/TortoiseProc/GitLogCache.cpp b/src/TortoiseProc/GitLogCache.cpp index 36eff94..0ba88b9 100644 --- a/src/TortoiseProc/GitLogCache.cpp +++ b/src/TortoiseProc/GitLogCache.cpp @@ -8,12 +8,43 @@ CLogCache::CLogCache() CLogCache::~CLogCache() { - this->m_IndexFile.Close(); - this->m_DataFile.Close(); + //this->m_IndexFile.Close(); + //this->m_DataFile.Close(); +} +int CLogCache::AddCacheEntry(GitRev &Rev) +{ + this->m_HashMap[Rev.m_CommitHash] = Rev; + return 0; } -int CLogCache::FetchCache(CString GitDir) +GitRev * CLogCache::GetCacheData(CGitHash &hash) +{ + if(this->m_HashMapIndex.find(hash)==m_HashMapIndex.end()) + { + if(this->m_HashMap.IsExist(hash)) + { + return &m_HashMap[hash]; + } + m_HashMap[hash].m_CommitHash=hash; + return &m_HashMap[hash]; + } + else + { + GitRev rev; + if(!LoadOneItem(rev,m_HashMapIndex[hash])) + { + m_HashMap[hash].CopyFrom(rev); + m_HashMap[hash].m_IsFull=true; + + return &m_HashMap[hash]; + } + } + m_HashMap[hash].m_CommitHash=hash; + return &m_HashMap[hash]; +} +int CLogCache::FetchCacheIndex(CString GitDir) { + if(this->m_IndexFile.m_hFile == CFile::hFileNull) { BOOL b=m_IndexFile.Open(GitDir+_T("\\.git\\")+INDEX_FILE_NAME, @@ -22,6 +53,12 @@ int CLogCache::FetchCache(CString GitDir) if(!b) return -1; } + //Cache has been fetched. + //if(m_GitDir == GitDir) + // return 0; + + m_GitDir=GitDir; + m_IndexFile.SeekToBegin(); SLogCacheIndexHeader header; UINT count=m_IndexFile.Read(&header,sizeof(SLogCacheIndexHeader)); @@ -37,21 +74,22 @@ int CLogCache::FetchCache(CString GitDir) SLogCacheItem Item; - for(int i=0;im_HashMapIndex.clear(); + + while(1) { count=m_IndexFile.Read(&Item,sizeof(SLogCacheItem)); if( count != sizeof(SLogCacheItem) ) break; - CString str; - g_Git.StringAppend(&str,Item.m_Hash,CP_UTF8,40); - this->m_HashMapIndex[str]=Item.m_Offset; + this->m_HashMapIndex[Item.m_Hash]=Item.m_Offset; } return 0; } -int CLogCache::SaveOneItem(CString &GitDir,GitRev &Rev,UINT offset) +int CLogCache::SaveOneItem(GitRev &Rev,ULONGLONG offset) { SLogCacheRevItemHeader header; @@ -59,7 +97,7 @@ int CLogCache::SaveOneItem(CString &GitDir,GitRev &Rev,UINT offset) if(this->m_DataFile.m_hFile == CFile::hFileNull) { - BOOL b=m_DataFile.Open(GitDir+_T("\\.git\\")+INDEX_FILE_NAME, + BOOL b=m_DataFile.Open(m_GitDir+_T("\\.git\\")+INDEX_FILE_NAME, CFile::modeRead|CFile::shareDenyNone| CFile::modeNoTruncate|CFile::modeCreate); if(!b) @@ -93,29 +131,30 @@ int CLogCache::SaveOneItem(CString &GitDir,GitRev &Rev,UINT offset) ar<m_DataFile.m_hFile == CFile::hFileNull) { - BOOL b=m_DataFile.Open(GitDir+_T("\\.git\\")+INDEX_FILE_NAME, + BOOL b=m_DataFile.Open(m_GitDir+_T("\\.git\\")+DATA_FILE_NAME, CFile::modeRead|CFile::shareDenyNone| CFile::modeNoTruncate|CFile::modeCreate); if(!b) return -1; } + m_DataFile.Seek(offset,CFile::begin); UINT count=m_DataFile.Read(&header,sizeof(SLogCacheRevItemHeader)); if( count != sizeof(SLogCacheRevItemHeader)) @@ -142,7 +181,7 @@ int CLogCache::LoadOneItem(CString &GitDir,GitRev &Rev,UINT offset) for(int i=0;iCheckHeader(header) ) return -1; + ar>>file; + ar>>oldfile; + path.SetFromGit(file,&oldfile); ar>>path.m_Action; ar>>path.m_Stage; ar>>path.m_StatAdd; ar>>path.m_StatDel; - ar>>file; - path.SetFromGit(file); + + Rev.m_Files.AddPath(path); } return 0; +} +int CLogCache::RebuildCacheFile() +{ + m_IndexFile.SetLength(0); + m_DataFile.SetLength(0); + { + SLogCacheIndexHeader header; + header.m_Magic=LOG_INDEX_MAGIC; + header.m_Version=LOG_INDEX_VERSION; + m_IndexFile.SeekToBegin(); + m_IndexFile.Write(&header,sizeof(SLogCacheIndexHeader)); + } + + { + SLogCacheRevFileHeader header; + header.m_Magic=LOG_DATA_MAGIC; + header.m_Version=LOG_INDEX_VERSION; + + m_DataFile.SeekToBegin(); + m_DataFile.Write(&header,sizeof(SLogCacheRevFileHeader)); + } + return 0; +} +int CLogCache::SaveCache() +{ + if( this->m_HashMap.size() == 0 ) + return 0; + + if( this->m_GitDir.IsEmpty()) + return 0; + + bool bIsRebuild=false; + if(this->m_DataFile.m_hFile != CFile::hFileNull) + m_DataFile.Close(); + if(this->m_IndexFile.m_hFile!=CFile::hFileNull) + m_IndexFile.Close(); + + if(this->m_IndexFile.m_hFile == CFile::hFileNull) + { + BOOL b=m_IndexFile.Open(m_GitDir+_T("\\.git\\")+INDEX_FILE_NAME, + CFile::modeReadWrite|CFile::shareDenyWrite| + CFile::modeNoTruncate|CFile::modeCreate); + if(!b) + return -1; + } + + if(this->m_DataFile.m_hFile == CFile::hFileNull) + { + BOOL b=m_DataFile.Open(m_GitDir+_T("\\.git\\")+DATA_FILE_NAME, + CFile::modeReadWrite|CFile::shareDenyWrite| + CFile::modeNoTruncate|CFile::modeCreate); + + + if(!b) + { + m_IndexFile.Close(); + return -1; + } + } + + { + SLogCacheIndexHeader header; + memset(&header,0,sizeof(SLogCacheIndexHeader)); + UINT count=m_IndexFile.Read(&header,sizeof(SLogCacheIndexHeader)); + if(count != sizeof(SLogCacheIndexHeader) || !this->CheckHeader(header)) + {// new file + RebuildCacheFile(); + bIsRebuild=true; + } + } + + { + + SLogCacheRevFileHeader header; + + UINT count=m_DataFile.Read(&header,sizeof(SLogCacheRevFileHeader)); + if( count != sizeof(SLogCacheRevFileHeader) || !CheckHeader(header)) + { + RebuildCacheFile(); + bIsRebuild=true; + } + + } + + m_DataFile.SeekToEnd(); + m_IndexFile.SeekToEnd(); + CGitHashMap::iterator i; + for(i=m_HashMap.begin();i!=m_HashMap.end();i++) + { + if(this->m_HashMapIndex.find((*i).second.m_CommitHash) == m_HashMapIndex.end() || bIsRebuild) + { + if((*i).second.m_IsFull && !(*i).second.m_CommitHash.IsEmpty()) + { + ULONGLONG offset = m_DataFile.GetPosition(); + this->SaveOneItem((*i).second,offset); + + SLogCacheItem item; + item.m_Hash = (*i).second.m_CommitHash; + item.m_Offset=offset; + + m_IndexFile.Write(&item,sizeof(SLogCacheItem)); + } + } + } + m_IndexFile.Close(); + m_DataFile.Close(); + return 0; +} + +int CLogCache::ClearAllParent() +{ + CGitHashMap::iterator i; + for(i=m_HashMap.begin();i!=m_HashMap.end();i++) + { + (*i).second.m_ParentHash.clear(); + (*i).second.m_Lanes.clear(); + } + return 0; } \ No newline at end of file