OSDN Git Service

merge original branch.
[tortoisegit/TortoiseGitJp.git] / src / Git / GitStatus.cpp
index 6d549a6..e2e9644 100644 (file)
 //\r
 \r
 #include "stdafx.h"\r
+#ifdef _TORTOISESHELL\r
+#include "ShellExt.h"\r
+#else\r
+#include "registry.h"\r
+#endif\r
 //#include "resource.h"\r
 #include "..\TortoiseShell\resource.h"\r
 //#include "git_config.h"\r
@@ -33,6 +38,9 @@
 //#    include "PathUtils.h"\r
 #endif\r
 #include "git.h"\r
+#include "gitindex.h"\r
+\r
+CGitIndexFileMap g_IndexFileMap;\r
 \r
 GitStatus::GitStatus(bool * pbCanceled)\r
        : status(NULL)\r
@@ -214,33 +222,58 @@ git_wc_status_kind GitStatus::GetAllStatus(const CTGitPath& path, git_depth_t de
 \r
        const BOOL bIsRecursive = (depth == git_depth_infinity || depth == git_depth_unknown); // taken from SVN source\r
 \r
-       LPCSTR lpszSubPath = NULL;\r
-       CStringA sSubPath;\r
-       CString s = path.GetWinPathString();\r
-       if (s.GetLength() > sProjectRoot.GetLength())\r
+#ifdef _TORTOISESHELL\r
+       if (g_ShellCache.GetCacheType() == ShellCache::dll)\r
+#else\r
+       if ((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\CacheType"), GetSystemMetrics(SM_REMOTESESSION) ? 2 : 1) == 2)\r
+#endif\r
        {\r
-               sSubPath = CStringA(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));\r
-               lpszSubPath = sSubPath;\r
+               // gitindex.h based status\r
+\r
+               CString sSubPath;\r
+               CString s = path.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
+               err = g_IndexFileMap.GetFileStatus(sProjectRoot,sSubPath,&statuskind);\r
        }\r
+       else\r
+       {\r
+               LPCTSTR lpszSubPath = NULL;\r
+               CString sSubPath;\r
+               CString s = path.GetWinPathString();\r
+               if (s.GetLength() > sProjectRoot.GetLength())\r
+               {\r
+                       sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\r
+                       lpszSubPath = sSubPath;\r
+                       // skip initial slash if necessary\r
+                       if (*lpszSubPath == _T('\\'))\r
+                               lpszSubPath++;\r
+               }\r
 \r
 #if 1\r
-       // when recursion enabled, let wingit determine the recursive status for folders instead of enumerating all files here\r
-       UINT nFlags = WGEFF_SingleFile;\r
-       if (!bIsRecursive)\r
-               nFlags |= WGEFF_NoRecurse;\r
-       if (!lpszSubPath)\r
-               // report root dir as normal (otherwise it could be considered git_wc_status_unversioned, which would be wrong?)\r
-               nFlags |= WGEFF_EmptyAsNormal;\r
+               // when recursion enabled, let wingit determine the recursive status for folders instead of enumerating all files here\r
+               UINT nFlags = WGEFF_SingleFile;\r
+               if (!bIsRecursive)\r
+                       nFlags |= WGEFF_NoRecurse;\r
+               if (!lpszSubPath)\r
+                       // report root dir as normal (otherwise it could be considered git_wc_status_unversioned, which would be wrong?)\r
+                       nFlags |= WGEFF_EmptyAsNormal;\r
 #else\r
-       // enumerate all files, recursively if requested\r
-       UINT nFlags = 0;\r
-       if (!bIsRecursive)\r
-               nFlags |= WGEFF_NoRecurse;\r
+               // enumerate all files, recursively if requested\r
+               UINT nFlags = 0;\r
+               if (!bIsRecursive)\r
+                       nFlags |= WGEFF_NoRecurse;\r
 #endif\r
 \r
-       err = !wgEnumFiles_safe(CStringA(sProjectRoot), lpszSubPath, nFlags, &getallstatus, &statuskind);\r
+               err = !wgEnumFiles(sProjectRoot, lpszSubPath, nFlags, &getallstatus, &statuskind);\r
 \r
-       /*err = git_client_status4 (&youngest,\r
+               /*err = git_client_status4 (&youngest,\r
                                                        path.GetSVNApiPath(pool),\r
                                                        &rev,\r
                                                        getallstatus,\r
@@ -253,6 +286,7 @@ git_wc_status_kind GitStatus::GetAllStatus(const CTGitPath& path, git_depth_t de
                                                        NULL,\r
                                                        ctx,\r
                                                        pool);*/\r
+       }\r
 \r
        // Error present\r
        if (err != NULL)\r
@@ -343,27 +377,54 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false
 //     hashbaton.exthash = exthash;\r
        hashbaton.pThis = this;\r
 \r
-       LPCSTR lpszSubPath = NULL;\r
-       CStringA sSubPath;\r
-       CString s = path.GetWinPathString();\r
-       if (s.GetLength() > sProjectRoot.GetLength())\r
+#ifdef _TORTOISESHELL\r
+       if (g_ShellCache.GetCacheType() == ShellCache::dll)\r
+#else\r
+       if ((DWORD)CRegStdWORD(_T("Software\\TortoiseGit\\CacheType"), GetSystemMetrics(SM_REMOTESESSION) ? 2 : 1) == 2)\r
+#endif\r
        {\r
-               sSubPath = CStringA(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));\r
-               lpszSubPath = sSubPath;\r
+               // gitindex.h based status\r
+\r
+               CString sSubPath;\r
+               CString s = path.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
+               m_status.prop_status = m_status.text_status = git_wc_status_none;\r
+\r
+               m_err = g_IndexFileMap.GetFileStatus(sProjectRoot,sSubPath,&m_status.text_status);\r
        }\r
+       else\r
+       {\r
+               LPCTSTR lpszSubPath = NULL;\r
+               CString sSubPath;\r
+               CString s = path.GetWinPathString();\r
+               if (s.GetLength() > sProjectRoot.GetLength())\r
+               {\r
+                       sSubPath = s.Right(s.GetLength() - sProjectRoot.GetLength());\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
-       UINT nFlags = WGEFF_SingleFile | WGEFF_NoRecurse;\r
-       if (!lpszSubPath)\r
-               // report root dir as normal (otherwise it could be considered git_wc_status_unversioned, which would be wrong?)\r
-               nFlags |= WGEFF_EmptyAsNormal;\r
+               // when recursion enabled, let wingit determine the recursive status for folders instead of enumerating all files here\r
+               UINT nFlags = WGEFF_SingleFile | WGEFF_NoRecurse;\r
+               if (!lpszSubPath)\r
+                       // report root dir as normal (otherwise it could be considered git_wc_status_unversioned, which would be wrong?)\r
+                       nFlags |= WGEFF_EmptyAsNormal;\r
 \r
-       m_status.prop_status = m_status.text_status = git_wc_status_none;\r
+               m_status.prop_status = m_status.text_status = git_wc_status_none;\r
 \r
-       // NOTE: currently wgEnumFiles_safe_safe_safe will not enumerate file if it isn't versioned (so status will be git_wc_status_none)\r
-       m_err = !wgEnumFiles_safe(CStringA(sProjectRoot), lpszSubPath, nFlags, &getstatus, &m_status);\r
+               // NOTE: currently wgEnumFiles will not enumerate file if it isn't versioned (so status will be git_wc_status_none)\r
+               m_err = !wgEnumFiles(sProjectRoot, lpszSubPath, nFlags, &getstatus, &m_status);\r
 \r
-       /*m_err = git_client_status4 (&youngest,\r
+               /*m_err = git_client_status4 (&youngest,\r
                                                        path.GetGitApiPath(m_pool),\r
                                                        &rev,\r
                                                        getstatushash,\r
@@ -376,10 +437,10 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false
                                                        NULL,\r
                                                        ctx,\r
                                                        m_pool);*/\r
-\r
+       }\r
 \r
        // Error present if function is not under version control\r
-       if ((m_err != NULL) /*|| (apr_hash_count(statushash) == 0)*/)\r
+       if (m_err) /*|| (apr_hash_count(statushash) == 0)*/\r
        {\r
                status = NULL;\r
 //             return -2;      \r
@@ -399,9 +460,9 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false
 \r
        if (update)\r
        {\r
-               const BYTE *sha1 = wgGetRevisionID_safe(CStringA(sProjectRoot), NULL);\r
-               if (sha1)\r
-                       youngest = ConvertHashToRevnum(sha1);\r
+               // done to match TSVN functionality of this function (not sure if any code uses the reutrn val)\r
+               // if TGit does not need this, then change the return type of function\r
+               youngest = g_Git.GetHash(CString(_T("HEAD")));\r
        }\r
 \r
        return youngest;\r