1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "..\TortoiseShell\resource.h"
23 #include "GitStatus.h"
24 #include "UnicodeUtils.h"
27 #include "shellcache.h"
29 extern CGitAdminDirMap g_AdminDirMap
;
30 CGitIndexFileMap g_IndexFileMap
;
31 CGitHeadFileMap g_HeadFileMap
;
32 CGitIgnoreList g_IgnoreList
;
34 GitStatus::GitStatus()
39 GitStatus::~GitStatus(void)
44 git_wc_status_kind
GitStatus::GetAllStatus(const CTGitPath
& path
, git_depth_t depth
, bool * assumeValid
, bool * skipWorktree
)
46 git_wc_status_kind statuskind
;
51 isDir
= path
.IsDirectory();
52 if (!path
.HasAdminDir(&sProjectRoot
))
53 return git_wc_status_none
;
55 // rev.kind = git_opt_revision_unspecified;
56 statuskind
= git_wc_status_none
;
58 const BOOL bIsRecursive
= (depth
== git_depth_infinity
|| depth
== git_depth_unknown
); // taken from SVN source
61 CString s
= path
.GetWinPathString();
62 if (s
.GetLength() > sProjectRoot
.GetLength())
64 if (sProjectRoot
.GetLength() == 3 && sProjectRoot
[1] == _T(':'))
65 sSubPath
= s
.Right(s
.GetLength() - sProjectRoot
.GetLength());
67 sSubPath
= s
.Right(s
.GetLength() - sProjectRoot
.GetLength() - 1/*otherwise it gets initial slash*/);
70 bool isfull
= ((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\CacheType"),
71 GetSystemMetrics(SM_REMOTESESSION
) ? ShellCache::dll
: ShellCache::exe
) == ShellCache::dllFull
);
75 err
= GetDirStatus(sProjectRoot
,sSubPath
,&statuskind
, isfull
,bIsRecursive
,isfull
,NULL
, NULL
);
76 // folders must not be displayed as added or deleted only as modified (this is for Shell Overlay-Modes)
77 if (statuskind
== git_wc_status_unversioned
&& sSubPath
.IsEmpty())
78 statuskind
= git_wc_status_normal
;
79 else if (statuskind
== git_wc_status_deleted
|| statuskind
== git_wc_status_added
)
80 statuskind
= git_wc_status_modified
;
84 err
= GetFileStatus(sProjectRoot
, sSubPath
, &statuskind
, isfull
, false, isfull
, NULL
, NULL
, assumeValid
, skipWorktree
);
91 git_wc_status_kind
GitStatus::GetAllStatusRecursive(const CTGitPath
& path
)
93 return GetAllStatus(path
, git_depth_infinity
);
97 git_wc_status_kind
GitStatus::GetMoreImportant(git_wc_status_kind status1
, git_wc_status_kind status2
)
99 if (GetStatusRanking(status1
) >= GetStatusRanking(status2
))
103 // static private method
104 int GitStatus::GetStatusRanking(git_wc_status_kind status
)
108 case git_wc_status_none
:
110 case git_wc_status_unversioned
:
112 case git_wc_status_ignored
:
114 case git_wc_status_incomplete
:
116 case git_wc_status_normal
:
117 case git_wc_status_external
:
119 case git_wc_status_added
:
121 case git_wc_status_missing
:
123 case git_wc_status_deleted
:
125 case git_wc_status_replaced
:
127 case git_wc_status_modified
:
129 case git_wc_status_merged
:
131 case git_wc_status_conflicted
:
133 case git_wc_status_obstructed
:
139 void GitStatus::GetStatus(const CTGitPath
& path
, bool /*update*/ /* = false */, bool noignore
/* = false */, bool /*noexternals*/ /* = false */)
141 // NOTE: unlike the SVN version this one does not cache the enumerated files, because in practice no code in all of
142 // Tortoise uses this, all places that call GetStatus create a temp GitStatus object which gets destroyed right
143 // after the call again
145 CString sProjectRoot
;
146 if ( !path
.HasAdminDir(&sProjectRoot
) )
149 bool isfull
= ((DWORD
)CRegStdDWORD(_T("Software\\TortoiseGit\\CacheType"),
150 GetSystemMetrics(SM_REMOTESESSION
) ? ShellCache::dll
: ShellCache::exe
) == ShellCache::dllFull
);
153 LPCTSTR lpszSubPath
= NULL
;
155 CString s
= path
.GetWinPathString();
156 if (s
.GetLength() > sProjectRoot
.GetLength())
158 sSubPath
= s
.Right(s
.GetLength() - sProjectRoot
.GetLength());
159 lpszSubPath
= sSubPath
;
160 // skip initial slash if necessary
161 if (*lpszSubPath
== _T('\\'))
165 m_status
.prop_status
= m_status
.text_status
= git_wc_status_none
;
166 m_status
.assumeValid
= false;
167 m_status
.skipWorktree
= false;
169 if(path
.IsDirectory())
171 m_err
= GetDirStatus(sProjectRoot
,CString(lpszSubPath
),&m_status
.text_status
, isfull
, false,!noignore
, NULL
, NULL
);
176 m_err
= GetFileStatus(sProjectRoot
, CString(lpszSubPath
), &m_status
.text_status
,isfull
, false,!noignore
, NULL
,NULL
, &m_status
.assumeValid
, &m_status
.skipWorktree
);
180 // Error present if function is not under version control
190 void GitStatus::GetStatusString(git_wc_status_kind status
, size_t buflen
, TCHAR
* string
)
195 case git_wc_status_none
:
198 case git_wc_status_unversioned
:
199 buf
= _T("unversioned\0");
201 case git_wc_status_normal
:
202 buf
= _T("normal\0");
204 case git_wc_status_added
:
207 case git_wc_status_missing
:
208 buf
= _T("missing\0");
210 case git_wc_status_deleted
:
211 buf
= _T("deleted\0");
213 case git_wc_status_replaced
:
214 buf
= _T("replaced\0");
216 case git_wc_status_modified
:
217 buf
= _T("modified\0");
219 case git_wc_status_merged
:
220 buf
= _T("merged\0");
222 case git_wc_status_conflicted
:
223 buf
= _T("conflicted\0");
225 case git_wc_status_obstructed
:
226 buf
= _T("obstructed\0");
228 case git_wc_status_ignored
:
231 case git_wc_status_external
:
232 buf
= _T("external");
234 case git_wc_status_incomplete
:
235 buf
= _T("incomplete\0");
241 _stprintf_s(string
, buflen
, _T("%s"), buf
);
244 void GitStatus::GetStatusString(HINSTANCE hInst
, git_wc_status_kind status
, TCHAR
* string
, int size
, WORD lang
)
248 case git_wc_status_none
:
249 LoadStringEx(hInst
, IDS_STATUSNONE
, string
, size
, lang
);
251 case git_wc_status_unversioned
:
252 LoadStringEx(hInst
, IDS_STATUSUNVERSIONED
, string
, size
, lang
);
254 case git_wc_status_normal
:
255 LoadStringEx(hInst
, IDS_STATUSNORMAL
, string
, size
, lang
);
257 case git_wc_status_added
:
258 LoadStringEx(hInst
, IDS_STATUSADDED
, string
, size
, lang
);
260 case git_wc_status_missing
:
261 LoadStringEx(hInst
, IDS_STATUSABSENT
, string
, size
, lang
);
263 case git_wc_status_deleted
:
264 LoadStringEx(hInst
, IDS_STATUSDELETED
, string
, size
, lang
);
266 case git_wc_status_replaced
:
267 LoadStringEx(hInst
, IDS_STATUSREPLACED
, string
, size
, lang
);
269 case git_wc_status_modified
:
270 LoadStringEx(hInst
, IDS_STATUSMODIFIED
, string
, size
, lang
);
272 case git_wc_status_merged
:
273 LoadStringEx(hInst
, IDS_STATUSMERGED
, string
, size
, lang
);
275 case git_wc_status_conflicted
:
276 LoadStringEx(hInst
, IDS_STATUSCONFLICTED
, string
, size
, lang
);
278 case git_wc_status_ignored
:
279 LoadStringEx(hInst
, IDS_STATUSIGNORED
, string
, size
, lang
);
281 case git_wc_status_obstructed
:
282 LoadStringEx(hInst
, IDS_STATUSOBSTRUCTED
, string
, size
, lang
);
284 case git_wc_status_external
:
285 LoadStringEx(hInst
, IDS_STATUSEXTERNAL
, string
, size
, lang
);
287 case git_wc_status_incomplete
:
288 LoadStringEx(hInst
, IDS_STATUSINCOMPLETE
, string
, size
, lang
);
291 LoadStringEx(hInst
, IDS_STATUSNONE
, string
, size
, lang
);
296 int GitStatus::LoadStringEx(HINSTANCE hInstance
, UINT uID
, LPTSTR lpBuffer
, int nBufferMax
, WORD wLanguage
)
298 const STRINGRESOURCEIMAGE
* pImage
;
299 const STRINGRESOURCEIMAGE
* pImageEnd
;
305 HRSRC hResource
= FindResourceEx(hInstance
, RT_STRING
, MAKEINTRESOURCE(((uID
>>4)+1)), wLanguage
);
308 // try the default language before giving up!
309 hResource
= FindResource(hInstance
, MAKEINTRESOURCE(((uID
>>4)+1)), RT_STRING
);
313 hGlobal
= LoadResource(hInstance
, hResource
);
316 pImage
= (const STRINGRESOURCEIMAGE
*)::LockResource(hGlobal
);
320 nResourceSize
= ::SizeofResource(hInstance
, hResource
);
321 pImageEnd
= (const STRINGRESOURCEIMAGE
*)(LPBYTE(pImage
)+nResourceSize
);
324 while ((iIndex
> 0) && (pImage
< pImageEnd
))
326 pImage
= (const STRINGRESOURCEIMAGE
*)(LPBYTE(pImage
)+(sizeof(STRINGRESOURCEIMAGE
)+(pImage
->nLength
*sizeof(WCHAR
))));
329 if (pImage
>= pImageEnd
)
331 if (pImage
->nLength
== 0)
334 ret
= pImage
->nLength
;
335 if (pImage
->nLength
> nBufferMax
)
337 wcsncpy_s(lpBuffer
, nBufferMax
, pImage
->achString
, pImage
->nLength
-1);
338 lpBuffer
[nBufferMax
-1] = 0;
342 wcsncpy_s(lpBuffer
, nBufferMax
, pImage
->achString
, pImage
->nLength
);
348 typedef CComCritSecLock
<CComCriticalSection
> CAutoLocker
;
350 int GitStatus::GetFileStatus(const CString
&gitdir
, const CString
&pathParam
, git_wc_status_kind
* status
,BOOL IsFull
, BOOL
/*IsRecursive*/,BOOL IsIgnore
, FIll_STATUS_CALLBACK callback
, void *pData
, bool * assumeValid
, bool * skipWorktree
)
354 CString path
= pathParam
;
356 TCHAR oldpath
[MAX_PATH
+1];
357 memset(oldpath
,0,MAX_PATH
+1);
359 path
.Replace(_T('\\'),_T('/'));
361 CString lowcasepath
=path
;
362 lowcasepath
.MakeLower();
366 git_wc_status_kind st
= git_wc_status_none
;
369 g_IndexFileMap
.GetFileStatus(gitdir
, path
, &st
, IsFull
, false, callback
, pData
, &hash
, true, assumeValid
, skipWorktree
);
371 if( st
== git_wc_status_conflicted
)
375 callback(gitdir
+ _T("/") + path
, st
, false, pData
, *assumeValid
, *skipWorktree
);
379 if( st
== git_wc_status_unversioned
)
383 *status
= git_wc_status_unversioned
;
385 callback(gitdir
+ _T("/") + path
, *status
, false, pData
, *assumeValid
, *skipWorktree
);
389 if( g_IgnoreList
.CheckIgnoreChanged(gitdir
,path
))
391 g_IgnoreList
.LoadAllIgnoreFile(gitdir
,path
);
393 if( g_IgnoreList
.IsIgnore(path
, gitdir
) )
395 st
= git_wc_status_ignored
;
399 callback(gitdir
+ _T("/") + path
, st
, false, pData
, *assumeValid
, *skipWorktree
);
404 if( st
== git_wc_status_normal
&& IsFull
)
407 g_HeadFileMap
.CheckHeadAndUpdate(gitdir
);
409 SHARED_TREE_PTR treeptr
= g_HeadFileMap
.SafeGet(gitdir
);
411 // Check Head Tree Hash;
415 int start
=SearchInSortVector(*treeptr
,lowcasepath
.GetBuffer(),-1);
416 lowcasepath
.ReleaseBuffer();
420 *status
=st
=git_wc_status_added
;
421 ATLTRACE(_T("File miss in head tree %s"), path
);
423 callback(gitdir
+ _T("/") + path
, st
, false, pData
, *assumeValid
, *skipWorktree
);
427 //staged and not commit
428 if( treeptr
->at(start
).m_Hash
!= hash
)
430 *status
=st
=git_wc_status_modified
;
432 callback(gitdir
+ _T("/") + path
, st
, false, pData
, *assumeValid
, *skipWorktree
);
440 callback(gitdir
+ _T("/") + path
, st
, false, pData
, *assumeValid
, *skipWorktree
);
447 *status
= git_wc_status_none
;
455 bool GitStatus::HasIgnoreFilesChanged(const CString
&gitdir
, const CString
&subpaths
)
457 return g_IgnoreList
.CheckIgnoreChanged(gitdir
, subpaths
);
460 int GitStatus::LoadIgnoreFile(const CString
&gitdir
,const CString
&subpaths
)
462 return g_IgnoreList
.LoadAllIgnoreFile(gitdir
,subpaths
);
464 int GitStatus::IsUnderVersionControl(const CString
&gitdir
, const CString
&path
, bool isDir
,bool *isVersion
)
466 if (g_IndexFileMap
.IsUnderVersionControl(gitdir
, path
, isDir
, isVersion
))
469 return g_HeadFileMap
.IsUnderVersionControl(gitdir
, path
, isDir
, isVersion
);
473 __int64
GitStatus::GetIndexFileTime(const CString
&gitdir
)
475 SHARED_INDEX_PTR ptr
=g_IndexFileMap
.SafeGet(gitdir
);
476 if(ptr
.get() == NULL
)
479 return ptr
->m_LastModifyTime
;
482 int GitStatus::IsIgnore(const CString
&gitdir
, const CString
&path
, bool *isIgnore
)
484 if(::g_IgnoreList
.CheckIgnoreChanged(gitdir
,path
))
485 g_IgnoreList
.LoadAllIgnoreFile(gitdir
,path
);
487 *isIgnore
= g_IgnoreList
.IsIgnore(path
,gitdir
);
492 static bool SortFileName(CGitFileName
&Item1
, CGitFileName
&Item2
)
494 return Item1
.m_FileName
.Compare(Item2
.m_FileName
)<0;
497 int GitStatus::GetFileList(const CString
&gitdir
, const CString
&subpath
, std::vector
<CGitFileName
> &list
)
499 WIN32_FIND_DATA data
;
500 HANDLE handle
=::FindFirstFile(gitdir
+_T("\\")+subpath
+_T("\\*.*"), &data
);
503 if(_tcscmp(data
.cFileName
, _T(".git")) == 0)
506 if(_tcscmp(data
.cFileName
, _T(".")) == 0)
509 if(_tcscmp(data
.cFileName
, _T("..")) == 0)
512 CGitFileName filename
;
514 filename
.m_CaseFileName
= filename
.m_FileName
= data
.cFileName
;
515 filename
.m_FileName
.MakeLower();
517 if(data
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
519 filename
.m_FileName
+= _T('/');
522 list
.push_back(filename
);
524 }while(::FindNextFile(handle
, &data
));
528 std::sort(list
.begin(), list
.end(), SortFileName
);
532 int GitStatus::EnumDirStatus(const CString
&gitdir
,const CString
&subpath
,git_wc_status_kind
* status
,BOOL IsFul
, BOOL IsRecursive
, BOOL IsIgnore
, FIll_STATUS_CALLBACK callback
, void *pData
)
536 TCHAR oldpath
[MAX_PATH
+1];
537 memset(oldpath
,0,MAX_PATH
+1);
539 CString path
=subpath
;
541 path
.Replace(_T('\\'),_T('/'));
543 if(path
[path
.GetLength()-1] != _T('/'))
544 path
+= _T('/'); //Add trail / to show it is directory, not file name.
546 CString lowcasepath
= path
;
547 lowcasepath
.MakeLower();
549 std::vector
<CGitFileName
> filelist
;
550 GetFileList(gitdir
, subpath
, filelist
);
554 g_IndexFileMap
.CheckAndUpdate(gitdir
,true);
556 g_HeadFileMap
.CheckHeadAndUpdate(gitdir
);
558 SHARED_INDEX_PTR indexptr
= g_IndexFileMap
.SafeGet(gitdir
);
559 SHARED_TREE_PTR treeptr
= g_HeadFileMap
.SafeGet(gitdir
);
561 std::vector
<CGitFileName
>::iterator it
;
563 // new git working tree has no index file
564 if (indexptr
.get() == NULL
)
566 for (it
= filelist
.begin(); it
< filelist
.end(); ++it
)
568 CString casepath
= path
+ it
->m_CaseFileName
;
571 if (casepath
.GetLength() > 0 && casepath
[casepath
.GetLength() - 1] == _T('/'))
574 if (bIsDir
) /*check if it is directory*/
576 if (::PathFileExists(gitdir
+ casepath
+ _T("\\.git")))
577 { /* That is git submodule */
578 *status
= git_wc_status_unknown
;
580 callback(gitdir
+ _T("/") + casepath
, *status
, bIsDir
, pData
, false, false);
587 if (g_IgnoreList
.CheckIgnoreChanged(gitdir
, casepath
))
588 g_IgnoreList
.LoadAllIgnoreFile(gitdir
, casepath
);
590 if (g_IgnoreList
.IsIgnore(casepath
, gitdir
))
591 *status
= git_wc_status_ignored
;
595 *status
= git_wc_status_unversioned
;
600 *status
= git_wc_status_unversioned
;
603 callback(gitdir
+ _T("/") + casepath
, *status
, bIsDir
, pData
, false, false);
610 for (it
= filelist
.begin(); it
< filelist
.end(); ++it
)
612 casepath
=onepath
= path
;
614 onepath
+= it
->m_FileName
;
615 casepath
+= it
->m_CaseFileName
;
617 LPTSTR onepathBuffer
= onepath
.GetBuffer();
618 int pos
= SearchInSortVector(*indexptr
, onepathBuffer
, onepath
.GetLength());
619 int posintree
= SearchInSortVector(*treeptr
, onepathBuffer
, onepath
.GetLength());
620 onepath
.ReleaseBuffer();
623 if(onepath
.GetLength()>0 && onepath
[onepath
.GetLength()-1] == _T('/'))
626 if(pos
<0 && posintree
<0)
628 if(onepath
.GetLength() ==0)
631 if(bIsDir
) /*check if it is directory*/
633 if(::PathFileExists(gitdir
+onepath
+_T("/.git")))
634 { /* That is git submodule */
635 *status
= git_wc_status_unknown
;
637 callback(gitdir
+ _T("/") + casepath
, *status
, bIsDir
, pData
, false, false);
644 *status
= git_wc_status_unversioned
;
646 callback(gitdir
+ _T("/") + casepath
, *status
, bIsDir
, pData
, false, false);
650 if(::g_IgnoreList
.CheckIgnoreChanged(gitdir
,casepath
))
651 g_IgnoreList
.LoadAllIgnoreFile(gitdir
,casepath
);
653 if(g_IgnoreList
.IsIgnore(casepath
,gitdir
))
654 *status
= git_wc_status_ignored
;
656 *status
= git_wc_status_unversioned
;
659 callback(gitdir
+ _T("/") + casepath
, *status
, bIsDir
, pData
, false, false);
662 else if(pos
<0 && posintree
>=0) /* check if file delete in index */
664 *status
= git_wc_status_deleted
;
666 callback(gitdir
+ _T("/") + casepath
, *status
, bIsDir
, pData
, false, false);
669 else if(pos
>=0 && posintree
<0) /* Check if file added */
671 *status
= git_wc_status_added
;
673 callback(gitdir
+ _T("/") + casepath
, *status
, bIsDir
, pData
, false, false);
677 if(onepath
.GetLength() ==0)
680 if(onepath
[onepath
.GetLength()-1] == _T('/'))
682 *status
= git_wc_status_normal
;
684 callback(gitdir
+ _T("/") + casepath
, *status
, bIsDir
, pData
, false, false);
688 bool assumeValid
= false;
689 bool skipWorktree
= false;
690 git_wc_status_kind filestatus
;
691 GetFileStatus(gitdir
, casepath
, &filestatus
, IsFul
, IsRecursive
, IsIgnore
, callback
, pData
, &assumeValid
, &skipWorktree
);
697 /* Check deleted file in system */
698 LPTSTR lowcasepathBuffer
= lowcasepath
.GetBuffer();
700 int pos
=SearchInSortVector(*indexptr
, lowcasepathBuffer
, lowcasepath
.GetLength());
702 if (GetRangeInSortVector(*indexptr
, lowcasepathBuffer
, lowcasepath
.GetLength(), &start
, &end
, pos
) == 0)
704 CGitIndexList::iterator it
;
707 for (it
= indexptr
->begin() + start
; it
<= indexptr
->begin() + end
; ++it
)
709 int start
= lowcasepath
.GetLength();
710 int index
= (*it
).m_FileName
.Find(_T('/'), start
);
712 index
= (*it
).m_FileName
.GetLength();
714 CString filename
= (*it
).m_FileName
.Mid(start
, index
-start
);
715 if(oldstring
!= filename
)
717 oldstring
= filename
;
718 if(SearchInSortVector(filelist
, filename
.GetBuffer(), filename
.GetLength())<0)
720 *status
= git_wc_status_deleted
;
722 callback(gitdir
+ _T("/") + filename
, *status
, false, pData
, false, false);
729 pos
=SearchInSortVector(*treeptr
, lowcasepathBuffer
, lowcasepath
.GetLength());
730 if (GetRangeInSortVector(*treeptr
, lowcasepathBuffer
, lowcasepath
.GetLength(), &start
, &end
, pos
) == 0)
732 CGitHeadFileList::iterator it
;
735 for (it
= treeptr
->begin() + start
; it
<= treeptr
->begin() + end
; ++it
)
737 int start
= lowcasepath
.GetLength();
738 int index
= (*it
).m_FileName
.Find(_T('/'), start
);
740 index
= (*it
).m_FileName
.GetLength();
742 CString filename
= (*it
).m_FileName
.Mid(start
, index
-start
);
743 if(oldstring
!= filename
)
745 oldstring
= filename
;
746 if(SearchInSortVector(filelist
, filename
.GetBuffer(), filename
.GetLength())<0)
748 *status
= git_wc_status_deleted
;
750 callback(gitdir
+ _T("/") + (*it
).m_FileName
, *status
, false, pData
, false, false);
755 lowcasepath
.ReleaseBuffer();
757 }/*End of if status*/
765 int GitStatus::GetDirStatus(const CString
&gitdir
,const CString
&subpath
,git_wc_status_kind
* status
,BOOL IsFul
, BOOL IsRecursive
,BOOL IsIgnore
,FIll_STATUS_CALLBACK callback
,void *pData
)
769 TCHAR oldpath
[MAX_PATH
+1];
770 memset(oldpath
,0,MAX_PATH
+1);
772 CString path
=subpath
;
774 path
.Replace(_T('\\'),_T('/'));
776 if(path
[path
.GetLength()-1] != _T('/'))
777 path
+= _T('/'); //Add trail / to show it is directory, not file name.
779 CString lowcasepath
= path
;
780 lowcasepath
.MakeLower();
784 g_IndexFileMap
.CheckAndUpdate(gitdir
, true);
786 SHARED_INDEX_PTR indexptr
= g_IndexFileMap
.SafeGet(gitdir
);
788 if (indexptr
== NULL
)
790 *status
= git_wc_status_unversioned
;
794 int pos
=SearchInSortVector(*indexptr
,lowcasepath
.GetBuffer(),lowcasepath
.GetLength());
795 lowcasepath
.ReleaseBuffer();
797 //Not In Version Contorl
802 *status
= git_wc_status_unversioned
;
804 callback(gitdir
+ _T("/") + path
, *status
, false, pData
, false, false);
807 //Check ignore always.
809 if(::g_IgnoreList
.CheckIgnoreChanged(gitdir
,path
))
810 g_IgnoreList
.LoadAllIgnoreFile(gitdir
,path
);
812 if(g_IgnoreList
.IsIgnore(path
,gitdir
))
813 *status
= git_wc_status_ignored
;
815 *status
= git_wc_status_unversioned
;
817 g_HeadFileMap
.CheckHeadAndUpdate(gitdir
, false);
819 SHARED_TREE_PTR treeptr
= g_HeadFileMap
.SafeGet(gitdir
);
820 //Check init repository
821 if (treeptr
->HeadIsEmpty() && path
.IsEmpty())
822 *status
= git_wc_status_normal
;
826 else // In version control
828 *status
= git_wc_status_normal
;
835 end
= (int)indexptr
->size() - 1;
837 LPTSTR lowcasepathBuffer
= lowcasepath
.GetBuffer();
838 GetRangeInSortVector(*indexptr
, lowcasepathBuffer
, lowcasepath
.GetLength(), &start
, &end
, pos
);
839 lowcasepath
.ReleaseBuffer();
840 CGitIndexList::iterator it
;
842 it
= indexptr
->begin()+start
;
845 for (int i
= start
; i
<= end
; ++i
)
847 if (((*it
).m_Flags
& GIT_IDXENTRY_STAGEMASK
) !=0)
849 *status
= git_wc_status_conflicted
;
852 int dirpos
= (*it
).m_FileName
.Find(_T('/'), path
.GetLength());
853 if(dirpos
<0 || IsRecursive
)
854 callback(gitdir
+ _T("\\") + it
->m_FileName
, git_wc_status_conflicted
, false, pData
, false, false);
862 if( IsFul
&& (*status
!= git_wc_status_conflicted
))
864 *status
= git_wc_status_normal
;
866 g_HeadFileMap
.CheckHeadAndUpdate(gitdir
);
869 it
= indexptr
->begin()+start
;
873 //Check if new init repository
874 SHARED_TREE_PTR treeptr
= g_HeadFileMap
.SafeGet(gitdir
);
876 if (!treeptr
->empty() || treeptr
->HeadIsEmpty())
878 for (int i
= start
; i
<= end
; ++i
)
880 pos
=SearchInSortVector(*treeptr
, (*it
).m_FileName
.GetBuffer(), -1);
881 (*it
).m_FileName
.ReleaseBuffer();
885 *status
= max(git_wc_status_added
, *status
); // added file found
888 int dirpos
= (*it
).m_FileName
.Find(_T('/'), path
.GetLength());
889 if(dirpos
<0 || IsRecursive
)
890 callback(gitdir
+ _T("\\") + it
->m_FileName
, git_wc_status_added
, false, pData
, false, false);
897 if( pos
>=0 && treeptr
->at(pos
).m_Hash
!= (*it
).m_IndexHash
)
899 *status
= max(git_wc_status_modified
, *status
); // modified file found
902 int dirpos
= (*it
).m_FileName
.Find(_T('/'), path
.GetLength());
903 if(dirpos
<0 || IsRecursive
)
904 callback(gitdir
+ _T("\\") + it
->m_FileName
, git_wc_status_modified
, false, pData
, ((*it
).m_Flags
& GIT_IDXENTRY_VALID
) && !((*it
).m_Flags
& GIT_IDXENTRY_SKIP_WORKTREE
), ((*it
).m_Flags
& GIT_IDXENTRY_SKIP_WORKTREE
) != 0);
915 if( *status
== git_wc_status_normal
)
917 pos
= SearchInSortVector(*treeptr
, lowcasepathBuffer
, lowcasepath
.GetLength());
920 *status
= max(git_wc_status_added
, *status
); // added file found
926 GetRangeInSortVector(*treeptr
, lowcasepathBuffer
, lowcasepath
.GetLength(), &hstart
, &hend
, pos
);
927 CGitHeadFileList::iterator hit
;
928 hit
= treeptr
->begin() + hstart
;
929 CGitHeadFileList::iterator lastElement
= treeptr
->end();
930 for (int i
= hstart
; i
<= hend
&& hit
!= lastElement
; ++i
)
932 if( SearchInSortVector(*indexptr
,(*hit
).m_FileName
.GetBuffer(),-1) < 0)
934 (*hit
).m_FileName
.ReleaseBuffer();
935 *status
= max(git_wc_status_deleted
, *status
); // deleted file found
938 (*hit
).m_FileName
.ReleaseBuffer();
946 lowcasepath
.ReleaseBuffer();
947 // If define callback, it need update each file status.
948 // If not define callback, status == git_wc_status_conflicted, needn't check each file status
949 // because git_wc_status_conflicted is highest.s
950 if(callback
|| (*status
!= git_wc_status_conflicted
))
955 CString sub
, currentPath
;
956 it
= indexptr
->begin()+start
;
957 for (int i
= start
; i
<= end
; ++i
, ++it
)
961 //skip child directory
962 int pos
= (*it
).m_FileName
.Find(_T('/'), path
.GetLength());
966 currentPath
= (*it
).m_FileName
.Left(pos
);
967 if( callback
&& (sub
!= currentPath
) )
970 ATLTRACE(_T("index subdir %s\n"),sub
);
971 if(callback
) callback(gitdir
+ _T("\\") + sub
,
972 git_wc_status_normal
, true, pData
, false, false);
978 git_wc_status_kind filestatus
= git_wc_status_none
;
979 bool assumeValid
= false;
980 bool skipWorktree
= false;
981 GetFileStatus(gitdir
, (*it
).m_FileName
, &filestatus
, IsFul
, IsRecursive
, IsIgnore
, callback
, pData
, &assumeValid
, &skipWorktree
);
987 if(callback
) callback(gitdir
+ _T("/") + subpath
, *status
, true, pData
, false, false);
993 *status
= git_wc_status_none
;
1000 bool GitStatus::IsExistIndexLockFile(const CString
&gitdir
)
1002 CString sDirName
= gitdir
;
1006 if(PathFileExists(sDirName
+ _T("\\.git")))
1008 if(PathFileExists(g_AdminDirMap
.GetAdminDir(sDirName
) + _T("index.lock")))
1014 int x
= sDirName
.ReverseFind(_T('\\'));
1018 sDirName
= sDirName
.Left(x
);