From f151c0ddf205fa1fc1ff886b8cfc4af87d373b26 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Sat, 12 Mar 2011 13:54:01 +0800 Subject: [PATCH] Change file name to lowcase at index and tree because windows system filename is case-insensitive Signed-off-by: Frank Li --- src/Git/GitIndex.cpp | 30 +++++++++++++++++++++++++----- src/Git/GitStatus.cpp | 27 ++++++++++++++++++--------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/Git/GitIndex.cpp b/src/Git/GitIndex.cpp index 928c546af..11b28284b 100644 --- a/src/Git/GitIndex.cpp +++ b/src/Git/GitIndex.cpp @@ -16,6 +16,7 @@ #define FILL_DATA() \ m_FileName.Empty();\ g_Git.StringAppend(&m_FileName,(BYTE*)entry->name,CP_ACP,Big2lit(entry->flags)&CE_NAMEMASK);\ + m_FileName.MakeLower(); \ this->m_Flags=Big2lit(entry->flags);\ this->m_ModifyTime=Big2lit(entry->mtime.sec);\ this->m_IndexHash=(char*)(entry->sha1); @@ -49,6 +50,16 @@ CGitIndexList::CGitIndexList() this->m_LastModifyTime=0; } +static bool SortIndex(CGitIndex &Item1, CGitIndex &Item2) +{ + return Item1.m_FileName.Compare(Item2.m_FileName)<0; +} + +static bool SortTree(CGitTreeItem &Item1, CGitTreeItem &Item2) +{ + return Item1.m_FileName.Compare(Item2.m_FileName)<0; +} + int CGitIndexList::ReadIndex(CString IndexFile) { HANDLE hfile=INVALID_HANDLE_VALUE; @@ -127,6 +138,7 @@ int CGitIndexList::ReadIndex(CString IndexFile) } } + std::sort(this->begin(), this->end(), SortIndex); g_Git.GetFileModifyTime(IndexFile, &this->m_LastModifyTime); }while(0); }catch(...) @@ -146,10 +158,13 @@ int CGitIndexList::ReadIndex(CString IndexFile) return ret; } -int CGitIndexList::GetFileStatus(const CString &gitdir,const CString &path,git_wc_status_kind *status,__int64 time,FIll_STATUS_CALLBACK callback,void *pData, CGitHash *pHash) +int CGitIndexList::GetFileStatus(const CString &gitdir,const CString &pathorg,git_wc_status_kind *status,__int64 time,FIll_STATUS_CALLBACK callback,void *pData, CGitHash *pHash) { if(status) { + CString path = pathorg; + path.MakeLower(); + int start=SearchInSortVector(*this, ((CString&)path).GetBuffer(), path.GetLength()); ((CString&)path).ReleaseBuffer(); @@ -187,7 +202,7 @@ int CGitIndexList::GetFileStatus(const CString &gitdir,const CString &path,git_w } if(callback && status) - callback(gitdir+_T("\\")+path,*status,false, pData); + callback(gitdir+_T("\\")+pathorg,*status,false, pData); return 0; } @@ -376,6 +391,8 @@ int CGitIndexFileMap::IsUnderVersionControl(const CString &gitdir, const CString if(isDir) subpath+=_T('/'); + subpath.MakeLower(); + CheckAndUpdate(gitdir, isLoadUpdateIndex); SHARED_INDEX_PTR pIndex = this->SafeGet(gitdir); @@ -434,7 +451,7 @@ int CGitHeadFileList::GetPackRef(const CString &gitdir) break; } - int filesize = GetFileSize(hfile,NULL); + DWORD filesize = GetFileSize(hfile,NULL); DWORD size =0; char *buff; buff = new char[filesize]; @@ -450,7 +467,7 @@ int CGitHeadFileList::GetPackRef(const CString &gitdir) CString hash; CString ref; - for(int i=0;iat(cur).m_FileName,(BYTE*)pathname,CP_ACP); + p->at(cur).m_FileName.MakeLower(); + //p->at(cur).m_FileName.Replace(_T('/'),_T('\\')); //p->m_Map[p->at(cur).m_FileName]=cur; @@ -803,6 +822,7 @@ int CGitHeadFileList::ReadTree() if(ret) break; + std::sort(this->begin(), this->end(), SortTree); this->m_TreeHash = (char*)(git_commit_id(commit)->id); }while(0); diff --git a/src/Git/GitStatus.cpp b/src/Git/GitStatus.cpp index 2935ab7ab..2a2866239 100644 --- a/src/Git/GitStatus.cpp +++ b/src/Git/GitStatus.cpp @@ -902,6 +902,9 @@ int GitStatus::GetFileStatus(const CString &gitdir,const CString &pathParam,git_ path.Replace(_T('\\'),_T('/')); + CString lowcasepath =path; + lowcasepath.MakeLower(); + if(status) { git_wc_status_kind st = git_wc_status_none; @@ -982,7 +985,7 @@ int GitStatus::GetFileStatus(const CString &gitdir,const CString &pathParam,git_ { //add item - int start =SearchInSortVector(*treeptr,path.GetBuffer(),path.GetLength()); + int start =SearchInSortVector(*treeptr,lowcasepath.GetBuffer(),lowcasepath.GetLength()); if(start<0) { @@ -1093,6 +1096,9 @@ int GitStatus::EnumDirStatus(const CString &gitdir,const CString &subpath,git_wc if(path[path.GetLength()-1] != _T('/')) path += _T('/'); //Add trail / to show it is directory, not file name. + CString lowcasepath = path; + lowcasepath.MakeLower(); + if(status) { g_IndexFileMap.CheckAndUpdate(gitdir,true); @@ -1104,7 +1110,7 @@ int GitStatus::EnumDirStatus(const CString &gitdir,const CString &subpath,git_wc int pos; { - pos=SearchInSortVector(*indexptr,path.GetBuffer(),path.GetLength()); + pos=SearchInSortVector(*indexptr,lowcasepath.GetBuffer(),lowcasepath.GetLength()); } if(subpath.IsEmpty() && pos<0) @@ -1157,7 +1163,7 @@ int GitStatus::EnumDirStatus(const CString &gitdir,const CString &subpath,git_wc end=indexptr->size()-1; } - GetRangeInSortVector(*indexptr,path.GetBuffer(),path.GetLength(),&start,&end,pos); + GetRangeInSortVector(*indexptr,lowcasepath.GetBuffer(),lowcasepath.GetLength(),&start,&end,pos); CGitIndexList::iterator it; it = indexptr->begin()+start; @@ -1226,7 +1232,7 @@ int GitStatus::EnumDirStatus(const CString &gitdir,const CString &subpath,git_wc //Check Delete if( *status == git_wc_status_normal ) { - pos = SearchInSortVector(*treeptr, path.GetBuffer(), path.GetLength()); + pos = SearchInSortVector(*treeptr, lowcasepath.GetBuffer(), lowcasepath.GetLength()); if(pos <0) { *status = max(git_wc_status_added, *status) ; @@ -1234,7 +1240,7 @@ int GitStatus::EnumDirStatus(const CString &gitdir,const CString &subpath,git_wc }else { int hstart,hend; - GetRangeInSortVector(*treeptr,path.GetBuffer(),path.GetLength(),&hstart,&hend,pos); + GetRangeInSortVector(*treeptr,lowcasepath.GetBuffer(),lowcasepath.GetLength(),&hstart,&hend,pos); CGitHeadFileList::iterator hit; hit = treeptr->begin()+hstart; for(int i=hstart;i<=hend;i++) @@ -1281,13 +1287,16 @@ int GitStatus::GetDirStatus(const CString &gitdir,const CString &subpath,git_wc_ if(path[path.GetLength()-1] != _T('/')) path += _T('/'); //Add trail / to show it is directory, not file name. + CString lowcasepath = path; + lowcasepath.MakeLower(); + if(status) { g_IndexFileMap.CheckAndUpdate(gitdir, true); SHARED_INDEX_PTR indexptr = g_IndexFileMap.SafeGet(gitdir); - int pos=SearchInSortVector(*indexptr,path.GetBuffer(),path.GetLength()); + int pos=SearchInSortVector(*indexptr,lowcasepath.GetBuffer(),lowcasepath.GetLength()); if(subpath.IsEmpty() && pos<0) { // for new init repository @@ -1336,7 +1345,7 @@ int GitStatus::GetDirStatus(const CString &gitdir,const CString &subpath,git_wc_ start=0; end=indexptr->size()-1; } - GetRangeInSortVector(*indexptr,path.GetBuffer(),path.GetLength(),&start,&end,pos); + GetRangeInSortVector(*indexptr,lowcasepath.GetBuffer(),lowcasepath.GetLength(),&start,&end,pos); CGitIndexList::iterator it; it = indexptr->begin()+start; @@ -1424,7 +1433,7 @@ int GitStatus::GetDirStatus(const CString &gitdir,const CString &subpath,git_wc_ //Check Delete if( *status == git_wc_status_normal ) { - pos = SearchInSortVector(*treeptr, path.GetBuffer(), path.GetLength()); + pos = SearchInSortVector(*treeptr, lowcasepath.GetBuffer(), lowcasepath.GetLength()); if(pos <0) { *status = git_wc_status_added; @@ -1432,7 +1441,7 @@ int GitStatus::GetDirStatus(const CString &gitdir,const CString &subpath,git_wc_ }else { int hstart,hend; - GetRangeInSortVector(*treeptr,path.GetBuffer(),path.GetLength(),&hstart,&hend,pos); + GetRangeInSortVector(*treeptr,lowcasepath.GetBuffer(),lowcasepath.GetLength(),&hstart,&hend,pos); CGitHeadFileList::iterator hit; hit = treeptr->begin()+start; for(int i=hstart;i<=hend;i++) -- 2.11.4.GIT