}\r
//Must use sperate function to convert ANSI str to union code string\r
//Becuase A2W use stack as internal convert buffer. \r
-void CGit::StringAppend(CString *str,BYTE *p,int code)\r
+void CGit::StringAppend(CString *str,BYTE *p,int code,int length)\r
{\r
//USES_CONVERSION;\r
//str->Append(A2W_CP((LPCSTR)p,code));\r
WCHAR * buf;\r
- int len = strlen((const char*)p);\r
+\r
+ int len ;\r
+ if(length<0)\r
+ len= strlen((const char*)p);\r
+ else\r
+ len=length;\r
//if (len==0)\r
// return ;\r
//buf = new WCHAR[len*4 + 1];\r
\r
int BuildOutputFormat(CString &format,bool IsFull=TRUE);\r
//int GetShortLog(CString &log,CTGitPath * path=NULL, int count =-1);\r
- static void StringAppend(CString *str,BYTE *p,int code=CP_UTF8);\r
+ static void StringAppend(CString *str,BYTE *p,int code=CP_UTF8,int length=-1);\r
\r
BOOL IsInitRepos();\r
\r
--- /dev/null
+#include "stdafx.h"\r
+#include "GitLogCache.h"\r
+\r
+CLogCache::CLogCache()\r
+{\r
+\r
+}\r
+\r
+CLogCache::~CLogCache()\r
+{\r
+ this->m_IndexFile.Close();\r
+ this->m_DataFile.Close();\r
+}\r
+\r
+int CLogCache::FetchCache(CString GitDir)\r
+{\r
+ if(this->m_IndexFile.m_hFile == CFile::hFileNull)\r
+ {\r
+ BOOL b=m_IndexFile.Open(GitDir+_T("\\.git\\")+INDEX_FILE_NAME,\r
+ CFile::modeRead|CFile::shareDenyNone|\r
+ CFile::modeNoTruncate|CFile::modeCreate);\r
+ if(!b)\r
+ return -1;\r
+ }\r
+\r
+ SLogCacheIndexHeader header;\r
+ UINT count=m_IndexFile.Read(&header,sizeof(SLogCacheIndexHeader));\r
+ if(count != sizeof(SLogCacheIndexHeader))\r
+ return -2;\r
+\r
+ if( header.m_Magic != LOG_INDEX_MAGIC )\r
+ return -3;\r
+\r
+ if( header.m_Version != LOG_INDEX_VERSION )\r
+ return -4;\r
+\r
+\r
+ SLogCacheItem Item;\r
+\r
+ for(int i=0;i<header.m_ItemCount;i++)\r
+ {\r
+ count=m_IndexFile.Read(&Item,sizeof(SLogCacheItem)); \r
+ if(count != sizeof(SLogCacheItem)\r
+ break;\r
+\r
+ CString str;\r
+ g_Git.StringAppend(&str,Item.m_Hash,CP_UTF8,40);\r
+ this->m_HashMapIndex[str]=Item.m_Offset;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+int CLogCache::SaveOneItem(GitRev &Rev)\r
+{\r
+ \r
+}\r
+\r
+int CLogCache::LoadOneItem(GitRev &Rev,UINT offset)\r
+{\r
+ SLogCacheRevItemHeader header;\r
+ m_DataFile.Seek(offset,CFile::begin);\r
+\r
+ if(this->m_DataFile.m_hFile == CFile::hFileNull)\r
+ {\r
+ BOOL b=m_DataFile.Open(GitDir+_T("\\.git\\")+INDEX_FILE_NAME,\r
+ CFile::modeRead|CFile::shareDenyNone|\r
+ CFile::modeNoTruncate|CFile::modeCreate);\r
+ if(!b)\r
+ return -1;\r
+ }\r
+\r
+ UINT count=m_DataFile.Read(&header,sizeof(SLogCacheRevItemHeader));\r
+ if( count != sizeof(SLogCacheRevItemHeader))\r
+ return -1;\r
+ if( !CheckHeader(header))\r
+ return -2;\r
+ \r
+ CGitByteArray stream;\r
+\r
+ stream.resize(header.m_RevSize-sizeof(SLogCacheRevItemHeader));\r
+\r
+ count=m_DataFile.Read(&stream[0],stream.size());\r
+ if( count != stream.size)\r
+ return;\r
+\r
+ \r
+\r
+\r
+ \r
+}
\ No newline at end of file
>\r
</File>\r
<File\r
- RelativePath="..\Resources\explorer.ico"\r
+ RelativePath=".\explorer.ico"\r
>\r
</File>\r
<File\r
- RelativePath=".\explorer.ico"\r
+ RelativePath="..\Resources\explorer.ico"\r
>\r
</File>\r
<File\r
>\r
</File>\r
<File\r
- RelativePath="..\Resources\newfolder.ico"\r
+ RelativePath=".\newfolder.ico"\r
>\r
</File>\r
<File\r
- RelativePath=".\newfolder.ico"\r
+ RelativePath="..\Resources\newfolder.ico"\r
>\r
</File>\r
<File\r
- RelativePath="..\Resources\open.ico"\r
+ RelativePath=".\open.ico"\r
>\r
</File>\r
<File\r
- RelativePath=".\open.ico"\r
+ RelativePath="..\Resources\open.ico"\r
>\r
</File>\r
<File\r
>\r
</File>\r
<File\r
- RelativePath="..\Resources\save.ico"\r
+ RelativePath=".\save.ico"\r
>\r
</File>\r
<File\r
- RelativePath=".\save.ico"\r
+ RelativePath="..\Resources\save.ico"\r
>\r
</File>\r
<File\r
- RelativePath="..\Resources\saveas.ico"\r
+ RelativePath=".\saveas.ico"\r
>\r
</File>\r
<File\r
- RelativePath=".\saveas.ico"\r
+ RelativePath="..\Resources\saveas.ico"\r
>\r
</File>\r
<File\r
>\r
</File>\r
<File\r
- RelativePath="..\Resources\up.ico"\r
+ RelativePath=".\up.ico"\r
>\r
</File>\r
<File\r
- RelativePath=".\up.ico"\r
+ RelativePath="..\Resources\up.ico"\r
>\r
</File>\r
<File\r
Name="Log"\r
>\r
<File\r
+ RelativePath=".\GitLogCache.cpp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\gitlogcache.h"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\GitLogList.h"\r
>\r
</File>\r
--- /dev/null
+#pragma once\r
+\r
+#include "Git.h"\r
+#include "TGitPath.h"\r
+#include "GitRev.h"\r
+\r
+#define LOG_INDEX_MAGIC 0x88445566\r
+#define LOG_DATA_MAGIC 0x99aa00FF\r
+#define LOG_DATA_ITEM_MAGIC 0x0F8899CC\r
+#define LOG_INDEX_VERSION 0x1\r
+\r
+struct SLogCacheIndexHeader \r
+{\r
+ DWORD m_Magic;\r
+ DWORD m_Version;\r
+ DWORD m_ItemCount;\r
+};\r
+\r
+struct SLogCacheItem\r
+{\r
+ BYTE m_Hash[40];\r
+ DWORD m_Offset;\r
+};\r
+\r
+struct SLogCacheRevFileHeader\r
+{\r
+ DWORD m_Magic;\r
+ DWORD m_Version;\r
+};\r
+\r
+struct SLogCacheRevItemHeader\r
+{\r
+ DWORD m_Magic;\r
+ DWORD m_Version;\r
+ DWORD m_RevSize;\r
+ DWORD m_FileCount;\r
+};\r
+\r
+#define INDEX_FILE_NAME _T("tortoisegit.index")\r
+#define DATA_FILE_NAME _T("tortoisegit.data")\r
+#define LOCK_FILE_NAME _T("tortoisegit.lock")\r
+\r
+class CLogCache\r
+{\r
+protected:\r
+ CFile m_IndexFile;\r
+ CFile m_DataFile;\r
+ CFile m_LockFile;\r
+\r
+ BOOL CheckHeader(SLogCacheRevFileHeader &header)\r
+ {\r
+ if(header.m_Magic == LOG_DATA_MAGIC)\r
+ return TRUE;\r
+ else\r
+ return FALSE;\r
+\r
+ if(header.m_Version == LOG_INDEX_VERSION)\r
+ return TRUE;\r
+ else\r
+ return FALSE;\r
+ }\r
+\r
+ BOOL CheckHeader(SLogCacheRevItemHeader &header)\r
+ {\r
+ if(header.m_Magic == LOG_DATA_ITEM_MAGIC)\r
+ return TRUE;\r
+ else\r
+ return FALSE;\r
+\r
+ if(header.m_Version == LOG_INDEX_VERSION)\r
+ return TRUE;\r
+ else\r
+ return FALSE;\r
+\r
+ }\r
+\r
+ int SaveOneItem(GitRev &Rev);\r
+ int LoadOneItem(GitRev &Rev,UINT offset);\r
+\r
+public:\r
+ CLogCache();\r
+ ~CLogCache();\r
+ int FetchCache(CString GitDir);\r
+ std::vector<GitRev> m_NewCacheEntry;\r
+ std::map<CString, DWORD> m_HashMapIndex;\r
+ int GetCacheData(GitRev &Rev);\r
+ int AddCacheEntry(GitRev &Rev);\r
+\r
+};
\ No newline at end of file