OSDN Git Service

fixed issues with status (and icon overlays) in root directories
authorMyagi <snowcoder@gmail.com>
Fri, 17 Jul 2009 16:11:43 +0000 (18:11 +0200)
committerFrank Li <lznuaa@gmail.com>
Sat, 18 Jul 2009 04:13:42 +0000 (12:13 +0800)
src/Git/GitAdminDir.cpp
src/Git/GitFolderStatus.cpp
src/Git/GitStatus.cpp
src/TGitCache/CachedDirectory.cpp

index d7b882f..e09a6e8 100644 (file)
@@ -118,7 +118,7 @@ bool GitAdminDir::HasAdminDir(const CString& path, bool bDir,CString *ProjectTop
        CString sDirName = path;\r
        if (!bDir)\r
        {\r
        CString sDirName = path;\r
        if (!bDir)\r
        {\r
-               sDirName = path.Left(path.ReverseFind('\\'));\r
+               sDirName = path.Left(path.ReverseFind(_T('\\')));\r
        }\r
        \r
        // a .git dir or anything inside it should be left out, only interested in working copy files -- Myagi\r
        }\r
        \r
        // a .git dir or anything inside it should be left out, only interested in working copy files -- Myagi\r
@@ -141,7 +141,7 @@ bool GitAdminDir::HasAdminDir(const CString& path, bool bDir,CString *ProjectTop
        }\r
        }\r
 \r
        }\r
        }\r
 \r
-       do\r
+       for (;;)\r
        {\r
                if(PathFileExists(sDirName + _T("\\.git")))\r
                {\r
        {\r
                if(PathFileExists(sDirName + _T("\\.git")))\r
                {\r
@@ -149,14 +149,18 @@ bool GitAdminDir::HasAdminDir(const CString& path, bool bDir,CString *ProjectTop
                        {\r
                                *ProjectTopDir=sDirName;\r
                                // Make sure to add the trailing slash to root paths such as 'C:'\r
                        {\r
                                *ProjectTopDir=sDirName;\r
                                // Make sure to add the trailing slash to root paths such as 'C:'\r
-                               if (sDirName.GetLength() == 2 && sDirName[1] == ':')\r
+                               if (sDirName.GetLength() == 2 && sDirName[1] == _T(':'))\r
                                        (*ProjectTopDir) += _T("\\");\r
                        }\r
                        return true;\r
                }\r
                                        (*ProjectTopDir) += _T("\\");\r
                        }\r
                        return true;\r
                }\r
-               sDirName = sDirName.Left(sDirName.ReverseFind('\\'));\r
 \r
 \r
-       }while(sDirName.ReverseFind('\\')>0);\r
+               int x = sDirName.ReverseFind(_T('\\'));\r
+               if (x < 2)\r
+                       break;\r
+\r
+               sDirName = sDirName.Left(x);\r
+       }\r
 \r
        return false;\r
        \r
 \r
        return false;\r
        \r
index fd680b0..475915d 100644 (file)
@@ -240,6 +240,9 @@ const FileStatusCacheEntry * GitFolderStatus::BuildCache(const CTGitPath& filepa
                        CString s = filepath.GetWinPathString();\r
                        if (s.GetLength() > sProjectRoot.GetLength())\r
                        {\r
                        CString s = filepath.GetWinPathString();\r
                        if (s.GetLength() > sProjectRoot.GetLength())\r
                        {\r
+                               if (sProjectRoot.GetLength() == 3 && sProjectRoot[1] == _T(':'))\r
+                                       sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\r
+                               else\r
                                        sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);\r
                        }\r
 \r
                                        sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);\r
                        }\r
 \r
@@ -256,8 +259,11 @@ const FileStatusCacheEntry * GitFolderStatus::BuildCache(const CTGitPath& filepa
                        CString s = filepath.GetDirectory().GetWinPathString();\r
                        if (s.GetLength() > sProjectRoot.GetLength())\r
                        {\r
                        CString s = filepath.GetDirectory().GetWinPathString();\r
                        if (s.GetLength() > sProjectRoot.GetLength())\r
                        {\r
-                               sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);\r
+                               sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\r
                                lpszSubPath = sSubPath;\r
                                lpszSubPath = sSubPath;\r
+                               // skip initial slash if necessary\r
+                               if (*lpszSubPath == _T('\\'))\r
+                                       lpszSubPath++;\r
                        }\r
 \r
 //if (lpszSubPath) MessageBoxA(NULL, lpszSubPath, "BuildCache", MB_OK);\r
                        }\r
 \r
 //if (lpszSubPath) MessageBoxA(NULL, lpszSubPath, "BuildCache", MB_OK);\r
index ff344e8..e2e9644 100644 (file)
@@ -234,7 +234,10 @@ git_wc_status_kind GitStatus::GetAllStatus(const CTGitPath& path, git_depth_t de
                CString s = path.GetWinPathString();\r
                if (s.GetLength() > sProjectRoot.GetLength())\r
                {\r
                CString s = path.GetWinPathString();\r
                if (s.GetLength() > sProjectRoot.GetLength())\r
                {\r
-                       sSubPath = CStringA(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));\r
+                       if (sProjectRoot.GetLength() == 3 && sProjectRoot[1] == _T(':'))\r
+                               sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\r
+                       else\r
+                               sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);\r
                }\r
 \r
                err = g_IndexFileMap.GetFileStatus(sProjectRoot,sSubPath,&statuskind);\r
                }\r
 \r
                err = g_IndexFileMap.GetFileStatus(sProjectRoot,sSubPath,&statuskind);\r
@@ -246,8 +249,11 @@ git_wc_status_kind GitStatus::GetAllStatus(const CTGitPath& path, git_depth_t de
                CString s = path.GetWinPathString();\r
                if (s.GetLength() > sProjectRoot.GetLength())\r
                {\r
                CString s = path.GetWinPathString();\r
                if (s.GetLength() > sProjectRoot.GetLength())\r
                {\r
-                       sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);\r
+                       sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\r
                        lpszSubPath = sSubPath;\r
                        lpszSubPath = sSubPath;\r
+                       // skip initial slash if necessary\r
+                       if (*lpszSubPath == _T('\\'))\r
+                               lpszSubPath++;\r
                }\r
 \r
 #if 1\r
                }\r
 \r
 #if 1\r
@@ -383,7 +389,10 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false
                CString s = path.GetWinPathString();\r
                if (s.GetLength() > sProjectRoot.GetLength())\r
                {\r
                CString s = path.GetWinPathString();\r
                if (s.GetLength() > sProjectRoot.GetLength())\r
                {\r
-                       sSubPath = CString(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));\r
+                       if (sProjectRoot.GetLength() == 3 && sProjectRoot[1] == _T(':'))\r
+                               sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\r
+                       else\r
+                               sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);\r
                }\r
 \r
                m_status.prop_status = m_status.text_status = git_wc_status_none;\r
                }\r
 \r
                m_status.prop_status = m_status.text_status = git_wc_status_none;\r
@@ -397,8 +406,11 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false
                CString s = path.GetWinPathString();\r
                if (s.GetLength() > sProjectRoot.GetLength())\r
                {\r
                CString s = path.GetWinPathString();\r
                if (s.GetLength() > sProjectRoot.GetLength())\r
                {\r
-                       sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);\r
+                       sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\r
                        lpszSubPath = sSubPath;\r
                        lpszSubPath = sSubPath;\r
+                       // skip initial slash if necessary\r
+                       if (*lpszSubPath == _T('\\'))\r
+                               lpszSubPath++;\r
                }\r
 \r
                // when recursion enabled, let wingit determine the recursive status for folders instead of enumerating all files here\r
                }\r
 \r
                // when recursion enabled, let wingit determine the recursive status for folders instead of enumerating all files here\r
index 6460789..c85ae6e 100644 (file)
@@ -409,8 +409,11 @@ CStatusCacheEntry CCachedDirectory::GetStatusForMember(const CTGitPath& path, bo
                        CString s = m_directoryPath.GetDirectory().GetWinPathString();\r
                        if (s.GetLength() > sProjectRoot.GetLength())\r
                        {\r
                        CString s = m_directoryPath.GetDirectory().GetWinPathString();\r
                        if (s.GetLength() > sProjectRoot.GetLength())\r
                        {\r
-                               sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/);\r
+                               sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\r
                                lpszSubPath = sSubPath;\r
                                lpszSubPath = sSubPath;\r
+                               // skip initial slash if necessary\r
+                               if (*lpszSubPath == _T('\\'))\r
+                                       lpszSubPath++;\r
                        }\r
 //MessageBoxA(NULL, CStringA(sProjectRoot), sSubPath, MB_OK);\r
 //OutputDebugStringA("###");OutputDebugStringW(sProjectRoot);OutputDebugStringA(" - ");OutputDebugStringA(sSubPath);OutputDebugStringA("\r\n");\r
                        }\r
 //MessageBoxA(NULL, CStringA(sProjectRoot), sSubPath, MB_OK);\r
 //OutputDebugStringA("###");OutputDebugStringW(sProjectRoot);OutputDebugStringA(" - ");OutputDebugStringA(sSubPath);OutputDebugStringA("\r\n");\r