OSDN Git Service

status bar cancel button work
[tortoisegit/TortoiseGitJp.git] / Git / GitAdminDir.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseGit\r
4 \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
9 \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
14 \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
18 #include "StdAfx.h"\r
19 #include "UnicodeUtils.h"\r
20 #include "GitAdminDir.h"\r
21 \r
22 GitAdminDir g_GitAdminDir;\r
23 \r
24 GitAdminDir::GitAdminDir()\r
25         : m_nInit(0)\r
26 //      , m_bVSNETHack(false)\r
27 //      , m_pool(NULL)\r
28 {\r
29 }\r
30 \r
31 GitAdminDir::~GitAdminDir()\r
32 {\r
33 //      if (m_nInit)\r
34 //               (m_pool);\r
35 }\r
36 \r
37 bool GitAdminDir::Init()\r
38 {\r
39         if (m_nInit==0)\r
40         {\r
41 #if 0   \r
42                 m_bVSNETHack = false;\r
43                 m_pool = svn_pool_create(NULL);\r
44                 size_t ret = 0;\r
45                 getenv_s(&ret, NULL, 0, "GIT_ASP_DOT_NET_HACK");\r
46                 if (ret)\r
47                 {\r
48                         svn_error_clear(svn_wc_set_adm_dir("_git", m_pool));\r
49                         m_bVSNETHack = true;\r
50                 }\r
51 #endif\r
52         }\r
53         m_nInit++;\r
54         return true;\r
55 }\r
56 \r
57 bool GitAdminDir::Close()\r
58 {\r
59         m_nInit--;\r
60         if (m_nInit>0)\r
61                 return false;\r
62 #if 0\r
63         svn_pool_destroy(m_pool);\r
64 #endif\r
65         return true;\r
66 }\r
67 \r
68 bool GitAdminDir::IsAdminDirName(const CString& name) const\r
69 {\r
70 #if 0\r
71         CStringA nameA = CUnicodeUtils::GetUTF8(name).MakeLower();\r
72         return !!svn_wc_is_adm_dir(nameA, m_pool);\r
73 #endif\r
74         return name == ".git";\r
75 }\r
76 \r
77 bool GitAdminDir::HasAdminDir(const CString& path) const\r
78 {\r
79         return HasAdminDir(path, !!PathIsDirectory(path));\r
80 }\r
81 \r
82 bool GitAdminDir::HasAdminDir(const CString& path, bool bDir) const\r
83 {\r
84         if (path.IsEmpty())\r
85                 return false;\r
86         bool bHasAdminDir = false;\r
87         CString sDirName = path;\r
88         if (!bDir)\r
89         {\r
90                 sDirName = path.Left(path.ReverseFind('\\'));\r
91         }\r
92         \r
93         do\r
94         {\r
95                 if(PathFileExists(sDirName + _T("\\.git")))\r
96                         return true;\r
97                 sDirName = sDirName.Left(sDirName.ReverseFind('\\'));\r
98 \r
99         }while(sDirName.ReverseFind('\\')>0);\r
100 \r
101         return false;\r
102         \r
103 }\r
104 \r
105 bool GitAdminDir::IsAdminDirPath(const CString& path) const\r
106 {\r
107         if (path.IsEmpty())\r
108                 return false;\r
109         bool bIsAdminDir = false;\r
110         CString lowerpath = path;\r
111         lowerpath.MakeLower();\r
112         int ind = -1;\r
113         int ind1 = 0;\r
114         while ((ind1 = lowerpath.Find(_T("\\.git"), ind1))>=0)\r
115         {\r
116                 ind = ind1++;\r
117                 if (ind == (lowerpath.GetLength() - 5))\r
118                 {\r
119                         bIsAdminDir = true;\r
120                         break;\r
121                 }\r
122                 else if (lowerpath.Find(_T("\\.git\\"), ind)>=0)\r
123                 {\r
124                         bIsAdminDir = true;\r
125                         break;\r
126                 }\r
127         }\r
128 \r
129         return bIsAdminDir;\r
130 }\r
131 \r