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
87 int CTGitPath::ParserAction(BYTE action)
\r
89 //action=action.TrimLeft();
\r
90 //TCHAR c=action.GetAt(0);
\r
92 m_Action|= LOGACTIONS_MODIFIED;
\r
94 m_Action|= LOGACTIONS_REPLACED;
\r
96 m_Action|= LOGACTIONS_ADDED;
\r
98 m_Action|= LOGACTIONS_DELETED;
\r
100 m_Action|= LOGACTIONS_UNMERGED;
\r
102 m_Action|= LOGACTIONS_DELETED;
\r
104 m_Action|= LOGACTIONS_CACHE;
\r
106 m_Action|= LOGACTIONS_COPY;
\r
110 void CTGitPath::SetFromGit(const char* pPath)
\r
115 int len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, NULL, 0);
\r
118 len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, m_sFwdslashPath.GetBuffer(len+1), len+1);
\r
119 m_sFwdslashPath.ReleaseBuffer(len-1);
\r
121 SanitizeRootPath(m_sFwdslashPath, true);
\r
124 void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
\r
127 m_bDirectoryKnown = true;
\r
128 m_bIsDirectory = bIsDirectory;
\r
131 void CTGitPath::SetFromGit(const TCHAR* pPath, bool bIsDirectory)
\r
136 m_sFwdslashPath = pPath;
\r
137 SanitizeRootPath(m_sFwdslashPath, true);
\r
139 m_bDirectoryKnown = true;
\r
140 m_bIsDirectory = bIsDirectory;
\r
143 void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)
\r
146 m_sFwdslashPath = sPath;
\r
147 SanitizeRootPath(m_sFwdslashPath, true);
\r
149 m_sOldFwdslashPath = *oldpath;
\r
152 void CTGitPath::SetFromWin(LPCTSTR pPath)
\r
155 m_sBackslashPath = pPath;
\r
156 SanitizeRootPath(m_sBackslashPath, false);
\r
157 ATLASSERT(m_sBackslashPath.Find('/')<0);
\r
159 void CTGitPath::SetFromWin(const CString& sPath)
\r
162 m_sBackslashPath = sPath;
\r
163 SanitizeRootPath(m_sBackslashPath, false);
\r
165 void CTGitPath::SetFromWin(const CString& sPath, bool bIsDirectory)
\r
168 m_sBackslashPath = sPath;
\r
169 m_bIsDirectory = bIsDirectory;
\r
170 m_bDirectoryKnown = true;
\r
171 SanitizeRootPath(m_sBackslashPath, false);
\r
173 void CTGitPath::SetFromUnknown(const CString& sPath)
\r
176 // Just set whichever path we think is most likely to be used
\r
177 // GitAdminDir admin;
\r
179 // if(admin.HasAdminDir(sPath,&p))
\r
180 // SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));
\r
182 SetFwdslashPath(sPath);
\r
185 LPCTSTR CTGitPath::GetWinPath() const
\r
191 if(m_sBackslashPath.IsEmpty())
\r
193 SetBackslashPath(m_sFwdslashPath);
\r
195 return m_sBackslashPath;
\r
197 // This is a temporary function, to be used during the migration to
\r
198 // the path class. Ultimately, functions consuming paths should take a CTGitPath&, not a CString
\r
199 const CString& CTGitPath::GetWinPathString() const
\r
201 if(m_sBackslashPath.IsEmpty())
\r
203 SetBackslashPath(m_sFwdslashPath);
\r
205 return m_sBackslashPath;
\r
208 const CString& CTGitPath::GetGitPathString() const
\r
210 if(m_sFwdslashPath.IsEmpty())
\r
212 SetFwdslashPath(m_sBackslashPath);
\r
214 return m_sFwdslashPath;
\r
217 const CString &CTGitPath::GetGitOldPathString() const
\r
219 return m_sOldFwdslashPath;
\r
222 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const
\r
224 // This funny-looking 'if' is to avoid a subtle problem with empty paths, whereby
\r
225 // each call to GetGitApiPath returns a different pointer value.
\r
226 // If you made multiple calls to GetGitApiPath on the same string, only the last
\r
227 // one would give you a valid pointer to an empty string, because each
\r
228 // call would invalidate the previous call's return.
\r
233 if(m_sFwdslashPath.IsEmpty())
\r
235 SetFwdslashPath(m_sBackslashPath);
\r
237 if(m_sUTF8FwdslashPath.IsEmpty())
\r
239 SetUTF8FwdslashPath(m_sFwdslashPath);
\r
241 if (svn_path_is_url(m_sUTF8FwdslashPath))
\r
243 m_sUTF8FwdslashPathEscaped = CPathUtils::PathEscape(m_sUTF8FwdslashPath);
\r
244 m_sUTF8FwdslashPathEscaped.Replace("file:////", "file:///\\");
\r
245 m_sUTF8FwdslashPathEscaped = svn_path_canonicalize(m_sUTF8FwdslashPathEscaped, pool);
\r
246 return m_sUTF8FwdslashPathEscaped;
\r
248 m_sUTF8FwdslashPath = svn_path_canonicalize(m_sUTF8FwdslashPath, pool);
\r
250 return m_sUTF8FwdslashPath;
\r
254 const CString& CTGitPath::GetUIPathString() const
\r
256 if (m_sUIPath.IsEmpty())
\r
258 #if defined(_MFC_VER)
\r
259 //BUGBUG HORRIBLE!!! - CPathUtils::IsEscaped doesn't need to be MFC-only
\r
262 m_sUIPath = CPathUtils::PathUnescape(GetGitPathString());
\r
263 m_sUIPath.Replace(_T("file:////"), _T("file:///\\"));
\r
269 m_sUIPath = GetWinPathString();
\r
275 void CTGitPath::SetFwdslashPath(const CString& sPath) const
\r
277 m_sFwdslashPath = sPath;
\r
278 m_sFwdslashPath.Replace('\\', '/');
\r
280 // We don't leave a trailing /
\r
281 m_sFwdslashPath.TrimRight('/');
\r
283 SanitizeRootPath(m_sFwdslashPath, true);
\r
285 m_sFwdslashPath.Replace(_T("file:////"), _T("file:///\\"));
\r
287 m_sUTF8FwdslashPath.Empty();
\r
290 void CTGitPath::SetBackslashPath(const CString& sPath) const
\r
292 m_sBackslashPath = sPath;
\r
293 m_sBackslashPath.Replace('/', '\\');
\r
294 m_sBackslashPath.TrimRight('\\');
\r
295 SanitizeRootPath(m_sBackslashPath, false);
\r
298 void CTGitPath::SetUTF8FwdslashPath(const CString& sPath) const
\r
300 m_sUTF8FwdslashPath = CUnicodeUtils::GetUTF8(sPath);
\r
303 void CTGitPath::SanitizeRootPath(CString& sPath, bool bIsForwardPath) const
\r
305 // Make sure to add the trailing slash to root paths such as 'C:'
\r
306 if (sPath.GetLength() == 2 && sPath[1] == ':')
\r
308 sPath += (bIsForwardPath) ? _T("/") : _T("\\");
\r
312 bool CTGitPath::IsUrl() const
\r
317 EnsureFwdslashPathSet();
\r
318 if(m_sUTF8FwdslashPath.IsEmpty())
\r
320 SetUTF8FwdslashPath(m_sFwdslashPath);
\r
322 m_bIsURL = !!svn_path_is_url(m_sUTF8FwdslashPath);
\r
323 m_bURLKnown = true;
\r
330 bool CTGitPath::IsDirectory() const
\r
332 if(!m_bDirectoryKnown)
\r
334 UpdateAttributes();
\r
336 return m_bIsDirectory;
\r
339 bool CTGitPath::Exists() const
\r
341 if (!m_bExistsKnown)
\r
343 UpdateAttributes();
\r
348 bool CTGitPath::Delete(bool bTrash) const
\r
350 EnsureBackslashPathSet();
\r
351 ::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);
\r
355 if ((bTrash)||(IsDirectory()))
\r
357 TCHAR * buf = new TCHAR[m_sBackslashPath.GetLength()+2];
\r
358 _tcscpy_s(buf, m_sBackslashPath.GetLength()+2, m_sBackslashPath);
\r
359 buf[m_sBackslashPath.GetLength()] = 0;
\r
360 buf[m_sBackslashPath.GetLength()+1] = 0;
\r
361 SHFILEOPSTRUCT shop = {0};
\r
362 shop.wFunc = FO_DELETE;
\r
364 shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
\r
366 shop.fFlags |= FOF_ALLOWUNDO;
\r
367 bRet = (SHFileOperation(&shop) == 0);
\r
372 bRet = !!::DeleteFile(m_sBackslashPath);
\r
376 m_bExistsKnown = true;
\r
380 __int64 CTGitPath::GetLastWriteTime() const
\r
382 if(!m_bLastWriteTimeKnown)
\r
384 UpdateAttributes();
\r
386 return m_lastWriteTime;
\r
389 bool CTGitPath::IsReadOnly() const
\r
391 if(!m_bLastWriteTimeKnown)
\r
393 UpdateAttributes();
\r
395 return m_bIsReadOnly;
\r
398 void CTGitPath::UpdateAttributes() const
\r
400 EnsureBackslashPathSet();
\r
401 WIN32_FILE_ATTRIBUTE_DATA attribs;
\r
402 if(GetFileAttributesEx(m_sBackslashPath, GetFileExInfoStandard, &attribs))
\r
404 m_bIsDirectory = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
\r
405 m_lastWriteTime = *(__int64*)&attribs.ftLastWriteTime;
\r
406 m_bIsReadOnly = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_READONLY);
\r
411 DWORD err = GetLastError();
\r
412 if ((err == ERROR_FILE_NOT_FOUND)||(err == ERROR_PATH_NOT_FOUND)||(err == ERROR_INVALID_NAME))
\r
414 m_bIsDirectory = false;
\r
415 m_lastWriteTime = 0;
\r
420 m_bIsDirectory = false;
\r
421 m_lastWriteTime = 0;
\r
426 m_bDirectoryKnown = true;
\r
427 m_bLastWriteTimeKnown = true;
\r
428 m_bExistsKnown = true;
\r
432 void CTGitPath::EnsureBackslashPathSet() const
\r
434 if(m_sBackslashPath.IsEmpty())
\r
436 SetBackslashPath(m_sFwdslashPath);
\r
437 ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());
\r
440 void CTGitPath::EnsureFwdslashPathSet() const
\r
442 if(m_sFwdslashPath.IsEmpty())
\r
444 SetFwdslashPath(m_sBackslashPath);
\r
445 ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());
\r
450 // Reset all the caches
\r
451 void CTGitPath::Reset()
\r
453 m_bDirectoryKnown = false;
\r
454 m_bURLKnown = false;
\r
455 m_bLastWriteTimeKnown = false;
\r
456 m_bHasAdminDirKnown = false;
\r
457 m_bIsValidOnWindowsKnown = false;
\r
458 m_bIsAdminDirKnown = false;
\r
459 m_bExistsKnown = false;
\r
460 m_bIsSpecialDirectoryKnown = false;
\r
461 m_bIsSpecialDirectory = false;
\r
463 m_sBackslashPath.Empty();
\r
464 m_sFwdslashPath.Empty();
\r
465 m_sUTF8FwdslashPath.Empty();
\r
467 this->m_StatAdd=_T("");
\r
468 this->m_StatDel=_T("");
\r
469 ATLASSERT(IsEmpty());
\r
472 CTGitPath CTGitPath::GetDirectory() const
\r
474 if ((IsDirectory())||(!Exists()))
\r
478 return GetContainingDirectory();
\r
481 CTGitPath CTGitPath::GetContainingDirectory() const
\r
483 EnsureBackslashPathSet();
\r
485 CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));
\r
486 if(sDirName.GetLength() == 2 && sDirName[1] == ':')
\r
488 // This is a root directory, which needs a trailing slash
\r
490 if(sDirName == m_sBackslashPath)
\r
492 // We were clearly provided with a root path to start with - we should return nothing now
\r
496 if(sDirName.GetLength() == 1 && sDirName[0] == '\\')
\r
498 // We have an UNC path and we already are the root
\r
502 retVal.SetFromWin(sDirName);
\r
506 CString CTGitPath::GetRootPathString() const
\r
508 EnsureBackslashPathSet();
\r
509 CString workingPath = m_sBackslashPath;
\r
510 LPTSTR pPath = workingPath.GetBuffer(MAX_PATH); // MAX_PATH ok here.
\r
511 ATLVERIFY(::PathStripToRoot(pPath));
\r
512 workingPath.ReleaseBuffer();
\r
513 return workingPath;
\r
517 CString CTGitPath::GetFilename() const
\r
519 ATLASSERT(!IsDirectory());
\r
520 return GetFileOrDirectoryName();
\r
523 CString CTGitPath::GetFileOrDirectoryName() const
\r
525 EnsureBackslashPathSet();
\r
526 return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);
\r
529 CString CTGitPath::GetUIFileOrDirectoryName() const
\r
532 return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);
\r
535 CString CTGitPath::GetFileExtension() const
\r
539 EnsureBackslashPathSet();
\r
540 int dotPos = m_sBackslashPath.ReverseFind('.');
\r
541 int slashPos = m_sBackslashPath.ReverseFind('\\');
\r
542 if (dotPos > slashPos)
\r
543 return m_sBackslashPath.Mid(dotPos);
\r
547 CString CTGitPath::GetBaseFilename() const
\r
550 CString filename=GetFilename();
\r
551 dot = filename.ReverseFind(_T('.'));
\r
553 return filename.Left(dot-1);
\r
558 bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)
\r
560 int length = sP1.GetLength();
\r
561 if(length != sP2.GetLength())
\r
563 // Different lengths
\r
566 // We work from the end of the strings, because path differences
\r
567 // are more likely to occur at the far end of a string
\r
568 LPCTSTR pP1Start = sP1;
\r
569 LPCTSTR pP1 = pP1Start+(length-1);
\r
570 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
\r
571 while(length-- > 0)
\r
573 if(_totlower(*pP1--) != _totlower(*pP2--))
\r
581 bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)
\r
583 int length = sP1.GetLength();
\r
584 if(length != sP2.GetLength())
\r
586 // Different lengths
\r
589 // We work from the end of the strings, because path differences
\r
590 // are more likely to occur at the far end of a string
\r
591 LPCTSTR pP1Start = sP1;
\r
592 LPCTSTR pP1 = pP1Start+(length-1);
\r
593 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
\r
594 while(length-- > 0)
\r
596 if((*pP1--) != (*pP2--))
\r
604 bool CTGitPath::IsEmpty() const
\r
606 // Check the backward slash path first, since the chance that this
\r
607 // one is set is higher. In case of a 'false' return value it's a little
\r
609 return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();
\r
612 // Test if both paths refer to the same item
\r
613 // Ignores case and slash direction
\r
614 bool CTGitPath::IsEquivalentTo(const CTGitPath& rhs) const
\r
616 // Try and find a slash direction which avoids having to convert
\r
618 if(!m_sBackslashPath.IsEmpty())
\r
620 // *We've* got a \ path - make sure that the RHS also has a \ path
\r
621 rhs.EnsureBackslashPathSet();
\r
622 return ArePathStringsEqualWithCase(m_sBackslashPath, rhs.m_sBackslashPath);
\r
626 // Assume we've got a fwdslash path and make sure that the RHS has one
\r
627 rhs.EnsureFwdslashPathSet();
\r
628 return ArePathStringsEqualWithCase(m_sFwdslashPath, rhs.m_sFwdslashPath);
\r
632 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const
\r
634 // Try and find a slash direction which avoids having to convert
\r
636 if(!m_sBackslashPath.IsEmpty())
\r
638 // *We've* got a \ path - make sure that the RHS also has a \ path
\r
639 rhs.EnsureBackslashPathSet();
\r
640 return ArePathStringsEqual(m_sBackslashPath, rhs.m_sBackslashPath);
\r
644 // Assume we've got a fwdslash path and make sure that the RHS has one
\r
645 rhs.EnsureFwdslashPathSet();
\r
646 return ArePathStringsEqual(m_sFwdslashPath, rhs.m_sFwdslashPath);
\r
650 bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const
\r
652 possibleDescendant.EnsureBackslashPathSet();
\r
653 EnsureBackslashPathSet();
\r
655 bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));
\r
656 if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())
\r
658 return bPathStringsEqual;
\r
661 return (bPathStringsEqual &&
\r
662 ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||
\r
663 (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));
\r
666 // Get a string representing the file path, optionally with a base
\r
667 // section stripped off the front.
\r
668 CString CTGitPath::GetDisplayString(const CTGitPath* pOptionalBasePath /* = NULL*/) const
\r
670 EnsureFwdslashPathSet();
\r
671 if(pOptionalBasePath != NULL)
\r
673 // Find the length of the base-path without having to do an 'ensure' on it
\r
674 int baseLength = max(pOptionalBasePath->m_sBackslashPath.GetLength(), pOptionalBasePath->m_sFwdslashPath.GetLength());
\r
676 // Now, chop that baseLength of the front of the path
\r
677 return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');
\r
679 return m_sFwdslashPath;
\r
682 int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)
\r
684 left.EnsureBackslashPathSet();
\r
685 right.EnsureBackslashPathSet();
\r
686 return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);
\r
689 bool operator<(const CTGitPath& left, const CTGitPath& right)
\r
691 return CTGitPath::Compare(left, right) < 0;
\r
694 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)
\r
696 return left.IsEquivalentTo(right);
\r
699 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)
\r
701 if (left.IsAdminDir() && right.IsAdminDir())
\r
703 CTGitPath l = left;
\r
704 CTGitPath r = right;
\r
707 l = l.GetContainingDirectory();
\r
708 } while(l.HasAdminDir());
\r
711 r = r.GetContainingDirectory();
\r
712 } while(r.HasAdminDir());
\r
713 return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());
\r
715 return left.GetDirectory().IsEquivalentTo(right.GetDirectory());
\r
718 bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)
\r
720 return parent.IsAncestorOf(child);
\r
723 void CTGitPath::AppendRawString(const CString& sAppend)
\r
725 EnsureFwdslashPathSet();
\r
726 CString strCopy = m_sFwdslashPath += sAppend;
\r
727 SetFromUnknown(strCopy);
\r
730 void CTGitPath::AppendPathString(const CString& sAppend)
\r
732 EnsureBackslashPathSet();
\r
733 CString cleanAppend(sAppend);
\r
734 cleanAppend.Replace('/', '\\');
\r
735 cleanAppend.TrimLeft('\\');
\r
736 m_sBackslashPath.TrimRight('\\');
\r
737 CString strCopy = m_sBackslashPath + _T("\\") + cleanAppend;
\r
738 SetFromWin(strCopy);
\r
741 bool CTGitPath::HasAdminDir() const
\r
743 if (m_bHasAdminDirKnown)
\r
744 return m_bHasAdminDir;
\r
746 EnsureBackslashPathSet();
\r
747 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
\r
748 m_bHasAdminDirKnown = true;
\r
749 return m_bHasAdminDir;
\r
752 bool CTGitPath::HasAdminDir(CString *ProjectTopDir) const
\r
754 if (m_bHasAdminDirKnown)
\r
757 *ProjectTopDir = m_sProjectRoot;
\r
758 return m_bHasAdminDir;
\r
761 EnsureBackslashPathSet();
\r
762 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
\r
763 m_bHasAdminDirKnown = true;
\r
765 *ProjectTopDir = m_sProjectRoot;
\r
766 return m_bHasAdminDir;
\r
769 bool CTGitPath::IsAdminDir() const
\r
771 if (m_bIsAdminDirKnown)
\r
772 return m_bIsAdminDir;
\r
774 EnsureBackslashPathSet();
\r
775 m_bIsAdminDir = g_GitAdminDir.IsAdminDirPath(m_sBackslashPath);
\r
776 m_bIsAdminDirKnown = true;
\r
777 return m_bIsAdminDir;
\r
780 bool CTGitPath::IsValidOnWindows() const
\r
782 if (m_bIsValidOnWindowsKnown)
\r
783 return m_bIsValidOnWindows;
\r
785 m_bIsValidOnWindows = false;
\r
786 EnsureBackslashPathSet();
\r
787 CString sMatch = m_sBackslashPath + _T("\r\n");
\r
789 // the 'file://' URL is just a normal windows path:
\r
790 if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)
\r
792 sMatch = sMatch.Mid(7);
\r
793 sMatch.TrimLeft(_T("\\"));
\r
794 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
798 sPattern = _T("^((http|https|svn|svn\\+ssh|file)\\:\\\\+([^\\\\@\\:]+\\:[^\\\\@\\:]+@)?\\\\[^\\\\]+(\\:\\d+)?)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
802 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
807 tr1::wregex rx(sPattern, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
808 tr1::wsmatch match;
\r
810 wstring rmatch = wstring((LPCTSTR)sMatch);
\r
811 if (tr1::regex_match(rmatch, match, rx))
\r
813 if (wstring(match[0]).compare(sMatch)==0)
\r
814 m_bIsValidOnWindows = true;
\r
816 if (m_bIsValidOnWindows)
\r
818 // now check for illegal filenames
\r
819 tr1::wregex rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
820 rmatch = m_sBackslashPath;
\r
821 if (tr1::regex_search(rmatch, rx2, tr1::regex_constants::match_default))
\r
822 m_bIsValidOnWindows = false;
\r
825 catch (exception) {}
\r
827 m_bIsValidOnWindowsKnown = true;
\r
828 return m_bIsValidOnWindows;
\r
831 bool CTGitPath::IsSpecialDirectory() const
\r
833 if (m_bIsSpecialDirectoryKnown)
\r
834 return m_bIsSpecialDirectory;
\r
836 static LPCTSTR specialDirectories[]
\r
837 = { _T("trunk"), _T("tags"), _T("branches") };
\r
839 for (int i=0 ; i<(sizeof(specialDirectories) / sizeof(specialDirectories[0])) ; ++i)
\r
841 CString name = GetFileOrDirectoryName();
\r
842 if (0 == name.CompareNoCase(specialDirectories[i]))
\r
844 m_bIsSpecialDirectory = true;
\r
849 m_bIsSpecialDirectoryKnown = true;
\r
851 return m_bIsSpecialDirectory;
\r
854 //////////////////////////////////////////////////////////////////////////
\r
856 CTGitPathList::CTGitPathList()
\r
861 // A constructor which allows a path list to be easily built which one initial entry in
\r
862 CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)
\r
864 AddPath(firstEntry);
\r
866 int CTGitPathList::ParserFromLsFile(BYTE_VECTOR &out,bool staged)
\r
872 while(pos>=0 && pos<out.size())
\r
877 g_Git.StringAppend(&one,&out[pos],CP_OEMCP);
\r
879 path.m_Action=path.ParserAction(out[pos]);
\r
880 one.Tokenize(_T("\t"),tabstart);
\r
883 path.SetFromGit(one.Right(one.GetLength()-tabstart));
\r
887 part=one.Tokenize(_T(" "),tabstart); //Tag
\r
889 part=one.Tokenize(_T(" "),tabstart); //Mode
\r
891 part=one.Tokenize(_T(" "),tabstart); //Hash
\r
893 part=one.Tokenize(_T("\t"),tabstart); //Stage
\r
895 path.m_Stage=_ttol(part);
\r
897 this->AddPath(path);
\r
899 pos=out.findNextString(pos);
\r
903 int CTGitPathList::FillUnRev(int action,CTGitPathList *list)
\r
913 count=list->GetCount();
\r
914 for(int i=0;i<count;i++)
\r
920 if(action & CTGitPath::LOGACTIONS_IGNORE)
\r
921 ignored= _T(" --ignored");
\r
925 cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");
\r
930 { cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z %s-- \"%s\""),
\r
932 (*list)[i].GetWinPathString());
\r
937 g_Git.Run(cmd,&out);
\r
941 while( pos>=0 && pos<out.size())
\r
944 g_Git.StringAppend(&one,&out[pos],CP_OEMCP);
\r
947 //SetFromGit will clear all status
\r
948 path.SetFromGit(one);
\r
949 path.m_Action=action;
\r
952 pos=out.findNextString(pos);
\r
958 int CTGitPathList::ParserFromLog(BYTE_VECTOR &log)
\r
966 while( pos>=0 && pos<log.size())
\r
968 //one=log.Tokenize(_T("\n"),pos);
\r
975 int end=log.find(0,pos);
\r
976 int actionstart=-1;
\r
978 int file1=-1,file2=-1;
\r
981 actionstart=log.find(' ',end-6);
\r
984 if( actionstart>0 )
\r
988 file1 = log.find(0,actionstart);
\r
994 if( log[actionstart] == 'C' || log[actionstart] == 'R' )
\r
998 file1 = log.find(0,file1);
\r
1008 CString pathname1;
\r
1009 CString pathname2;
\r
1012 g_Git.StringAppend(&pathname1,&log[file1],CP_OEMCP);
\r
1014 g_Git.StringAppend(&pathname2,&log[file2],CP_OEMCP);
\r
1016 CTGitPath *GitPath=LookForGitPath(pathname1);
\r
1020 this->m_Action|=GitPath->ParserAction( log[actionstart] );
\r
1024 int ac=path.ParserAction(log[actionstart] );
\r
1026 path.SetFromGit(pathname1,&pathname2);
\r
1028 //action must be set after setfromgit. SetFromGit will clear all status.
\r
1029 this->m_Action|=ac;
\r
1043 tabstart=log.find('\t',pos);
\r
1047 g_Git.StringAppend(&StatAdd,&log[pos],CP_UTF8);
\r
1051 tabstart=log.find('\t',pos);
\r
1056 g_Git.StringAppend(&StatDel,&log[pos],CP_UTF8);
\r
1060 if(log[pos] == 0) //rename
\r
1063 g_Git.StringAppend(&file2,&log[pos],CP_OEMCP);
\r
1064 int sec=log.find(0,pos);
\r
1068 g_Git.StringAppend(&file1,&log[sec],CP_OEMCP);
\r
1074 g_Git.StringAppend(&file1,&log[pos],CP_OEMCP);
\r
1076 path.SetFromGit(file1,&file2);
\r
1078 CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());
\r
1081 GitPath->m_StatAdd=StatAdd;
\r
1082 GitPath->m_StatDel=StatDel;
\r
1085 //path.SetFromGit(pathname);
\r
1086 path.m_StatAdd=StatAdd;
\r
1087 path.m_StatDel=StatDel;
\r
1092 pos=log.findNextString(pos);
\r
1097 void CTGitPathList::AddPath(const CTGitPath& newPath)
\r
1099 m_paths.push_back(newPath);
\r
1100 m_commonBaseDirectory.Reset();
\r
1102 int CTGitPathList::GetCount() const
\r
1104 return (int)m_paths.size();
\r
1106 void CTGitPathList::Clear()
\r
1109 m_commonBaseDirectory.Reset();
\r
1112 const CTGitPath& CTGitPathList::operator[](INT_PTR index) const
\r
1114 ATLASSERT(index >= 0 && index < (INT_PTR)m_paths.size());
\r
1115 return m_paths[index];
\r
1118 bool CTGitPathList::AreAllPathsFiles() const
\r
1120 // Look through the vector for any directories - if we find them, return false
\r
1121 return std::find_if(m_paths.begin(), m_paths.end(), std::mem_fun_ref(&CTGitPath::IsDirectory)) == m_paths.end();
\r
1125 #if defined(_MFC_VER)
\r
1127 bool CTGitPathList::LoadFromFile(const CTGitPath& filename)
\r
1133 CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite);
\r
1135 // for every selected file/folder
\r
1137 while (file.ReadString(strLine))
\r
1139 path.SetFromUnknown(strLine);
\r
1144 catch (CFileException* pE)
\r
1146 TRACE("CFileException loading target file list\n");
\r
1147 TCHAR error[10000] = {0};
\r
1148 pE->GetErrorMessage(error, 10000);
\r
1149 // CMessageBox::Show(NULL, error, _T("TortoiseGit"), MB_ICONERROR);
\r
1156 bool CTGitPathList::WriteToFile(const CString& sFilename, bool bANSI /* = false */) const
\r
1162 CStdioFile file(sFilename, CFile::typeText | CFile::modeReadWrite | CFile::modeCreate);
\r
1163 PathVector::const_iterator it;
\r
1164 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1166 CStringA line = CStringA(it->GetGitPathString()) + '\n';
\r
1167 file.Write(line, line.GetLength());
\r
1173 CStdioFile file(sFilename, CFile::typeBinary | CFile::modeReadWrite | CFile::modeCreate);
\r
1174 PathVector::const_iterator it;
\r
1175 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1177 file.WriteString(it->GetGitPathString()+_T("\n"));
\r
1182 catch (CFileException* pE)
\r
1184 TRACE("CFileException in writing temp file\n");
\r
1192 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString& sPathString)
\r
1198 temp = sPathString.Tokenize(_T("*"),pos);
\r
1199 if(temp.IsEmpty())
\r
1203 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp)));
\r
1207 CString CTGitPathList::CreateAsteriskSeparatedString() const
\r
1210 PathVector::const_iterator it;
\r
1211 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1213 if (!sRet.IsEmpty())
\r
1215 sRet += it->GetWinPathString();
\r
1219 #endif // _MFC_VER
\r
1222 CTGitPathList::AreAllPathsFilesInOneDirectory() const
\r
1224 // Check if all the paths are files and in the same directory
\r
1225 PathVector::const_iterator it;
\r
1226 m_commonBaseDirectory.Reset();
\r
1227 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1229 if(it->IsDirectory())
\r
1233 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1234 if(m_commonBaseDirectory.IsEmpty())
\r
1236 m_commonBaseDirectory = baseDirectory;
\r
1238 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1241 m_commonBaseDirectory.Reset();
\r
1248 CTGitPath CTGitPathList::GetCommonDirectory() const
\r
1250 if (m_commonBaseDirectory.IsEmpty())
\r
1252 PathVector::const_iterator it;
\r
1253 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1255 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1256 if(m_commonBaseDirectory.IsEmpty())
\r
1258 m_commonBaseDirectory = baseDirectory;
\r
1260 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1263 m_commonBaseDirectory.Reset();
\r
1268 // since we only checked strings, not paths,
\r
1269 // we have to make sure now that we really return a *path* here
\r
1270 PathVector::const_iterator iter;
\r
1271 for(iter = m_paths.begin(); iter != m_paths.end(); ++iter)
\r
1273 if (!m_commonBaseDirectory.IsAncestorOf(*iter))
\r
1275 m_commonBaseDirectory = m_commonBaseDirectory.GetContainingDirectory();
\r
1279 return m_commonBaseDirectory;
\r
1282 CTGitPath CTGitPathList::GetCommonRoot() const
\r
1284 PathVector::const_iterator it;
\r
1285 CString sRoot, sTempRoot;
\r
1286 bool bEqual = true;
\r
1288 if (GetCount() == 1)
\r
1289 return m_paths[0];
\r
1291 int backSlashPos = 0;
\r
1292 int searchStartPos = 0;
\r
1295 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1297 if (backSlashPos == 0)
\r
1299 backSlashPos = it->GetWinPathString().Find('\\', searchStartPos+1);
\r
1300 if ((backSlashPos < 0)&&(searchStartPos != it->GetWinPathString().GetLength()))
\r
1301 backSlashPos = it->GetWinPathString().GetLength();
\r
1303 else if (it->GetWinPathString().Find('\\', searchStartPos+1) != backSlashPos)
\r
1305 if (it->GetWinPathString().Find('\\', searchStartPos+1) < 0)
\r
1307 if (it->GetWinPathString().GetLength() != backSlashPos)
\r
1319 if (backSlashPos < 0)
\r
1325 if (bEqual == false)
\r
1327 if (searchStartPos)
\r
1328 sRoot = m_paths[0].GetWinPathString().Left(searchStartPos+1);
\r
1332 searchStartPos = backSlashPos;
\r
1337 return CTGitPath(sRoot.TrimRight('\\'));
\r
1340 void CTGitPathList::SortByPathname(bool bReverse /*= false*/)
\r
1342 std::sort(m_paths.begin(), m_paths.end());
\r
1344 std::reverse(m_paths.begin(), m_paths.end());
\r
1347 void CTGitPathList::DeleteAllFiles(bool bTrash)
\r
1349 PathVector::const_iterator it;
\r
1354 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1356 if ((it->Exists())&&(!it->IsDirectory()))
\r
1358 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1359 sPaths += it->GetWinPath();
\r
1365 SHFILEOPSTRUCT shop = {0};
\r
1366 shop.wFunc = FO_DELETE;
\r
1367 shop.pFrom = (LPCTSTR)sPaths;
\r
1368 shop.fFlags = FOF_ALLOWUNDO|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
\r
1369 SHFileOperation(&shop);
\r
1373 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1375 if (!it->IsDirectory())
\r
1377 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1378 ::DeleteFile(it->GetWinPath());
\r
1385 void CTGitPathList::RemoveDuplicates()
\r
1388 // Remove the duplicates
\r
1389 // (Unique moves them to the end of the vector, then erase chops them off)
\r
1390 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::PredLeftEquivalentToRight), m_paths.end());
\r
1393 void CTGitPathList::RemoveAdminPaths()
\r
1395 PathVector::iterator it;
\r
1396 for(it = m_paths.begin(); it != m_paths.end(); )
\r
1398 if (it->IsAdminDir())
\r
1400 m_paths.erase(it);
\r
1401 it = m_paths.begin();
\r
1408 void CTGitPathList::RemovePath(const CTGitPath& path)
\r
1410 PathVector::iterator it;
\r
1411 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1413 if (it->IsEquivalentTo(path))
\r
1415 m_paths.erase(it);
\r
1421 void CTGitPathList::RemoveItem(CTGitPath & path)
\r
1423 PathVector::iterator it;
\r
1424 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1426 if (it->GetGitPathString()==path.GetGitPathString())
\r
1428 m_paths.erase(it);
\r
1433 void CTGitPathList::RemoveChildren()
\r
1436 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::CheckChild), m_paths.end());
\r
1439 bool CTGitPathList::IsEqual(const CTGitPathList& list)
\r
1441 if (list.GetCount() != GetCount())
\r
1443 for (int i=0; i<list.GetCount(); ++i)
\r
1445 if (!list[i].IsEquivalentTo(m_paths[i]))
\r
1451 //////////////////////////////////////////////////////////////////////////
\r
1453 apr_array_header_t * CTGitPathList::MakePathArray (apr_pool_t *pool) const
\r
1455 apr_array_header_t *targets = apr_array_make (pool, GetCount(), sizeof(const char *));
\r
1457 for(int nItem = 0; nItem < GetCount(); nItem++)
\r
1459 const char * target = m_paths[nItem].GetGitApiPath(pool);
\r
1460 (*((const char **) apr_array_push (targets))) = target;
\r
1466 //////////////////////////////////////////////////////////////////////////
\r
1469 #if defined(_DEBUG)
\r
1470 // Some test cases for these classes
\r
1471 static class CTGitPathTests
\r
1477 pool = svn_pool_create(NULL);
\r
1478 GetDirectoryTest();
\r
1483 RemoveDuplicatesTest();
\r
1484 RemoveChildrenTest();
\r
1485 ContainingDirectoryTest();
\r
1487 SubversionPathTest();
\r
1488 GetCommonRootTest();
\r
1489 #if defined(_MFC_VER)
\r
1490 ValidPathAndUrlTest();
\r
1491 ListLoadingTest();
\r
1497 // apr_pool_t * pool;
\r
1498 void GetDirectoryTest()
\r
1500 // Bit tricky, this test, because we need to know something about the file
\r
1501 // layout on the machine which is running the test
\r
1502 TCHAR winDir[MAX_PATH+1];
\r
1503 GetWindowsDirectory(winDir, MAX_PATH);
\r
1504 CString sWinDir(winDir);
\r
1506 CTGitPath testPath;
\r
1507 // This is a file which we know will always be there
\r
1508 testPath.SetFromUnknown(sWinDir + _T("\\win.ini"));
\r
1509 ATLASSERT(!testPath.IsDirectory());
\r
1510 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
\r
1511 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() == sWinDir);
\r
1513 // Now do the test on the win directory itself - It's hard to be sure about the containing directory
\r
1514 // but we know it must be different to the directory itself
\r
1515 testPath.SetFromUnknown(sWinDir);
\r
1516 ATLASSERT(testPath.IsDirectory());
\r
1517 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
\r
1518 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() != sWinDir);
\r
1519 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString().GetLength() < sWinDir.GetLength());
\r
1521 // Try a root path
\r
1522 testPath.SetFromUnknown(_T("C:\\"));
\r
1523 ATLASSERT(testPath.IsDirectory());
\r
1524 ATLASSERT(testPath.GetDirectory().GetWinPathString().CompareNoCase(_T("C:\\"))==0);
\r
1525 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
\r
1526 // Try a root UNC path
\r
1527 testPath.SetFromUnknown(_T("\\MYSTATION"));
\r
1528 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
\r
1531 void AdminDirTest()
\r
1533 CTGitPath testPath;
\r
1534 testPath.SetFromUnknown(_T("c:\\.svndir"));
\r
1535 ATLASSERT(!testPath.IsAdminDir());
\r
1536 testPath.SetFromUnknown(_T("c:\\test.svn"));
\r
1537 ATLASSERT(!testPath.IsAdminDir());
\r
1538 testPath.SetFromUnknown(_T("c:\\.svn"));
\r
1539 ATLASSERT(testPath.IsAdminDir());
\r
1540 testPath.SetFromUnknown(_T("c:\\.svndir\\test"));
\r
1541 ATLASSERT(!testPath.IsAdminDir());
\r
1542 testPath.SetFromUnknown(_T("c:\\.svn\\test"));
\r
1543 ATLASSERT(testPath.IsAdminDir());
\r
1545 CTGitPathList pathList;
\r
1546 pathList.AddPath(CTGitPath(_T("c:\\.svndir")));
\r
1547 pathList.AddPath(CTGitPath(_T("c:\\.svn")));
\r
1548 pathList.AddPath(CTGitPath(_T("c:\\.svn\\test")));
\r
1549 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1550 pathList.RemoveAdminPaths();
\r
1551 ATLASSERT(pathList.GetCount()==2);
\r
1553 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1554 pathList.RemoveAdminPaths();
\r
1555 ATLASSERT(pathList.GetCount()==1);
\r
1560 CTGitPathList testList;
\r
1561 CTGitPath testPath;
\r
1562 testPath.SetFromUnknown(_T("c:/Z"));
\r
1563 testList.AddPath(testPath);
\r
1564 testPath.SetFromUnknown(_T("c:/B"));
\r
1565 testList.AddPath(testPath);
\r
1566 testPath.SetFromUnknown(_T("c:\\a"));
\r
1567 testList.AddPath(testPath);
\r
1568 testPath.SetFromUnknown(_T("c:/Test"));
\r
1569 testList.AddPath(testPath);
\r
1571 testList.SortByPathname();
\r
1573 ATLASSERT(testList[0].GetWinPathString() == _T("c:\\a"));
\r
1574 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\B"));
\r
1575 ATLASSERT(testList[2].GetWinPathString() == _T("c:\\Test"));
\r
1576 ATLASSERT(testList[3].GetWinPathString() == _T("c:\\Z"));
\r
1579 void RawAppendTest()
\r
1581 CTGitPath testPath(_T("c:/test/"));
\r
1582 testPath.AppendRawString(_T("/Hello"));
\r
1583 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1585 testPath.AppendRawString(_T("\\T2"));
\r
1586 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\r
1588 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
\r
1589 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
\r
1590 testBasePath.AppendRawString(testFilePath.GetFileExtension());
\r
1591 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt.ini"));
\r
1594 void PathAppendTest()
\r
1596 CTGitPath testPath(_T("c:/test/"));
\r
1597 testPath.AppendPathString(_T("/Hello"));
\r
1598 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1600 testPath.AppendPathString(_T("T2"));
\r
1601 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\r
1603 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
\r
1604 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
\r
1605 // You wouldn't want to do this in real life - you'd use append-raw
\r
1606 testBasePath.AppendPathString(testFilePath.GetFileExtension());
\r
1607 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt\\.ini"));
\r
1610 void RemoveDuplicatesTest()
\r
1612 CTGitPathList list;
\r
1613 list.AddPath(CTGitPath(_T("Z")));
\r
1614 list.AddPath(CTGitPath(_T("A")));
\r
1615 list.AddPath(CTGitPath(_T("E")));
\r
1616 list.AddPath(CTGitPath(_T("E")));
\r
1618 ATLASSERT(list[2].IsEquivalentTo(list[3]));
\r
1619 ATLASSERT(list[2]==list[3]);
\r
1621 ATLASSERT(list.GetCount() == 4);
\r
1623 list.RemoveDuplicates();
\r
1625 ATLASSERT(list.GetCount() == 3);
\r
1627 ATLASSERT(list[0].GetWinPathString() == _T("A"));
\r
1628 ATLASSERT(list[1].GetWinPathString().Compare(_T("E")) == 0);
\r
1629 ATLASSERT(list[2].GetWinPathString() == _T("Z"));
\r
1632 void RemoveChildrenTest()
\r
1634 CTGitPathList list;
\r
1635 list.AddPath(CTGitPath(_T("c:\\test")));
\r
1636 list.AddPath(CTGitPath(_T("c:\\test\\file")));
\r
1637 list.AddPath(CTGitPath(_T("c:\\testfile")));
\r
1638 list.AddPath(CTGitPath(_T("c:\\parent")));
\r
1639 list.AddPath(CTGitPath(_T("c:\\parent\\child")));
\r
1640 list.AddPath(CTGitPath(_T("c:\\parent\\child1")));
\r
1641 list.AddPath(CTGitPath(_T("c:\\parent\\child2")));
\r
1643 ATLASSERT(list.GetCount() == 7);
\r
1645 list.RemoveChildren();
\r
1647 ATLTRACE("count = %d\n", list.GetCount());
\r
1648 ATLASSERT(list.GetCount() == 3);
\r
1650 list.SortByPathname();
\r
1652 ATLASSERT(list[0].GetWinPathString().Compare(_T("c:\\parent")) == 0);
\r
1653 ATLASSERT(list[1].GetWinPathString().Compare(_T("c:\\test")) == 0);
\r
1654 ATLASSERT(list[2].GetWinPathString().Compare(_T("c:\\testfile")) == 0);
\r
1657 #if defined(_MFC_VER)
\r
1658 void ListLoadingTest()
\r
1660 TCHAR buf[MAX_PATH];
\r
1661 GetCurrentDirectory(MAX_PATH, buf);
\r
1662 CString sPathList(_T("Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"));
\r
1663 CTGitPathList testList;
\r
1664 testList.LoadFromAsteriskSeparatedString(sPathList);
\r
1666 ATLASSERT(testList.GetCount() == 3);
\r
1667 ATLASSERT(testList[0].GetWinPathString() == CString(buf) + _T("\\Path1"));
\r
1668 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\path2 with spaces and stuff"));
\r
1669 ATLASSERT(testList[2].GetWinPathString() == _T("\\funnypath"));
\r
1671 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T(""));
\r
1673 sPathList = _T("c:\\path2 with spaces and stuff*c:\\funnypath\\*");
\r
1674 testList.LoadFromAsteriskSeparatedString(sPathList);
\r
1675 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T("c:\\"));
\r
1679 void ContainingDirectoryTest()
\r
1682 CTGitPath testPath;
\r
1683 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\r
1685 dir = testPath.GetContainingDirectory();
\r
1686 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c\\d"));
\r
1687 dir = dir.GetContainingDirectory();
\r
1688 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c"));
\r
1689 dir = dir.GetContainingDirectory();
\r
1690 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b"));
\r
1691 dir = dir.GetContainingDirectory();
\r
1692 ATLASSERT(dir.GetWinPathString() == _T("c:\\a"));
\r
1693 dir = dir.GetContainingDirectory();
\r
1694 ATLASSERT(dir.GetWinPathString() == _T("c:\\"));
\r
1695 dir = dir.GetContainingDirectory();
\r
1696 ATLASSERT(dir.IsEmpty());
\r
1697 ATLASSERT(dir.GetWinPathString() == _T(""));
\r
1700 void AncestorTest()
\r
1702 CTGitPath testPath;
\r
1703 testPath.SetFromWin(_T("c:\\windows"));
\r
1704 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\")))==false);
\r
1705 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows"))));
\r
1706 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windowsdummy")))==false);
\r
1707 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\test.txt"))));
\r
1708 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\system32\\test.txt"))));
\r
1711 void SubversionPathTest()
\r
1713 CTGitPath testPath;
\r
1714 testPath.SetFromWin(_T("c:\\"));
\r
1715 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:") == 0);
\r
1716 testPath.SetFromWin(_T("c:\\folder"));
\r
1717 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);
\r
1718 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\r
1719 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);
\r
1720 testPath.SetFromUnknown(_T("http://testing/"));
\r
1721 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);
\r
1722 testPath.SetFromGit(NULL);
\r
1723 ATLASSERT(strlen(testPath.GetGitApiPath(pool))==0);
\r
1724 #if defined(_MFC_VER)
\r
1725 testPath.SetFromUnknown(_T("http://testing again"));
\r
1726 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
\r
1727 testPath.SetFromUnknown(_T("http://testing%20again"));
\r
1728 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
\r
1729 testPath.SetFromUnknown(_T("http://testing special chars \344\366\374"));
\r
1730 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);
\r
1734 void GetCommonRootTest()
\r
1736 CTGitPath pathA (_T("C:\\Development\\LogDlg.cpp"));
\r
1737 CTGitPath pathB (_T("C:\\Development\\LogDlg.h"));
\r
1738 CTGitPath pathC (_T("C:\\Development\\SomeDir\\LogDlg.h"));
\r
1740 CTGitPathList list;
\r
1741 list.AddPath(pathA);
\r
1742 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development\\LogDlg.cpp"))==0);
\r
1743 list.AddPath(pathB);
\r
1744 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
\r
1745 list.AddPath(pathC);
\r
1746 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
\r
1749 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
1750 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1751 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("D:\\Development\\StExBar"))==0);
\r
1754 sPathList = _T("c:\\windows\\explorer.exe*c:\\windows");
\r
1755 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1756 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1759 sPathList = _T("c:\\windows\\*c:\\windows");
\r
1760 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1761 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1764 sPathList = _T("c:\\windows\\system32*c:\\windows\\system");
\r
1765 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1766 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1769 sPathList = _T("c:\\windowsdummy*c:\\windows");
\r
1770 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1771 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\"))==0);
\r
1775 void ValidPathAndUrlTest()
\r
1777 CTGitPath testPath;
\r
1778 testPath.SetFromWin(_T("c:\\a\\b\\c.test.txt"));
\r
1779 ATLASSERT(testPath.IsValidOnWindows());
\r
1780 testPath.SetFromWin(_T("c:\\"));
\r
1781 ATLASSERT(testPath.IsValidOnWindows());
\r
1782 testPath.SetFromWin(_T("D:\\.Net\\SpindleSearch\\"));
\r
1783 ATLASSERT(testPath.IsValidOnWindows());
\r
1784 testPath.SetFromWin(_T("c"));
\r
1785 ATLASSERT(testPath.IsValidOnWindows());
\r
1786 testPath.SetFromWin(_T("c:\\test folder\\file"));
\r
1787 ATLASSERT(testPath.IsValidOnWindows());
\r
1788 testPath.SetFromWin(_T("c:\\folder\\"));
\r
1789 ATLASSERT(testPath.IsValidOnWindows());
\r
1790 testPath.SetFromWin(_T("c:\\ext.ext.ext\\ext.ext.ext.ext"));
\r
1791 ATLASSERT(testPath.IsValidOnWindows());
\r
1792 testPath.SetFromWin(_T("c:\\.svn"));
\r
1793 ATLASSERT(testPath.IsValidOnWindows());
\r
1794 testPath.SetFromWin(_T("c:\\com\\file"));
\r
1795 ATLASSERT(testPath.IsValidOnWindows());
\r
1796 testPath.SetFromWin(_T("c:\\test\\conf"));
\r
1797 ATLASSERT(testPath.IsValidOnWindows());
\r
1798 testPath.SetFromWin(_T("c:\\LPT"));
\r
1799 ATLASSERT(testPath.IsValidOnWindows());
\r
1800 testPath.SetFromWin(_T("c:\\test\\LPT"));
\r
1801 ATLASSERT(testPath.IsValidOnWindows());
\r
1802 testPath.SetFromWin(_T("c:\\com1test"));
\r
1803 ATLASSERT(testPath.IsValidOnWindows());
\r
1804 testPath.SetFromWin(_T("\\\\?\\c:\\test\\com1test"));
\r
1805 ATLASSERT(testPath.IsValidOnWindows());
\r
1807 testPath.SetFromWin(_T("\\\\Share\\filename"));
\r
1808 ATLASSERT(testPath.IsValidOnWindows());
\r
1809 testPath.SetFromWin(_T("\\\\Share\\filename.extension"));
\r
1810 ATLASSERT(testPath.IsValidOnWindows());
\r
1811 testPath.SetFromWin(_T("\\\\Share\\.svn"));
\r
1812 ATLASSERT(testPath.IsValidOnWindows());
\r
1814 // now the negative tests
\r
1815 testPath.SetFromWin(_T("c:\\test:folder"));
\r
1816 ATLASSERT(!testPath.IsValidOnWindows());
\r
1817 testPath.SetFromWin(_T("c:\\file<name"));
\r
1818 ATLASSERT(!testPath.IsValidOnWindows());
\r
1819 testPath.SetFromWin(_T("c:\\something*else"));
\r
1820 ATLASSERT(!testPath.IsValidOnWindows());
\r
1821 testPath.SetFromWin(_T("c:\\folder\\file?nofile"));
\r
1822 ATLASSERT(!testPath.IsValidOnWindows());
\r
1823 testPath.SetFromWin(_T("c:\\ext.>ension"));
\r
1824 ATLASSERT(!testPath.IsValidOnWindows());
\r
1825 testPath.SetFromWin(_T("c:\\com1\\filename"));
\r
1826 ATLASSERT(!testPath.IsValidOnWindows());
\r
1827 testPath.SetFromWin(_T("c:\\com1"));
\r
1828 ATLASSERT(!testPath.IsValidOnWindows());
\r
1829 testPath.SetFromWin(_T("c:\\com1\\AuX"));
\r
1830 ATLASSERT(!testPath.IsValidOnWindows());
\r
1832 testPath.SetFromWin(_T("\\\\Share\\lpt9\\filename"));
\r
1833 ATLASSERT(!testPath.IsValidOnWindows());
\r
1834 testPath.SetFromWin(_T("\\\\Share\\prn"));
\r
1835 ATLASSERT(!testPath.IsValidOnWindows());
\r
1836 testPath.SetFromWin(_T("\\\\Share\\NUL"));
\r
1837 ATLASSERT(!testPath.IsValidOnWindows());
\r
1839 // now come some URL tests
\r
1840 testPath.SetFromGit(_T("http://myserver.com/repos/trunk"));
\r
1841 ATLASSERT(testPath.IsValidOnWindows());
\r
1842 testPath.SetFromGit(_T("https://myserver.com/repos/trunk/file%20with%20spaces"));
\r
1843 ATLASSERT(testPath.IsValidOnWindows());
\r
1844 testPath.SetFromGit(_T("svn://myserver.com/repos/trunk/file with spaces"));
\r
1845 ATLASSERT(testPath.IsValidOnWindows());
\r
1846 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk"));
\r
1847 ATLASSERT(testPath.IsValidOnWindows());
\r
1848 testPath.SetFromGit(_T("http://localhost:90/repos/trunk"));
\r
1849 ATLASSERT(testPath.IsValidOnWindows());
\r
1850 testPath.SetFromGit(_T("file:///C:/GitRepos/Tester/Proj1/tags/t2"));
\r
1851 ATLASSERT(testPath.IsValidOnWindows());
\r
1852 // and some negative URL tests
\r
1853 testPath.SetFromGit(_T("httpp://myserver.com/repos/trunk"));
\r
1854 ATLASSERT(!testPath.IsValidOnWindows());
\r
1855 testPath.SetFromGit(_T("https://myserver.com/rep:os/trunk/file%20with%20spaces"));
\r
1856 ATLASSERT(!testPath.IsValidOnWindows());
\r
1857 testPath.SetFromGit(_T("svn://myserver.com/rep<os/trunk/file with spaces"));
\r
1858 ATLASSERT(!testPath.IsValidOnWindows());
\r
1859 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk/prn/"));
\r
1860 ATLASSERT(!testPath.IsValidOnWindows());
\r
1861 testPath.SetFromGit(_T("http://localhost:90/repos/trunk/com1"));
\r
1862 ATLASSERT(!testPath.IsValidOnWindows());
\r
1866 } TGitPathTestobject;
\r
1870 CTGitPath * CTGitPathList::LookForGitPath(CString path)
\r
1873 for(i=0;i<this->GetCount();i++)
\r
1875 if((*this)[i].GetGitPathString() == path )
\r
1876 return (CTGitPath*)&(*this)[i];
\r
1880 CString CTGitPath::GetActionName(int action)
\r
1882 if(action & CTGitPath::LOGACTIONS_UNMERGED)
\r
1883 return _T("Conflict");
\r
1884 if(action & CTGitPath::LOGACTIONS_ADDED)
\r
1885 return _T("Added");
\r
1886 if(action & CTGitPath::LOGACTIONS_DELETED)
\r
1887 return _T("Deleted");
\r
1888 if(action & CTGitPath::LOGACTIONS_MODIFIED)
\r
1889 return _T("Modified");
\r
1890 if(action & CTGitPath::LOGACTIONS_REPLACED)
\r
1891 return _T("Rename");
\r
1892 if(action & CTGitPath::LOGACTIONS_COPY)
\r
1893 return _T("Copy");
\r
1894 if(action & CTGitPath::LOGACTIONS_REBASE_EDIT)
\r
1895 return _T("Edit");
\r
1896 if(action & CTGitPath::LOGACTIONS_REBASE_SQUASH)
\r
1897 return _T("Squash");
\r
1898 if(action & CTGitPath::LOGACTIONS_REBASE_PICK)
\r
1899 return _T("Pick");
\r
1900 if(action & CTGitPath::LOGACTIONS_REBASE_SKIP)
\r
1901 return _T("Skip");
\r
1903 return _T("Unknown");
\r
1905 CString CTGitPath::GetActionName()
\r
1907 return GetActionName(m_Action);
\r
1910 int CTGitPathList::GetAction()
\r