From 99dcad3e4ee2283008a12eed920c9ff6769e4113 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Mon, 26 Jan 2009 23:00:45 +0800 Subject: [PATCH] Add Log Cache Code --- src/Git/Git.cpp | 9 +++- src/Git/Git.h | 2 +- src/TortoiseProc/GitLogCache.cpp | 91 ++++++++++++++++++++++++++++++++++++ src/TortoiseProc/TortoiseProc.vcproj | 32 ++++++++----- src/TortoiseProc/gitlogcache.h | 89 +++++++++++++++++++++++++++++++++++ 5 files changed, 208 insertions(+), 15 deletions(-) create mode 100644 src/TortoiseProc/GitLogCache.cpp create mode 100644 src/TortoiseProc/gitlogcache.h diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 23164db..7fafa44 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -73,12 +73,17 @@ int CGit::RunAsync(CString cmd,PROCESS_INFORMATION *piOut,HANDLE *hReadOut,CStri } //Must use sperate function to convert ANSI str to union code string //Becuase A2W use stack as internal convert buffer. -void CGit::StringAppend(CString *str,BYTE *p,int code) +void CGit::StringAppend(CString *str,BYTE *p,int code,int length) { //USES_CONVERSION; //str->Append(A2W_CP((LPCSTR)p,code)); WCHAR * buf; - int len = strlen((const char*)p); + + int len ; + if(length<0) + len= strlen((const char*)p); + else + len=length; //if (len==0) // return ; //buf = new WCHAR[len*4 + 1]; diff --git a/src/Git/Git.h b/src/Git/Git.h index b7bde0c..dfcd4b1 100644 --- a/src/Git/Git.h +++ b/src/Git/Git.h @@ -63,7 +63,7 @@ public: int BuildOutputFormat(CString &format,bool IsFull=TRUE); //int GetShortLog(CString &log,CTGitPath * path=NULL, int count =-1); - static void StringAppend(CString *str,BYTE *p,int code=CP_UTF8); + static void StringAppend(CString *str,BYTE *p,int code=CP_UTF8,int length=-1); BOOL IsInitRepos(); diff --git a/src/TortoiseProc/GitLogCache.cpp b/src/TortoiseProc/GitLogCache.cpp new file mode 100644 index 0000000..30e9072 --- /dev/null +++ b/src/TortoiseProc/GitLogCache.cpp @@ -0,0 +1,91 @@ +#include "stdafx.h" +#include "GitLogCache.h" + +CLogCache::CLogCache() +{ + +} + +CLogCache::~CLogCache() +{ + this->m_IndexFile.Close(); + this->m_DataFile.Close(); +} + +int CLogCache::FetchCache(CString GitDir) +{ + if(this->m_IndexFile.m_hFile == CFile::hFileNull) + { + BOOL b=m_IndexFile.Open(GitDir+_T("\\.git\\")+INDEX_FILE_NAME, + CFile::modeRead|CFile::shareDenyNone| + CFile::modeNoTruncate|CFile::modeCreate); + if(!b) + return -1; + } + + SLogCacheIndexHeader header; + UINT count=m_IndexFile.Read(&header,sizeof(SLogCacheIndexHeader)); + if(count != sizeof(SLogCacheIndexHeader)) + return -2; + + if( header.m_Magic != LOG_INDEX_MAGIC ) + return -3; + + if( header.m_Version != LOG_INDEX_VERSION ) + return -4; + + + SLogCacheItem Item; + + for(int i=0;im_HashMapIndex[str]=Item.m_Offset; + } + + return 0; +} + +int CLogCache::SaveOneItem(GitRev &Rev) +{ + +} + +int CLogCache::LoadOneItem(GitRev &Rev,UINT offset) +{ + SLogCacheRevItemHeader header; + m_DataFile.Seek(offset,CFile::begin); + + if(this->m_DataFile.m_hFile == CFile::hFileNull) + { + BOOL b=m_DataFile.Open(GitDir+_T("\\.git\\")+INDEX_FILE_NAME, + CFile::modeRead|CFile::shareDenyNone| + CFile::modeNoTruncate|CFile::modeCreate); + if(!b) + return -1; + } + + UINT count=m_DataFile.Read(&header,sizeof(SLogCacheRevItemHeader)); + if( count != sizeof(SLogCacheRevItemHeader)) + return -1; + if( !CheckHeader(header)) + return -2; + + CGitByteArray stream; + + stream.resize(header.m_RevSize-sizeof(SLogCacheRevItemHeader)); + + count=m_DataFile.Read(&stream[0],stream.size()); + if( count != stream.size) + return; + + + + + +} \ No newline at end of file diff --git a/src/TortoiseProc/TortoiseProc.vcproj b/src/TortoiseProc/TortoiseProc.vcproj index ab94fa6..7fe42bb 100644 --- a/src/TortoiseProc/TortoiseProc.vcproj +++ b/src/TortoiseProc/TortoiseProc.vcproj @@ -576,11 +576,11 @@ > + + + + diff --git a/src/TortoiseProc/gitlogcache.h b/src/TortoiseProc/gitlogcache.h new file mode 100644 index 0000000..c3da454 --- /dev/null +++ b/src/TortoiseProc/gitlogcache.h @@ -0,0 +1,89 @@ +#pragma once + +#include "Git.h" +#include "TGitPath.h" +#include "GitRev.h" + +#define LOG_INDEX_MAGIC 0x88445566 +#define LOG_DATA_MAGIC 0x99aa00FF +#define LOG_DATA_ITEM_MAGIC 0x0F8899CC +#define LOG_INDEX_VERSION 0x1 + +struct SLogCacheIndexHeader +{ + DWORD m_Magic; + DWORD m_Version; + DWORD m_ItemCount; +}; + +struct SLogCacheItem +{ + BYTE m_Hash[40]; + DWORD m_Offset; +}; + +struct SLogCacheRevFileHeader +{ + DWORD m_Magic; + DWORD m_Version; +}; + +struct SLogCacheRevItemHeader +{ + DWORD m_Magic; + DWORD m_Version; + DWORD m_RevSize; + DWORD m_FileCount; +}; + +#define INDEX_FILE_NAME _T("tortoisegit.index") +#define DATA_FILE_NAME _T("tortoisegit.data") +#define LOCK_FILE_NAME _T("tortoisegit.lock") + +class CLogCache +{ +protected: + CFile m_IndexFile; + CFile m_DataFile; + CFile m_LockFile; + + BOOL CheckHeader(SLogCacheRevFileHeader &header) + { + if(header.m_Magic == LOG_DATA_MAGIC) + return TRUE; + else + return FALSE; + + if(header.m_Version == LOG_INDEX_VERSION) + return TRUE; + else + return FALSE; + } + + BOOL CheckHeader(SLogCacheRevItemHeader &header) + { + if(header.m_Magic == LOG_DATA_ITEM_MAGIC) + return TRUE; + else + return FALSE; + + if(header.m_Version == LOG_INDEX_VERSION) + return TRUE; + else + return FALSE; + + } + + int SaveOneItem(GitRev &Rev); + int LoadOneItem(GitRev &Rev,UINT offset); + +public: + CLogCache(); + ~CLogCache(); + int FetchCache(CString GitDir); + std::vector m_NewCacheEntry; + std::map m_HashMapIndex; + int GetCacheData(GitRev &Rev); + int AddCacheEntry(GitRev &Rev); + +}; \ No newline at end of file -- 2.11.0