1 // TortoiseGit - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseGit
\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
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
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
20 #include "TGitPath.h"
\r
21 #include "UnicodeUtils.h"
\r
22 #include "GitAdminDir.h"
\r
23 #include "PathUtils.h"
\r
26 #if defined(_MFC_VER)
\r
27 //#include "MessageBox.h"
\r
28 //#include "AppUtils.h"
\r
34 using namespace std;
\r
37 CTGitPath::CTGitPath(void) :
\r
38 m_bDirectoryKnown(false),
\r
39 m_bIsDirectory(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
49 m_bExistsKnown(false),
\r
50 m_bLastWriteTimeKnown(0),
\r
53 m_bIsSpecialDirectoryKnown(false),
\r
54 m_bIsSpecialDirectory(false)
\r
59 CTGitPath::~CTGitPath(void)
\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
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
75 m_bExistsKnown(false),
\r
76 m_bLastWriteTimeKnown(0),
\r
79 m_bIsSpecialDirectoryKnown(false),
\r
80 m_bIsSpecialDirectory(false)
\r
82 SetFromUnknown(sUnknownPath);
\r
86 int CTGitPath::ParserAction(BYTE action)
\r
88 //action=action.TrimLeft();
\r
89 //TCHAR c=action.GetAt(0);
\r
91 m_Action|= LOGACTIONS_MODIFIED;
\r
93 m_Action|= LOGACTIONS_REPLACED;
\r
95 m_Action|= LOGACTIONS_ADDED;
\r
97 m_Action|= LOGACTIONS_DELETED;
\r
99 m_Action|= LOGACTIONS_UNMERGED;
\r
103 void CTGitPath::SetFromGit(const char* pPath)
\r
108 int len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, NULL, 0);
\r
111 len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, m_sFwdslashPath.GetBuffer(len+1), len+1);
\r
112 m_sFwdslashPath.ReleaseBuffer(len-1);
\r
114 SanitizeRootPath(m_sFwdslashPath, true);
\r
117 void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
\r
120 m_bDirectoryKnown = true;
\r
121 m_bIsDirectory = bIsDirectory;
\r
124 void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)
\r
127 m_sFwdslashPath = sPath;
\r
128 SanitizeRootPath(m_sFwdslashPath, true);
\r
130 m_sOldFwdslashPath = *oldpath;
\r
133 void CTGitPath::SetFromWin(LPCTSTR pPath)
\r
136 m_sBackslashPath = pPath;
\r
137 SanitizeRootPath(m_sBackslashPath, false);
\r
138 ATLASSERT(m_sBackslashPath.Find('/')<0);
\r
140 void CTGitPath::SetFromWin(const CString& sPath)
\r
143 m_sBackslashPath = sPath;
\r
144 SanitizeRootPath(m_sBackslashPath, false);
\r
146 void CTGitPath::SetFromWin(const CString& sPath, bool bIsDirectory)
\r
149 m_sBackslashPath = sPath;
\r
150 m_bIsDirectory = bIsDirectory;
\r
151 m_bDirectoryKnown = true;
\r
152 SanitizeRootPath(m_sBackslashPath, false);
\r
154 void CTGitPath::SetFromUnknown(const CString& sPath)
\r
157 // Just set whichever path we think is most likely to be used
\r
158 // GitAdminDir admin;
\r
160 // if(admin.HasAdminDir(sPath,&p))
\r
161 // SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));
\r
163 SetFwdslashPath(sPath);
\r
166 LPCTSTR CTGitPath::GetWinPath() const
\r
172 if(m_sBackslashPath.IsEmpty())
\r
174 SetBackslashPath(m_sFwdslashPath);
\r
176 return m_sBackslashPath;
\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
182 if(m_sBackslashPath.IsEmpty())
\r
184 SetBackslashPath(m_sFwdslashPath);
\r
186 return m_sBackslashPath;
\r
189 const CString& CTGitPath::GetGitPathString() const
\r
191 if(m_sFwdslashPath.IsEmpty())
\r
193 SetFwdslashPath(m_sBackslashPath);
\r
195 return m_sFwdslashPath;
\r
198 const CString &CTGitPath::GetGitOldPathString() const
\r
200 return m_sOldFwdslashPath;
\r
203 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const
\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
214 if(m_sFwdslashPath.IsEmpty())
\r
216 SetFwdslashPath(m_sBackslashPath);
\r
218 if(m_sUTF8FwdslashPath.IsEmpty())
\r
220 SetUTF8FwdslashPath(m_sFwdslashPath);
\r
222 if (svn_path_is_url(m_sUTF8FwdslashPath))
\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
229 m_sUTF8FwdslashPath = svn_path_canonicalize(m_sUTF8FwdslashPath, pool);
\r
231 return m_sUTF8FwdslashPath;
\r
235 const CString& CTGitPath::GetUIPathString() const
\r
237 if (m_sUIPath.IsEmpty())
\r
239 #if defined(_MFC_VER)
\r
240 //BUGBUG HORRIBLE!!! - CPathUtils::IsEscaped doesn't need to be MFC-only
\r
243 m_sUIPath = CPathUtils::PathUnescape(GetGitPathString());
\r
244 m_sUIPath.Replace(_T("file:////"), _T("file:///\\"));
\r
250 m_sUIPath = GetWinPathString();
\r
256 void CTGitPath::SetFwdslashPath(const CString& sPath) const
\r
258 m_sFwdslashPath = sPath;
\r
259 m_sFwdslashPath.Replace('\\', '/');
\r
261 // We don't leave a trailing /
\r
262 m_sFwdslashPath.TrimRight('/');
\r
264 SanitizeRootPath(m_sFwdslashPath, true);
\r
266 m_sFwdslashPath.Replace(_T("file:////"), _T("file:///\\"));
\r
268 m_sUTF8FwdslashPath.Empty();
\r
271 void CTGitPath::SetBackslashPath(const CString& sPath) const
\r
273 m_sBackslashPath = sPath;
\r
274 m_sBackslashPath.Replace('/', '\\');
\r
275 m_sBackslashPath.TrimRight('\\');
\r
276 SanitizeRootPath(m_sBackslashPath, false);
\r
279 void CTGitPath::SetUTF8FwdslashPath(const CString& sPath) const
\r
281 m_sUTF8FwdslashPath = CUnicodeUtils::GetUTF8(sPath);
\r
284 void CTGitPath::SanitizeRootPath(CString& sPath, bool bIsForwardPath) const
\r
286 // Make sure to add the trailing slash to root paths such as 'C:'
\r
287 if (sPath.GetLength() == 2 && sPath[1] == ':')
\r
289 sPath += (bIsForwardPath) ? _T("/") : _T("\\");
\r
293 bool CTGitPath::IsUrl() const
\r
298 EnsureFwdslashPathSet();
\r
299 if(m_sUTF8FwdslashPath.IsEmpty())
\r
301 SetUTF8FwdslashPath(m_sFwdslashPath);
\r
303 m_bIsURL = !!svn_path_is_url(m_sUTF8FwdslashPath);
\r
304 m_bURLKnown = true;
\r
311 bool CTGitPath::IsDirectory() const
\r
313 if(!m_bDirectoryKnown)
\r
315 UpdateAttributes();
\r
317 return m_bIsDirectory;
\r
320 bool CTGitPath::Exists() const
\r
322 if (!m_bExistsKnown)
\r
324 UpdateAttributes();
\r
329 bool CTGitPath::Delete(bool bTrash) const
\r
331 EnsureBackslashPathSet();
\r
332 ::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);
\r
336 if ((bTrash)||(IsDirectory()))
\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
345 shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
\r
347 shop.fFlags |= FOF_ALLOWUNDO;
\r
348 bRet = (SHFileOperation(&shop) == 0);
\r
353 bRet = !!::DeleteFile(m_sBackslashPath);
\r
357 m_bExistsKnown = true;
\r
361 __int64 CTGitPath::GetLastWriteTime() const
\r
363 if(!m_bLastWriteTimeKnown)
\r
365 UpdateAttributes();
\r
367 return m_lastWriteTime;
\r
370 bool CTGitPath::IsReadOnly() const
\r
372 if(!m_bLastWriteTimeKnown)
\r
374 UpdateAttributes();
\r
376 return m_bIsReadOnly;
\r
379 void CTGitPath::UpdateAttributes() const
\r
381 EnsureBackslashPathSet();
\r
382 WIN32_FILE_ATTRIBUTE_DATA attribs;
\r
383 if(GetFileAttributesEx(m_sBackslashPath, GetFileExInfoStandard, &attribs))
\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
392 DWORD err = GetLastError();
\r
393 if ((err == ERROR_FILE_NOT_FOUND)||(err == ERROR_PATH_NOT_FOUND)||(err == ERROR_INVALID_NAME))
\r
395 m_bIsDirectory = false;
\r
396 m_lastWriteTime = 0;
\r
401 m_bIsDirectory = false;
\r
402 m_lastWriteTime = 0;
\r
407 m_bDirectoryKnown = true;
\r
408 m_bLastWriteTimeKnown = true;
\r
409 m_bExistsKnown = true;
\r
413 void CTGitPath::EnsureBackslashPathSet() const
\r
415 if(m_sBackslashPath.IsEmpty())
\r
417 SetBackslashPath(m_sFwdslashPath);
\r
418 ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());
\r
421 void CTGitPath::EnsureFwdslashPathSet() const
\r
423 if(m_sFwdslashPath.IsEmpty())
\r
425 SetFwdslashPath(m_sBackslashPath);
\r
426 ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());
\r
431 // Reset all the caches
\r
432 void CTGitPath::Reset()
\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
444 m_sBackslashPath.Empty();
\r
445 m_sFwdslashPath.Empty();
\r
446 m_sUTF8FwdslashPath.Empty();
\r
448 this->m_StatAdd=_T("");
\r
449 this->m_StatDel=_T("");
\r
450 ATLASSERT(IsEmpty());
\r
453 CTGitPath CTGitPath::GetDirectory() const
\r
455 if ((IsDirectory())||(!Exists()))
\r
459 return GetContainingDirectory();
\r
462 CTGitPath CTGitPath::GetContainingDirectory() const
\r
464 EnsureBackslashPathSet();
\r
466 CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));
\r
467 if(sDirName.GetLength() == 2 && sDirName[1] == ':')
\r
469 // This is a root directory, which needs a trailing slash
\r
471 if(sDirName == m_sBackslashPath)
\r
473 // We were clearly provided with a root path to start with - we should return nothing now
\r
477 if(sDirName.GetLength() == 1 && sDirName[0] == '\\')
\r
479 // We have an UNC path and we already are the root
\r
483 retVal.SetFromWin(sDirName);
\r
487 CString CTGitPath::GetRootPathString() const
\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
498 CString CTGitPath::GetFilename() const
\r
500 ATLASSERT(!IsDirectory());
\r
501 return GetFileOrDirectoryName();
\r
504 CString CTGitPath::GetFileOrDirectoryName() const
\r
506 EnsureBackslashPathSet();
\r
507 return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);
\r
510 CString CTGitPath::GetUIFileOrDirectoryName() const
\r
513 return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);
\r
516 CString CTGitPath::GetFileExtension() const
\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
528 CString CTGitPath::GetBaseFilename() const
\r
531 CString filename=GetFilename();
\r
532 dot = filename.ReverseFind(_T('.'));
\r
534 return filename.Left(dot-1);
\r
539 bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)
\r
541 int length = sP1.GetLength();
\r
542 if(length != sP2.GetLength())
\r
544 // Different lengths
\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
554 if(_totlower(*pP1--) != _totlower(*pP2--))
\r
562 bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)
\r
564 int length = sP1.GetLength();
\r
565 if(length != sP2.GetLength())
\r
567 // Different lengths
\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
577 if((*pP1--) != (*pP2--))
\r
585 bool CTGitPath::IsEmpty() const
\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
590 return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();
\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
597 // Try and find a slash direction which avoids having to convert
\r
599 if(!m_sBackslashPath.IsEmpty())
\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
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
613 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const
\r
615 // Try and find a slash direction which avoids having to convert
\r
617 if(!m_sBackslashPath.IsEmpty())
\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
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
631 bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const
\r
633 possibleDescendant.EnsureBackslashPathSet();
\r
634 EnsureBackslashPathSet();
\r
636 bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));
\r
637 if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())
\r
639 return bPathStringsEqual;
\r
642 return (bPathStringsEqual &&
\r
643 ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||
\r
644 (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));
\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
651 EnsureFwdslashPathSet();
\r
652 if(pOptionalBasePath != NULL)
\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
657 // Now, chop that baseLength of the front of the path
\r
658 return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');
\r
660 return m_sFwdslashPath;
\r
663 int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)
\r
665 left.EnsureBackslashPathSet();
\r
666 right.EnsureBackslashPathSet();
\r
667 return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);
\r
670 bool operator<(const CTGitPath& left, const CTGitPath& right)
\r
672 return CTGitPath::Compare(left, right) < 0;
\r
675 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)
\r
677 return left.IsEquivalentTo(right);
\r
680 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)
\r
682 if (left.IsAdminDir() && right.IsAdminDir())
\r
684 CTGitPath l = left;
\r
685 CTGitPath r = right;
\r
688 l = l.GetContainingDirectory();
\r
689 } while(l.HasAdminDir());
\r
692 r = r.GetContainingDirectory();
\r
693 } while(r.HasAdminDir());
\r
694 return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());
\r
696 return left.GetDirectory().IsEquivalentTo(right.GetDirectory());
\r
699 bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)
\r
701 return parent.IsAncestorOf(child);
\r
704 void CTGitPath::AppendRawString(const CString& sAppend)
\r
706 EnsureFwdslashPathSet();
\r
707 CString strCopy = m_sFwdslashPath += sAppend;
\r
708 SetFromUnknown(strCopy);
\r
711 void CTGitPath::AppendPathString(const CString& sAppend)
\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
722 bool CTGitPath::HasAdminDir() const
\r
724 if (m_bHasAdminDirKnown)
\r
725 return m_bHasAdminDir;
\r
727 EnsureBackslashPathSet();
\r
728 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory());
\r
729 m_bHasAdminDirKnown = true;
\r
730 return m_bHasAdminDir;
\r
733 bool CTGitPath::IsAdminDir() const
\r
735 if (m_bIsAdminDirKnown)
\r
736 return m_bIsAdminDir;
\r
738 EnsureBackslashPathSet();
\r
739 m_bIsAdminDir = g_GitAdminDir.IsAdminDirPath(m_sBackslashPath);
\r
740 m_bIsAdminDirKnown = true;
\r
741 return m_bIsAdminDir;
\r
744 bool CTGitPath::IsValidOnWindows() const
\r
746 if (m_bIsValidOnWindowsKnown)
\r
747 return m_bIsValidOnWindows;
\r
749 m_bIsValidOnWindows = false;
\r
750 EnsureBackslashPathSet();
\r
751 CString sMatch = m_sBackslashPath + _T("\r\n");
\r
753 // the 'file://' URL is just a normal windows path:
\r
754 if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)
\r
756 sMatch = sMatch.Mid(7);
\r
757 sMatch.TrimLeft(_T("\\"));
\r
758 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
762 sPattern = _T("^((http|https|svn|svn\\+ssh|file)\\:\\\\+([^\\\\@\\:]+\\:[^\\\\@\\:]+@)?\\\\[^\\\\]+(\\:\\d+)?)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
766 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
771 tr1::wregex rx(sPattern, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
772 tr1::wsmatch match;
\r
774 wstring rmatch = wstring((LPCTSTR)sMatch);
\r
775 if (tr1::regex_match(rmatch, match, rx))
\r
777 if (wstring(match[0]).compare(sMatch)==0)
\r
778 m_bIsValidOnWindows = true;
\r
780 if (m_bIsValidOnWindows)
\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
789 catch (exception) {}
\r
791 m_bIsValidOnWindowsKnown = true;
\r
792 return m_bIsValidOnWindows;
\r
795 bool CTGitPath::IsSpecialDirectory() const
\r
797 if (m_bIsSpecialDirectoryKnown)
\r
798 return m_bIsSpecialDirectory;
\r
800 static LPCTSTR specialDirectories[]
\r
801 = { _T("trunk"), _T("tags"), _T("branches") };
\r
803 for (int i=0 ; i<(sizeof(specialDirectories) / sizeof(specialDirectories[0])) ; ++i)
\r
805 CString name = GetFileOrDirectoryName();
\r
806 if (0 == name.CompareNoCase(specialDirectories[i]))
\r
808 m_bIsSpecialDirectory = true;
\r
813 m_bIsSpecialDirectoryKnown = true;
\r
815 return m_bIsSpecialDirectory;
\r
818 //////////////////////////////////////////////////////////////////////////
\r
820 CTGitPathList::CTGitPathList()
\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
828 AddPath(firstEntry);
\r
830 int CTGitPathList::FillUnRev(int action,CTGitPathList *list)
\r
840 count=list->GetCount();
\r
841 for(int i=0;i<count;i++)
\r
847 if(action & CTGitPath::LOGACTIONS_IGNORE)
\r
848 ignored= _T(" --ignored");
\r
852 cmd=_T("git.exe ls-files --exclude-standard --full-name --others");
\r
857 { cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others %s-- \"%s\""),
\r
859 (*list)[i].GetWinPathString());
\r
863 g_Git.Run(cmd,&out);
\r
868 one=out.Tokenize(_T("\n"),pos);
\r
871 //SetFromGit will clear all status
\r
872 path.SetFromGit(one);
\r
873 path.m_Action=action;
\r
881 int CTGitPathList::ParserFromLog(BYTE_VECTOR &log)
\r
889 while( pos>=0 && pos<log.size())
\r
891 //one=log.Tokenize(_T("\n"),pos);
\r
898 int end=log.find(0,pos);
\r
899 int actionstart=-1;
\r
901 int file1=-1,file2=-1;
\r
904 actionstart=log.find(' ',end-6);
\r
907 if( actionstart>0 )
\r
911 file1 = log.find(0,actionstart);
\r
917 if( log[actionstart] == 'C' || log[actionstart] == 'R' )
\r
921 file1 = log.find(0,file1);
\r
935 g_Git.StringAppend(&pathname1,&log[file1],CP_OEMCP);
\r
937 g_Git.StringAppend(&pathname2,&log[file2],CP_OEMCP);
\r
939 CTGitPath *GitPath=LookForGitPath(pathname1);
\r
943 this->m_Action|=GitPath->ParserAction( log[actionstart] );
\r
947 int ac=path.ParserAction(log[actionstart] );
\r
949 path.SetFromGit(pathname1,&pathname2);
\r
951 //action must be set after setfromgit. SetFromGit will clear all status.
\r
952 this->m_Action|=ac;
\r
966 tabstart=log.find('\t',pos);
\r
970 g_Git.StringAppend(&StatAdd,&log[pos],CP_UTF8);
\r
974 tabstart=log.find('\t',pos);
\r
979 g_Git.StringAppend(&StatDel,&log[pos],CP_UTF8);
\r
983 if(log[pos] == 0) //rename
\r
986 g_Git.StringAppend(&file2,&log[pos],CP_OEMCP);
\r
987 int sec=log.find(0,pos);
\r
991 g_Git.StringAppend(&file1,&log[sec],CP_OEMCP);
\r
996 g_Git.StringAppend(&file1,&log[pos],CP_OEMCP);
\r
998 path.SetFromGit(file1,&file2);
\r
1000 CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());
\r
1003 GitPath->m_StatAdd=StatAdd;
\r
1004 GitPath->m_StatDel=StatDel;
\r
1007 //path.SetFromGit(pathname);
\r
1008 path.m_StatAdd=StatAdd;
\r
1009 path.m_StatDel=StatDel;
\r
1014 pos=log.findNextString(pos);
\r
1019 void CTGitPathList::AddPath(const CTGitPath& newPath)
\r
1021 m_paths.push_back(newPath);
\r
1022 m_commonBaseDirectory.Reset();
\r
1024 int CTGitPathList::GetCount() const
\r
1026 return (int)m_paths.size();
\r
1028 void CTGitPathList::Clear()
\r
1031 m_commonBaseDirectory.Reset();
\r
1034 const CTGitPath& CTGitPathList::operator[](INT_PTR index) const
\r
1036 ATLASSERT(index >= 0 && index < (INT_PTR)m_paths.size());
\r
1037 return m_paths[index];
\r
1040 bool CTGitPathList::AreAllPathsFiles() const
\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
1047 #if defined(_MFC_VER)
\r
1049 bool CTGitPathList::LoadFromFile(const CTGitPath& filename)
\r
1055 CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite);
\r
1057 // for every selected file/folder
\r
1059 while (file.ReadString(strLine))
\r
1061 path.SetFromUnknown(strLine);
\r
1066 catch (CFileException* pE)
\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
1078 bool CTGitPathList::WriteToFile(const CString& sFilename, bool bANSI /* = false */) const
\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
1088 CStringA line = CStringA(it->GetGitPathString()) + '\n';
\r
1089 file.Write(line, line.GetLength());
\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
1099 file.WriteString(it->GetGitPathString()+_T("\n"));
\r
1104 catch (CFileException* pE)
\r
1106 TRACE("CFileException in writing temp file\n");
\r
1114 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString& sPathString)
\r
1120 temp = sPathString.Tokenize(_T("*"),pos);
\r
1121 if(temp.IsEmpty())
\r
1125 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp)));
\r
1129 CString CTGitPathList::CreateAsteriskSeparatedString() const
\r
1132 PathVector::const_iterator it;
\r
1133 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1135 if (!sRet.IsEmpty())
\r
1137 sRet += it->GetWinPathString();
\r
1141 #endif // _MFC_VER
\r
1144 CTGitPathList::AreAllPathsFilesInOneDirectory() const
\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
1151 if(it->IsDirectory())
\r
1155 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1156 if(m_commonBaseDirectory.IsEmpty())
\r
1158 m_commonBaseDirectory = baseDirectory;
\r
1160 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1163 m_commonBaseDirectory.Reset();
\r
1170 CTGitPath CTGitPathList::GetCommonDirectory() const
\r
1172 if (m_commonBaseDirectory.IsEmpty())
\r
1174 PathVector::const_iterator it;
\r
1175 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1177 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1178 if(m_commonBaseDirectory.IsEmpty())
\r
1180 m_commonBaseDirectory = baseDirectory;
\r
1182 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1185 m_commonBaseDirectory.Reset();
\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
1195 if (!m_commonBaseDirectory.IsAncestorOf(*iter))
\r
1197 m_commonBaseDirectory = m_commonBaseDirectory.GetContainingDirectory();
\r
1201 return m_commonBaseDirectory;
\r
1204 CTGitPath CTGitPathList::GetCommonRoot() const
\r
1206 PathVector::const_iterator it;
\r
1207 CString sRoot, sTempRoot;
\r
1208 bool bEqual = true;
\r
1210 if (GetCount() == 1)
\r
1211 return m_paths[0];
\r
1213 int backSlashPos = 0;
\r
1214 int searchStartPos = 0;
\r
1217 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1219 if (backSlashPos == 0)
\r
1221 backSlashPos = it->GetWinPathString().Find('\\', searchStartPos+1);
\r
1222 if ((backSlashPos < 0)&&(searchStartPos != it->GetWinPathString().GetLength()))
\r
1223 backSlashPos = it->GetWinPathString().GetLength();
\r
1225 else if (it->GetWinPathString().Find('\\', searchStartPos+1) != backSlashPos)
\r
1227 if (it->GetWinPathString().Find('\\', searchStartPos+1) < 0)
\r
1229 if (it->GetWinPathString().GetLength() != backSlashPos)
\r
1241 if (backSlashPos < 0)
\r
1247 if (bEqual == false)
\r
1249 if (searchStartPos)
\r
1250 sRoot = m_paths[0].GetWinPathString().Left(searchStartPos+1);
\r
1254 searchStartPos = backSlashPos;
\r
1259 return CTGitPath(sRoot.TrimRight('\\'));
\r
1262 void CTGitPathList::SortByPathname(bool bReverse /*= false*/)
\r
1264 std::sort(m_paths.begin(), m_paths.end());
\r
1266 std::reverse(m_paths.begin(), m_paths.end());
\r
1269 void CTGitPathList::DeleteAllFiles(bool bTrash)
\r
1271 PathVector::const_iterator it;
\r
1276 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1278 if ((it->Exists())&&(!it->IsDirectory()))
\r
1280 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1281 sPaths += it->GetWinPath();
\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
1295 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1297 if (!it->IsDirectory())
\r
1299 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1300 ::DeleteFile(it->GetWinPath());
\r
1307 void CTGitPathList::RemoveDuplicates()
\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
1315 void CTGitPathList::RemoveAdminPaths()
\r
1317 PathVector::iterator it;
\r
1318 for(it = m_paths.begin(); it != m_paths.end(); )
\r
1320 if (it->IsAdminDir())
\r
1322 m_paths.erase(it);
\r
1323 it = m_paths.begin();
\r
1330 void CTGitPathList::RemovePath(const CTGitPath& path)
\r
1332 PathVector::iterator it;
\r
1333 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1335 if (it->IsEquivalentTo(path))
\r
1337 m_paths.erase(it);
\r
1343 void CTGitPathList::RemoveItem(CTGitPath & path)
\r
1345 PathVector::iterator it;
\r
1346 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1348 if (it->GetGitPathString()==path.GetGitPathString())
\r
1350 m_paths.erase(it);
\r
1355 void CTGitPathList::RemoveChildren()
\r
1358 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::CheckChild), m_paths.end());
\r
1361 bool CTGitPathList::IsEqual(const CTGitPathList& list)
\r
1363 if (list.GetCount() != GetCount())
\r
1365 for (int i=0; i<list.GetCount(); ++i)
\r
1367 if (!list[i].IsEquivalentTo(m_paths[i]))
\r
1373 //////////////////////////////////////////////////////////////////////////
\r
1375 apr_array_header_t * CTGitPathList::MakePathArray (apr_pool_t *pool) const
\r
1377 apr_array_header_t *targets = apr_array_make (pool, GetCount(), sizeof(const char *));
\r
1379 for(int nItem = 0; nItem < GetCount(); nItem++)
\r
1381 const char * target = m_paths[nItem].GetGitApiPath(pool);
\r
1382 (*((const char **) apr_array_push (targets))) = target;
\r
1388 //////////////////////////////////////////////////////////////////////////
\r
1391 #if defined(_DEBUG)
\r
1392 // Some test cases for these classes
\r
1393 static class CTGitPathTests
\r
1399 pool = svn_pool_create(NULL);
\r
1400 GetDirectoryTest();
\r
1405 RemoveDuplicatesTest();
\r
1406 RemoveChildrenTest();
\r
1407 ContainingDirectoryTest();
\r
1409 SubversionPathTest();
\r
1410 GetCommonRootTest();
\r
1411 #if defined(_MFC_VER)
\r
1412 ValidPathAndUrlTest();
\r
1413 ListLoadingTest();
\r
1419 // apr_pool_t * pool;
\r
1420 void GetDirectoryTest()
\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
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
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
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
1453 void AdminDirTest()
\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
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
1475 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1476 pathList.RemoveAdminPaths();
\r
1477 ATLASSERT(pathList.GetCount()==1);
\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
1493 testList.SortByPathname();
\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
1501 void RawAppendTest()
\r
1503 CTGitPath testPath(_T("c:/test/"));
\r
1504 testPath.AppendRawString(_T("/Hello"));
\r
1505 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1507 testPath.AppendRawString(_T("\\T2"));
\r
1508 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\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
1516 void PathAppendTest()
\r
1518 CTGitPath testPath(_T("c:/test/"));
\r
1519 testPath.AppendPathString(_T("/Hello"));
\r
1520 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1522 testPath.AppendPathString(_T("T2"));
\r
1523 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\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
1532 void RemoveDuplicatesTest()
\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
1540 ATLASSERT(list[2].IsEquivalentTo(list[3]));
\r
1541 ATLASSERT(list[2]==list[3]);
\r
1543 ATLASSERT(list.GetCount() == 4);
\r
1545 list.RemoveDuplicates();
\r
1547 ATLASSERT(list.GetCount() == 3);
\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
1554 void RemoveChildrenTest()
\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
1565 ATLASSERT(list.GetCount() == 7);
\r
1567 list.RemoveChildren();
\r
1569 ATLTRACE("count = %d\n", list.GetCount());
\r
1570 ATLASSERT(list.GetCount() == 3);
\r
1572 list.SortByPathname();
\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
1579 #if defined(_MFC_VER)
\r
1580 void ListLoadingTest()
\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
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
1593 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T(""));
\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
1601 void ContainingDirectoryTest()
\r
1604 CTGitPath testPath;
\r
1605 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\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
1622 void AncestorTest()
\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
1633 void SubversionPathTest()
\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
1656 void GetCommonRootTest()
\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
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
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
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
1681 sPathList = _T("c:\\windows\\*c:\\windows");
\r
1682 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1683 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\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
1691 sPathList = _T("c:\\windowsdummy*c:\\windows");
\r
1692 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1693 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\"))==0);
\r
1697 void ValidPathAndUrlTest()
\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
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
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
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
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
1788 } TGitPathTestobject;
\r
1792 CTGitPath * CTGitPathList::LookForGitPath(CString path)
\r
1795 for(i=0;i<this->GetCount();i++)
\r
1797 if((*this)[i].GetGitPathString() == path )
\r
1798 return (CTGitPath*)&(*this)[i];
\r
1803 CString CTGitPath::GetActionName()
\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
1816 int CTGitPathList::GetAction()
\r