1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // External Cache Copyright (C) 2005-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include ".\cacheddirectory.h"
\r
21 //#include "SVNHelpers.h"
\r
22 #include "GitStatusCache.h"
\r
23 #include "GitStatus.h"
\r
26 CCachedDirectory::CCachedDirectory(void)
\r
28 m_indexFileTime = 0;
\r
29 // m_propsFileTime = 0;
\r
30 m_currentStatusFetchingPathTicks = 0;
\r
31 m_bCurrentFullStatusValid = false;
\r
32 m_currentFullStatus = m_mostImportantFileStatus = git_wc_status_none;
\r
33 m_bRecursive = true;
\r
36 CCachedDirectory::~CCachedDirectory(void)
\r
40 CCachedDirectory::CCachedDirectory(const CTGitPath& directoryPath)
\r
42 ATLASSERT(directoryPath.IsDirectory() || !PathFileExists(directoryPath.GetWinPath()));
\r
44 m_directoryPath = directoryPath;
\r
45 m_indexFileTime = 0;
\r
46 // m_propsFileTime = 0;
\r
47 m_currentStatusFetchingPathTicks = 0;
\r
48 m_bCurrentFullStatusValid = false;
\r
49 m_currentFullStatus = m_mostImportantFileStatus = git_wc_status_none;
\r
50 m_bRecursive = true;
\r
53 BOOL CCachedDirectory::SaveToDisk(FILE * pFile)
\r
55 AutoLocker lock(m_critSec);
\r
56 #define WRITEVALUETOFILE(x) if (fwrite(&x, sizeof(x), 1, pFile)!=1) return false;
\r
58 unsigned int value = 1;
\r
59 WRITEVALUETOFILE(value); // 'version' of this save-format
\r
60 value = (int)m_entryCache.size();
\r
61 WRITEVALUETOFILE(value); // size of the cache map
\r
62 // now iterate through the maps and save every entry.
\r
63 for (CacheEntryMap::iterator I = m_entryCache.begin(); I != m_entryCache.end(); ++I)
\r
65 const CString& key = I->first;
\r
66 value = key.GetLength();
\r
67 WRITEVALUETOFILE(value);
\r
70 if (fwrite((LPCTSTR)key, sizeof(TCHAR), value, pFile)!=value)
\r
72 if (!I->second.SaveToDisk(pFile))
\r
76 value = (int)m_childDirectories.size();
\r
77 WRITEVALUETOFILE(value);
\r
78 for (ChildDirStatus::iterator I = m_childDirectories.begin(); I != m_childDirectories.end(); ++I)
\r
80 const CString& path = I->first.GetWinPathString();
\r
81 value = path.GetLength();
\r
82 WRITEVALUETOFILE(value);
\r
85 if (fwrite((LPCTSTR)path, sizeof(TCHAR), value, pFile)!=value)
\r
87 git_wc_status_kind status = I->second;
\r
88 WRITEVALUETOFILE(status);
\r
91 WRITEVALUETOFILE(m_indexFileTime);
\r
92 // WRITEVALUETOFILE(m_propsFileTime);
\r
93 value = m_directoryPath.GetWinPathString().GetLength();
\r
94 WRITEVALUETOFILE(value);
\r
97 if (fwrite(m_directoryPath.GetWinPath(), sizeof(TCHAR), value, pFile)!=value)
\r
100 if (!m_ownStatus.SaveToDisk(pFile))
\r
102 WRITEVALUETOFILE(m_currentFullStatus);
\r
103 WRITEVALUETOFILE(m_mostImportantFileStatus);
\r
107 BOOL CCachedDirectory::LoadFromDisk(FILE * pFile)
\r
109 AutoLocker lock(m_critSec);
\r
110 #define LOADVALUEFROMFILE(x) if (fread(&x, sizeof(x), 1, pFile)!=1) return false;
\r
113 unsigned int value = 0;
\r
114 LOADVALUEFROMFILE(value);
\r
116 return false; // not the correct version
\r
118 LOADVALUEFROMFILE(mapsize);
\r
119 for (int i=0; i<mapsize; ++i)
\r
121 LOADVALUEFROMFILE(value);
\r
122 if (value > MAX_PATH)
\r
127 if (fread(sKey.GetBuffer(value+1), sizeof(TCHAR), value, pFile)!=value)
\r
129 sKey.ReleaseBuffer(0);
\r
132 sKey.ReleaseBuffer(value);
\r
133 CStatusCacheEntry entry;
\r
134 if (!entry.LoadFromDisk(pFile))
\r
136 m_entryCache[sKey] = entry;
\r
139 LOADVALUEFROMFILE(mapsize);
\r
140 for (int i=0; i<mapsize; ++i)
\r
142 LOADVALUEFROMFILE(value);
\r
143 if (value > MAX_PATH)
\r
148 if (fread(sPath.GetBuffer(value), sizeof(TCHAR), value, pFile)!=value)
\r
150 sPath.ReleaseBuffer(0);
\r
153 sPath.ReleaseBuffer(value);
\r
154 git_wc_status_kind status;
\r
155 LOADVALUEFROMFILE(status);
\r
156 m_childDirectories[CTGitPath(sPath)] = status;
\r
159 LOADVALUEFROMFILE(m_indexFileTime);
\r
160 // LOADVALUEFROMFILE(m_propsFileTime);
\r
161 LOADVALUEFROMFILE(value);
\r
162 if (value > MAX_PATH)
\r
167 if (fread(sPath.GetBuffer(value+1), sizeof(TCHAR), value, pFile)!=value)
\r
169 sPath.ReleaseBuffer(0);
\r
172 sPath.ReleaseBuffer(value);
\r
173 m_directoryPath.SetFromWin(sPath);
\r
175 if (!m_ownStatus.LoadFromDisk(pFile))
\r
178 LOADVALUEFROMFILE(m_currentFullStatus);
\r
179 LOADVALUEFROMFILE(m_mostImportantFileStatus);
\r
181 catch ( CAtlException )
\r
189 CStatusCacheEntry CCachedDirectory::GetStatusForMember(const CTGitPath& path, bool bRecursive, bool bFetch /* = true */)
\r
191 CString strCacheKey;
\r
192 bool bThisDirectoryIsUnversioned = false;
\r
193 bool bRequestForSelf = false;
\r
194 if(path.IsEquivalentToWithoutCase(m_directoryPath))
\r
196 bRequestForSelf = true;
\r
198 //OutputDebugStringA("GetStatusForMember: ");OutputDebugStringW(path.GetWinPathString());OutputDebugStringA("\r\n");
\r
199 // In all most circumstances, we ask for the status of a member of this directory.
\r
200 ATLASSERT(m_directoryPath.IsEquivalentToWithoutCase(path.GetContainingDirectory()) || bRequestForSelf);
\r
202 CString sProjectRoot;
\r
203 const BOOL bIsVersionedPath = m_directoryPath.HasAdminDir(&sProjectRoot);
\r
205 // Check if the index file has been changed
\r
206 CTGitPath indexFilePath(bIsVersionedPath ? sProjectRoot : m_directoryPath);
\r
207 // CTGitPath propsDirPath(m_directoryPath);
\r
208 if (g_GitAdminDir.IsVSNETHackActive())
\r
210 indexFilePath.AppendPathString(g_GitAdminDir.GetVSNETAdminDirName() + _T("\\index"));
\r
211 // propsDirPath.AppendPathString(g_GitAdminDir.GetVSNETAdminDirName() + _T("\\dir-props"));
\r
215 indexFilePath.AppendPathString(g_GitAdminDir.GetAdminDirName() + _T("\\index"));
\r
216 // propsDirPath.AppendPathString(g_GitAdminDir.GetAdminDirName() + _T("\\dir-props"));
\r
218 if ( (m_indexFileTime == indexFilePath.GetLastWriteTime()) /*&& ((indexFilePath.GetLastWriteTime() == 0) || (m_propsFileTime == propsDirPath.GetLastWriteTime()))*/ )
\r
220 // m_indexFileTime = indexFilePath.GetLastWriteTime();
\r
221 // if (m_indexFileTime)
\r
222 // m_propsFileTime = propsDirPath.GetLastWriteTime();
\r
224 //if(m_indexFileTime == 0)
\r
225 // a newly created project (without commits) has no index file but we still want it to count as versioned
\r
226 if(m_indexFileTime == 0 && !bIsVersionedPath)
\r
228 // We are a folder which is not in a working copy
\r
229 bThisDirectoryIsUnversioned = true;
\r
230 m_ownStatus.SetStatus(NULL);
\r
232 // If a user removes the .git directory, we get here with m_entryCache
\r
233 // not being empty, but still us being unversioned
\r
234 if (!m_entryCache.empty())
\r
236 m_entryCache.clear();
\r
238 ATLASSERT(m_entryCache.empty());
\r
240 // However, a member *DIRECTORY* might be the top of WC
\r
241 // so we need to ask them to get their own status
\r
242 if(!path.IsDirectory())
\r
244 if ((PathFileExists(path.GetWinPath()))||(bRequestForSelf))
\r
245 return CStatusCacheEntry();
\r
246 // the entry doesn't exist anymore!
\r
247 // but we can't remove it from the cache here:
\r
248 // the GetStatusForMember() method is called only with a read
\r
249 // lock and not a write lock!
\r
250 // So mark it for crawling, and let the crawler remove it
\r
252 CGitStatusCache::Instance().AddFolderForCrawling(path.GetContainingDirectory());
\r
254 return CStatusCacheEntry();
\r
258 // If we're in the special case of a directory being asked for its own status
\r
259 // and this directory is unversioned, then we should just return that here
\r
260 if(bRequestForSelf)
\r
261 return CStatusCacheEntry();
\r
265 if(path.IsDirectory())
\r
267 // We don't have directory status in our cache
\r
268 // Ask the directory if it knows its own status
\r
269 CCachedDirectory * dirEntry = CGitStatusCache::Instance().GetDirectoryCacheEntry(path);
\r
270 if ((dirEntry)&&(dirEntry->IsOwnStatusValid()))
\r
272 // To keep recursive status up to date, we'll request that children are all crawled again
\r
273 // This will be very quick if nothings changed, because it will all be cache hits
\r
276 AutoLocker lock(dirEntry->m_critSec);
\r
277 ChildDirStatus::const_iterator it;
\r
278 for(it = dirEntry->m_childDirectories.begin(); it != dirEntry->m_childDirectories.end(); ++it)
\r
280 CGitStatusCache::Instance().AddFolderForCrawling(it->first);
\r
283 return dirEntry->GetOwnStatus(bRecursive);
\r
289 // if we currently are fetching the status of the directory
\r
290 // we want the status for, we just return an empty entry here
\r
291 // and don't wait for that fetching to finish.
\r
292 // That's because fetching the status can take a *really* long
\r
293 // time (e.g. if a commit is also in progress on that same
\r
294 // directory), and we don't want to make the explorer appear
\r
296 AutoLocker pathlock(m_critSecPath);
\r
297 if ((!bFetch)&&(!m_currentStatusFetchingPath.IsEmpty()))
\r
299 if ((m_currentStatusFetchingPath.IsAncestorOf(path))&&((m_currentStatusFetchingPathTicks + 1000)<GetTickCount()))
\r
301 ATLTRACE(_T("returning empty status (status fetch in progress) for %s\n"), path.GetWinPath());
\r
302 m_currentFullStatus = m_mostImportantFileStatus = git_wc_status_none;
\r
303 return CStatusCacheEntry();
\r
307 // Look up a file in our own cache
\r
308 AutoLocker lock(m_critSec);
\r
309 strCacheKey = GetCacheKey(path);
\r
310 CacheEntryMap::iterator itMap = m_entryCache.find(strCacheKey);
\r
311 if(itMap != m_entryCache.end())
\r
313 // We've hit the cache - check for timeout
\r
314 if(!itMap->second.HasExpired((long)GetTickCount()))
\r
316 if(itMap->second.DoesFileTimeMatch(path.GetLastWriteTime()))
\r
318 if ((itMap->second.GetEffectiveStatus()!=git_wc_status_missing)||(!PathFileExists(path.GetWinPath())))
\r
320 // Note: the filetime matches after a modified has been committed too.
\r
321 // So in that case, we would return a wrong status (e.g. 'modified' instead
\r
322 // of 'normal') here.
\r
323 return itMap->second;
\r
332 AutoLocker pathlock(m_critSecPath);
\r
333 if ((!bFetch)&&(!m_currentStatusFetchingPath.IsEmpty()))
\r
335 if ((m_currentStatusFetchingPath.IsAncestorOf(path))&&((m_currentStatusFetchingPathTicks + 1000)<GetTickCount()))
\r
337 ATLTRACE(_T("returning empty status (status fetch in progress) for %s\n"), path.GetWinPath());
\r
338 m_currentFullStatus = m_mostImportantFileStatus = git_wc_status_none;
\r
339 return CStatusCacheEntry();
\r
342 // if we're fetching the status for the explorer,
\r
343 // we don't refresh the status but use the one
\r
344 // we already have (to save time and make the explorer
\r
345 // more responsive in stress conditions).
\r
346 // We leave the refreshing to the crawler.
\r
347 if ((!bFetch)&&(m_indexFileTime))
\r
349 CGitStatusCache::Instance().AddFolderForCrawling(path.GetDirectory());
\r
350 return CStatusCacheEntry();
\r
352 AutoLocker lock(m_critSec);
\r
353 m_indexFileTime = indexFilePath.GetLastWriteTime();
\r
354 // m_propsFileTime = propsDirPath.GetLastWriteTime();
\r
355 m_entryCache.clear();
\r
356 strCacheKey = GetCacheKey(path);
\r
359 // svn_opt_revision_t revision;
\r
360 // revision.kind = svn_opt_revision_unspecified;
\r
362 // We've not got this item in the cache - let's add it
\r
363 // We never bother asking SVN for the status of just one file, always for its containing directory
\r
365 if (g_GitAdminDir.IsAdminDirPath(path.GetWinPathString()))
\r
367 // We're being asked for the status of an .git directory
\r
368 // It's not worth asking for this
\r
369 return CStatusCacheEntry();
\r
374 AutoLocker pathlock(m_critSecPath);
\r
375 if ((!bFetch)&&(!m_currentStatusFetchingPath.IsEmpty()))
\r
377 if ((m_currentStatusFetchingPath.IsAncestorOf(path))&&((m_currentStatusFetchingPathTicks + 1000)<GetTickCount()))
\r
379 ATLTRACE(_T("returning empty status (status fetch in progress) for %s\n"), path.GetWinPath());
\r
380 m_currentFullStatus = m_mostImportantFileStatus = git_wc_status_none;
\r
381 return CStatusCacheEntry();
\r
385 // SVNPool subPool(CGitStatusCache::Instance().m_svnHelp.Pool());
\r
387 AutoLocker lock(m_critSec);
\r
388 m_mostImportantFileStatus = git_wc_status_none;
\r
389 m_childDirectories.clear();
\r
390 m_entryCache.clear();
\r
391 m_ownStatus.SetStatus(NULL);
\r
392 m_bRecursive = bRecursive;
\r
394 if(!bThisDirectoryIsUnversioned)
\r
397 AutoLocker pathlock(m_critSecPath);
\r
398 m_currentStatusFetchingPath = m_directoryPath;
\r
399 m_currentStatusFetchingPathTicks = GetTickCount();
\r
401 ATLTRACE(_T("git_enum_files for '%s' (req %s)\n"), m_directoryPath.GetWinPath(), path.GetWinPath());
\r
403 CString sProjectRoot;
\r
404 m_directoryPath.HasAdminDir(&sProjectRoot);
\r
405 ATLASSERT( !m_directoryPath.IsEmpty() );
\r
407 LPCTSTR lpszSubPath = NULL;
\r
409 CString s = m_directoryPath.GetDirectory().GetWinPathString();
\r
410 if (s.GetLength() > sProjectRoot.GetLength())
\r
412 sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);
\r
413 lpszSubPath = sSubPath;
\r
415 //MessageBoxA(NULL, CStringA(sProjectRoot), sSubPath, MB_OK);
\r
416 //OutputDebugStringA("###");OutputDebugStringW(sProjectRoot);OutputDebugStringA(" - ");OutputDebugStringA(sSubPath);OutputDebugStringA("\r\n");
\r
417 BOOL pErr = !wgEnumFiles(sProjectRoot, lpszSubPath, WGEFF_NoRecurse|WGEFF_FullPath, &GetStatusCallback, this);
\r
419 /*git_error_t* pErr = svn_client_status4 (
\r
421 m_directoryPath.GetSVNApiPath(subPool),
\r
425 svn_depth_immediates,
\r
429 FALSE, //ignore externals
\r
430 NULL, //changelists
\r
431 CGitStatusCache::Instance().m_svnHelp.ClientContext(),
\r
435 AutoLocker pathlock(m_critSecPath);
\r
436 m_currentStatusFetchingPath.Reset();
\r
438 ATLTRACE(_T("git_enum_files finished for '%s'\n"), m_directoryPath.GetWinPath(), path.GetWinPath());
\r
442 // The most likely error on a folder is that it's not part of a WC
\r
443 // In most circumstances, this will have been caught earlier,
\r
444 // but in some situations, we'll get this error.
\r
445 // If we allow ourselves to fall on through, then folders will be asked
\r
446 // for their own status, and will set themselves as unversioned, for the
\r
447 // benefit of future requests
\r
448 // ATLTRACE("git_enum_files err: '%s'\n", pErr->message);
\r
449 // svn_error_clear(pErr);
\r
450 // No assert here! Since we _can_ get here, an assertion is not an option!
\r
451 // Reasons to get here:
\r
452 // - renaming a folder with many sub folders --> results in "not a working copy" if the revert
\r
453 // happens between our checks and the svn_client_status() call.
\r
454 // - reverting a move/copy --> results in "not a working copy" (as above)
\r
455 if (!m_directoryPath.HasAdminDir())
\r
457 m_currentFullStatus = m_mostImportantFileStatus = git_wc_status_none;
\r
458 return CStatusCacheEntry();
\r
462 ATLTRACE("git_enum_files error, assume none status\n");
\r
463 // Since we only assume a none status here due to svn_client_status()
\r
464 // returning an error, make sure that this status times out soon.
\r
465 CGitStatusCache::Instance().m_folderCrawler.BlockPath(m_directoryPath, 2000);
\r
466 CGitStatusCache::Instance().AddFolderForCrawling(m_directoryPath);
\r
467 return CStatusCacheEntry();
\r
473 ATLTRACE("Skipped git status for unversioned folder\n");
\r
476 // Now that we've refreshed our SVN status, we can see if it's
\r
477 // changed the 'most important' status value for this directory.
\r
478 // If it has, then we should tell our parent
\r
479 UpdateCurrentStatus();
\r
481 if (path.IsDirectory())
\r
483 CCachedDirectory * dirEntry = CGitStatusCache::Instance().GetDirectoryCacheEntry(path);
\r
484 if ((dirEntry)&&(dirEntry->IsOwnStatusValid()))
\r
486 CGitStatusCache::Instance().AddFolderForCrawling(path);
\r
487 return dirEntry->GetOwnStatus(bRecursive);
\r
490 // If the status *still* isn't valid here, it means that
\r
491 // the current directory is unversioned, and we shall need to ask its children for info about themselves
\r
493 return dirEntry->GetStatusForMember(path,bRecursive);
\r
494 CGitStatusCache::Instance().AddFolderForCrawling(path);
\r
495 return CStatusCacheEntry();
\r
499 CacheEntryMap::iterator itMap = m_entryCache.find(strCacheKey);
\r
500 if(itMap != m_entryCache.end())
\r
502 return itMap->second;
\r
506 AddEntry(path, NULL);
\r
507 return CStatusCacheEntry();
\r
511 CCachedDirectory::AddEntry(const CTGitPath& path, const git_wc_status2_t* pGitStatus, DWORD validuntil /* = 0*/)
\r
513 AutoLocker lock(m_critSec);
\r
514 if(path.IsDirectory())
\r
516 CCachedDirectory * childDir = CGitStatusCache::Instance().GetDirectoryCacheEntry(path);
\r
519 if ((childDir->GetCurrentFullStatus() != git_wc_status_missing)||(pGitStatus==NULL)||(pGitStatus->text_status != git_wc_status_unversioned))
\r
520 childDir->m_ownStatus.SetStatus(pGitStatus);
\r
521 childDir->m_ownStatus.SetKind(git_node_dir);
\r
526 CString cachekey = GetCacheKey(path);
\r
527 CacheEntryMap::iterator entry_it = m_entryCache.lower_bound(cachekey);
\r
528 if (entry_it != m_entryCache.end() && entry_it->first == cachekey)
\r
532 if (entry_it->second.GetEffectiveStatus() > git_wc_status_none &&
\r
533 entry_it->second.GetEffectiveStatus() != GitStatus::GetMoreImportant(pGitStatus->prop_status, pGitStatus->text_status))
\r
535 CGitStatusCache::Instance().UpdateShell(path);
\r
536 ATLTRACE(_T("shell update for %s\n"), path.GetWinPath());
\r
542 entry_it = m_entryCache.insert(entry_it, std::make_pair(cachekey, CStatusCacheEntry()));
\r
544 entry_it->second = CStatusCacheEntry(pGitStatus, path.GetLastWriteTime(), path.IsReadOnly(), validuntil);
\r
545 // TEMP(?): git status doesn't not have "entry" that contains node type, so manually set as file
\r
546 entry_it->second.SetKind(git_node_file);
\r
552 CCachedDirectory::GetCacheKey(const CTGitPath& path)
\r
554 // All we put into the cache as a key is just the end portion of the pathname
\r
555 // There's no point storing the path of the containing directory for every item
\r
556 return path.GetWinPathString().Mid(m_directoryPath.GetWinPathString().GetLength());
\r
560 CCachedDirectory::GetFullPathString(const CString& cacheKey)
\r
562 return m_directoryPath.GetWinPathString() + _T("\\") + cacheKey;
\r
565 BOOL CCachedDirectory::GetStatusCallback(const struct wgFile_s *pFile, void *pUserData)
\r
567 CCachedDirectory* pThis = (CCachedDirectory*)pUserData;
\r
569 const TCHAR *path = pFile->sFileName;
\r
574 git_wc_status2_t _status;
\r
575 git_wc_status2_t *status = &_status;
\r
577 if ((pFile->nFlags & WGFF_Directory) && pFile->nStatus == WGFS_Unknown)
\r
578 status->prop_status = status->text_status = git_wc_status_incomplete;
\r
580 status->prop_status = status->text_status = GitStatusFromWingit(pFile->nStatus);
\r
581 //if (pFile->nStatus > WGFS_Normal) {CStringA s; s.Format("==>%s %d\r\n",pFile->sFileName,pFile->nStatus); OutputDebugStringA(s);}
\r
584 // if(status->entry)
\r
586 //if ((status->text_status != git_wc_status_none)&&(status->text_status != git_wc_status_missing))
\r
587 svnPath.SetFromGit(path, pFile->nFlags & WGFF_Directory);
\r
589 svnPath.SetFromGit(path);*/
\r
591 if (pFile->nFlags & WGFF_Directory)
\r
593 if ( !svnPath.IsEquivalentToWithoutCase(pThis->m_directoryPath) )
\r
595 if (pThis->m_bRecursive)
\r
597 // Add any versioned directory, which is not our 'self' entry, to the list for having its status updated
\r
598 //OutputDebugStringA("AddFolderCrawl: ");OutputDebugStringW(svnPath.GetWinPathString());OutputDebugStringA("\r\n");
\r
599 CGitStatusCache::Instance().AddFolderForCrawling(svnPath);
\r
602 // Make sure we know about this child directory
\r
603 // This initial status value is likely to be overwritten from below at some point
\r
604 git_wc_status_kind s = GitStatus::GetMoreImportant(status->text_status, status->prop_status);
\r
605 CCachedDirectory * cdir = CGitStatusCache::Instance().GetDirectoryCacheEntryNoCreate(svnPath);
\r
608 // This child directory is already in our cache!
\r
609 // So ask this dir about its recursive status
\r
610 git_wc_status_kind st = GitStatus::GetMoreImportant(s, cdir->GetCurrentFullStatus());
\r
611 AutoLocker lock(pThis->m_critSec);
\r
612 pThis->m_childDirectories[svnPath] = st;
\r
616 // the child directory is not in the cache. Create a new entry for it in the cache which is
\r
617 // initially 'unversioned'. But we added that directory to the crawling list above, which
\r
618 // means the cache will be updated soon.
\r
619 CGitStatusCache::Instance().GetDirectoryCacheEntry(svnPath);
\r
620 AutoLocker lock(pThis->m_critSec);
\r
621 pThis->m_childDirectories[svnPath] = s;
\r
627 // Keep track of the most important status of all the files in this directory
\r
628 // Don't include subdirectories in this figure, because they need to provide their
\r
629 // own 'most important' value
\r
630 pThis->m_mostImportantFileStatus = GitStatus::GetMoreImportant(pThis->m_mostImportantFileStatus, status->text_status);
\r
631 pThis->m_mostImportantFileStatus = GitStatus::GetMoreImportant(pThis->m_mostImportantFileStatus, status->prop_status);
\r
632 if (((status->text_status == git_wc_status_unversioned)||(status->text_status == git_wc_status_none))
\r
633 &&(CGitStatusCache::Instance().IsUnversionedAsModified()))
\r
635 // treat unversioned files as modified
\r
636 if (pThis->m_mostImportantFileStatus != git_wc_status_added)
\r
637 pThis->m_mostImportantFileStatus = GitStatus::GetMoreImportant(pThis->m_mostImportantFileStatus, git_wc_status_modified);
\r
644 svnPath.SetFromGit(path);
\r
645 // Subversion returns no 'entry' field for versioned folders if they're
\r
646 // part of another working copy (nested layouts).
\r
647 // So we have to make sure that such an 'unversioned' folder really
\r
649 if (((status->text_status == git_wc_status_unversioned)||(status->text_status == git_wc_status_missing))&&(!svnPath.IsEquivalentToWithoutCase(pThis->m_directoryPath))&&(svnPath.IsDirectory()))
\r
651 if (svnPath.HasAdminDir())
\r
653 CGitStatusCache::Instance().AddFolderForCrawling(svnPath);
\r
654 // Mark the directory as 'versioned' (status 'normal' for now).
\r
655 // This initial value will be overwritten from below some time later
\r
657 AutoLocker lock(pThis->m_critSec);
\r
658 pThis->m_childDirectories[svnPath] = git_wc_status_normal;
\r
660 // Make sure the entry is also in the cache
\r
661 CGitStatusCache::Instance().GetDirectoryCacheEntry(svnPath);
\r
662 // also mark the status in the status object as normal
\r
663 status->text_status = git_wc_status_normal;
\r
666 else if (status->text_status == git_wc_status_external)
\r
668 CGitStatusCache::Instance().AddFolderForCrawling(svnPath);
\r
669 // Mark the directory as 'versioned' (status 'normal' for now).
\r
670 // This initial value will be overwritten from below some time later
\r
672 AutoLocker lock(pThis->m_critSec);
\r
673 pThis->m_childDirectories[svnPath] = git_wc_status_normal;
\r
675 // we have added a directory to the child-directory list of this
\r
676 // directory. We now must make sure that this directory also has
\r
677 // an entry in the cache.
\r
678 CGitStatusCache::Instance().GetDirectoryCacheEntry(svnPath);
\r
679 // also mark the status in the status object as normal
\r
680 status->text_status = git_wc_status_normal;
\r
684 if (svnPath.IsDirectory())
\r
686 AutoLocker lock(pThis->m_critSec);
\r
687 pThis->m_childDirectories[svnPath] = GitStatus::GetMoreImportant(status->text_status, status->prop_status);
\r
689 else if ((CGitStatusCache::Instance().IsUnversionedAsModified())&&(status->text_status != git_wc_status_missing))
\r
691 // make this unversioned item change the most important status of this
\r
692 // folder to modified if it doesn't already have another status
\r
693 if (pThis->m_mostImportantFileStatus != git_wc_status_added)
\r
694 pThis->m_mostImportantFileStatus = GitStatus::GetMoreImportant(pThis->m_mostImportantFileStatus, git_wc_status_modified);
\r
700 pThis->AddEntry(svnPath, status);
\r
706 git_error_t * CCachedDirectory::GetStatusCallback(void *baton, const char *path, git_wc_status2_t *status)
\r
708 CCachedDirectory* pThis = (CCachedDirectory*)baton;
\r
717 if ((status->text_status != git_wc_status_none)&&(status->text_status != git_wc_status_missing))
\r
718 svnPath.SetFromSVN(path, (status->entry->kind == svn_node_dir));
\r
720 svnPath.SetFromSVN(path);
\r
722 if(svnPath.IsDirectory())
\r
724 if(!svnPath.IsEquivalentToWithoutCase(pThis->m_directoryPath))
\r
726 if (pThis->m_bRecursive)
\r
728 // Add any versioned directory, which is not our 'self' entry, to the list for having its status updated
\r
729 CGitStatusCache::Instance().AddFolderForCrawling(svnPath);
\r
732 // Make sure we know about this child directory
\r
733 // This initial status value is likely to be overwritten from below at some point
\r
734 git_wc_status_kind s = GitStatus::GetMoreImportant(status->text_status, status->prop_status);
\r
735 CCachedDirectory * cdir = CGitStatusCache::Instance().GetDirectoryCacheEntryNoCreate(svnPath);
\r
738 // This child directory is already in our cache!
\r
739 // So ask this dir about its recursive status
\r
740 git_wc_status_kind st = GitStatus::GetMoreImportant(s, cdir->GetCurrentFullStatus());
\r
741 AutoLocker lock(pThis->m_critSec);
\r
742 pThis->m_childDirectories[svnPath] = st;
\r
746 // the child directory is not in the cache. Create a new entry for it in the cache which is
\r
747 // initially 'unversioned'. But we added that directory to the crawling list above, which
\r
748 // means the cache will be updated soon.
\r
749 CGitStatusCache::Instance().GetDirectoryCacheEntry(svnPath);
\r
750 AutoLocker lock(pThis->m_critSec);
\r
751 pThis->m_childDirectories[svnPath] = s;
\r
757 // Keep track of the most important status of all the files in this directory
\r
758 // Don't include subdirectories in this figure, because they need to provide their
\r
759 // own 'most important' value
\r
760 pThis->m_mostImportantFileStatus = GitStatus::GetMoreImportant(pThis->m_mostImportantFileStatus, status->text_status);
\r
761 pThis->m_mostImportantFileStatus = GitStatus::GetMoreImportant(pThis->m_mostImportantFileStatus, status->prop_status);
\r
762 if (((status->text_status == git_wc_status_unversioned)||(status->text_status == git_wc_status_none))
\r
763 &&(CGitStatusCache::Instance().IsUnversionedAsModified()))
\r
765 // treat unversioned files as modified
\r
766 if (pThis->m_mostImportantFileStatus != git_wc_status_added)
\r
767 pThis->m_mostImportantFileStatus = GitStatus::GetMoreImportant(pThis->m_mostImportantFileStatus, git_wc_status_modified);
\r
773 svnPath.SetFromSVN(path);
\r
774 // Subversion returns no 'entry' field for versioned folders if they're
\r
775 // part of another working copy (nested layouts).
\r
776 // So we have to make sure that such an 'unversioned' folder really
\r
778 if (((status->text_status == git_wc_status_unversioned)||(status->text_status == git_wc_status_missing))&&(!svnPath.IsEquivalentToWithoutCase(pThis->m_directoryPath))&&(svnPath.IsDirectory()))
\r
780 if (svnPath.HasAdminDir())
\r
782 CGitStatusCache::Instance().AddFolderForCrawling(svnPath);
\r
783 // Mark the directory as 'versioned' (status 'normal' for now).
\r
784 // This initial value will be overwritten from below some time later
\r
786 AutoLocker lock(pThis->m_critSec);
\r
787 pThis->m_childDirectories[svnPath] = git_wc_status_normal;
\r
789 // Make sure the entry is also in the cache
\r
790 CGitStatusCache::Instance().GetDirectoryCacheEntry(svnPath);
\r
791 // also mark the status in the status object as normal
\r
792 status->text_status = git_wc_status_normal;
\r
795 else if (status->text_status == git_wc_status_external)
\r
797 CGitStatusCache::Instance().AddFolderForCrawling(svnPath);
\r
798 // Mark the directory as 'versioned' (status 'normal' for now).
\r
799 // This initial value will be overwritten from below some time later
\r
801 AutoLocker lock(pThis->m_critSec);
\r
802 pThis->m_childDirectories[svnPath] = git_wc_status_normal;
\r
804 // we have added a directory to the child-directory list of this
\r
805 // directory. We now must make sure that this directory also has
\r
806 // an entry in the cache.
\r
807 CGitStatusCache::Instance().GetDirectoryCacheEntry(svnPath);
\r
808 // also mark the status in the status object as normal
\r
809 status->text_status = git_wc_status_normal;
\r
813 if (svnPath.IsDirectory())
\r
815 AutoLocker lock(pThis->m_critSec);
\r
816 pThis->m_childDirectories[svnPath] = GitStatus::GetMoreImportant(status->text_status, status->prop_status);
\r
818 else if ((CGitStatusCache::Instance().IsUnversionedAsModified())&&(status->text_status != git_wc_status_missing))
\r
820 // make this unversioned item change the most important status of this
\r
821 // folder to modified if it doesn't already have another status
\r
822 if (pThis->m_mostImportantFileStatus != git_wc_status_added)
\r
823 pThis->m_mostImportantFileStatus = GitStatus::GetMoreImportant(pThis->m_mostImportantFileStatus, git_wc_status_modified);
\r
828 pThis->AddEntry(svnPath, status);
\r
835 CCachedDirectory::IsOwnStatusValid() const
\r
837 return m_ownStatus.HasBeenSet() &&
\r
838 !m_ownStatus.HasExpired(GetTickCount()) &&
\r
839 // 'external' isn't a valid status. That just
\r
840 // means the folder is not part of the current working
\r
841 // copy but it still has its own 'real' status
\r
842 m_ownStatus.GetEffectiveStatus()!=git_wc_status_external &&
\r
843 m_ownStatus.IsKindKnown();
\r
846 void CCachedDirectory::Invalidate()
\r
848 m_ownStatus.Invalidate();
\r
851 git_wc_status_kind CCachedDirectory::CalculateRecursiveStatus()
\r
853 // Combine our OWN folder status with the most important of our *FILES'* status.
\r
854 git_wc_status_kind retVal = GitStatus::GetMoreImportant(m_mostImportantFileStatus, m_ownStatus.GetEffectiveStatus());
\r
856 // NOTE: TSVN marks dir as modified if it contains added/deleted/missing files, but we prefer the most important
\r
857 // status to propagate upward in its original state
\r
858 /*if ((retVal != git_wc_status_modified)&&(retVal != m_ownStatus.GetEffectiveStatus()))
\r
860 if ((retVal == git_wc_status_added)||(retVal == git_wc_status_deleted)||(retVal == git_wc_status_missing))
\r
861 retVal = git_wc_status_modified;
\r
864 // Now combine all our child-directorie's status
\r
866 AutoLocker lock(m_critSec);
\r
867 ChildDirStatus::const_iterator it;
\r
868 for(it = m_childDirectories.begin(); it != m_childDirectories.end(); ++it)
\r
870 retVal = GitStatus::GetMoreImportant(retVal, it->second);
\r
871 /*if ((retVal != git_wc_status_modified)&&(retVal != m_ownStatus.GetEffectiveStatus()))
\r
873 if ((retVal == git_wc_status_added)||(retVal == git_wc_status_deleted)||(retVal == git_wc_status_missing))
\r
874 retVal = git_wc_status_modified;
\r
881 // Update our composite status and deal with things if it's changed
\r
882 void CCachedDirectory::UpdateCurrentStatus()
\r
884 git_wc_status_kind newStatus = CalculateRecursiveStatus();
\r
886 if ((newStatus != m_currentFullStatus)&&(m_ownStatus.IsVersioned()))
\r
888 if ((m_currentFullStatus != git_wc_status_none)&&(m_ownStatus.GetEffectiveStatus() != git_wc_status_missing))
\r
890 // Our status has changed - tell the shell
\r
891 ATLTRACE(_T("Dir %s, status change from %d to %d, send shell notification\n"), m_directoryPath.GetWinPath(), m_currentFullStatus, newStatus);
\r
892 CGitStatusCache::Instance().UpdateShell(m_directoryPath);
\r
894 if (m_ownStatus.GetEffectiveStatus() != git_wc_status_missing)
\r
895 m_currentFullStatus = newStatus;
\r
897 m_currentFullStatus = git_wc_status_missing;
\r
899 // And tell our parent, if we've got one...
\r
900 // we tell our parent *always* about our status, even if it hasn't
\r
901 // changed. This is to make sure that the parent has really our current
\r
902 // status - the parent can decide itself if our status has changed
\r
904 CTGitPath parentPath = m_directoryPath.GetContainingDirectory();
\r
905 if(!parentPath.IsEmpty())
\r
907 // We have a parent
\r
908 CCachedDirectory * cachedDir = CGitStatusCache::Instance().GetDirectoryCacheEntry(parentPath);
\r
910 cachedDir->UpdateChildDirectoryStatus(m_directoryPath, m_currentFullStatus);
\r
915 // Receive a notification from a child that its status has changed
\r
916 void CCachedDirectory::UpdateChildDirectoryStatus(const CTGitPath& childDir, git_wc_status_kind childStatus)
\r
918 git_wc_status_kind currentStatus = git_wc_status_none;
\r
920 AutoLocker lock(m_critSec);
\r
921 currentStatus = m_childDirectories[childDir];
\r
923 if ((currentStatus != childStatus)||(!IsOwnStatusValid()))
\r
926 AutoLocker lock(m_critSec);
\r
927 m_childDirectories[childDir] = childStatus;
\r
929 UpdateCurrentStatus();
\r
933 CStatusCacheEntry CCachedDirectory::GetOwnStatus(bool bRecursive)
\r
935 // Don't return recursive status if we're unversioned ourselves.
\r
936 if(bRecursive && m_ownStatus.GetEffectiveStatus() > git_wc_status_unversioned)
\r
938 CStatusCacheEntry recursiveStatus(m_ownStatus);
\r
939 UpdateCurrentStatus();
\r
940 recursiveStatus.ForceStatus(m_currentFullStatus);
\r
941 return recursiveStatus;
\r
945 return m_ownStatus;
\r
949 void CCachedDirectory::RefreshStatus(bool bRecursive)
\r
951 // Make sure that our own status is up-to-date
\r
952 GetStatusForMember(m_directoryPath,bRecursive);
\r
954 AutoLocker lock(m_critSec);
\r
955 // We also need to check if all our file members have the right date on them
\r
956 CacheEntryMap::iterator itMembers;
\r
957 std::set<CTGitPath> refreshedpaths;
\r
958 DWORD now = GetTickCount();
\r
959 if (m_entryCache.size() == 0)
\r
961 for (itMembers = m_entryCache.begin(); itMembers != m_entryCache.end(); ++itMembers)
\r
963 if (itMembers->first)
\r
965 CTGitPath filePath(m_directoryPath);
\r
966 filePath.AppendPathString(itMembers->first);
\r
967 std::set<CTGitPath>::iterator refr_it;
\r
968 if ((!filePath.IsEquivalentToWithoutCase(m_directoryPath))&&
\r
969 (((refr_it = refreshedpaths.lower_bound(filePath)) == refreshedpaths.end()) || !filePath.IsEquivalentToWithoutCase(*refr_it)))
\r
971 if ((itMembers->second.HasExpired(now))||(!itMembers->second.DoesFileTimeMatch(filePath.GetLastWriteTime())))
\r
974 // We need to request this item as well
\r
975 GetStatusForMember(filePath,bRecursive);
\r
976 // GetStatusForMember now has recreated the m_entryCache map.
\r
977 // So start the loop again, but add this path to the refreshed paths set
\r
978 // to make sure we don't refresh this path again. This is to make sure
\r
979 // that we don't end up in an endless loop.
\r
981 refreshedpaths.insert(refr_it, filePath);
\r
982 itMembers = m_entryCache.begin();
\r
983 if (m_entryCache.size()==0)
\r
987 else if ((bRecursive)&&(itMembers->second.IsDirectory()))
\r
989 // crawl all sub folders too! Otherwise a change deep inside the
\r
990 // tree which has changed won't get propagated up the tree.
\r
991 CGitStatusCache::Instance().AddFolderForCrawling(filePath);
\r
998 void CCachedDirectory::RefreshMostImportant()
\r
1000 CacheEntryMap::iterator itMembers;
\r
1001 git_wc_status_kind newStatus = m_ownStatus.GetEffectiveStatus();
\r
1002 for (itMembers = m_entryCache.begin(); itMembers != m_entryCache.end(); ++itMembers)
\r
1004 newStatus = GitStatus::GetMoreImportant(newStatus, itMembers->second.GetEffectiveStatus());
\r
1005 if (((itMembers->second.GetEffectiveStatus() == git_wc_status_unversioned)||(itMembers->second.GetEffectiveStatus() == git_wc_status_none))
\r
1006 &&(CGitStatusCache::Instance().IsUnversionedAsModified()))
\r
1008 // treat unversioned files as modified
\r
1009 if (newStatus != git_wc_status_added)
\r
1010 newStatus = GitStatus::GetMoreImportant(newStatus, git_wc_status_modified);
\r
1013 if (newStatus != m_mostImportantFileStatus)
\r
1015 ATLTRACE(_T("status change of path %s\n"), m_directoryPath.GetWinPath());
\r
1016 CGitStatusCache::Instance().UpdateShell(m_directoryPath);
\r
1018 m_mostImportantFileStatus = newStatus;
\r