From 10f86ade82c37734e4a6fdc81f1a3687e758057b Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 9 Aug 2015 20:25:19 +0200 Subject: [PATCH] Refactor: Drop try catch Signed-off-by: Sven Strickroth --- src/Git/GitIndex.cpp | 133 +++++------ src/Git/GitStatus.cpp | 638 ++++++++++++++++++++++++-------------------------- 2 files changed, 359 insertions(+), 412 deletions(-) diff --git a/src/Git/GitIndex.cpp b/src/Git/GitIndex.cpp index 50a9a5e44..a51f52662 100644 --- a/src/Git/GitIndex.cpp +++ b/src/Git/GitIndex.cpp @@ -316,19 +316,13 @@ int CGitIndexFileMap::Check(const CString &gitdir, bool *isChanged) int CGitIndexFileMap::LoadIndex(const CString &gitdir) { - try - { - SHARED_INDEX_PTR pIndex(new CGitIndexList); + SHARED_INDEX_PTR pIndex(new CGitIndexList); - if(pIndex->ReadIndex(g_AdminDirMap.GetAdminDir(gitdir))) - return -1; + if (pIndex->ReadIndex(g_AdminDirMap.GetAdminDir(gitdir))) + return -1; - this->SafeSet(gitdir, pIndex); + this->SafeSet(gitdir, pIndex); - }catch(...) - { - return -1; - } return 0; } @@ -337,61 +331,47 @@ int CGitIndexFileMap::GetFileStatus(const CString &gitdir, const CString &path, CGitHash *pHash, bool isLoadUpdatedIndex, bool * assumeValid, bool * skipWorktree) { - try - { - CheckAndUpdate(gitdir, isLoadUpdatedIndex); + CheckAndUpdate(gitdir, isLoadUpdatedIndex); - SHARED_INDEX_PTR pIndex = this->SafeGet(gitdir); - if (pIndex.get() != NULL) - { - pIndex->GetStatus(gitdir, path, status, IsFull, IsRecursive, callback, pData, pHash, assumeValid, skipWorktree); - } - else - { - // git working tree has not index - *status = git_wc_status_unversioned; - } - } - catch(...) + SHARED_INDEX_PTR pIndex = this->SafeGet(gitdir); + if (pIndex.get()) + pIndex->GetStatus(gitdir, path, status, IsFull, IsRecursive, callback, pData, pHash, assumeValid, skipWorktree); + else { - return -1; + // git working tree has not index + *status = git_wc_status_unversioned; } + return 0; } int CGitIndexFileMap::IsUnderVersionControl(const CString &gitdir, const CString &path, bool isDir,bool *isVersion, bool isLoadUpdateIndex) { - try + if (path.IsEmpty()) { - if (path.IsEmpty()) - { - *isVersion = true; - return 0; - } - - CString subpath = path; - subpath.Replace(_T('\\'), _T('/')); - if(isDir) - subpath += _T('/'); + *isVersion = true; + return 0; + } - subpath.MakeLower(); + CString subpath = path; + subpath.Replace(_T('\\'), _T('/')); + if (isDir) + subpath += _T('/'); - CheckAndUpdate(gitdir, isLoadUpdateIndex); + subpath.MakeLower(); - SHARED_INDEX_PTR pIndex = this->SafeGet(gitdir); + CheckAndUpdate(gitdir, isLoadUpdateIndex); - if(pIndex.get()) - { - if(isDir) - *isVersion = (SearchInSortVector(*pIndex, subpath, subpath.GetLength()) >= 0); - else - *isVersion = (SearchInSortVector(*pIndex, subpath, -1) >= 0); - } + SHARED_INDEX_PTR pIndex = this->SafeGet(gitdir); - }catch(...) + if (pIndex.get()) { - return -1; + if (isDir) + *isVersion = (SearchInSortVector(*pIndex, subpath, subpath.GetLength()) >= 0); + else + *isVersion = (SearchInSortVector(*pIndex, subpath, -1) >= 0); } + return 0; } @@ -1243,46 +1223,39 @@ bool CGitHeadFileMap::CheckHeadAndUpdate(const CString &gitdir, bool readTree /* int CGitHeadFileMap::IsUnderVersionControl(const CString &gitdir, const CString &path, bool isDir, bool *isVersion) { - try + if (path.IsEmpty()) { - if (path.IsEmpty()) - { - *isVersion = true; - return 0; - } + *isVersion = true; + return 0; + } - CString subpath = path; - subpath.Replace(_T('\\'), _T('/')); - if(isDir) - subpath += _T('/'); + CString subpath = path; + subpath.Replace(_T('\\'), _T('/')); + if (isDir) + subpath += _T('/'); - subpath.MakeLower(); + subpath.MakeLower(); - CheckHeadAndUpdate(gitdir); + CheckHeadAndUpdate(gitdir); - SHARED_TREE_PTR treeptr = SafeGet(gitdir); + SHARED_TREE_PTR treeptr = SafeGet(gitdir); - // Init Repository - if (treeptr->HeadFileIsEmpty()) - { - *isVersion = false; - return 0; - } - if (treeptr->empty()) - { - *isVersion = false; - return 1; - } - - if(isDir) - *isVersion = (SearchInSortVector(*treeptr, subpath, subpath.GetLength()) >= 0); - else - *isVersion = (SearchInSortVector(*treeptr, subpath, -1) >= 0); + // Init Repository + if (treeptr->HeadFileIsEmpty()) + { + *isVersion = false; + return 0; } - catch(...) + if (treeptr->empty()) { - return -1; + *isVersion = false; + return 1; } + if (isDir) + *isVersion = (SearchInSortVector(*treeptr, subpath, subpath.GetLength()) >= 0); + else + *isVersion = (SearchInSortVector(*treeptr, subpath, -1) >= 0); + return 0; } diff --git a/src/Git/GitStatus.cpp b/src/Git/GitStatus.cpp index e2b52ef51..9f91c4ab3 100644 --- a/src/Git/GitStatus.cpp +++ b/src/Git/GitStatus.cpp @@ -194,89 +194,78 @@ int GitStatus::GetFileStatus(const CString &gitdir, const CString &pathParam, gi if (!status) return 0; - try - { - CString path = pathParam; + CString path = pathParam; + + path.Replace(_T('\\'), _T('/')); - path.Replace(_T('\\'),_T('/')); + CString lowcasepath = path; + lowcasepath.MakeLower(); - CString lowcasepath =path; - lowcasepath.MakeLower(); + git_wc_status_kind st = git_wc_status_none; + CGitHash hash; - git_wc_status_kind st = git_wc_status_none; - CGitHash hash; + g_IndexFileMap.GetFileStatus(gitdir, path, &st, IsFull, false, callback, pData, &hash, true, assumeValid, skipWorktree); - g_IndexFileMap.GetFileStatus(gitdir, path, &st, IsFull, false, callback, pData, &hash, true, assumeValid, skipWorktree); + if (st == git_wc_status_conflicted) + { + *status = st; + if (callback && assumeValid && skipWorktree) + callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); + return 0; + } - if (st == git_wc_status_conflicted) + if (st == git_wc_status_unversioned) + { + if (!IsIgnore) { - *status = st; + *status = git_wc_status_unversioned; if (callback && assumeValid && skipWorktree) - callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); + callback(CombinePath(gitdir, path), *status, false, pData, *assumeValid, *skipWorktree); return 0; } - if (st == git_wc_status_unversioned) - { - if (!IsIgnore) - { - *status = git_wc_status_unversioned; - if (callback && assumeValid && skipWorktree) - callback(CombinePath(gitdir, path), *status, false, pData, *assumeValid, *skipWorktree); - return 0; - } + if (g_IgnoreList.CheckIgnoreChanged(gitdir, path, false)) + g_IgnoreList.LoadAllIgnoreFile(gitdir, path, false); + if (g_IgnoreList.IsIgnore(path, gitdir, false)) + st = git_wc_status_ignored; + + *status = st; + if (callback && assumeValid && skipWorktree) + callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); + + return 0; + } - if (g_IgnoreList.CheckIgnoreChanged(gitdir, path, false)) - g_IgnoreList.LoadAllIgnoreFile(gitdir, path, false); - if (g_IgnoreList.IsIgnore(path, gitdir, false)) - st = git_wc_status_ignored; + if ((st == git_wc_status_normal || st == git_wc_status_modified) && IsFull) + { + g_HeadFileMap.CheckHeadAndUpdate(gitdir); - *status = st; + // Check Head Tree Hash + SHARED_TREE_PTR treeptr = g_HeadFileMap.SafeGet(gitdir); + + //add item + int start = SearchInSortVector(*treeptr, lowcasepath, -1); + if (start < 0) + { + *status = st = git_wc_status_added; + CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": File miss in head tree %s"), (LPCTSTR)path); if (callback && assumeValid && skipWorktree) callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); - return 0; } - if ((st == git_wc_status_normal || st == git_wc_status_modified) && IsFull) + // staged and not commit + if (treeptr->at(start).m_Hash != hash) { - g_HeadFileMap.CheckHeadAndUpdate(gitdir); - - // Check Head Tree Hash - SHARED_TREE_PTR treeptr = g_HeadFileMap.SafeGet(gitdir); - - //add item - int start = SearchInSortVector(*treeptr, lowcasepath, -1); - if (start < 0) - { - *status = st = git_wc_status_added; - CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": File miss in head tree %s"), (LPCTSTR)path); - if (callback && assumeValid && skipWorktree) - callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); - return 0; - } - - // staged and not commit - if (treeptr->at(start).m_Hash != hash) - { - *status = st = git_wc_status_modified; - if (callback && assumeValid && skipWorktree) - callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); - return 0; - } + *status = st = git_wc_status_modified; + if (callback && assumeValid && skipWorktree) + callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); + return 0; } - *status = st; - if (callback && assumeValid && skipWorktree) - callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); - return 0; - } - catch(...) - { - if(status) - *status = git_wc_status_none; - return -1; } - + *status = st; + if (callback && assumeValid && skipWorktree) + callback(CombinePath(gitdir, path), st, false, pData, *assumeValid, *skipWorktree); return 0; } @@ -350,207 +339,201 @@ int GitStatus::EnumDirStatus(const CString &gitdir, const CString &subpath, git_ if (!status) return 0; - try - { - CString path =subpath; + CString path = subpath; - path.Replace(_T('\\'),_T('/')); - if (!path.IsEmpty() && path[path.GetLength()-1] != _T('/')) - path += _T('/'); //Add trail / to show it is directory, not file name. + path.Replace(_T('\\'), _T('/')); + if (!path.IsEmpty() && path[path.GetLength() - 1] != _T('/')) + path += _T('/'); // Add trail / to show it is directory, not file name. - std::vector filelist; - GetFileList(CombinePath(gitdir, subpath), filelist); + std::vector filelist; + GetFileList(CombinePath(gitdir, subpath), filelist); - g_IndexFileMap.CheckAndUpdate(gitdir,true); + g_IndexFileMap.CheckAndUpdate(gitdir,true); - g_HeadFileMap.CheckHeadAndUpdate(gitdir); + g_HeadFileMap.CheckHeadAndUpdate(gitdir); - SHARED_INDEX_PTR indexptr = g_IndexFileMap.SafeGet(gitdir); - SHARED_TREE_PTR treeptr = g_HeadFileMap.SafeGet(gitdir); + SHARED_INDEX_PTR indexptr = g_IndexFileMap.SafeGet(gitdir); + SHARED_TREE_PTR treeptr = g_HeadFileMap.SafeGet(gitdir); - // new git working tree has no index file - if (!indexptr.get()) + // new git working tree has no index file + if (!indexptr.get()) + { + for (auto it = filelist.cbegin(); it != filelist.cend(); ++it) { - for (auto it = filelist.cbegin(); it != filelist.cend(); ++it) - { - CString casepath = path; - casepath += it->m_CaseFileName; + CString casepath = path; + casepath += it->m_CaseFileName; - bool bIsDir = false; - if (it->m_FileName.GetLength() > 0 && it->m_FileName[it->m_FileName.GetLength() - 1] == _T('/')) - bIsDir = true; + bool bIsDir = false; + if (it->m_FileName.GetLength() > 0 && it->m_FileName[it->m_FileName.GetLength() - 1] == _T('/')) + bIsDir = true; - if (IsIgnore) - { - if (g_IgnoreList.CheckIgnoreChanged(gitdir, casepath, bIsDir)) - g_IgnoreList.LoadAllIgnoreFile(gitdir, casepath, bIsDir); + if (IsIgnore) + { + if (g_IgnoreList.CheckIgnoreChanged(gitdir, casepath, bIsDir)) + g_IgnoreList.LoadAllIgnoreFile(gitdir, casepath, bIsDir); - if (g_IgnoreList.IsIgnore(casepath, gitdir, bIsDir)) - *status = git_wc_status_ignored; - else if (bIsDir) - continue; - else - *status = git_wc_status_unversioned; - } + if (g_IgnoreList.IsIgnore(casepath, gitdir, bIsDir)) + *status = git_wc_status_ignored; else if (bIsDir) continue; else *status = git_wc_status_unversioned; - - if (callback) - callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); } - return 0; - } - - CString lowcasepath = path; - lowcasepath.MakeLower(); - - CString onepath; - CString casepath; - for (auto it = filelist.cbegin(), itend = filelist.cend(); it != itend; ++it) - { - casepath = onepath = lowcasepath; - onepath += it->m_FileName; - casepath += it->m_CaseFileName; + else if (bIsDir) + continue; + else + *status = git_wc_status_unversioned; - bool bIsDir = false; - if (!onepath.IsEmpty() && onepath[onepath.GetLength() - 1] == _T('/')) - bIsDir = true; + if (callback) + callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); + } + return 0; + } - int matchLength = -1; - if (bIsDir) - matchLength = onepath.GetLength(); - int pos = SearchInSortVector(*indexptr, onepath, matchLength); - int posintree = SearchInSortVector(*treeptr, onepath, matchLength); + CString lowcasepath = path; + lowcasepath.MakeLower(); - if (pos < 0 && posintree < 0) - { - if (onepath.IsEmpty()) - continue; + CString onepath; + CString casepath; + for (auto it = filelist.cbegin(), itend = filelist.cend(); it != itend; ++it) + { + casepath = onepath = lowcasepath; + onepath += it->m_FileName; + casepath += it->m_CaseFileName; - if (!IsIgnore) - { - *status = git_wc_status_unversioned; - if (callback) - callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); - continue; - } + bool bIsDir = false; + if (!onepath.IsEmpty() && onepath[onepath.GetLength() - 1] == _T('/')) + bIsDir = true; - if (g_IgnoreList.CheckIgnoreChanged(gitdir, casepath, bIsDir)) - g_IgnoreList.LoadAllIgnoreFile(gitdir, casepath, bIsDir); + int matchLength = -1; + if (bIsDir) + matchLength = onepath.GetLength(); + int pos = SearchInSortVector(*indexptr, onepath, matchLength); + int posintree = SearchInSortVector(*treeptr, onepath, matchLength); - if (g_IgnoreList.IsIgnore(casepath, gitdir, bIsDir)) - *status = git_wc_status_ignored; - else - *status = git_wc_status_unversioned; + if (pos < 0 && posintree < 0) + { + if (onepath.IsEmpty()) + continue; - if (callback) - callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); - } - else if (pos < 0 && posintree >= 0) /* check if file delete in index */ + if (!IsIgnore) { - *status = git_wc_status_deleted; + *status = git_wc_status_unversioned; if (callback) callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); + continue; } - else if (pos >= 0 && posintree < 0) /* Check if file added */ + + if (g_IgnoreList.CheckIgnoreChanged(gitdir, casepath, bIsDir)) + g_IgnoreList.LoadAllIgnoreFile(gitdir, casepath, bIsDir); + + if (g_IgnoreList.IsIgnore(casepath, gitdir, bIsDir)) + *status = git_wc_status_ignored; + else + *status = git_wc_status_unversioned; + + if (callback) + callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); + } + else if (pos < 0 && posintree >= 0) /* check if file delete in index */ + { + *status = git_wc_status_deleted; + if (callback) + callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); + } + else if (pos >= 0 && posintree < 0) /* Check if file added */ + { + *status = git_wc_status_added; + if (indexptr->at(pos).m_Flags & GIT_IDXENTRY_STAGEMASK) + *status = git_wc_status_conflicted; + if (callback) + callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); + } + else + { + if (onepath.IsEmpty()) + continue; + + if (bIsDir) { - *status = git_wc_status_added; - if (indexptr->at(pos).m_Flags & GIT_IDXENTRY_STAGEMASK) - *status = git_wc_status_conflicted; + *status = git_wc_status_normal; if (callback) callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); } else { - if (onepath.IsEmpty()) - continue; - - if (bIsDir) - { - *status = git_wc_status_normal; - if (callback) - callback(CombinePath(gitdir, casepath), *status, bIsDir, pData, false, false); - } - else - { - bool assumeValid = false; - bool skipWorktree = false; - git_wc_status_kind filestatus; - GetFileStatus(gitdir, casepath, &filestatus, IsFul, IsRecursive, IsIgnore, callback, pData, &assumeValid, &skipWorktree); - } + bool assumeValid = false; + bool skipWorktree = false; + git_wc_status_kind filestatus; + GetFileStatus(gitdir, casepath, &filestatus, IsFul, IsRecursive, IsIgnore, callback, pData, &assumeValid, &skipWorktree); } - }/*End of For*/ + } + }/*End of For*/ - /* Check deleted file in system */ - int start = 0, end = 0; - int pos = SearchInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength()); // match path prefix, (sub)folders end with slash - std::map skipWorktreeMap; + /* Check deleted file in system */ + int start = 0, end = 0; + int pos = SearchInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength()); // match path prefix, (sub)folders end with slash + std::map skipWorktreeMap; - if (GetRangeInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos) == 0) + if (GetRangeInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos) == 0) + { + CString oldstring; + for (auto it = indexptr->cbegin() + start, itlast = indexptr->cbegin() + end; it <= itlast; ++it) { - CString oldstring; - for (auto it = indexptr->cbegin() + start, itlast = indexptr->cbegin() + end; it <= itlast; ++it) - { - int commonPrefixLength = lowcasepath.GetLength(); - int index = (*it).m_FileName.Find(_T('/'), commonPrefixLength); - if (index < 0) - index = (*it).m_FileName.GetLength(); - else - ++index; // include slash at the end for subfolders, so that we do not match files by mistake + int commonPrefixLength = lowcasepath.GetLength(); + int index = (*it).m_FileName.Find(_T('/'), commonPrefixLength); + if (index < 0) + index = (*it).m_FileName.GetLength(); + else + ++index; // include slash at the end for subfolders, so that we do not match files by mistake - CString filename = (*it).m_FileName.Mid(commonPrefixLength, index - commonPrefixLength); - if (oldstring != filename) + CString filename = (*it).m_FileName.Mid(commonPrefixLength, index - commonPrefixLength); + if (oldstring != filename) + { + oldstring = filename; + if (SearchInSortVector(filelist, filename, filename.GetLength()) < 0) { - oldstring = filename; - if (SearchInSortVector(filelist, filename, filename.GetLength()) < 0) + bool skipWorktree = false; + *status = git_wc_status_deleted; + if (((*it).m_Flags & GIT_IDXENTRY_SKIP_WORKTREE) != 0) { - bool skipWorktree = false; - *status = git_wc_status_deleted; - if (((*it).m_Flags & GIT_IDXENTRY_SKIP_WORKTREE) != 0) - { - skipWorktreeMap[filename] = true; - skipWorktree = true; - *status = git_wc_status_normal; - } - if (callback) - callback(CombinePath(gitdir, (*it).m_FileName), *status, false, pData, false, skipWorktree); + skipWorktreeMap[filename] = true; + skipWorktree = true; + *status = git_wc_status_normal; } + if (callback) + callback(CombinePath(gitdir, (*it).m_FileName), *status, false, pData, false, skipWorktree); } } } + } - start = end = 0; - pos = SearchInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength()); // match path prefix, (sub)folders end with slash - if (GetRangeInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos) == 0) + start = end = 0; + pos = SearchInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength()); // match path prefix, (sub)folders end with slash + if (GetRangeInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos) == 0) + { + CString oldstring; + for (auto it = treeptr->cbegin() + start, itlast = treeptr->cbegin() + end; it <= itlast; ++it) { - CString oldstring; - for (auto it = treeptr->cbegin() + start, itlast = treeptr->cbegin() + end; it <= itlast; ++it) - { - int commonPrefixLength = lowcasepath.GetLength(); - int index = (*it).m_FileName.Find(_T('/'), commonPrefixLength); - if (index < 0) - index = (*it).m_FileName.GetLength(); - else - ++index; // include slash at the end for subfolders, so that we do not match files by mistake + int commonPrefixLength = lowcasepath.GetLength(); + int index = (*it).m_FileName.Find(_T('/'), commonPrefixLength); + if (index < 0) + index = (*it).m_FileName.GetLength(); + else + ++index; // include slash at the end for subfolders, so that we do not match files by mistake - CString filename = (*it).m_FileName.Mid(commonPrefixLength, index - commonPrefixLength); - if (oldstring != filename && skipWorktreeMap[filename] != true) + CString filename = (*it).m_FileName.Mid(commonPrefixLength, index - commonPrefixLength); + if (oldstring != filename && skipWorktreeMap[filename] != true) + { + oldstring = filename; + if (SearchInSortVector(filelist, filename, filename.GetLength()) < 0) { - oldstring = filename; - if (SearchInSortVector(filelist, filename, filename.GetLength()) < 0) - { - *status = git_wc_status_deleted; - if (callback) - callback(CombinePath(gitdir, (*it).m_FileName), *status, false, pData, false, false); - } + *status = git_wc_status_deleted; + if (callback) + callback(CombinePath(gitdir, (*it).m_FileName), *status, false, pData, false, false); } } } - }catch(...) - { - return -1; } return 0; } @@ -562,164 +545,155 @@ int GitStatus::GetDirStatus(const CString& gitdir, const CString& subpath, git_w if (!status) return 0; - try - { - CString path =subpath; + CString path = subpath; + + path.Replace(_T('\\'), _T('/')); + if (!path.IsEmpty() && path[path.GetLength() - 1] != _T('/')) + path += _T('/'); //Add trail / to show it is directory, not file name. + + g_IndexFileMap.CheckAndUpdate(gitdir, true); + + SHARED_INDEX_PTR indexptr = g_IndexFileMap.SafeGet(gitdir); - path.Replace(_T('\\'),_T('/')); - if (!path.IsEmpty() && path[path.GetLength() - 1] != _T('/')) - path += _T('/'); //Add trail / to show it is directory, not file name. + if (!indexptr) + { + *status = git_wc_status_unversioned; + return 0; + } - g_IndexFileMap.CheckAndUpdate(gitdir, true); + CString lowcasepath = path; + lowcasepath.MakeLower(); - SHARED_INDEX_PTR indexptr = g_IndexFileMap.SafeGet(gitdir); + int pos = SearchInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength()); - if (!indexptr) + // Not In Version Contorl + if (pos < 0) + { + if (!IsIgnore) { *status = git_wc_status_unversioned; return 0; } - CString lowcasepath = path; - lowcasepath.MakeLower(); + // Check ignore always. + if (g_IgnoreList.CheckIgnoreChanged(gitdir, path, true)) + g_IgnoreList.LoadAllIgnoreFile(gitdir, path, true); - int pos = SearchInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength()); + if (g_IgnoreList.IsIgnore(path, gitdir, true)) + *status = git_wc_status_ignored; + else + *status = git_wc_status_unversioned; - // Not In Version Contorl - if (pos < 0) - { - if (!IsIgnore) - { - *status = git_wc_status_unversioned; - return 0; - } + g_HeadFileMap.CheckHeadAndUpdate(gitdir); + + SHARED_TREE_PTR treeptr = g_HeadFileMap.SafeGet(gitdir); + // Check init repository + if (treeptr->HeadIsEmpty() && path.IsEmpty()) + *status = git_wc_status_normal; + // check if only one file in repository is deleted in index + else if (path.IsEmpty() && !treeptr->empty()) + *status = git_wc_status_deleted; - //Check ignore always. - if (g_IgnoreList.CheckIgnoreChanged(gitdir, path, true)) - g_IgnoreList.LoadAllIgnoreFile(gitdir, path, true); + return 0; + } - if (g_IgnoreList.IsIgnore(path, gitdir, true)) - *status = git_wc_status_ignored; - else - *status = git_wc_status_unversioned; + // In version control + *status = git_wc_status_normal; - g_HeadFileMap.CheckHeadAndUpdate(gitdir); + int start = 0; + int end = 0; + if (path.IsEmpty()) + end = (int)indexptr->size() - 1; - SHARED_TREE_PTR treeptr = g_HeadFileMap.SafeGet(gitdir); - //Check init repository - if (treeptr->HeadIsEmpty() && path.IsEmpty()) - *status = git_wc_status_normal; - // check if only one file in repository is deleted in index - else if (path.IsEmpty() && !treeptr->empty()) - *status = git_wc_status_deleted; + GetRangeInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos); - return 0; + // Check Conflict; + for (auto it = indexptr->cbegin() + start, itlast = indexptr->cbegin() + end; it <= itlast; ++it) + { + if (((*it).m_Flags & GIT_IDXENTRY_STAGEMASK) != 0) + { + *status = git_wc_status_conflicted; + break; } + } - // In version control + if (IsFul && (*status != git_wc_status_conflicted)) + { *status = git_wc_status_normal; - int start = 0; - int end = 0; - if (path.IsEmpty()) - end = (int)indexptr->size() - 1; - - GetRangeInSortVector(*indexptr, lowcasepath, lowcasepath.GetLength(), &start, &end, pos); - - // Check Conflict; - for (auto it = indexptr->cbegin() + start, itlast = indexptr->cbegin() + end; it <= itlast; ++it) - { - if (((*it).m_Flags & GIT_IDXENTRY_STAGEMASK) != 0) - { - *status = git_wc_status_conflicted; - break; - } - } + g_HeadFileMap.CheckHeadAndUpdate(gitdir); - if (IsFul && (*status != git_wc_status_conflicted)) + // Check Add { - *status = git_wc_status_normal; - - g_HeadFileMap.CheckHeadAndUpdate(gitdir); + // Check if new init repository + SHARED_TREE_PTR treeptr = g_HeadFileMap.SafeGet(gitdir); - // Check Add + if (!treeptr->empty() || treeptr->HeadIsEmpty()) { - // Check if new init repository - SHARED_TREE_PTR treeptr = g_HeadFileMap.SafeGet(gitdir); - - if (!treeptr->empty() || treeptr->HeadIsEmpty()) + for (auto it = indexptr->cbegin() + start, itlast = indexptr->cbegin() + end; it <= itlast; ++it) { - for (auto it = indexptr->cbegin() + start, itlast = indexptr->cbegin() + end; it <= itlast; ++it) - { - pos = SearchInSortVector(*treeptr, (*it).m_FileName, -1); - - if (pos < 0) - { - *status = max(git_wc_status_added, *status); // added file found - break; - } + pos = SearchInSortVector(*treeptr, (*it).m_FileName, -1); - if (pos >= 0 && treeptr->at(pos).m_Hash != (*it).m_IndexHash) - { - *status = max(git_wc_status_modified, *status); // modified file found - break; - } + if (pos < 0) + { + *status = max(git_wc_status_added, *status); // added file found + break; } - //Check Delete - if (*status == git_wc_status_normal) + if (pos >= 0 && treeptr->at(pos).m_Hash != (*it).m_IndexHash) { - pos = SearchInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength()); - if (pos < 0) - *status = max(git_wc_status_added, *status); // added file found + *status = max(git_wc_status_modified, *status); // modified file found + break; + } + } - else + // Check Delete + if (*status == git_wc_status_normal) + { + pos = SearchInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength()); + if (pos < 0) + *status = max(git_wc_status_added, *status); // added file found + else + { + int hstart, hend; + GetRangeInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength(), &hstart, &hend, pos); + for (auto hit = treeptr->cbegin() + hstart, lastElement = treeptr->cbegin() + hend; hit <= lastElement; ++hit) { - int hstart, hend; - GetRangeInSortVector(*treeptr, lowcasepath, lowcasepath.GetLength(), &hstart, &hend, pos); - for (auto hit = treeptr->cbegin() + hstart, lastElement = treeptr->cbegin() + hend; hit <= lastElement; ++hit) + if (SearchInSortVector(*indexptr, (*hit).m_FileName, -1) < 0) { - if (SearchInSortVector(*indexptr, (*hit).m_FileName, -1) < 0) - { - *status = max(git_wc_status_deleted, *status); // deleted file found - break; - } + *status = max(git_wc_status_deleted, *status); // deleted file found + break; } } } } - }/* End lock*/ - } + } + } /* End lock*/ + } - // When status == git_wc_status_conflicted, needn't check each file status - // because git_wc_status_conflicted is highest.s - if (*status == git_wc_status_conflicted) - return 0; + // When status == git_wc_status_conflicted, needn't check each file status + // because git_wc_status_conflicted is highest.s + if (*status == git_wc_status_conflicted) + return 0; - for (auto it = indexptr->cbegin() + start, itlast = indexptr->cbegin() + end; it <= itlast; ++it) - { - //skip child directory - if (!IsRecursive && (*it).m_FileName.Find(_T('/'), path.GetLength()) > 0) - continue; + for (auto it = indexptr->cbegin() + start, itlast = indexptr->cbegin() + end; it <= itlast; ++it) + { + //skip child directory + if (!IsRecursive && (*it).m_FileName.Find(_T('/'), path.GetLength()) > 0) + continue; - git_wc_status_kind filestatus = git_wc_status_none; - bool assumeValid = false; - bool skipWorktree = false; - GetFileStatus(gitdir, (*it).m_FileName, &filestatus, IsFul, IsRecursive, IsIgnore, nullptr, nullptr, &assumeValid, &skipWorktree); - switch (filestatus) - { - case git_wc_status_added: - case git_wc_status_modified: - case git_wc_status_deleted: - case git_wc_status_conflicted: - *status = GetMoreImportant(filestatus, *status); - } + git_wc_status_kind filestatus = git_wc_status_none; + bool assumeValid = false; + bool skipWorktree = false; + GetFileStatus(gitdir, (*it).m_FileName, &filestatus, IsFul, IsRecursive, IsIgnore, nullptr, nullptr, &assumeValid, &skipWorktree); + switch (filestatus) + { + case git_wc_status_added: + case git_wc_status_modified: + case git_wc_status_deleted: + case git_wc_status_conflicted: + *status = GetMoreImportant(filestatus, *status); } - }catch(...) - { - if(status) - *status = git_wc_status_none; - return -1; } return 0; -- 2.11.4.GIT