OSDN Git Service

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