OSDN Git Service

Fix TortoiseGitBlame commit is not in log list problem.
[tortoisegit/TortoiseGitJp.git] / src / Git / TGitPath.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 //\r
19 #include "StdAfx.h"\r
20 #include "TGitPath.h"\r
21 #include "UnicodeUtils.h"\r
22 #include "GitAdminDir.h"\r
23 #include "PathUtils.h"\r
24 #include <regex>\r
25 #include "git.h"\r
26 #if defined(_MFC_VER)\r
27 //#include "MessageBox.h"\r
28 //#include "AppUtils.h"\r
29 #endif\r
30 \r
31 #ifndef ASSERT\r
32 #define ASSERT()\r
33 #endif\r
34 using namespace std;\r
35 extern CGit g_Git;\r
36 \r
37 CTGitPath::CTGitPath(void) :\r
38         m_bDirectoryKnown(false),\r
39         m_bIsDirectory(false),\r
40         m_bIsURL(false),\r
41         m_bURLKnown(false),\r
42         m_bHasAdminDirKnown(false),\r
43         m_bHasAdminDir(false),\r
44         m_bIsValidOnWindowsKnown(false),\r
45         m_bIsReadOnly(false),\r
46         m_bIsAdminDirKnown(false),\r
47         m_bIsAdminDir(false),\r
48         m_bExists(false),\r
49         m_bExistsKnown(false),\r
50         m_bLastWriteTimeKnown(0),\r
51         m_lastWriteTime(0),\r
52         m_customData(NULL),\r
53         m_bIsSpecialDirectoryKnown(false),\r
54         m_bIsSpecialDirectory(false)\r
55 {\r
56         m_Action=0;\r
57 }\r
58 \r
59 CTGitPath::~CTGitPath(void)\r
60 {\r
61 }\r
62 // Create a TGitPath object from an unknown path type (same as using SetFromUnknown)\r
63 CTGitPath::CTGitPath(const CString& sUnknownPath) :\r
64         m_bDirectoryKnown(false),\r
65         m_bIsDirectory(false),\r
66         m_bIsURL(false),\r
67         m_bURLKnown(false),\r
68         m_bHasAdminDirKnown(false),\r
69         m_bHasAdminDir(false),\r
70         m_bIsValidOnWindowsKnown(false),\r
71         m_bIsReadOnly(false),\r
72         m_bIsAdminDirKnown(false),\r
73         m_bIsAdminDir(false),\r
74         m_bExists(false),\r
75         m_bExistsKnown(false),\r
76         m_bLastWriteTimeKnown(0),\r
77         m_lastWriteTime(0),\r
78         m_customData(NULL),\r
79         m_bIsSpecialDirectoryKnown(false),\r
80         m_bIsSpecialDirectory(false)\r
81 {\r
82         SetFromUnknown(sUnknownPath);\r
83         m_Action=0;\r
84         m_Stage=0;\r
85 }\r
86 \r
87 int CTGitPath::ParserAction(BYTE action)\r
88 {\r
89         //action=action.TrimLeft();\r
90         //TCHAR c=action.GetAt(0);\r
91         if(action == 'M')\r
92                 m_Action|= LOGACTIONS_MODIFIED;\r
93         if(action == 'R')\r
94                 m_Action|= LOGACTIONS_REPLACED;\r
95         if(action == 'A')\r
96                 m_Action|= LOGACTIONS_ADDED;\r
97         if(action == 'D')\r
98                 m_Action|= LOGACTIONS_DELETED;\r
99         if(action == 'U')\r
100                 m_Action|= LOGACTIONS_UNMERGED;\r
101         if(action == 'K')\r
102                 m_Action|= LOGACTIONS_DELETED;\r
103         if(action == 'H')\r
104                 m_Action|= LOGACTIONS_CACHE;\r
105         return m_Action;\r
106 }\r
107 void CTGitPath::SetFromGit(const char* pPath)\r
108 {\r
109         Reset();\r
110         if (pPath == NULL)\r
111                 return;\r
112         int len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, NULL, 0);\r
113         if (len)\r
114         {\r
115                 len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, m_sFwdslashPath.GetBuffer(len+1), len+1);\r
116                 m_sFwdslashPath.ReleaseBuffer(len-1);\r
117         }\r
118         SanitizeRootPath(m_sFwdslashPath, true);\r
119 }\r
120 \r
121 void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)\r
122 {\r
123         SetFromGit(pPath);\r
124         m_bDirectoryKnown = true;\r
125         m_bIsDirectory = bIsDirectory;\r
126 }\r
127 \r
128 void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)\r
129 {\r
130         Reset();\r
131         m_sFwdslashPath = sPath;\r
132         SanitizeRootPath(m_sFwdslashPath, true);\r
133         if(oldpath)\r
134                 m_sOldFwdslashPath = *oldpath;\r
135 }\r
136 \r
137 void CTGitPath::SetFromWin(LPCTSTR pPath)\r
138 {\r
139         Reset();\r
140         m_sBackslashPath = pPath;\r
141         SanitizeRootPath(m_sBackslashPath, false);\r
142         ATLASSERT(m_sBackslashPath.Find('/')<0);\r
143 }\r
144 void CTGitPath::SetFromWin(const CString& sPath)\r
145 {\r
146         Reset();\r
147         m_sBackslashPath = sPath;\r
148         SanitizeRootPath(m_sBackslashPath, false);\r
149 }\r
150 void CTGitPath::SetFromWin(const CString& sPath, bool bIsDirectory)\r
151 {\r
152         Reset();\r
153         m_sBackslashPath = sPath;\r
154         m_bIsDirectory = bIsDirectory;\r
155         m_bDirectoryKnown = true;\r
156         SanitizeRootPath(m_sBackslashPath, false);\r
157 }\r
158 void CTGitPath::SetFromUnknown(const CString& sPath)\r
159 {\r
160         Reset();\r
161         // Just set whichever path we think is most likely to be used\r
162 //      GitAdminDir admin;\r
163 //      CString p;\r
164 //      if(admin.HasAdminDir(sPath,&p))\r
165 //              SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));\r
166 //      else\r
167                 SetFwdslashPath(sPath);\r
168 }\r
169 \r
170 LPCTSTR CTGitPath::GetWinPath() const\r
171 {\r
172         if(IsEmpty())\r
173         {\r
174                 return _T("");\r
175         }\r
176         if(m_sBackslashPath.IsEmpty())\r
177         {\r
178                 SetBackslashPath(m_sFwdslashPath);\r
179         }\r
180         return m_sBackslashPath;\r
181 }\r
182 // This is a temporary function, to be used during the migration to \r
183 // the path class.  Ultimately, functions consuming paths should take a CTGitPath&, not a CString\r
184 const CString& CTGitPath::GetWinPathString() const\r
185 {\r
186         if(m_sBackslashPath.IsEmpty())\r
187         {\r
188                 SetBackslashPath(m_sFwdslashPath);\r
189         }\r
190         return m_sBackslashPath;\r
191 }\r
192 \r
193 const CString& CTGitPath::GetGitPathString() const\r
194 {\r
195         if(m_sFwdslashPath.IsEmpty())\r
196         {\r
197                 SetFwdslashPath(m_sBackslashPath);\r
198         }\r
199         return m_sFwdslashPath;\r
200 }\r
201 \r
202 const CString &CTGitPath::GetGitOldPathString() const\r
203 {\r
204         return m_sOldFwdslashPath;\r
205 }\r
206 #if 0\r
207 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const\r
208 {\r
209         // This funny-looking 'if' is to avoid a subtle problem with empty paths, whereby\r
210         // each call to GetGitApiPath returns a different pointer value.\r
211         // If you made multiple calls to GetGitApiPath on the same string, only the last\r
212         // one would give you a valid pointer to an empty string, because each \r
213         // call would invalidate the previous call's return. \r
214         if(IsEmpty())\r
215         {\r
216                 return "";\r
217         }\r
218         if(m_sFwdslashPath.IsEmpty())\r
219         {\r
220                 SetFwdslashPath(m_sBackslashPath);\r
221         }\r
222         if(m_sUTF8FwdslashPath.IsEmpty())\r
223         {\r
224                 SetUTF8FwdslashPath(m_sFwdslashPath);\r
225         }\r
226         if (svn_path_is_url(m_sUTF8FwdslashPath))\r
227         {\r
228                 m_sUTF8FwdslashPathEscaped = CPathUtils::PathEscape(m_sUTF8FwdslashPath);\r
229                 m_sUTF8FwdslashPathEscaped.Replace("file:////", "file:///\\");\r
230                 m_sUTF8FwdslashPathEscaped = svn_path_canonicalize(m_sUTF8FwdslashPathEscaped, pool);\r
231                 return m_sUTF8FwdslashPathEscaped;\r
232         }\r
233         m_sUTF8FwdslashPath = svn_path_canonicalize(m_sUTF8FwdslashPath, pool);\r
234 \r
235         return m_sUTF8FwdslashPath;\r
236 }\r
237 #endif\r
238 \r
239 const CString& CTGitPath::GetUIPathString() const\r
240 {\r
241         if (m_sUIPath.IsEmpty())\r
242         {\r
243 #if defined(_MFC_VER)\r
244                 //BUGBUG HORRIBLE!!! - CPathUtils::IsEscaped doesn't need to be MFC-only\r
245                 if (IsUrl())\r
246                 {\r
247                         m_sUIPath = CPathUtils::PathUnescape(GetGitPathString());\r
248                         m_sUIPath.Replace(_T("file:////"), _T("file:///\\"));\r
249 \r
250                 }\r
251                 else\r
252 #endif \r
253                 {\r
254                         m_sUIPath = GetWinPathString();\r
255                 }\r
256         }\r
257         return m_sUIPath;\r
258 }\r
259 \r
260 void CTGitPath::SetFwdslashPath(const CString& sPath) const\r
261 {\r
262         m_sFwdslashPath = sPath;\r
263         m_sFwdslashPath.Replace('\\', '/');\r
264 \r
265         // We don't leave a trailing /\r
266         m_sFwdslashPath.TrimRight('/'); \r
267 \r
268         SanitizeRootPath(m_sFwdslashPath, true);\r
269 \r
270         m_sFwdslashPath.Replace(_T("file:////"), _T("file:///\\"));\r
271 \r
272         m_sUTF8FwdslashPath.Empty();\r
273 }\r
274 \r
275 void CTGitPath::SetBackslashPath(const CString& sPath) const\r
276 {\r
277         m_sBackslashPath = sPath;\r
278         m_sBackslashPath.Replace('/', '\\');\r
279         m_sBackslashPath.TrimRight('\\');\r
280         SanitizeRootPath(m_sBackslashPath, false);\r
281 }\r
282 \r
283 void CTGitPath::SetUTF8FwdslashPath(const CString& sPath) const\r
284 {\r
285         m_sUTF8FwdslashPath = CUnicodeUtils::GetUTF8(sPath);\r
286 }\r
287 \r
288 void CTGitPath::SanitizeRootPath(CString& sPath, bool bIsForwardPath) const\r
289 {\r
290         // Make sure to add the trailing slash to root paths such as 'C:'\r
291         if (sPath.GetLength() == 2 && sPath[1] == ':')\r
292         {\r
293                 sPath += (bIsForwardPath) ? _T("/") : _T("\\");\r
294         }\r
295 }\r
296 \r
297 bool CTGitPath::IsUrl() const\r
298 {\r
299 #if 0\r
300         if (!m_bURLKnown)\r
301         {\r
302                 EnsureFwdslashPathSet();\r
303                 if(m_sUTF8FwdslashPath.IsEmpty())\r
304                 {\r
305                         SetUTF8FwdslashPath(m_sFwdslashPath);\r
306                 }\r
307                 m_bIsURL = !!svn_path_is_url(m_sUTF8FwdslashPath);\r
308                 m_bURLKnown = true;\r
309         }\r
310         return m_bIsURL;\r
311 #endif \r
312         return false;\r
313 }\r
314 \r
315 bool CTGitPath::IsDirectory() const\r
316 {\r
317         if(!m_bDirectoryKnown)\r
318         {\r
319                 UpdateAttributes();\r
320         }\r
321         return m_bIsDirectory;\r
322 }\r
323 \r
324 bool CTGitPath::Exists() const\r
325 {\r
326         if (!m_bExistsKnown)\r
327         {\r
328                 UpdateAttributes();\r
329         }\r
330         return m_bExists;\r
331 }\r
332 \r
333 bool CTGitPath::Delete(bool bTrash) const\r
334 {\r
335         EnsureBackslashPathSet();\r
336         ::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);\r
337         bool bRet = false;\r
338         if (Exists())\r
339         {\r
340                 if ((bTrash)||(IsDirectory()))\r
341                 {\r
342                         TCHAR * buf = new TCHAR[m_sBackslashPath.GetLength()+2];\r
343                         _tcscpy_s(buf, m_sBackslashPath.GetLength()+2, m_sBackslashPath);\r
344                         buf[m_sBackslashPath.GetLength()] = 0;\r
345                         buf[m_sBackslashPath.GetLength()+1] = 0;\r
346                         SHFILEOPSTRUCT shop = {0};\r
347                         shop.wFunc = FO_DELETE;\r
348                         shop.pFrom = buf;\r
349                         shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;\r
350                         if (bTrash)\r
351                                 shop.fFlags |= FOF_ALLOWUNDO;\r
352                         bRet = (SHFileOperation(&shop) == 0);\r
353                         delete [] buf;\r
354                 }\r
355                 else\r
356                 {\r
357                         bRet = !!::DeleteFile(m_sBackslashPath);\r
358                 }\r
359         }\r
360         m_bExists = false;\r
361         m_bExistsKnown = true;\r
362         return bRet;\r
363 }\r
364 \r
365 __int64  CTGitPath::GetLastWriteTime() const\r
366 {\r
367         if(!m_bLastWriteTimeKnown)\r
368         {\r
369                 UpdateAttributes();\r
370         }\r
371         return m_lastWriteTime;\r
372 }\r
373 \r
374 bool CTGitPath::IsReadOnly() const\r
375 {\r
376         if(!m_bLastWriteTimeKnown)\r
377         {\r
378                 UpdateAttributes();\r
379         }\r
380         return m_bIsReadOnly;\r
381 }\r
382 \r
383 void CTGitPath::UpdateAttributes() const\r
384 {\r
385         EnsureBackslashPathSet();\r
386         WIN32_FILE_ATTRIBUTE_DATA attribs;\r
387         if(GetFileAttributesEx(m_sBackslashPath, GetFileExInfoStandard, &attribs))\r
388         {\r
389                 m_bIsDirectory = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);\r
390                 m_lastWriteTime = *(__int64*)&attribs.ftLastWriteTime;\r
391                 m_bIsReadOnly = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_READONLY);\r
392                 m_bExists = true;\r
393         }\r
394         else\r
395         {\r
396                 DWORD err = GetLastError();\r
397                 if ((err == ERROR_FILE_NOT_FOUND)||(err == ERROR_PATH_NOT_FOUND)||(err == ERROR_INVALID_NAME))\r
398                 {\r
399                         m_bIsDirectory = false;\r
400                         m_lastWriteTime = 0;\r
401                         m_bExists = false;\r
402                 }\r
403                 else\r
404                 {\r
405                         m_bIsDirectory = false;\r
406                         m_lastWriteTime = 0;\r
407                         m_bExists = true;\r
408                         return;\r
409                 }\r
410         }\r
411         m_bDirectoryKnown = true;\r
412         m_bLastWriteTimeKnown = true;\r
413         m_bExistsKnown = true;\r
414 }\r
415 \r
416 \r
417 void CTGitPath::EnsureBackslashPathSet() const\r
418 {\r
419         if(m_sBackslashPath.IsEmpty())\r
420         {\r
421                 SetBackslashPath(m_sFwdslashPath);\r
422                 ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());\r
423         }\r
424 }\r
425 void CTGitPath::EnsureFwdslashPathSet() const\r
426 {\r
427         if(m_sFwdslashPath.IsEmpty())\r
428         {\r
429                 SetFwdslashPath(m_sBackslashPath);\r
430                 ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());\r
431         }\r
432 }\r
433 \r
434 \r
435 // Reset all the caches\r
436 void CTGitPath::Reset()\r
437 {\r
438         m_bDirectoryKnown = false;\r
439         m_bURLKnown = false;\r
440         m_bLastWriteTimeKnown = false;\r
441         m_bHasAdminDirKnown = false;\r
442         m_bIsValidOnWindowsKnown = false;\r
443         m_bIsAdminDirKnown = false;\r
444         m_bExistsKnown = false;\r
445         m_bIsSpecialDirectoryKnown = false;\r
446         m_bIsSpecialDirectory = false;\r
447 \r
448         m_sBackslashPath.Empty();\r
449         m_sFwdslashPath.Empty();\r
450         m_sUTF8FwdslashPath.Empty();\r
451         this->m_Action=0;\r
452         this->m_StatAdd=_T("");\r
453         this->m_StatDel=_T("");\r
454         ATLASSERT(IsEmpty());\r
455 }\r
456 \r
457 CTGitPath CTGitPath::GetDirectory() const\r
458 {\r
459         if ((IsDirectory())||(!Exists()))\r
460         {\r
461                 return *this;\r
462         }\r
463         return GetContainingDirectory();\r
464 }\r
465 \r
466 CTGitPath CTGitPath::GetContainingDirectory() const\r
467 {\r
468         EnsureBackslashPathSet();\r
469 \r
470         CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));\r
471         if(sDirName.GetLength() == 2 && sDirName[1] == ':')\r
472         {\r
473                 // This is a root directory, which needs a trailing slash\r
474                 sDirName += '\\';\r
475                 if(sDirName == m_sBackslashPath)\r
476                 {\r
477                         // We were clearly provided with a root path to start with - we should return nothing now\r
478                         sDirName.Empty();\r
479                 }\r
480         }\r
481         if(sDirName.GetLength() == 1 && sDirName[0] == '\\')\r
482         {\r
483                 // We have an UNC path and we already are the root\r
484                 sDirName.Empty();\r
485         }\r
486         CTGitPath retVal;\r
487         retVal.SetFromWin(sDirName);\r
488         return retVal;\r
489 }\r
490 \r
491 CString CTGitPath::GetRootPathString() const\r
492 {\r
493         EnsureBackslashPathSet();\r
494         CString workingPath = m_sBackslashPath;\r
495         LPTSTR pPath = workingPath.GetBuffer(MAX_PATH);         // MAX_PATH ok here.\r
496         ATLVERIFY(::PathStripToRoot(pPath));\r
497         workingPath.ReleaseBuffer();\r
498         return workingPath;\r
499 }\r
500 \r
501 \r
502 CString CTGitPath::GetFilename() const\r
503 {\r
504         ATLASSERT(!IsDirectory());\r
505         return GetFileOrDirectoryName();\r
506 }\r
507 \r
508 CString CTGitPath::GetFileOrDirectoryName() const\r
509 {\r
510         EnsureBackslashPathSet();\r
511         return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);\r
512 }\r
513 \r
514 CString CTGitPath::GetUIFileOrDirectoryName() const\r
515 {\r
516         GetUIPathString();\r
517         return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);\r
518 }\r
519 \r
520 CString CTGitPath::GetFileExtension() const\r
521 {\r
522         if(!IsDirectory())\r
523         {\r
524                 EnsureBackslashPathSet();\r
525                 int dotPos = m_sBackslashPath.ReverseFind('.');\r
526                 int slashPos = m_sBackslashPath.ReverseFind('\\');\r
527                 if (dotPos > slashPos)\r
528                         return m_sBackslashPath.Mid(dotPos);\r
529         }\r
530         return CString();\r
531 }\r
532 CString CTGitPath::GetBaseFilename() const\r
533 {\r
534         int dot;\r
535         CString filename=GetFilename();\r
536         dot = filename.ReverseFind(_T('.'));\r
537         if(dot>0)\r
538                 return filename.Left(dot-1);\r
539         else\r
540                 return filename;\r
541 }\r
542 \r
543 bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)\r
544 {\r
545         int length = sP1.GetLength();\r
546         if(length != sP2.GetLength())\r
547         {\r
548                 // Different lengths\r
549                 return false;\r
550         }\r
551         // We work from the end of the strings, because path differences\r
552         // are more likely to occur at the far end of a string\r
553         LPCTSTR pP1Start = sP1;\r
554         LPCTSTR pP1 = pP1Start+(length-1);\r
555         LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);\r
556         while(length-- > 0)\r
557         {\r
558                 if(_totlower(*pP1--) != _totlower(*pP2--))\r
559                 {\r
560                         return false;\r
561                 }\r
562         }\r
563         return true;\r
564 }\r
565 \r
566 bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)\r
567 {\r
568         int length = sP1.GetLength();\r
569         if(length != sP2.GetLength())\r
570         {\r
571                 // Different lengths\r
572                 return false;\r
573         }\r
574         // We work from the end of the strings, because path differences\r
575         // are more likely to occur at the far end of a string\r
576         LPCTSTR pP1Start = sP1;\r
577         LPCTSTR pP1 = pP1Start+(length-1);\r
578         LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);\r
579         while(length-- > 0)\r
580         {\r
581                 if((*pP1--) != (*pP2--))\r
582                 {\r
583                         return false;\r
584                 }\r
585         }\r
586         return true;\r
587 }\r
588 \r
589 bool CTGitPath::IsEmpty() const\r
590 {\r
591         // Check the backward slash path first, since the chance that this\r
592         // one is set is higher. In case of a 'false' return value it's a little\r
593         // bit faster.\r
594         return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();\r
595 }\r
596 \r
597 // Test if both paths refer to the same item\r
598 // Ignores case and slash direction\r
599 bool CTGitPath::IsEquivalentTo(const CTGitPath& rhs) const\r
600 {\r
601         // Try and find a slash direction which avoids having to convert\r
602         // both filenames\r
603         if(!m_sBackslashPath.IsEmpty())\r
604         {\r
605                 // *We've* got a \ path - make sure that the RHS also has a \ path\r
606                 rhs.EnsureBackslashPathSet();\r
607                 return ArePathStringsEqualWithCase(m_sBackslashPath, rhs.m_sBackslashPath);\r
608         }\r
609         else\r
610         {\r
611                 // Assume we've got a fwdslash path and make sure that the RHS has one\r
612                 rhs.EnsureFwdslashPathSet();\r
613                 return ArePathStringsEqualWithCase(m_sFwdslashPath, rhs.m_sFwdslashPath);\r
614         }\r
615 }\r
616 \r
617 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const\r
618 {\r
619         // Try and find a slash direction which avoids having to convert\r
620         // both filenames\r
621         if(!m_sBackslashPath.IsEmpty())\r
622         {\r
623                 // *We've* got a \ path - make sure that the RHS also has a \ path\r
624                 rhs.EnsureBackslashPathSet();\r
625                 return ArePathStringsEqual(m_sBackslashPath, rhs.m_sBackslashPath);\r
626         }\r
627         else\r
628         {\r
629                 // Assume we've got a fwdslash path and make sure that the RHS has one\r
630                 rhs.EnsureFwdslashPathSet();\r
631                 return ArePathStringsEqual(m_sFwdslashPath, rhs.m_sFwdslashPath);\r
632         }\r
633 }\r
634 \r
635 bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const\r
636 {\r
637         possibleDescendant.EnsureBackslashPathSet();\r
638         EnsureBackslashPathSet();\r
639 \r
640         bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));\r
641         if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())\r
642         {\r
643                 return bPathStringsEqual;               \r
644         }\r
645         \r
646         return (bPathStringsEqual && \r
647                         ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||\r
648                         (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));\r
649 }\r
650 \r
651 // Get a string representing the file path, optionally with a base \r
652 // section stripped off the front.\r
653 CString CTGitPath::GetDisplayString(const CTGitPath* pOptionalBasePath /* = NULL*/) const\r
654 {\r
655         EnsureFwdslashPathSet();\r
656         if(pOptionalBasePath != NULL)\r
657         {\r
658                 // Find the length of the base-path without having to do an 'ensure' on it\r
659                 int baseLength = max(pOptionalBasePath->m_sBackslashPath.GetLength(), pOptionalBasePath->m_sFwdslashPath.GetLength());\r
660 \r
661                 // Now, chop that baseLength of the front of the path\r
662                 return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');\r
663         }\r
664         return m_sFwdslashPath;\r
665 }\r
666 \r
667 int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)\r
668 {\r
669         left.EnsureBackslashPathSet();\r
670         right.EnsureBackslashPathSet();\r
671         return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);\r
672 }\r
673 \r
674 bool operator<(const CTGitPath& left, const CTGitPath& right)\r
675 {\r
676         return CTGitPath::Compare(left, right) < 0;\r
677 }\r
678 \r
679 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)\r
680 {\r
681         return left.IsEquivalentTo(right);\r
682 }\r
683 \r
684 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)\r
685 {\r
686         if (left.IsAdminDir() && right.IsAdminDir())\r
687         {\r
688                 CTGitPath l = left;\r
689                 CTGitPath r = right;\r
690                 do \r
691                 {\r
692                         l = l.GetContainingDirectory();\r
693                 } while(l.HasAdminDir());\r
694                 do \r
695                 {\r
696                         r = r.GetContainingDirectory();\r
697                 } while(r.HasAdminDir());\r
698                 return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());\r
699         }\r
700         return left.GetDirectory().IsEquivalentTo(right.GetDirectory());\r
701 }\r
702 \r
703 bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)\r
704 {\r
705         return parent.IsAncestorOf(child);\r
706 }\r
707 \r
708 void CTGitPath::AppendRawString(const CString& sAppend)\r
709 {\r
710         EnsureFwdslashPathSet();\r
711         CString strCopy = m_sFwdslashPath += sAppend;\r
712         SetFromUnknown(strCopy);\r
713 }\r
714 \r
715 void CTGitPath::AppendPathString(const CString& sAppend)\r
716 {\r
717         EnsureBackslashPathSet();\r
718         CString cleanAppend(sAppend);\r
719         cleanAppend.Replace('/', '\\');\r
720         cleanAppend.TrimLeft('\\');\r
721         m_sBackslashPath.TrimRight('\\');\r
722         CString strCopy = m_sBackslashPath + _T("\\") + cleanAppend;\r
723         SetFromWin(strCopy);\r
724 }\r
725 \r
726 bool CTGitPath::HasAdminDir() const\r
727 {\r
728         if (m_bHasAdminDirKnown)\r
729                 return m_bHasAdminDir;\r
730 \r
731         EnsureBackslashPathSet();\r
732         m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory());\r
733         m_bHasAdminDirKnown = true;\r
734         return m_bHasAdminDir;\r
735 }\r
736 \r
737 bool CTGitPath::IsAdminDir() const\r
738 {\r
739         if (m_bIsAdminDirKnown)\r
740                 return m_bIsAdminDir;\r
741         \r
742         EnsureBackslashPathSet();\r
743         m_bIsAdminDir = g_GitAdminDir.IsAdminDirPath(m_sBackslashPath);\r
744         m_bIsAdminDirKnown = true;\r
745         return m_bIsAdminDir;\r
746 }\r
747 \r
748 bool CTGitPath::IsValidOnWindows() const\r
749 {\r
750         if (m_bIsValidOnWindowsKnown)\r
751                 return m_bIsValidOnWindows;\r
752 \r
753         m_bIsValidOnWindows = false;\r
754         EnsureBackslashPathSet();\r
755         CString sMatch = m_sBackslashPath + _T("\r\n");\r
756         wstring sPattern;\r
757         // the 'file://' URL is just a normal windows path:\r
758         if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)\r
759         {\r
760                 sMatch = sMatch.Mid(7);\r
761                 sMatch.TrimLeft(_T("\\"));\r
762                 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");\r
763         }\r
764         else if (IsUrl())\r
765         {\r
766                 sPattern = _T("^((http|https|svn|svn\\+ssh|file)\\:\\\\+([^\\\\@\\:]+\\:[^\\\\@\\:]+@)?\\\\[^\\\\]+(\\:\\d+)?)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");\r
767         }\r
768         else\r
769         {\r
770                 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");\r
771         }\r
772 \r
773         try\r
774         {\r
775                 tr1::wregex rx(sPattern, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);\r
776                 tr1::wsmatch match;\r
777 \r
778                 wstring rmatch = wstring((LPCTSTR)sMatch);\r
779                 if (tr1::regex_match(rmatch, match, rx))\r
780                 {\r
781                         if (wstring(match[0]).compare(sMatch)==0)\r
782                                 m_bIsValidOnWindows = true;\r
783                 }\r
784                 if (m_bIsValidOnWindows)\r
785                 {\r
786                         // now check for illegal filenames\r
787                         tr1::wregex rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);\r
788                         rmatch = m_sBackslashPath;\r
789                         if (tr1::regex_search(rmatch, rx2, tr1::regex_constants::match_default))\r
790                                 m_bIsValidOnWindows = false;\r
791                 }\r
792         }\r
793         catch (exception) {}\r
794 \r
795         m_bIsValidOnWindowsKnown = true;\r
796         return m_bIsValidOnWindows;\r
797 }\r
798 \r
799 bool CTGitPath::IsSpecialDirectory() const\r
800 {\r
801         if (m_bIsSpecialDirectoryKnown)\r
802                 return m_bIsSpecialDirectory;\r
803 \r
804         static LPCTSTR specialDirectories[]\r
805                 = { _T("trunk"), _T("tags"), _T("branches") };\r
806 \r
807         for (int i=0 ; i<(sizeof(specialDirectories) / sizeof(specialDirectories[0])) ; ++i)\r
808         {\r
809                 CString name = GetFileOrDirectoryName();\r
810                 if (0 == name.CompareNoCase(specialDirectories[i]))\r
811                 {\r
812                         m_bIsSpecialDirectory = true;\r
813                         break;\r
814                 }\r
815         }\r
816 \r
817         m_bIsSpecialDirectoryKnown = true;\r
818 \r
819         return m_bIsSpecialDirectory;\r
820 }\r
821 \r
822 //////////////////////////////////////////////////////////////////////////\r
823 \r
824 CTGitPathList::CTGitPathList()\r
825 {\r
826 \r
827 }\r
828 \r
829 // A constructor which allows a path list to be easily built which one initial entry in\r
830 CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)\r
831 {\r
832         AddPath(firstEntry);\r
833 }\r
834 int CTGitPathList::ParserFromLsFile(BYTE_VECTOR &out,bool staged)\r
835 {\r
836         int pos=0;\r
837         CString one;\r
838         CTGitPath path;\r
839         CString part;\r
840         while(pos>=0 && pos<out.size())\r
841         {\r
842                 one.Empty();\r
843                 path.Reset();\r
844 \r
845                 g_Git.StringAppend(&one,&out[pos],CP_OEMCP);\r
846                 int tabstart=0;\r
847                 path.m_Action=path.ParserAction(out[pos]);\r
848                 one.Tokenize(_T("\t"),tabstart); \r
849 \r
850                 if(tabstart>=0)\r
851                         path.SetFromGit(one.Right(one.GetLength()-tabstart));\r
852 \r
853                 tabstart=0;\r
854 \r
855                 part=one.Tokenize(_T(" "),tabstart); //Tag\r
856 \r
857                 part=one.Tokenize(_T(" "),tabstart); //Mode\r
858                 \r
859                 part=one.Tokenize(_T(" "),tabstart); //Hash\r
860 \r
861                 part=one.Tokenize(_T("\t"),tabstart); //Stage\r
862 \r
863                 path.m_Stage=_ttol(part);\r
864 \r
865                 this->AddPath(path);\r
866 \r
867                 pos=out.findNextString(pos);\r
868         }\r
869         return pos;\r
870 }\r
871 int CTGitPathList::FillUnRev(int action,CTGitPathList *list)\r
872 {\r
873         int pos=0;\r
874         this->Clear();\r
875         CTGitPath path;\r
876 \r
877         int count;\r
878         if(list==NULL)\r
879                 count=1;\r
880         else\r
881                 count=list->GetCount();\r
882         for(int i=0;i<count;i++)\r
883         {       \r
884                 CString cmd;\r
885                 pos=0;\r
886                 \r
887                 CString ignored;\r
888                 if(action & CTGitPath::LOGACTIONS_IGNORE)\r
889                         ignored= _T(" --ignored");\r
890                 \r
891                 if(list==NULL)\r
892                 {\r
893                         cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");\r
894                         cmd+=ignored;\r
895                         \r
896                 }\r
897                 else\r
898                 {       cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z %s-- \"%s\""),\r
899                                         ignored,\r
900                                         (*list)[i].GetWinPathString());\r
901                 }\r
902 \r
903                 BYTE_VECTOR out;\r
904                 out.clear();\r
905                 g_Git.Run(cmd,&out);\r
906                 \r
907                 pos=0;\r
908                 CString one;\r
909                 while( pos>=0 && pos<out.size())\r
910                 {\r
911                         g_Git.StringAppend(&one,&out[pos],CP_OEMCP);\r
912                         if(!one.IsEmpty())\r
913                         {\r
914                                 //SetFromGit will clear all status\r
915                                 path.SetFromGit(one);\r
916                                 path.m_Action=action;\r
917                                 AddPath(path);\r
918                         }\r
919                         pos=out.findNextString(pos);\r
920                 }\r
921 \r
922         }\r
923         return 0;\r
924 }\r
925 int CTGitPathList::ParserFromLog(BYTE_VECTOR &log)\r
926 {\r
927         this->Clear();\r
928         int pos=0;\r
929         //BYTE *p=&log[0];\r
930         //CString one;\r
931         CTGitPath path;\r
932         m_Action=0;\r
933         while( pos>=0 && pos<log.size())\r
934         {\r
935                 //one=log.Tokenize(_T("\n"),pos);\r
936                 path.Reset();\r
937                 if(log[pos]=='\n')\r
938                         pos++;\r
939 \r
940                 if(log[pos]==':')\r
941                 {\r
942                         int end=log.find(0,pos);\r
943                         int actionstart=-1;\r
944                         int numfile=1;\r
945                         int file1=-1,file2=-1;\r
946                         if( end>0 )\r
947                         {\r
948                                 actionstart=log.find(' ',end-6);\r
949                                 pos=actionstart;\r
950                         }\r
951                         if( actionstart>0 )\r
952                         {\r
953                                 actionstart++;\r
954 \r
955                                 file1 = log.find(0,actionstart);\r
956                                 if( file1>=0 )\r
957                                 {\r
958                                         file1++;\r
959                                         pos=file1;\r
960                                 }\r
961                                 if( log[actionstart] == 'C' || log[actionstart] == 'R' )\r
962                                 {\r
963                                         file2=file1;\r
964                                         numfile=2;\r
965                                         file1 = log.find(0,file1);\r
966                                         if(file1>=0 )\r
967                                         {\r
968                                                 file1++;\r
969                                                 pos=file1;\r
970                                         }\r
971 \r
972                                 }\r
973                         }\r
974                         \r
975                         CString pathname1;\r
976                         CString pathname2;\r
977 \r
978                         if( file1>=0 )\r
979                                 g_Git.StringAppend(&pathname1,&log[file1],CP_OEMCP);\r
980                         if( file2>=0 )\r
981                                 g_Git.StringAppend(&pathname2,&log[file2],CP_OEMCP);\r
982 \r
983                         CTGitPath *GitPath=LookForGitPath(pathname1);\r
984 \r
985                         if(GitPath)\r
986                         {\r
987                                 this->m_Action|=GitPath->ParserAction( log[actionstart] );      \r
988                                                         \r
989                         }else\r
990                         {       \r
991                                 int ac=path.ParserAction(log[actionstart] );\r
992 \r
993                                 path.SetFromGit(pathname1,&pathname2);\r
994                                 path.m_Action=ac;\r
995                                         //action must be set after setfromgit. SetFromGit will clear all status. \r
996                                 this->m_Action|=ac;\r
997                                 AddPath(path);\r
998                                 \r
999                         }\r
1000         \r
1001                 }else\r
1002                 {                       \r
1003                         int tabstart=0;\r
1004                         path.Reset();\r
1005                         CString StatAdd;\r
1006                         CString StatDel;\r
1007                         CString file1;\r
1008                         CString file2;\r
1009 \r
1010                         tabstart=log.find('\t',pos);\r
1011                         if(tabstart >=0)\r
1012                         {\r
1013                                 log[tabstart]=0;\r
1014                                 g_Git.StringAppend(&StatAdd,&log[pos],CP_UTF8);\r
1015                                 pos=tabstart+1;\r
1016                         }\r
1017 \r
1018                         tabstart=log.find('\t',pos);\r
1019                         if(tabstart >=0)\r
1020                         {\r
1021                                 log[tabstart]=0;\r
1022                                 \r
1023                                 g_Git.StringAppend(&StatDel,&log[pos],CP_UTF8);\r
1024                                 pos=tabstart+1;\r
1025                         }\r
1026                         \r
1027                         if(log[pos] == 0) //rename\r
1028                         {\r
1029                                 pos++;\r
1030                                 g_Git.StringAppend(&file2,&log[pos],CP_OEMCP);\r
1031                                 int sec=log.find(0,pos);\r
1032                                 if(sec>=0)\r
1033                                 {\r
1034                                         sec++;\r
1035                                         g_Git.StringAppend(&file1,&log[sec],CP_OEMCP);\r
1036                                 }\r
1037 \r
1038                         }else\r
1039                         {\r
1040                                 g_Git.StringAppend(&file1,&log[pos],CP_OEMCP);\r
1041                         }\r
1042                         path.SetFromGit(file1,&file2);\r
1043         \r
1044                         CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());\r
1045                         if(GitPath)\r
1046                         {\r
1047                                 GitPath->m_StatAdd=StatAdd;\r
1048                                 GitPath->m_StatDel=StatDel;\r
1049                         }else\r
1050                         {\r
1051                                 //path.SetFromGit(pathname);\r
1052                                 path.m_StatAdd=StatAdd;\r
1053                                 path.m_StatDel=StatDel;\r
1054                                 AddPath(path);\r
1055                         }\r
1056 \r
1057                 }\r
1058                 pos=log.findNextString(pos);\r
1059         }\r
1060         return pos;\r
1061 }\r
1062 \r
1063 void CTGitPathList::AddPath(const CTGitPath& newPath)\r
1064 {\r
1065         m_paths.push_back(newPath);\r
1066         m_commonBaseDirectory.Reset();\r
1067 }\r
1068 int CTGitPathList::GetCount() const\r
1069 {\r
1070         return (int)m_paths.size();\r
1071 }\r
1072 void CTGitPathList::Clear()\r
1073 {\r
1074         m_paths.clear();\r
1075         m_commonBaseDirectory.Reset();\r
1076 }\r
1077 \r
1078 const CTGitPath& CTGitPathList::operator[](INT_PTR index) const\r
1079 {\r
1080         ATLASSERT(index >= 0 && index < (INT_PTR)m_paths.size());\r
1081         return m_paths[index];\r
1082 }\r
1083 \r
1084 bool CTGitPathList::AreAllPathsFiles() const\r
1085 {\r
1086         // Look through the vector for any directories - if we find them, return false\r
1087         return std::find_if(m_paths.begin(), m_paths.end(), std::mem_fun_ref(&CTGitPath::IsDirectory)) == m_paths.end();\r
1088 }\r
1089 \r
1090 \r
1091 #if defined(_MFC_VER)\r
1092 \r
1093 bool CTGitPathList::LoadFromFile(const CTGitPath& filename)\r
1094 {\r
1095         Clear();\r
1096         try\r
1097         {\r
1098                 CString strLine;\r
1099                 CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite);\r
1100 \r
1101                 // for every selected file/folder\r
1102                 CTGitPath path;\r
1103                 while (file.ReadString(strLine))\r
1104                 {\r
1105                         path.SetFromUnknown(strLine);\r
1106                         AddPath(path);\r
1107                 }\r
1108                 file.Close();\r
1109         }\r
1110         catch (CFileException* pE)\r
1111         {\r
1112                 TRACE("CFileException loading target file list\n");\r
1113                 TCHAR error[10000] = {0};\r
1114                 pE->GetErrorMessage(error, 10000);\r
1115 //              CMessageBox::Show(NULL, error, _T("TortoiseGit"), MB_ICONERROR);\r
1116                 pE->Delete();\r
1117                 return false;\r
1118         }\r
1119         return true;\r
1120 }\r
1121 \r
1122 bool CTGitPathList::WriteToFile(const CString& sFilename, bool bANSI /* = false */) const\r
1123 {\r
1124         try\r
1125         {\r
1126                 if (bANSI)\r
1127                 {\r
1128                         CStdioFile file(sFilename, CFile::typeText | CFile::modeReadWrite | CFile::modeCreate);\r
1129                         PathVector::const_iterator it;\r
1130                         for(it = m_paths.begin(); it != m_paths.end(); ++it)\r
1131                         {\r
1132                                 CStringA line = CStringA(it->GetGitPathString()) + '\n';\r
1133                                 file.Write(line, line.GetLength());\r
1134                         } \r
1135                         file.Close();\r
1136                 }\r
1137                 else\r
1138                 {\r
1139                         CStdioFile file(sFilename, CFile::typeBinary | CFile::modeReadWrite | CFile::modeCreate);\r
1140                         PathVector::const_iterator it;\r
1141                         for(it = m_paths.begin(); it != m_paths.end(); ++it)\r
1142                         {\r
1143                                 file.WriteString(it->GetGitPathString()+_T("\n"));\r
1144                         } \r
1145                         file.Close();\r
1146                 }\r
1147         }\r
1148         catch (CFileException* pE)\r
1149         {\r
1150                 TRACE("CFileException in writing temp file\n");\r
1151                 pE->Delete();\r
1152                 return false;\r
1153         }\r
1154         return true;\r
1155 }\r
1156 \r
1157 \r
1158 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString& sPathString)\r
1159 {\r
1160         int pos = 0;\r
1161         CString temp;\r
1162         for(;;)\r
1163         {\r
1164                 temp = sPathString.Tokenize(_T("*"),pos);\r
1165                 if(temp.IsEmpty())\r
1166                 {\r
1167                         break;\r
1168                 }\r
1169                 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp)));\r
1170         } \r
1171 }\r
1172 \r
1173 CString CTGitPathList::CreateAsteriskSeparatedString() const\r
1174 {\r
1175         CString sRet;\r
1176         PathVector::const_iterator it;\r
1177         for(it = m_paths.begin(); it != m_paths.end(); ++it)\r
1178         {\r
1179                 if (!sRet.IsEmpty())\r
1180                         sRet += _T("*");\r
1181                 sRet += it->GetWinPathString();\r
1182         }\r
1183         return sRet;\r
1184 }\r
1185 #endif // _MFC_VER\r
1186 \r
1187 bool \r
1188 CTGitPathList::AreAllPathsFilesInOneDirectory() const\r
1189 {\r
1190         // Check if all the paths are files and in the same directory\r
1191         PathVector::const_iterator it;\r
1192         m_commonBaseDirectory.Reset();\r
1193         for(it = m_paths.begin(); it != m_paths.end(); ++it)\r
1194         {\r
1195                 if(it->IsDirectory())\r
1196                 {\r
1197                         return false;\r
1198                 }\r
1199                 const CTGitPath& baseDirectory = it->GetDirectory();\r
1200                 if(m_commonBaseDirectory.IsEmpty())\r
1201                 {\r
1202                         m_commonBaseDirectory = baseDirectory;\r
1203                 }\r
1204                 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))\r
1205                 {\r
1206                         // Different path\r
1207                         m_commonBaseDirectory.Reset();\r
1208                         return false;\r
1209                 }\r
1210         }\r
1211         return true;\r
1212 }\r
1213 \r
1214 CTGitPath CTGitPathList::GetCommonDirectory() const\r
1215 {\r
1216         if (m_commonBaseDirectory.IsEmpty())\r
1217         {\r
1218                 PathVector::const_iterator it;\r
1219                 for(it = m_paths.begin(); it != m_paths.end(); ++it)\r
1220                 {\r
1221                         const CTGitPath& baseDirectory = it->GetDirectory();\r
1222                         if(m_commonBaseDirectory.IsEmpty())\r
1223                         {\r
1224                                 m_commonBaseDirectory = baseDirectory;\r
1225                         }\r
1226                         else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))\r
1227                         {\r
1228                                 // Different path\r
1229                                 m_commonBaseDirectory.Reset();\r
1230                                 break;\r
1231                         }\r
1232                 }\r
1233         }\r
1234         // since we only checked strings, not paths,\r
1235         // we have to make sure now that we really return a *path* here\r
1236         PathVector::const_iterator iter;\r
1237         for(iter = m_paths.begin(); iter != m_paths.end(); ++iter)\r
1238         {\r
1239                 if (!m_commonBaseDirectory.IsAncestorOf(*iter))\r
1240                 {\r
1241                         m_commonBaseDirectory = m_commonBaseDirectory.GetContainingDirectory();\r
1242                         break;\r
1243                 }\r
1244         }       \r
1245         return m_commonBaseDirectory;\r
1246 }\r
1247 \r
1248 CTGitPath CTGitPathList::GetCommonRoot() const\r
1249 {\r
1250         PathVector::const_iterator it;\r
1251         CString sRoot, sTempRoot;\r
1252         bool bEqual = true;\r
1253 \r
1254         if (GetCount() == 1)\r
1255                 return m_paths[0];\r
1256 \r
1257         int backSlashPos = 0;\r
1258         int searchStartPos = 0;\r
1259         while (bEqual)\r
1260         {\r
1261                 for (it = m_paths.begin(); it != m_paths.end(); ++it)\r
1262                 {\r
1263                         if (backSlashPos == 0)\r
1264                         {\r
1265                                 backSlashPos = it->GetWinPathString().Find('\\', searchStartPos+1);\r
1266                                 if ((backSlashPos < 0)&&(searchStartPos != it->GetWinPathString().GetLength()))\r
1267                                         backSlashPos = it->GetWinPathString().GetLength();\r
1268                         }\r
1269                         else if (it->GetWinPathString().Find('\\', searchStartPos+1) != backSlashPos)\r
1270                         {\r
1271                                 if (it->GetWinPathString().Find('\\', searchStartPos+1) < 0)\r
1272                                 {\r
1273                                         if (it->GetWinPathString().GetLength() != backSlashPos)\r
1274                                         {\r
1275                                                 bEqual = false;\r
1276                                                 break;\r
1277                                         }\r
1278                                 }\r
1279                                 else\r
1280                                 {\r
1281                                         bEqual = false;\r
1282                                         break;\r
1283                                 }\r
1284                         }\r
1285                         if (backSlashPos < 0)\r
1286                         {\r
1287                                 bEqual = false;\r
1288                                 break;\r
1289                         }\r
1290                 }\r
1291                 if (bEqual == false)\r
1292                 {\r
1293                         if (searchStartPos)\r
1294                                 sRoot = m_paths[0].GetWinPathString().Left(searchStartPos+1);\r
1295                 }\r
1296                 else\r
1297                 {\r
1298                         searchStartPos = backSlashPos;\r
1299                 }\r
1300                 backSlashPos = 0;\r
1301         }\r
1302 \r
1303         return CTGitPath(sRoot.TrimRight('\\'));\r
1304 }\r
1305 \r
1306 void CTGitPathList::SortByPathname(bool bReverse /*= false*/)\r
1307 {\r
1308         std::sort(m_paths.begin(), m_paths.end());\r
1309         if (bReverse)\r
1310                 std::reverse(m_paths.begin(), m_paths.end());\r
1311 }\r
1312 \r
1313 void CTGitPathList::DeleteAllFiles(bool bTrash)\r
1314 {\r
1315         PathVector::const_iterator it;\r
1316         if (bTrash)\r
1317         {\r
1318                 SortByPathname();\r
1319                 CString sPaths;\r
1320                 for (it = m_paths.begin(); it != m_paths.end(); ++it)\r
1321                 {\r
1322                         if ((it->Exists())&&(!it->IsDirectory()))\r
1323                         {\r
1324                                 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);\r
1325                                 sPaths += it->GetWinPath();\r
1326                                 sPaths += '\0';\r
1327                         }\r
1328                 }\r
1329                 sPaths += '\0';\r
1330                 sPaths += '\0';\r
1331                 SHFILEOPSTRUCT shop = {0};\r
1332                 shop.wFunc = FO_DELETE;\r
1333                 shop.pFrom = (LPCTSTR)sPaths;\r
1334                 shop.fFlags = FOF_ALLOWUNDO|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;\r
1335                 SHFileOperation(&shop);\r
1336         }\r
1337         else\r
1338         {\r
1339                 for (it = m_paths.begin(); it != m_paths.end(); ++it)\r
1340                 {\r
1341                         if (!it->IsDirectory())\r
1342                         {\r
1343                                 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);\r
1344                                 ::DeleteFile(it->GetWinPath());\r
1345                         }\r
1346                 }\r
1347         }\r
1348         Clear();\r
1349 }\r
1350 \r
1351 void CTGitPathList::RemoveDuplicates()\r
1352 {\r
1353         SortByPathname();\r
1354         // Remove the duplicates\r
1355         // (Unique moves them to the end of the vector, then erase chops them off)\r
1356         m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::PredLeftEquivalentToRight), m_paths.end());\r
1357 }\r
1358 \r
1359 void CTGitPathList::RemoveAdminPaths()\r
1360 {\r
1361         PathVector::iterator it;\r
1362         for(it = m_paths.begin(); it != m_paths.end(); )\r
1363         {\r
1364                 if (it->IsAdminDir())\r
1365                 {\r
1366                         m_paths.erase(it);\r
1367                         it = m_paths.begin();\r
1368                 }\r
1369                 else\r
1370                         ++it;\r
1371         }\r
1372 }\r
1373 \r
1374 void CTGitPathList::RemovePath(const CTGitPath& path)\r
1375 {\r
1376         PathVector::iterator it;\r
1377         for(it = m_paths.begin(); it != m_paths.end(); ++it)\r
1378         {\r
1379                 if (it->IsEquivalentTo(path))\r
1380                 {\r
1381                         m_paths.erase(it);\r
1382                         return;\r
1383                 }\r
1384         }\r
1385 }\r
1386 \r
1387 void CTGitPathList::RemoveItem(CTGitPath & path)\r
1388 {\r
1389         PathVector::iterator it;\r
1390         for(it = m_paths.begin(); it != m_paths.end(); ++it)\r
1391         {\r
1392                 if (it->GetGitPathString()==path.GetGitPathString())\r
1393                 {\r
1394                         m_paths.erase(it);\r
1395                         return;\r
1396                 }\r
1397         }\r
1398 }\r
1399 void CTGitPathList::RemoveChildren()\r
1400 {\r
1401         SortByPathname();\r
1402         m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::CheckChild), m_paths.end());\r
1403 }\r
1404 \r
1405 bool CTGitPathList::IsEqual(const CTGitPathList& list)\r
1406 {\r
1407         if (list.GetCount() != GetCount())\r
1408                 return false;\r
1409         for (int i=0; i<list.GetCount(); ++i)\r
1410         {\r
1411                 if (!list[i].IsEquivalentTo(m_paths[i]))\r
1412                         return false;\r
1413         }\r
1414         return true;\r
1415 }\r
1416 \r
1417 //////////////////////////////////////////////////////////////////////////\r
1418 #if 0\r
1419 apr_array_header_t * CTGitPathList::MakePathArray (apr_pool_t *pool) const\r
1420 {\r
1421         apr_array_header_t *targets = apr_array_make (pool, GetCount(), sizeof(const char *));\r
1422 \r
1423         for(int nItem = 0; nItem < GetCount(); nItem++)\r
1424         {\r
1425                 const char * target = m_paths[nItem].GetGitApiPath(pool);\r
1426                 (*((const char **) apr_array_push (targets))) = target;\r
1427         }\r
1428 \r
1429         return targets;\r
1430 }\r
1431 #endif\r
1432 //////////////////////////////////////////////////////////////////////////\r
1433 \r
1434 #if 0\r
1435 #if defined(_DEBUG)\r
1436 // Some test cases for these classes\r
1437 static class CTGitPathTests\r
1438 {\r
1439 public:\r
1440         CTGitPathTests()\r
1441         {\r
1442                 apr_initialize();\r
1443                 pool = svn_pool_create(NULL);\r
1444                 GetDirectoryTest();\r
1445                 AdminDirTest();\r
1446                 SortTest();\r
1447                 RawAppendTest();\r
1448                 PathAppendTest();\r
1449                 RemoveDuplicatesTest();\r
1450                 RemoveChildrenTest();\r
1451                 ContainingDirectoryTest();\r
1452                 AncestorTest();\r
1453                 SubversionPathTest();\r
1454                 GetCommonRootTest();\r
1455 #if defined(_MFC_VER)\r
1456                 ValidPathAndUrlTest();\r
1457                 ListLoadingTest();\r
1458 #endif\r
1459                 apr_terminate();\r
1460         }\r
1461 \r
1462 private:\r
1463 //      apr_pool_t * pool;\r
1464         void GetDirectoryTest()\r
1465         {\r
1466                 // Bit tricky, this test, because we need to know something about the file\r
1467                 // layout on the machine which is running the test\r
1468                 TCHAR winDir[MAX_PATH+1];\r
1469                 GetWindowsDirectory(winDir, MAX_PATH);\r
1470                 CString sWinDir(winDir);\r
1471 \r
1472                 CTGitPath testPath;\r
1473                 // This is a file which we know will always be there\r
1474                 testPath.SetFromUnknown(sWinDir + _T("\\win.ini"));\r
1475                 ATLASSERT(!testPath.IsDirectory());\r
1476                 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);\r
1477                 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() == sWinDir);\r
1478 \r
1479                 // Now do the test on the win directory itself - It's hard to be sure about the containing directory\r
1480                 // but we know it must be different to the directory itself\r
1481                 testPath.SetFromUnknown(sWinDir);\r
1482                 ATLASSERT(testPath.IsDirectory());\r
1483                 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);\r
1484                 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() != sWinDir);\r
1485                 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString().GetLength() < sWinDir.GetLength());\r
1486 \r
1487                 // Try a root path\r
1488                 testPath.SetFromUnknown(_T("C:\\"));\r
1489                 ATLASSERT(testPath.IsDirectory());\r
1490                 ATLASSERT(testPath.GetDirectory().GetWinPathString().CompareNoCase(_T("C:\\"))==0);\r
1491                 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());\r
1492                 // Try a root UNC path\r
1493                 testPath.SetFromUnknown(_T("\\MYSTATION"));\r
1494                 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());\r
1495         }\r
1496 \r
1497         void AdminDirTest()\r
1498         {\r
1499                 CTGitPath testPath;\r
1500                 testPath.SetFromUnknown(_T("c:\\.svndir"));\r
1501                 ATLASSERT(!testPath.IsAdminDir());\r
1502                 testPath.SetFromUnknown(_T("c:\\test.svn"));\r
1503                 ATLASSERT(!testPath.IsAdminDir());\r
1504                 testPath.SetFromUnknown(_T("c:\\.svn"));\r
1505                 ATLASSERT(testPath.IsAdminDir());\r
1506                 testPath.SetFromUnknown(_T("c:\\.svndir\\test"));\r
1507                 ATLASSERT(!testPath.IsAdminDir());\r
1508                 testPath.SetFromUnknown(_T("c:\\.svn\\test"));\r
1509                 ATLASSERT(testPath.IsAdminDir());\r
1510                 \r
1511                 CTGitPathList pathList;\r
1512                 pathList.AddPath(CTGitPath(_T("c:\\.svndir")));\r
1513                 pathList.AddPath(CTGitPath(_T("c:\\.svn")));\r
1514                 pathList.AddPath(CTGitPath(_T("c:\\.svn\\test")));\r
1515                 pathList.AddPath(CTGitPath(_T("c:\\test")));\r
1516                 pathList.RemoveAdminPaths();\r
1517                 ATLASSERT(pathList.GetCount()==2);\r
1518                 pathList.Clear();\r
1519                 pathList.AddPath(CTGitPath(_T("c:\\test")));\r
1520                 pathList.RemoveAdminPaths();\r
1521                 ATLASSERT(pathList.GetCount()==1);\r
1522         }\r
1523         \r
1524         void SortTest()\r
1525         {\r
1526                 CTGitPathList testList;\r
1527                 CTGitPath testPath;\r
1528                 testPath.SetFromUnknown(_T("c:/Z"));\r
1529                 testList.AddPath(testPath);\r
1530                 testPath.SetFromUnknown(_T("c:/B"));\r
1531                 testList.AddPath(testPath);\r
1532                 testPath.SetFromUnknown(_T("c:\\a"));\r
1533                 testList.AddPath(testPath);\r
1534                 testPath.SetFromUnknown(_T("c:/Test"));\r
1535                 testList.AddPath(testPath);\r
1536 \r
1537                 testList.SortByPathname();\r
1538 \r
1539                 ATLASSERT(testList[0].GetWinPathString() == _T("c:\\a"));\r
1540                 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\B"));\r
1541                 ATLASSERT(testList[2].GetWinPathString() == _T("c:\\Test"));\r
1542                 ATLASSERT(testList[3].GetWinPathString() == _T("c:\\Z"));\r
1543         }\r
1544 \r
1545         void RawAppendTest()\r
1546         {\r
1547                 CTGitPath testPath(_T("c:/test/"));\r
1548                 testPath.AppendRawString(_T("/Hello"));\r
1549                 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));\r
1550 \r
1551                 testPath.AppendRawString(_T("\\T2"));\r
1552                 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));\r
1553 \r
1554                 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));\r
1555                 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));\r
1556                 testBasePath.AppendRawString(testFilePath.GetFileExtension());\r
1557                 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt.ini"));\r
1558         }\r
1559 \r
1560         void PathAppendTest()\r
1561         {\r
1562                 CTGitPath testPath(_T("c:/test/"));\r
1563                 testPath.AppendPathString(_T("/Hello"));\r
1564                 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));\r
1565 \r
1566                 testPath.AppendPathString(_T("T2"));\r
1567                 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));\r
1568 \r
1569                 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));\r
1570                 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));\r
1571                 // You wouldn't want to do this in real life - you'd use append-raw\r
1572                 testBasePath.AppendPathString(testFilePath.GetFileExtension());\r
1573                 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt\\.ini"));\r
1574         }\r
1575 \r
1576         void RemoveDuplicatesTest()\r
1577         {\r
1578                 CTGitPathList list;\r
1579                 list.AddPath(CTGitPath(_T("Z")));\r
1580                 list.AddPath(CTGitPath(_T("A")));\r
1581                 list.AddPath(CTGitPath(_T("E")));\r
1582                 list.AddPath(CTGitPath(_T("E")));\r
1583 \r
1584                 ATLASSERT(list[2].IsEquivalentTo(list[3]));\r
1585                 ATLASSERT(list[2]==list[3]);\r
1586                 \r
1587                 ATLASSERT(list.GetCount() == 4);\r
1588 \r
1589                 list.RemoveDuplicates();\r
1590 \r
1591                 ATLASSERT(list.GetCount() == 3);\r
1592 \r
1593                 ATLASSERT(list[0].GetWinPathString() == _T("A"));\r
1594                 ATLASSERT(list[1].GetWinPathString().Compare(_T("E")) == 0);\r
1595                 ATLASSERT(list[2].GetWinPathString() == _T("Z"));\r
1596         }\r
1597         \r
1598         void RemoveChildrenTest()\r
1599         {\r
1600                 CTGitPathList list;\r
1601                 list.AddPath(CTGitPath(_T("c:\\test")));\r
1602                 list.AddPath(CTGitPath(_T("c:\\test\\file")));\r
1603                 list.AddPath(CTGitPath(_T("c:\\testfile")));\r
1604                 list.AddPath(CTGitPath(_T("c:\\parent")));\r
1605                 list.AddPath(CTGitPath(_T("c:\\parent\\child")));\r
1606                 list.AddPath(CTGitPath(_T("c:\\parent\\child1")));\r
1607                 list.AddPath(CTGitPath(_T("c:\\parent\\child2")));\r
1608                 \r
1609                 ATLASSERT(list.GetCount() == 7);\r
1610 \r
1611                 list.RemoveChildren();\r
1612                 \r
1613                 ATLTRACE("count = %d\n", list.GetCount());\r
1614                 ATLASSERT(list.GetCount() == 3);\r
1615 \r
1616                 list.SortByPathname();\r
1617 \r
1618                 ATLASSERT(list[0].GetWinPathString().Compare(_T("c:\\parent")) == 0);\r
1619                 ATLASSERT(list[1].GetWinPathString().Compare(_T("c:\\test")) == 0);\r
1620                 ATLASSERT(list[2].GetWinPathString().Compare(_T("c:\\testfile")) == 0);\r
1621         }\r
1622 \r
1623 #if defined(_MFC_VER)\r
1624         void ListLoadingTest()\r
1625         {\r
1626                 TCHAR buf[MAX_PATH];\r
1627                 GetCurrentDirectory(MAX_PATH, buf);\r
1628                 CString sPathList(_T("Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"));\r
1629                 CTGitPathList testList;\r
1630                 testList.LoadFromAsteriskSeparatedString(sPathList);\r
1631 \r
1632                 ATLASSERT(testList.GetCount() == 3);\r
1633                 ATLASSERT(testList[0].GetWinPathString() == CString(buf) + _T("\\Path1"));\r
1634                 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\path2 with spaces and stuff"));\r
1635                 ATLASSERT(testList[2].GetWinPathString() == _T("\\funnypath"));\r
1636                 \r
1637                 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T(""));\r
1638                 testList.Clear();\r
1639                 sPathList = _T("c:\\path2 with spaces and stuff*c:\\funnypath\\*");\r
1640                 testList.LoadFromAsteriskSeparatedString(sPathList);\r
1641                 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T("c:\\"));\r
1642         }\r
1643 #endif \r
1644 \r
1645         void ContainingDirectoryTest()\r
1646         {\r
1647 \r
1648                 CTGitPath testPath;\r
1649                 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));\r
1650                 CTGitPath dir;\r
1651                 dir = testPath.GetContainingDirectory();\r
1652                 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c\\d"));\r
1653                 dir = dir.GetContainingDirectory();\r
1654                 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c"));\r
1655                 dir = dir.GetContainingDirectory();\r
1656                 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b"));\r
1657                 dir = dir.GetContainingDirectory();\r
1658                 ATLASSERT(dir.GetWinPathString() == _T("c:\\a"));\r
1659                 dir = dir.GetContainingDirectory();\r
1660                 ATLASSERT(dir.GetWinPathString() == _T("c:\\"));\r
1661                 dir = dir.GetContainingDirectory();\r
1662                 ATLASSERT(dir.IsEmpty());\r
1663                 ATLASSERT(dir.GetWinPathString() == _T(""));\r
1664         }\r
1665         \r
1666         void AncestorTest()\r
1667         {\r
1668                 CTGitPath testPath;\r
1669                 testPath.SetFromWin(_T("c:\\windows"));\r
1670                 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\")))==false);\r
1671                 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows"))));\r
1672                 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windowsdummy")))==false);\r
1673                 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\test.txt"))));\r
1674                 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\system32\\test.txt"))));\r
1675         }\r
1676 \r
1677         void SubversionPathTest()\r
1678         {\r
1679                 CTGitPath testPath;\r
1680                 testPath.SetFromWin(_T("c:\\"));\r
1681                 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:") == 0);\r
1682                 testPath.SetFromWin(_T("c:\\folder"));\r
1683                 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);\r
1684                 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));\r
1685                 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);\r
1686                 testPath.SetFromUnknown(_T("http://testing/"));\r
1687                 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);\r
1688                 testPath.SetFromGit(NULL);\r
1689                 ATLASSERT(strlen(testPath.GetGitApiPath(pool))==0);\r
1690 #if defined(_MFC_VER)\r
1691                 testPath.SetFromUnknown(_T("http://testing again"));\r
1692                 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);\r
1693                 testPath.SetFromUnknown(_T("http://testing%20again"));\r
1694                 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);\r
1695                 testPath.SetFromUnknown(_T("http://testing special chars \344\366\374"));\r
1696                 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);          \r
1697 #endif\r
1698         }\r
1699 \r
1700         void GetCommonRootTest()\r
1701         {\r
1702                 CTGitPath pathA (_T("C:\\Development\\LogDlg.cpp"));\r
1703                 CTGitPath pathB (_T("C:\\Development\\LogDlg.h"));\r
1704                 CTGitPath pathC (_T("C:\\Development\\SomeDir\\LogDlg.h"));\r
1705                 \r
1706                 CTGitPathList list;\r
1707                 list.AddPath(pathA);\r
1708                 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development\\LogDlg.cpp"))==0);\r
1709                 list.AddPath(pathB);\r
1710                 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);\r
1711                 list.AddPath(pathC);\r
1712                 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);\r
1713 #ifdef _MFC_VER\r
1714                 list.Clear();\r
1715                 CString sPathList = _T("D:\\Development\\StExBar\\StExBar\\src\\setup\\Setup64.wxs*D:\\Development\\StExBar\\StExBar\\src\\setup\\Setup.wxs*D:\\Development\\StExBar\\SKTimeStamp\\src\\setup\\Setup.wxs*D:\\Development\\StExBar\\SKTimeStamp\\src\\setup\\Setup64.wxs");\r
1716                 list.LoadFromAsteriskSeparatedString(sPathList);\r
1717                 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("D:\\Development\\StExBar"))==0);\r
1718 \r
1719                 list.Clear();\r
1720                 sPathList = _T("c:\\windows\\explorer.exe*c:\\windows");\r
1721                 list.LoadFromAsteriskSeparatedString(sPathList);\r
1722                 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);\r
1723 \r
1724                 list.Clear();\r
1725                 sPathList = _T("c:\\windows\\*c:\\windows");\r
1726                 list.LoadFromAsteriskSeparatedString(sPathList);\r
1727                 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);\r
1728 \r
1729                 list.Clear();\r
1730                 sPathList = _T("c:\\windows\\system32*c:\\windows\\system");\r
1731                 list.LoadFromAsteriskSeparatedString(sPathList);\r
1732                 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);\r
1733 \r
1734                 list.Clear();\r
1735                 sPathList = _T("c:\\windowsdummy*c:\\windows");\r
1736                 list.LoadFromAsteriskSeparatedString(sPathList);\r
1737                 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\"))==0);\r
1738 #endif\r
1739         }\r
1740         \r
1741         void ValidPathAndUrlTest()\r
1742         {\r
1743                 CTGitPath testPath;\r
1744                 testPath.SetFromWin(_T("c:\\a\\b\\c.test.txt"));\r
1745                 ATLASSERT(testPath.IsValidOnWindows());\r
1746                 testPath.SetFromWin(_T("c:\\"));\r
1747                 ATLASSERT(testPath.IsValidOnWindows());\r
1748                 testPath.SetFromWin(_T("D:\\.Net\\SpindleSearch\\"));\r
1749                 ATLASSERT(testPath.IsValidOnWindows());\r
1750                 testPath.SetFromWin(_T("c"));\r
1751                 ATLASSERT(testPath.IsValidOnWindows());\r
1752                 testPath.SetFromWin(_T("c:\\test folder\\file"));\r
1753                 ATLASSERT(testPath.IsValidOnWindows());\r
1754                 testPath.SetFromWin(_T("c:\\folder\\"));\r
1755                 ATLASSERT(testPath.IsValidOnWindows());\r
1756                 testPath.SetFromWin(_T("c:\\ext.ext.ext\\ext.ext.ext.ext"));\r
1757                 ATLASSERT(testPath.IsValidOnWindows());\r
1758                 testPath.SetFromWin(_T("c:\\.svn"));\r
1759                 ATLASSERT(testPath.IsValidOnWindows());\r
1760                 testPath.SetFromWin(_T("c:\\com\\file"));\r
1761                 ATLASSERT(testPath.IsValidOnWindows());\r
1762                 testPath.SetFromWin(_T("c:\\test\\conf"));\r
1763                 ATLASSERT(testPath.IsValidOnWindows());\r
1764                 testPath.SetFromWin(_T("c:\\LPT"));\r
1765                 ATLASSERT(testPath.IsValidOnWindows());\r
1766                 testPath.SetFromWin(_T("c:\\test\\LPT"));\r
1767                 ATLASSERT(testPath.IsValidOnWindows());\r
1768                 testPath.SetFromWin(_T("c:\\com1test"));\r
1769                 ATLASSERT(testPath.IsValidOnWindows());\r
1770                 testPath.SetFromWin(_T("\\\\?\\c:\\test\\com1test"));\r
1771                 ATLASSERT(testPath.IsValidOnWindows());\r
1772 \r
1773                 testPath.SetFromWin(_T("\\\\Share\\filename"));\r
1774                 ATLASSERT(testPath.IsValidOnWindows());\r
1775                 testPath.SetFromWin(_T("\\\\Share\\filename.extension"));\r
1776                 ATLASSERT(testPath.IsValidOnWindows());\r
1777                 testPath.SetFromWin(_T("\\\\Share\\.svn"));\r
1778                 ATLASSERT(testPath.IsValidOnWindows());\r
1779 \r
1780                 // now the negative tests\r
1781                 testPath.SetFromWin(_T("c:\\test:folder"));\r
1782                 ATLASSERT(!testPath.IsValidOnWindows());\r
1783                 testPath.SetFromWin(_T("c:\\file<name"));\r
1784                 ATLASSERT(!testPath.IsValidOnWindows());\r
1785                 testPath.SetFromWin(_T("c:\\something*else"));\r
1786                 ATLASSERT(!testPath.IsValidOnWindows());\r
1787                 testPath.SetFromWin(_T("c:\\folder\\file?nofile"));\r
1788                 ATLASSERT(!testPath.IsValidOnWindows());\r
1789                 testPath.SetFromWin(_T("c:\\ext.>ension"));\r
1790                 ATLASSERT(!testPath.IsValidOnWindows());\r
1791                 testPath.SetFromWin(_T("c:\\com1\\filename"));\r
1792                 ATLASSERT(!testPath.IsValidOnWindows());\r
1793                 testPath.SetFromWin(_T("c:\\com1"));\r
1794                 ATLASSERT(!testPath.IsValidOnWindows());\r
1795                 testPath.SetFromWin(_T("c:\\com1\\AuX"));\r
1796                 ATLASSERT(!testPath.IsValidOnWindows());\r
1797 \r
1798                 testPath.SetFromWin(_T("\\\\Share\\lpt9\\filename"));\r
1799                 ATLASSERT(!testPath.IsValidOnWindows());\r
1800                 testPath.SetFromWin(_T("\\\\Share\\prn"));\r
1801                 ATLASSERT(!testPath.IsValidOnWindows());\r
1802                 testPath.SetFromWin(_T("\\\\Share\\NUL"));\r
1803                 ATLASSERT(!testPath.IsValidOnWindows());\r
1804                 \r
1805                 // now come some URL tests\r
1806                 testPath.SetFromGit(_T("http://myserver.com/repos/trunk"));\r
1807                 ATLASSERT(testPath.IsValidOnWindows());\r
1808                 testPath.SetFromGit(_T("https://myserver.com/repos/trunk/file%20with%20spaces"));\r
1809                 ATLASSERT(testPath.IsValidOnWindows());\r
1810                 testPath.SetFromGit(_T("svn://myserver.com/repos/trunk/file with spaces"));\r
1811                 ATLASSERT(testPath.IsValidOnWindows());\r
1812                 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk"));\r
1813                 ATLASSERT(testPath.IsValidOnWindows());\r
1814                 testPath.SetFromGit(_T("http://localhost:90/repos/trunk"));\r
1815                 ATLASSERT(testPath.IsValidOnWindows());\r
1816                 testPath.SetFromGit(_T("file:///C:/GitRepos/Tester/Proj1/tags/t2"));\r
1817                 ATLASSERT(testPath.IsValidOnWindows());\r
1818                 // and some negative URL tests\r
1819                 testPath.SetFromGit(_T("httpp://myserver.com/repos/trunk"));\r
1820                 ATLASSERT(!testPath.IsValidOnWindows());\r
1821                 testPath.SetFromGit(_T("https://myserver.com/rep:os/trunk/file%20with%20spaces"));\r
1822                 ATLASSERT(!testPath.IsValidOnWindows());\r
1823                 testPath.SetFromGit(_T("svn://myserver.com/rep<os/trunk/file with spaces"));\r
1824                 ATLASSERT(!testPath.IsValidOnWindows());\r
1825                 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk/prn/"));\r
1826                 ATLASSERT(!testPath.IsValidOnWindows());\r
1827                 testPath.SetFromGit(_T("http://localhost:90/repos/trunk/com1"));\r
1828                 ATLASSERT(!testPath.IsValidOnWindows());\r
1829                 \r
1830         }\r
1831 \r
1832 } TGitPathTestobject;\r
1833 #endif\r
1834 #endif\r
1835 \r
1836 CTGitPath * CTGitPathList::LookForGitPath(CString path)\r
1837 {\r
1838         int i=0;\r
1839         for(i=0;i<this->GetCount();i++)\r
1840         {\r
1841                 if((*this)[i].GetGitPathString() == path )\r
1842                         return (CTGitPath*)&(*this)[i];\r
1843         }\r
1844         return NULL;\r
1845 }\r
1846 \r
1847 CString CTGitPath::GetActionName()\r
1848 {\r
1849         if(m_Action  & CTGitPath::LOGACTIONS_ADDED)\r
1850                 return _T("Added");\r
1851         if(m_Action  & CTGitPath::LOGACTIONS_DELETED)\r
1852                 return _T("Deleted");\r
1853         if(m_Action  & CTGitPath::LOGACTIONS_UNMERGED)\r
1854                 return _T("Conflict");\r
1855         if(m_Action  & CTGitPath::LOGACTIONS_MODIFIED)\r
1856                 return _T("Modified");\r
1857         if(m_Action  & CTGitPath::LOGACTIONS_REPLACED)\r
1858                 return _T("Rename");\r
1859         return _T("Unknown");\r
1860 }\r
1861 \r
1862 int CTGitPathList::GetAction()\r
1863 {\r
1864         return m_Action;\r
1865 }\r