OSDN Git Service

Change Dir Structure to be same as TortoiseSVN'
[tortoisegit/TortoiseGitJp.git] / src / Git / GitAdminDir.cpp
diff --git a/src/Git/GitAdminDir.cpp b/src/Git/GitAdminDir.cpp
new file mode 100644 (file)
index 0000000..3ed2137
--- /dev/null
@@ -0,0 +1,131 @@
+// TortoiseGit - a Windows shell extension for easy version control\r
+\r
+// Copyright (C) 2003-2008 - TortoiseGit\r
+\r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// as published by the Free Software Foundation; either version 2\r
+// of the License, or (at your option) any later version.\r
+\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+// GNU General Public License for more details.\r
+\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software Foundation,\r
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
+#include "StdAfx.h"\r
+#include "UnicodeUtils.h"\r
+#include "GitAdminDir.h"\r
+\r
+GitAdminDir g_GitAdminDir;\r
+\r
+GitAdminDir::GitAdminDir()\r
+       : m_nInit(0)\r
+//     , m_bVSNETHack(false)\r
+//     , m_pool(NULL)\r
+{\r
+}\r
+\r
+GitAdminDir::~GitAdminDir()\r
+{\r
+//     if (m_nInit)\r
+//              (m_pool);\r
+}\r
+\r
+bool GitAdminDir::Init()\r
+{\r
+       if (m_nInit==0)\r
+       {\r
+#if 0  \r
+               m_bVSNETHack = false;\r
+               m_pool = svn_pool_create(NULL);\r
+               size_t ret = 0;\r
+               getenv_s(&ret, NULL, 0, "GIT_ASP_DOT_NET_HACK");\r
+               if (ret)\r
+               {\r
+                       svn_error_clear(svn_wc_set_adm_dir("_git", m_pool));\r
+                       m_bVSNETHack = true;\r
+               }\r
+#endif\r
+       }\r
+       m_nInit++;\r
+       return true;\r
+}\r
+\r
+bool GitAdminDir::Close()\r
+{\r
+       m_nInit--;\r
+       if (m_nInit>0)\r
+               return false;\r
+#if 0\r
+       svn_pool_destroy(m_pool);\r
+#endif\r
+       return true;\r
+}\r
+\r
+bool GitAdminDir::IsAdminDirName(const CString& name) const\r
+{\r
+#if 0\r
+       CStringA nameA = CUnicodeUtils::GetUTF8(name).MakeLower();\r
+       return !!svn_wc_is_adm_dir(nameA, m_pool);\r
+#endif\r
+       return name == ".git";\r
+}\r
+\r
+bool GitAdminDir::HasAdminDir(const CString& path) const\r
+{\r
+       return HasAdminDir(path, !!PathIsDirectory(path));\r
+}\r
+\r
+bool GitAdminDir::HasAdminDir(const CString& path, bool bDir) const\r
+{\r
+       if (path.IsEmpty())\r
+               return false;\r
+       bool bHasAdminDir = false;\r
+       CString sDirName = path;\r
+       if (!bDir)\r
+       {\r
+               sDirName = path.Left(path.ReverseFind('\\'));\r
+       }\r
+       \r
+       do\r
+       {\r
+               if(PathFileExists(sDirName + _T("\\.git")))\r
+                       return true;\r
+               sDirName = sDirName.Left(sDirName.ReverseFind('\\'));\r
+\r
+       }while(sDirName.ReverseFind('\\')>0);\r
+\r
+       return false;\r
+       \r
+}\r
+\r
+bool GitAdminDir::IsAdminDirPath(const CString& path) const\r
+{\r
+       if (path.IsEmpty())\r
+               return false;\r
+       bool bIsAdminDir = false;\r
+       CString lowerpath = path;\r
+       lowerpath.MakeLower();\r
+       int ind = -1;\r
+       int ind1 = 0;\r
+       while ((ind1 = lowerpath.Find(_T("\\.git"), ind1))>=0)\r
+       {\r
+               ind = ind1++;\r
+               if (ind == (lowerpath.GetLength() - 5))\r
+               {\r
+                       bIsAdminDir = true;\r
+                       break;\r
+               }\r
+               else if (lowerpath.Find(_T("\\.git\\"), ind)>=0)\r
+               {\r
+                       bIsAdminDir = true;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return bIsAdminDir;\r
+}\r
+\r