Fixed some unused variables warnings
[TortoiseGit.git] / src / Git / GitAdminDir.cpp
blob8727b3220413cd6e351b9b8c73c4c177189e517f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #include "StdAfx.h"
19 #include "UnicodeUtils.h"
20 #include "GitAdminDir.h"
21 #include "Git.h"
22 GitAdminDir g_GitAdminDir;
24 GitAdminDir::GitAdminDir()
25 : m_nInit(0)
26 // , m_bVSNETHack(false)
27 // , m_pool(NULL)
31 GitAdminDir::~GitAdminDir()
33 // if (m_nInit)
34 // (m_pool);
37 bool GitAdminDir::Init()
39 if (m_nInit==0)
41 #if 0
42 m_bVSNETHack = false;
43 m_pool = svn_pool_create(NULL);
44 size_t ret = 0;
45 getenv_s(&ret, NULL, 0, "GIT_ASP_DOT_NET_HACK");
46 if (ret)
48 svn_error_clear(svn_wc_set_adm_dir("_git", m_pool));
49 m_bVSNETHack = true;
51 #endif
53 m_nInit++;
54 return true;
57 bool GitAdminDir::Close()
59 m_nInit--;
60 if (m_nInit>0)
61 return false;
62 #if 0
63 svn_pool_destroy(m_pool);
64 #endif
65 return true;
68 CString GitAdminDir::GetSuperProjectRoot(const CString& path)
70 CString projectroot=path;
74 if(CGit::GitPathFileExists(projectroot + _T("\\.gitmodules")))
76 return projectroot;
79 projectroot = projectroot.Left(projectroot.ReverseFind('\\'));
81 }while(projectroot.ReverseFind('\\')>0);
83 return _T("");
87 bool GitAdminDir::IsAdminDirName(const CString& name) const
89 #if 0
90 CStringA nameA = CUnicodeUtils::GetUTF8(name).MakeLower();
91 return !!svn_wc_is_adm_dir(nameA, m_pool);
92 #endif
93 return name == ".git";
95 CString GitAdminDir::GetGitTopDir(const CString& path)
97 CString str;
98 str=_T("");
99 HasAdminDir(path,!!PathIsDirectory(path),&str);
100 return str;
103 bool GitAdminDir::HasAdminDir(const CString& path) const
105 return HasAdminDir(path, !!PathIsDirectory(path));
108 bool GitAdminDir::HasAdminDir(const CString& path,CString *ProjectTopDir) const
110 return HasAdminDir(path, !!PathIsDirectory(path),ProjectTopDir);
113 bool GitAdminDir::HasAdminDir(const CString& path, bool bDir,CString *ProjectTopDir) const
115 if (path.IsEmpty())
116 return false;
117 CString sDirName = path;
118 if (!bDir)
120 sDirName = path.Left(path.ReverseFind(_T('\\')));
123 // a .git dir or anything inside it should be left out, only interested in working copy files -- Myagi
125 int n = 0;
126 for (;;)
128 n = sDirName.Find(_T("\\.git"), n);
129 if (n < 0)
131 break;
134 // check for actual .git dir (and not .gitignore or something else), continue search if false match
135 n += 5;
136 if (sDirName[n] == _T('\\') || sDirName[n] == 0)
138 return false;
143 for (;;)
145 if(CGit::GitPathFileExists(sDirName + _T("\\.git")))
147 if(ProjectTopDir)
149 *ProjectTopDir=sDirName;
150 // Make sure to add the trailing slash to root paths such as 'C:'
151 if (sDirName.GetLength() == 2 && sDirName[1] == _T(':'))
152 (*ProjectTopDir) += _T("\\");
154 return true;
157 int x = sDirName.ReverseFind(_T('\\'));
158 if (x < 2)
159 break;
161 sDirName = sDirName.Left(x);
164 return false;
168 bool GitAdminDir::IsAdminDirPath(const CString& path) const
170 if (path.IsEmpty())
171 return false;
172 bool bIsAdminDir = false;
173 CString lowerpath = path;
174 lowerpath.MakeLower();
175 int ind = -1;
176 int ind1 = 0;
177 while ((ind1 = lowerpath.Find(_T("\\.git"), ind1))>=0)
179 ind = ind1++;
180 if (ind == (lowerpath.GetLength() - 5))
182 bIsAdminDir = true;
183 break;
185 else if (lowerpath.Find(_T("\\.git\\"), ind)>=0)
187 bIsAdminDir = true;
188 break;
192 return bIsAdminDir;