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
431 CTGitPath CTGitPath::GetSubPath(CTGitPath &root)
\r
435 if(GetWinPathString().Left(root.GetWinPathString().GetLength()) == root.GetWinPathString())
\r
437 CString str=GetWinPathString();
\r
438 path.SetFromWin(str.Right(str.GetLength()-root.GetWinPathString().GetLength()-1));
\r
443 void CTGitPath::EnsureBackslashPathSet() const
\r
445 if(m_sBackslashPath.IsEmpty())
\r
447 SetBackslashPath(m_sFwdslashPath);
\r
448 ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());
\r
451 void CTGitPath::EnsureFwdslashPathSet() const
\r
453 if(m_sFwdslashPath.IsEmpty())
\r
455 SetFwdslashPath(m_sBackslashPath);
\r
456 ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());
\r
461 // Reset all the caches
\r
462 void CTGitPath::Reset()
\r
464 m_bDirectoryKnown = false;
\r
465 m_bURLKnown = false;
\r
466 m_bLastWriteTimeKnown = false;
\r
467 m_bHasAdminDirKnown = false;
\r
468 m_bIsValidOnWindowsKnown = false;
\r
469 m_bIsAdminDirKnown = false;
\r
470 m_bExistsKnown = false;
\r
471 m_bIsSpecialDirectoryKnown = false;
\r
472 m_bIsSpecialDirectory = false;
\r
474 m_sBackslashPath.Empty();
\r
475 m_sFwdslashPath.Empty();
\r
476 m_sUTF8FwdslashPath.Empty();
\r
478 this->m_StatAdd=_T("");
\r
479 this->m_StatDel=_T("");
\r
480 ATLASSERT(IsEmpty());
\r
483 CTGitPath CTGitPath::GetDirectory() const
\r
485 if ((IsDirectory())||(!Exists()))
\r
489 return GetContainingDirectory();
\r
492 CTGitPath CTGitPath::GetContainingDirectory() const
\r
494 EnsureBackslashPathSet();
\r
496 CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));
\r
497 if(sDirName.GetLength() == 2 && sDirName[1] == ':')
\r
499 // This is a root directory, which needs a trailing slash
\r
501 if(sDirName == m_sBackslashPath)
\r
503 // We were clearly provided with a root path to start with - we should return nothing now
\r
507 if(sDirName.GetLength() == 1 && sDirName[0] == '\\')
\r
509 // We have an UNC path and we already are the root
\r
513 retVal.SetFromWin(sDirName);
\r
517 CString CTGitPath::GetRootPathString() const
\r
519 EnsureBackslashPathSet();
\r
520 CString workingPath = m_sBackslashPath;
\r
521 LPTSTR pPath = workingPath.GetBuffer(MAX_PATH); // MAX_PATH ok here.
\r
522 ATLVERIFY(::PathStripToRoot(pPath));
\r
523 workingPath.ReleaseBuffer();
\r
524 return workingPath;
\r
528 CString CTGitPath::GetFilename() const
\r
530 ATLASSERT(!IsDirectory());
\r
531 return GetFileOrDirectoryName();
\r
534 CString CTGitPath::GetFileOrDirectoryName() const
\r
536 EnsureBackslashPathSet();
\r
537 return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);
\r
540 CString CTGitPath::GetUIFileOrDirectoryName() const
\r
543 return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);
\r
546 CString CTGitPath::GetFileExtension() const
\r
550 EnsureBackslashPathSet();
\r
551 int dotPos = m_sBackslashPath.ReverseFind('.');
\r
552 int slashPos = m_sBackslashPath.ReverseFind('\\');
\r
553 if (dotPos > slashPos)
\r
554 return m_sBackslashPath.Mid(dotPos);
\r
558 CString CTGitPath::GetBaseFilename() const
\r
561 CString filename=GetFilename();
\r
562 dot = filename.ReverseFind(_T('.'));
\r
564 return filename.Left(dot);
\r
569 bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)
\r
571 int length = sP1.GetLength();
\r
572 if(length != sP2.GetLength())
\r
574 // Different lengths
\r
577 // We work from the end of the strings, because path differences
\r
578 // are more likely to occur at the far end of a string
\r
579 LPCTSTR pP1Start = sP1;
\r
580 LPCTSTR pP1 = pP1Start+(length-1);
\r
581 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
\r
582 while(length-- > 0)
\r
584 if(_totlower(*pP1--) != _totlower(*pP2--))
\r
592 bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)
\r
594 int length = sP1.GetLength();
\r
595 if(length != sP2.GetLength())
\r
597 // Different lengths
\r
600 // We work from the end of the strings, because path differences
\r
601 // are more likely to occur at the far end of a string
\r
602 LPCTSTR pP1Start = sP1;
\r
603 LPCTSTR pP1 = pP1Start+(length-1);
\r
604 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
\r
605 while(length-- > 0)
\r
607 if((*pP1--) != (*pP2--))
\r
615 bool CTGitPath::IsEmpty() const
\r
617 // Check the backward slash path first, since the chance that this
\r
618 // one is set is higher. In case of a 'false' return value it's a little
\r
620 return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();
\r
623 // Test if both paths refer to the same item
\r
624 // Ignores case and slash direction
\r
625 bool CTGitPath::IsEquivalentTo(const CTGitPath& rhs) const
\r
627 // Try and find a slash direction which avoids having to convert
\r
629 if(!m_sBackslashPath.IsEmpty())
\r
631 // *We've* got a \ path - make sure that the RHS also has a \ path
\r
632 rhs.EnsureBackslashPathSet();
\r
633 return ArePathStringsEqualWithCase(m_sBackslashPath, rhs.m_sBackslashPath);
\r
637 // Assume we've got a fwdslash path and make sure that the RHS has one
\r
638 rhs.EnsureFwdslashPathSet();
\r
639 return ArePathStringsEqualWithCase(m_sFwdslashPath, rhs.m_sFwdslashPath);
\r
643 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const
\r
645 // Try and find a slash direction which avoids having to convert
\r
647 if(!m_sBackslashPath.IsEmpty())
\r
649 // *We've* got a \ path - make sure that the RHS also has a \ path
\r
650 rhs.EnsureBackslashPathSet();
\r
651 return ArePathStringsEqual(m_sBackslashPath, rhs.m_sBackslashPath);
\r
655 // Assume we've got a fwdslash path and make sure that the RHS has one
\r
656 rhs.EnsureFwdslashPathSet();
\r
657 return ArePathStringsEqual(m_sFwdslashPath, rhs.m_sFwdslashPath);
\r
661 bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const
\r
663 possibleDescendant.EnsureBackslashPathSet();
\r
664 EnsureBackslashPathSet();
\r
666 bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));
\r
667 if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())
\r
669 return bPathStringsEqual;
\r
672 return (bPathStringsEqual &&
\r
673 ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||
\r
674 (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));
\r
677 // Get a string representing the file path, optionally with a base
\r
678 // section stripped off the front.
\r
679 CString CTGitPath::GetDisplayString(const CTGitPath* pOptionalBasePath /* = NULL*/) const
\r
681 EnsureFwdslashPathSet();
\r
682 if(pOptionalBasePath != NULL)
\r
684 // Find the length of the base-path without having to do an 'ensure' on it
\r
685 int baseLength = max(pOptionalBasePath->m_sBackslashPath.GetLength(), pOptionalBasePath->m_sFwdslashPath.GetLength());
\r
687 // Now, chop that baseLength of the front of the path
\r
688 return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');
\r
690 return m_sFwdslashPath;
\r
693 int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)
\r
695 left.EnsureBackslashPathSet();
\r
696 right.EnsureBackslashPathSet();
\r
697 return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);
\r
700 bool operator<(const CTGitPath& left, const CTGitPath& right)
\r
702 return CTGitPath::Compare(left, right) < 0;
\r
705 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)
\r
707 return left.IsEquivalentTo(right);
\r
710 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)
\r
712 if (left.IsAdminDir() && right.IsAdminDir())
\r
714 CTGitPath l = left;
\r
715 CTGitPath r = right;
\r
718 l = l.GetContainingDirectory();
\r
719 } while(l.HasAdminDir());
\r
722 r = r.GetContainingDirectory();
\r
723 } while(r.HasAdminDir());
\r
724 return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());
\r
726 return left.GetDirectory().IsEquivalentTo(right.GetDirectory());
\r
729 bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)
\r
731 return parent.IsAncestorOf(child);
\r
734 void CTGitPath::AppendRawString(const CString& sAppend)
\r
736 EnsureFwdslashPathSet();
\r
737 CString strCopy = m_sFwdslashPath += sAppend;
\r
738 SetFromUnknown(strCopy);
\r
741 void CTGitPath::AppendPathString(const CString& sAppend)
\r
743 EnsureBackslashPathSet();
\r
744 CString cleanAppend(sAppend);
\r
745 cleanAppend.Replace('/', '\\');
\r
746 cleanAppend.TrimLeft('\\');
\r
747 m_sBackslashPath.TrimRight('\\');
\r
748 CString strCopy = m_sBackslashPath + _T("\\") + cleanAppend;
\r
749 SetFromWin(strCopy);
\r
752 bool CTGitPath::HasAdminDir() const
\r
754 if (m_bHasAdminDirKnown)
\r
755 return m_bHasAdminDir;
\r
757 EnsureBackslashPathSet();
\r
758 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
\r
759 m_bHasAdminDirKnown = true;
\r
760 return m_bHasAdminDir;
\r
763 bool CTGitPath::HasSubmodules() const
\r
765 return !g_GitAdminDir.GetSuperProjectRoot(GetWinPathString()).IsEmpty();
\r
768 bool CTGitPath::HasGitSVNDir() const
\r
771 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
\r
776 topdir+=g_GitAdminDir.GetAdminDirName();
\r
777 topdir+=_T("\\svn");
\r
778 return PathFileExists(topdir);
\r
780 bool CTGitPath::HasAdminDir(CString *ProjectTopDir) const
\r
782 if (m_bHasAdminDirKnown)
\r
785 *ProjectTopDir = m_sProjectRoot;
\r
786 return m_bHasAdminDir;
\r
789 EnsureBackslashPathSet();
\r
790 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
\r
791 m_bHasAdminDirKnown = true;
\r
793 *ProjectTopDir = m_sProjectRoot;
\r
794 return m_bHasAdminDir;
\r
797 bool CTGitPath::IsAdminDir() const
\r
799 if (m_bIsAdminDirKnown)
\r
800 return m_bIsAdminDir;
\r
802 EnsureBackslashPathSet();
\r
803 m_bIsAdminDir = g_GitAdminDir.IsAdminDirPath(m_sBackslashPath);
\r
804 m_bIsAdminDirKnown = true;
\r
805 return m_bIsAdminDir;
\r
808 bool CTGitPath::IsValidOnWindows() const
\r
810 if (m_bIsValidOnWindowsKnown)
\r
811 return m_bIsValidOnWindows;
\r
813 m_bIsValidOnWindows = false;
\r
814 EnsureBackslashPathSet();
\r
815 CString sMatch = m_sBackslashPath + _T("\r\n");
\r
817 // the 'file://' URL is just a normal windows path:
\r
818 if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)
\r
820 sMatch = sMatch.Mid(7);
\r
821 sMatch.TrimLeft(_T("\\"));
\r
822 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
826 sPattern = _T("^((http|https|svn|svn\\+ssh|file)\\:\\\\+([^\\\\@\\:]+\\:[^\\\\@\\:]+@)?\\\\[^\\\\]+(\\:\\d+)?)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
830 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
835 tr1::wregex rx(sPattern, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
836 tr1::wsmatch match;
\r
838 wstring rmatch = wstring((LPCTSTR)sMatch);
\r
839 if (tr1::regex_match(rmatch, match, rx))
\r
841 if (wstring(match[0]).compare(sMatch)==0)
\r
842 m_bIsValidOnWindows = true;
\r
844 if (m_bIsValidOnWindows)
\r
846 // now check for illegal filenames
\r
847 tr1::wregex rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
848 rmatch = m_sBackslashPath;
\r
849 if (tr1::regex_search(rmatch, rx2, tr1::regex_constants::match_default))
\r
850 m_bIsValidOnWindows = false;
\r
853 catch (exception) {}
\r
855 m_bIsValidOnWindowsKnown = true;
\r
856 return m_bIsValidOnWindows;
\r
859 bool CTGitPath::IsSpecialDirectory() const
\r
861 if (m_bIsSpecialDirectoryKnown)
\r
862 return m_bIsSpecialDirectory;
\r
864 static LPCTSTR specialDirectories[]
\r
865 = { _T("trunk"), _T("tags"), _T("branches") };
\r
867 for (int i=0 ; i<(sizeof(specialDirectories) / sizeof(specialDirectories[0])) ; ++i)
\r
869 CString name = GetFileOrDirectoryName();
\r
870 if (0 == name.CompareNoCase(specialDirectories[i]))
\r
872 m_bIsSpecialDirectory = true;
\r
877 m_bIsSpecialDirectoryKnown = true;
\r
879 return m_bIsSpecialDirectory;
\r
882 //////////////////////////////////////////////////////////////////////////
\r
884 CTGitPathList::CTGitPathList()
\r
889 // A constructor which allows a path list to be easily built which one initial entry in
\r
890 CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)
\r
892 AddPath(firstEntry);
\r
894 int CTGitPathList::ParserFromLsFile(BYTE_VECTOR &out,bool staged)
\r
900 while(pos>=0 && pos<out.size())
\r
905 g_Git.StringAppend(&one,&out[pos],CP_ACP);
\r
907 path.m_Action=path.ParserAction(out[pos]);
\r
908 one.Tokenize(_T("\t"),tabstart);
\r
911 path.SetFromGit(one.Right(one.GetLength()-tabstart));
\r
915 part=one.Tokenize(_T(" "),tabstart); //Tag
\r
917 part=one.Tokenize(_T(" "),tabstart); //Mode
\r
919 part=one.Tokenize(_T(" "),tabstart); //Hash
\r
921 part=one.Tokenize(_T("\t"),tabstart); //Stage
\r
923 path.m_Stage=_ttol(part);
\r
925 this->AddPath(path);
\r
927 pos=out.findNextString(pos);
\r
931 int CTGitPathList::FillUnRev(int action,CTGitPathList *list)
\r
941 count=list->GetCount();
\r
942 for(int i=0;i<count;i++)
\r
948 if(action & CTGitPath::LOGACTIONS_IGNORE)
\r
949 ignored= _T(" --ignored");
\r
953 cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");
\r
958 { cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z %s-- \"%s\""),
\r
960 (*list)[i].GetWinPathString());
\r
965 g_Git.Run(cmd,&out);
\r
969 while( pos>=0 && pos<out.size())
\r
972 g_Git.StringAppend(&one,&out[pos],CP_ACP);
\r
975 //SetFromGit will clear all status
\r
976 path.SetFromGit(one);
\r
977 path.m_Action=action;
\r
980 pos=out.findNextString(pos);
\r
986 int CTGitPathList::ParserFromLog(BYTE_VECTOR &log)
\r
994 while( pos>=0 && pos<log.size())
\r
996 //one=log.Tokenize(_T("\n"),pos);
\r
1003 bool merged=false;
\r
1004 if(log[pos+1] ==':')
\r
1008 int end=log.find(0,pos);
\r
1009 int actionstart=-1;
\r
1011 int file1=-1,file2=-1;
\r
1014 actionstart=log.find(' ',end-6);
\r
1017 if( actionstart>0 )
\r
1021 file1 = log.find(0,actionstart);
\r
1027 if( log[actionstart] == 'C' || log[actionstart] == 'R' )
\r
1031 file1 = log.find(0,file1);
\r
1041 CString pathname1;
\r
1042 CString pathname2;
\r
1045 g_Git.StringAppend(&pathname1,&log[file1],CP_ACP);
\r
1047 g_Git.StringAppend(&pathname2,&log[file2],CP_ACP);
\r
1049 CTGitPath *GitPath=LookForGitPath(pathname1);
\r
1053 GitPath->ParserAction( log[actionstart] );
\r
1057 GitPath->m_Action |= CTGitPath::LOGACTIONS_MERGED;
\r
1058 GitPath->m_Action &= ~CTGitPath::LOGACTIONS_FORWORD;
\r
1060 m_Action |=GitPath->m_Action;
\r
1064 int ac=path.ParserAction(log[actionstart] );
\r
1065 ac |= merged?CTGitPath::LOGACTIONS_MERGED:0;
\r
1067 path.SetFromGit(pathname1,&pathname2);
\r
1069 //action must be set after setfromgit. SetFromGit will clear all status.
\r
1070 this->m_Action|=ac;
\r
1085 tabstart=log.find('\t',pos);
\r
1089 g_Git.StringAppend(&StatAdd,&log[pos],CP_UTF8);
\r
1093 tabstart=log.find('\t',pos);
\r
1098 g_Git.StringAppend(&StatDel,&log[pos],CP_UTF8);
\r
1102 if(log[pos] == 0) //rename
\r
1105 g_Git.StringAppend(&file2,&log[pos],CP_ACP);
\r
1106 int sec=log.find(0,pos);
\r
1110 g_Git.StringAppend(&file1,&log[sec],CP_ACP);
\r
1116 g_Git.StringAppend(&file1,&log[pos],CP_ACP);
\r
1118 path.SetFromGit(file1,&file2);
\r
1120 CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());
\r
1123 GitPath->m_StatAdd=StatAdd;
\r
1124 GitPath->m_StatDel=StatDel;
\r
1127 //path.SetFromGit(pathname);
\r
1128 path.m_StatAdd=StatAdd;
\r
1129 path.m_StatDel=StatDel;
\r
1130 path.m_Action |= CTGitPath::LOGACTIONS_FORWORD;
\r
1135 pos=log.findNextString(pos);
\r
1140 void CTGitPathList::AddPath(const CTGitPath& newPath)
\r
1142 m_paths.push_back(newPath);
\r
1143 m_commonBaseDirectory.Reset();
\r
1145 int CTGitPathList::GetCount() const
\r
1147 return (int)m_paths.size();
\r
1149 void CTGitPathList::Clear()
\r
1152 m_commonBaseDirectory.Reset();
\r
1155 const CTGitPath& CTGitPathList::operator[](INT_PTR index) const
\r
1157 ATLASSERT(index >= 0 && index < (INT_PTR)m_paths.size());
\r
1158 return m_paths[index];
\r
1161 bool CTGitPathList::AreAllPathsFiles() const
\r
1163 // Look through the vector for any directories - if we find them, return false
\r
1164 return std::find_if(m_paths.begin(), m_paths.end(), std::mem_fun_ref(&CTGitPath::IsDirectory)) == m_paths.end();
\r
1168 #if defined(_MFC_VER)
\r
1170 bool CTGitPathList::LoadFromFile(const CTGitPath& filename)
\r
1176 CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite);
\r
1178 // for every selected file/folder
\r
1180 while (file.ReadString(strLine))
\r
1182 path.SetFromUnknown(strLine);
\r
1187 catch (CFileException* pE)
\r
1189 TRACE("CFileException loading target file list\n");
\r
1190 TCHAR error[10000] = {0};
\r
1191 pE->GetErrorMessage(error, 10000);
\r
1192 // CMessageBox::Show(NULL, error, _T("TortoiseGit"), MB_ICONERROR);
\r
1199 bool CTGitPathList::WriteToFile(const CString& sFilename, bool bANSI /* = false */) const
\r
1205 CStdioFile file(sFilename, CFile::typeText | CFile::modeReadWrite | CFile::modeCreate);
\r
1206 PathVector::const_iterator it;
\r
1207 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1209 CStringA line = CStringA(it->GetGitPathString()) + '\n';
\r
1210 file.Write(line, line.GetLength());
\r
1216 CStdioFile file(sFilename, CFile::typeBinary | CFile::modeReadWrite | CFile::modeCreate);
\r
1217 PathVector::const_iterator it;
\r
1218 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1220 file.WriteString(it->GetGitPathString()+_T("\n"));
\r
1225 catch (CFileException* pE)
\r
1227 TRACE("CFileException in writing temp file\n");
\r
1235 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString& sPathString)
\r
1241 temp = sPathString.Tokenize(_T("*"),pos);
\r
1242 if(temp.IsEmpty())
\r
1246 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp)));
\r
1250 CString CTGitPathList::CreateAsteriskSeparatedString() const
\r
1253 PathVector::const_iterator it;
\r
1254 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1256 if (!sRet.IsEmpty())
\r
1258 sRet += it->GetWinPathString();
\r
1262 #endif // _MFC_VER
\r
1265 CTGitPathList::AreAllPathsFilesInOneDirectory() const
\r
1267 // Check if all the paths are files and in the same directory
\r
1268 PathVector::const_iterator it;
\r
1269 m_commonBaseDirectory.Reset();
\r
1270 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1272 if(it->IsDirectory())
\r
1276 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1277 if(m_commonBaseDirectory.IsEmpty())
\r
1279 m_commonBaseDirectory = baseDirectory;
\r
1281 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1284 m_commonBaseDirectory.Reset();
\r
1291 CTGitPath CTGitPathList::GetCommonDirectory() const
\r
1293 if (m_commonBaseDirectory.IsEmpty())
\r
1295 PathVector::const_iterator it;
\r
1296 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1298 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1299 if(m_commonBaseDirectory.IsEmpty())
\r
1301 m_commonBaseDirectory = baseDirectory;
\r
1303 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1306 m_commonBaseDirectory.Reset();
\r
1311 // since we only checked strings, not paths,
\r
1312 // we have to make sure now that we really return a *path* here
\r
1313 PathVector::const_iterator iter;
\r
1314 for(iter = m_paths.begin(); iter != m_paths.end(); ++iter)
\r
1316 if (!m_commonBaseDirectory.IsAncestorOf(*iter))
\r
1318 m_commonBaseDirectory = m_commonBaseDirectory.GetContainingDirectory();
\r
1322 return m_commonBaseDirectory;
\r
1325 CTGitPath CTGitPathList::GetCommonRoot() const
\r
1327 PathVector::const_iterator it;
\r
1328 CString sRoot, sTempRoot;
\r
1329 bool bEqual = true;
\r
1331 if (GetCount() == 1)
\r
1332 return m_paths[0];
\r
1334 int backSlashPos = 0;
\r
1335 int searchStartPos = 0;
\r
1338 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1340 if (backSlashPos == 0)
\r
1342 backSlashPos = it->GetWinPathString().Find('\\', searchStartPos+1);
\r
1343 if ((backSlashPos < 0)&&(searchStartPos != it->GetWinPathString().GetLength()))
\r
1344 backSlashPos = it->GetWinPathString().GetLength();
\r
1346 else if (it->GetWinPathString().Find('\\', searchStartPos+1) != backSlashPos)
\r
1348 if (it->GetWinPathString().Find('\\', searchStartPos+1) < 0)
\r
1350 if (it->GetWinPathString().GetLength() != backSlashPos)
\r
1362 if (backSlashPos < 0)
\r
1368 if (bEqual == false)
\r
1370 if (searchStartPos)
\r
1371 sRoot = m_paths[0].GetWinPathString().Left(searchStartPos+1);
\r
1375 searchStartPos = backSlashPos;
\r
1380 return CTGitPath(sRoot.TrimRight('\\'));
\r
1383 void CTGitPathList::SortByPathname(bool bReverse /*= false*/)
\r
1385 std::sort(m_paths.begin(), m_paths.end());
\r
1387 std::reverse(m_paths.begin(), m_paths.end());
\r
1390 void CTGitPathList::DeleteAllFiles(bool bTrash)
\r
1392 PathVector::const_iterator it;
\r
1397 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1399 if ((it->Exists())&&(!it->IsDirectory()))
\r
1401 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1402 sPaths += it->GetWinPath();
\r
1408 SHFILEOPSTRUCT shop = {0};
\r
1409 shop.wFunc = FO_DELETE;
\r
1410 shop.pFrom = (LPCTSTR)sPaths;
\r
1411 shop.fFlags = FOF_ALLOWUNDO|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
\r
1412 SHFileOperation(&shop);
\r
1416 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1418 if (!it->IsDirectory())
\r
1420 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1421 ::DeleteFile(it->GetWinPath());
\r
1428 void CTGitPathList::RemoveDuplicates()
\r
1431 // Remove the duplicates
\r
1432 // (Unique moves them to the end of the vector, then erase chops them off)
\r
1433 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::PredLeftEquivalentToRight), m_paths.end());
\r
1436 void CTGitPathList::RemoveAdminPaths()
\r
1438 PathVector::iterator it;
\r
1439 for(it = m_paths.begin(); it != m_paths.end(); )
\r
1441 if (it->IsAdminDir())
\r
1443 m_paths.erase(it);
\r
1444 it = m_paths.begin();
\r
1451 void CTGitPathList::RemovePath(const CTGitPath& path)
\r
1453 PathVector::iterator it;
\r
1454 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1456 if (it->IsEquivalentTo(path))
\r
1458 m_paths.erase(it);
\r
1464 void CTGitPathList::RemoveItem(CTGitPath & path)
\r
1466 PathVector::iterator it;
\r
1467 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1469 if (it->GetGitPathString()==path.GetGitPathString())
\r
1471 m_paths.erase(it);
\r
1476 void CTGitPathList::RemoveChildren()
\r
1479 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::CheckChild), m_paths.end());
\r
1482 bool CTGitPathList::IsEqual(const CTGitPathList& list)
\r
1484 if (list.GetCount() != GetCount())
\r
1486 for (int i=0; i<list.GetCount(); ++i)
\r
1488 if (!list[i].IsEquivalentTo(m_paths[i]))
\r
1494 //////////////////////////////////////////////////////////////////////////
\r
1496 apr_array_header_t * CTGitPathList::MakePathArray (apr_pool_t *pool) const
\r
1498 apr_array_header_t *targets = apr_array_make (pool, GetCount(), sizeof(const char *));
\r
1500 for(int nItem = 0; nItem < GetCount(); nItem++)
\r
1502 const char * target = m_paths[nItem].GetGitApiPath(pool);
\r
1503 (*((const char **) apr_array_push (targets))) = target;
\r
1509 //////////////////////////////////////////////////////////////////////////
\r
1512 #if defined(_DEBUG)
\r
1513 // Some test cases for these classes
\r
1514 static class CTGitPathTests
\r
1520 pool = svn_pool_create(NULL);
\r
1521 GetDirectoryTest();
\r
1526 RemoveDuplicatesTest();
\r
1527 RemoveChildrenTest();
\r
1528 ContainingDirectoryTest();
\r
1530 SubversionPathTest();
\r
1531 GetCommonRootTest();
\r
1532 #if defined(_MFC_VER)
\r
1533 ValidPathAndUrlTest();
\r
1534 ListLoadingTest();
\r
1540 // apr_pool_t * pool;
\r
1541 void GetDirectoryTest()
\r
1543 // Bit tricky, this test, because we need to know something about the file
\r
1544 // layout on the machine which is running the test
\r
1545 TCHAR winDir[MAX_PATH+1];
\r
1546 GetWindowsDirectory(winDir, MAX_PATH);
\r
1547 CString sWinDir(winDir);
\r
1549 CTGitPath testPath;
\r
1550 // This is a file which we know will always be there
\r
1551 testPath.SetFromUnknown(sWinDir + _T("\\win.ini"));
\r
1552 ATLASSERT(!testPath.IsDirectory());
\r
1553 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
\r
1554 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() == sWinDir);
\r
1556 // Now do the test on the win directory itself - It's hard to be sure about the containing directory
\r
1557 // but we know it must be different to the directory itself
\r
1558 testPath.SetFromUnknown(sWinDir);
\r
1559 ATLASSERT(testPath.IsDirectory());
\r
1560 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
\r
1561 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() != sWinDir);
\r
1562 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString().GetLength() < sWinDir.GetLength());
\r
1564 // Try a root path
\r
1565 testPath.SetFromUnknown(_T("C:\\"));
\r
1566 ATLASSERT(testPath.IsDirectory());
\r
1567 ATLASSERT(testPath.GetDirectory().GetWinPathString().CompareNoCase(_T("C:\\"))==0);
\r
1568 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
\r
1569 // Try a root UNC path
\r
1570 testPath.SetFromUnknown(_T("\\MYSTATION"));
\r
1571 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
\r
1574 void AdminDirTest()
\r
1576 CTGitPath testPath;
\r
1577 testPath.SetFromUnknown(_T("c:\\.svndir"));
\r
1578 ATLASSERT(!testPath.IsAdminDir());
\r
1579 testPath.SetFromUnknown(_T("c:\\test.svn"));
\r
1580 ATLASSERT(!testPath.IsAdminDir());
\r
1581 testPath.SetFromUnknown(_T("c:\\.svn"));
\r
1582 ATLASSERT(testPath.IsAdminDir());
\r
1583 testPath.SetFromUnknown(_T("c:\\.svndir\\test"));
\r
1584 ATLASSERT(!testPath.IsAdminDir());
\r
1585 testPath.SetFromUnknown(_T("c:\\.svn\\test"));
\r
1586 ATLASSERT(testPath.IsAdminDir());
\r
1588 CTGitPathList pathList;
\r
1589 pathList.AddPath(CTGitPath(_T("c:\\.svndir")));
\r
1590 pathList.AddPath(CTGitPath(_T("c:\\.svn")));
\r
1591 pathList.AddPath(CTGitPath(_T("c:\\.svn\\test")));
\r
1592 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1593 pathList.RemoveAdminPaths();
\r
1594 ATLASSERT(pathList.GetCount()==2);
\r
1596 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1597 pathList.RemoveAdminPaths();
\r
1598 ATLASSERT(pathList.GetCount()==1);
\r
1603 CTGitPathList testList;
\r
1604 CTGitPath testPath;
\r
1605 testPath.SetFromUnknown(_T("c:/Z"));
\r
1606 testList.AddPath(testPath);
\r
1607 testPath.SetFromUnknown(_T("c:/B"));
\r
1608 testList.AddPath(testPath);
\r
1609 testPath.SetFromUnknown(_T("c:\\a"));
\r
1610 testList.AddPath(testPath);
\r
1611 testPath.SetFromUnknown(_T("c:/Test"));
\r
1612 testList.AddPath(testPath);
\r
1614 testList.SortByPathname();
\r
1616 ATLASSERT(testList[0].GetWinPathString() == _T("c:\\a"));
\r
1617 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\B"));
\r
1618 ATLASSERT(testList[2].GetWinPathString() == _T("c:\\Test"));
\r
1619 ATLASSERT(testList[3].GetWinPathString() == _T("c:\\Z"));
\r
1622 void RawAppendTest()
\r
1624 CTGitPath testPath(_T("c:/test/"));
\r
1625 testPath.AppendRawString(_T("/Hello"));
\r
1626 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1628 testPath.AppendRawString(_T("\\T2"));
\r
1629 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\r
1631 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
\r
1632 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
\r
1633 testBasePath.AppendRawString(testFilePath.GetFileExtension());
\r
1634 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt.ini"));
\r
1637 void PathAppendTest()
\r
1639 CTGitPath testPath(_T("c:/test/"));
\r
1640 testPath.AppendPathString(_T("/Hello"));
\r
1641 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1643 testPath.AppendPathString(_T("T2"));
\r
1644 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\r
1646 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
\r
1647 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
\r
1648 // You wouldn't want to do this in real life - you'd use append-raw
\r
1649 testBasePath.AppendPathString(testFilePath.GetFileExtension());
\r
1650 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt\\.ini"));
\r
1653 void RemoveDuplicatesTest()
\r
1655 CTGitPathList list;
\r
1656 list.AddPath(CTGitPath(_T("Z")));
\r
1657 list.AddPath(CTGitPath(_T("A")));
\r
1658 list.AddPath(CTGitPath(_T("E")));
\r
1659 list.AddPath(CTGitPath(_T("E")));
\r
1661 ATLASSERT(list[2].IsEquivalentTo(list[3]));
\r
1662 ATLASSERT(list[2]==list[3]);
\r
1664 ATLASSERT(list.GetCount() == 4);
\r
1666 list.RemoveDuplicates();
\r
1668 ATLASSERT(list.GetCount() == 3);
\r
1670 ATLASSERT(list[0].GetWinPathString() == _T("A"));
\r
1671 ATLASSERT(list[1].GetWinPathString().Compare(_T("E")) == 0);
\r
1672 ATLASSERT(list[2].GetWinPathString() == _T("Z"));
\r
1675 void RemoveChildrenTest()
\r
1677 CTGitPathList list;
\r
1678 list.AddPath(CTGitPath(_T("c:\\test")));
\r
1679 list.AddPath(CTGitPath(_T("c:\\test\\file")));
\r
1680 list.AddPath(CTGitPath(_T("c:\\testfile")));
\r
1681 list.AddPath(CTGitPath(_T("c:\\parent")));
\r
1682 list.AddPath(CTGitPath(_T("c:\\parent\\child")));
\r
1683 list.AddPath(CTGitPath(_T("c:\\parent\\child1")));
\r
1684 list.AddPath(CTGitPath(_T("c:\\parent\\child2")));
\r
1686 ATLASSERT(list.GetCount() == 7);
\r
1688 list.RemoveChildren();
\r
1690 ATLTRACE("count = %d\n", list.GetCount());
\r
1691 ATLASSERT(list.GetCount() == 3);
\r
1693 list.SortByPathname();
\r
1695 ATLASSERT(list[0].GetWinPathString().Compare(_T("c:\\parent")) == 0);
\r
1696 ATLASSERT(list[1].GetWinPathString().Compare(_T("c:\\test")) == 0);
\r
1697 ATLASSERT(list[2].GetWinPathString().Compare(_T("c:\\testfile")) == 0);
\r
1700 #if defined(_MFC_VER)
\r
1701 void ListLoadingTest()
\r
1703 TCHAR buf[MAX_PATH];
\r
1704 GetCurrentDirectory(MAX_PATH, buf);
\r
1705 CString sPathList(_T("Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"));
\r
1706 CTGitPathList testList;
\r
1707 testList.LoadFromAsteriskSeparatedString(sPathList);
\r
1709 ATLASSERT(testList.GetCount() == 3);
\r
1710 ATLASSERT(testList[0].GetWinPathString() == CString(buf) + _T("\\Path1"));
\r
1711 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\path2 with spaces and stuff"));
\r
1712 ATLASSERT(testList[2].GetWinPathString() == _T("\\funnypath"));
\r
1714 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T(""));
\r
1716 sPathList = _T("c:\\path2 with spaces and stuff*c:\\funnypath\\*");
\r
1717 testList.LoadFromAsteriskSeparatedString(sPathList);
\r
1718 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T("c:\\"));
\r
1722 void ContainingDirectoryTest()
\r
1725 CTGitPath testPath;
\r
1726 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\r
1728 dir = testPath.GetContainingDirectory();
\r
1729 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c\\d"));
\r
1730 dir = dir.GetContainingDirectory();
\r
1731 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c"));
\r
1732 dir = dir.GetContainingDirectory();
\r
1733 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b"));
\r
1734 dir = dir.GetContainingDirectory();
\r
1735 ATLASSERT(dir.GetWinPathString() == _T("c:\\a"));
\r
1736 dir = dir.GetContainingDirectory();
\r
1737 ATLASSERT(dir.GetWinPathString() == _T("c:\\"));
\r
1738 dir = dir.GetContainingDirectory();
\r
1739 ATLASSERT(dir.IsEmpty());
\r
1740 ATLASSERT(dir.GetWinPathString() == _T(""));
\r
1743 void AncestorTest()
\r
1745 CTGitPath testPath;
\r
1746 testPath.SetFromWin(_T("c:\\windows"));
\r
1747 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\")))==false);
\r
1748 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows"))));
\r
1749 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windowsdummy")))==false);
\r
1750 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\test.txt"))));
\r
1751 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\system32\\test.txt"))));
\r
1754 void SubversionPathTest()
\r
1756 CTGitPath testPath;
\r
1757 testPath.SetFromWin(_T("c:\\"));
\r
1758 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:") == 0);
\r
1759 testPath.SetFromWin(_T("c:\\folder"));
\r
1760 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);
\r
1761 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\r
1762 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);
\r
1763 testPath.SetFromUnknown(_T("http://testing/"));
\r
1764 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);
\r
1765 testPath.SetFromGit(NULL);
\r
1766 ATLASSERT(strlen(testPath.GetGitApiPath(pool))==0);
\r
1767 #if defined(_MFC_VER)
\r
1768 testPath.SetFromUnknown(_T("http://testing again"));
\r
1769 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
\r
1770 testPath.SetFromUnknown(_T("http://testing%20again"));
\r
1771 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
\r
1772 testPath.SetFromUnknown(_T("http://testing special chars \344\366\374"));
\r
1773 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);
\r
1777 void GetCommonRootTest()
\r
1779 CTGitPath pathA (_T("C:\\Development\\LogDlg.cpp"));
\r
1780 CTGitPath pathB (_T("C:\\Development\\LogDlg.h"));
\r
1781 CTGitPath pathC (_T("C:\\Development\\SomeDir\\LogDlg.h"));
\r
1783 CTGitPathList list;
\r
1784 list.AddPath(pathA);
\r
1785 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development\\LogDlg.cpp"))==0);
\r
1786 list.AddPath(pathB);
\r
1787 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
\r
1788 list.AddPath(pathC);
\r
1789 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
\r
1792 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
1793 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1794 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("D:\\Development\\StExBar"))==0);
\r
1797 sPathList = _T("c:\\windows\\explorer.exe*c:\\windows");
\r
1798 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1799 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1802 sPathList = _T("c:\\windows\\*c:\\windows");
\r
1803 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1804 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1807 sPathList = _T("c:\\windows\\system32*c:\\windows\\system");
\r
1808 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1809 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1812 sPathList = _T("c:\\windowsdummy*c:\\windows");
\r
1813 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1814 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\"))==0);
\r
1818 void ValidPathAndUrlTest()
\r
1820 CTGitPath testPath;
\r
1821 testPath.SetFromWin(_T("c:\\a\\b\\c.test.txt"));
\r
1822 ATLASSERT(testPath.IsValidOnWindows());
\r
1823 testPath.SetFromWin(_T("c:\\"));
\r
1824 ATLASSERT(testPath.IsValidOnWindows());
\r
1825 testPath.SetFromWin(_T("D:\\.Net\\SpindleSearch\\"));
\r
1826 ATLASSERT(testPath.IsValidOnWindows());
\r
1827 testPath.SetFromWin(_T("c"));
\r
1828 ATLASSERT(testPath.IsValidOnWindows());
\r
1829 testPath.SetFromWin(_T("c:\\test folder\\file"));
\r
1830 ATLASSERT(testPath.IsValidOnWindows());
\r
1831 testPath.SetFromWin(_T("c:\\folder\\"));
\r
1832 ATLASSERT(testPath.IsValidOnWindows());
\r
1833 testPath.SetFromWin(_T("c:\\ext.ext.ext\\ext.ext.ext.ext"));
\r
1834 ATLASSERT(testPath.IsValidOnWindows());
\r
1835 testPath.SetFromWin(_T("c:\\.svn"));
\r
1836 ATLASSERT(testPath.IsValidOnWindows());
\r
1837 testPath.SetFromWin(_T("c:\\com\\file"));
\r
1838 ATLASSERT(testPath.IsValidOnWindows());
\r
1839 testPath.SetFromWin(_T("c:\\test\\conf"));
\r
1840 ATLASSERT(testPath.IsValidOnWindows());
\r
1841 testPath.SetFromWin(_T("c:\\LPT"));
\r
1842 ATLASSERT(testPath.IsValidOnWindows());
\r
1843 testPath.SetFromWin(_T("c:\\test\\LPT"));
\r
1844 ATLASSERT(testPath.IsValidOnWindows());
\r
1845 testPath.SetFromWin(_T("c:\\com1test"));
\r
1846 ATLASSERT(testPath.IsValidOnWindows());
\r
1847 testPath.SetFromWin(_T("\\\\?\\c:\\test\\com1test"));
\r
1848 ATLASSERT(testPath.IsValidOnWindows());
\r
1850 testPath.SetFromWin(_T("\\\\Share\\filename"));
\r
1851 ATLASSERT(testPath.IsValidOnWindows());
\r
1852 testPath.SetFromWin(_T("\\\\Share\\filename.extension"));
\r
1853 ATLASSERT(testPath.IsValidOnWindows());
\r
1854 testPath.SetFromWin(_T("\\\\Share\\.svn"));
\r
1855 ATLASSERT(testPath.IsValidOnWindows());
\r
1857 // now the negative tests
\r
1858 testPath.SetFromWin(_T("c:\\test:folder"));
\r
1859 ATLASSERT(!testPath.IsValidOnWindows());
\r
1860 testPath.SetFromWin(_T("c:\\file<name"));
\r
1861 ATLASSERT(!testPath.IsValidOnWindows());
\r
1862 testPath.SetFromWin(_T("c:\\something*else"));
\r
1863 ATLASSERT(!testPath.IsValidOnWindows());
\r
1864 testPath.SetFromWin(_T("c:\\folder\\file?nofile"));
\r
1865 ATLASSERT(!testPath.IsValidOnWindows());
\r
1866 testPath.SetFromWin(_T("c:\\ext.>ension"));
\r
1867 ATLASSERT(!testPath.IsValidOnWindows());
\r
1868 testPath.SetFromWin(_T("c:\\com1\\filename"));
\r
1869 ATLASSERT(!testPath.IsValidOnWindows());
\r
1870 testPath.SetFromWin(_T("c:\\com1"));
\r
1871 ATLASSERT(!testPath.IsValidOnWindows());
\r
1872 testPath.SetFromWin(_T("c:\\com1\\AuX"));
\r
1873 ATLASSERT(!testPath.IsValidOnWindows());
\r
1875 testPath.SetFromWin(_T("\\\\Share\\lpt9\\filename"));
\r
1876 ATLASSERT(!testPath.IsValidOnWindows());
\r
1877 testPath.SetFromWin(_T("\\\\Share\\prn"));
\r
1878 ATLASSERT(!testPath.IsValidOnWindows());
\r
1879 testPath.SetFromWin(_T("\\\\Share\\NUL"));
\r
1880 ATLASSERT(!testPath.IsValidOnWindows());
\r
1882 // now come some URL tests
\r
1883 testPath.SetFromGit(_T("http://myserver.com/repos/trunk"));
\r
1884 ATLASSERT(testPath.IsValidOnWindows());
\r
1885 testPath.SetFromGit(_T("https://myserver.com/repos/trunk/file%20with%20spaces"));
\r
1886 ATLASSERT(testPath.IsValidOnWindows());
\r
1887 testPath.SetFromGit(_T("svn://myserver.com/repos/trunk/file with spaces"));
\r
1888 ATLASSERT(testPath.IsValidOnWindows());
\r
1889 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk"));
\r
1890 ATLASSERT(testPath.IsValidOnWindows());
\r
1891 testPath.SetFromGit(_T("http://localhost:90/repos/trunk"));
\r
1892 ATLASSERT(testPath.IsValidOnWindows());
\r
1893 testPath.SetFromGit(_T("file:///C:/GitRepos/Tester/Proj1/tags/t2"));
\r
1894 ATLASSERT(testPath.IsValidOnWindows());
\r
1895 // and some negative URL tests
\r
1896 testPath.SetFromGit(_T("httpp://myserver.com/repos/trunk"));
\r
1897 ATLASSERT(!testPath.IsValidOnWindows());
\r
1898 testPath.SetFromGit(_T("https://myserver.com/rep:os/trunk/file%20with%20spaces"));
\r
1899 ATLASSERT(!testPath.IsValidOnWindows());
\r
1900 testPath.SetFromGit(_T("svn://myserver.com/rep<os/trunk/file with spaces"));
\r
1901 ATLASSERT(!testPath.IsValidOnWindows());
\r
1902 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk/prn/"));
\r
1903 ATLASSERT(!testPath.IsValidOnWindows());
\r
1904 testPath.SetFromGit(_T("http://localhost:90/repos/trunk/com1"));
\r
1905 ATLASSERT(!testPath.IsValidOnWindows());
\r
1909 } TGitPathTestobject;
\r
1913 CTGitPath * CTGitPathList::LookForGitPath(CString path)
\r
1916 for(i=0;i<this->GetCount();i++)
\r
1918 if((*this)[i].GetGitPathString() == path )
\r
1919 return (CTGitPath*)&(*this)[i];
\r
1923 CString CTGitPath::GetActionName(int action)
\r
1925 if(action & CTGitPath::LOGACTIONS_UNMERGED)
\r
1926 return _T("Conflict");
\r
1927 if(action & CTGitPath::LOGACTIONS_ADDED)
\r
1928 return _T("Added");
\r
1929 if(action & CTGitPath::LOGACTIONS_DELETED)
\r
1930 return _T("Deleted");
\r
1931 if(action & CTGitPath::LOGACTIONS_MERGED )
\r
1932 return _T("Merged");
\r
1934 if(action & CTGitPath::LOGACTIONS_MODIFIED)
\r
1935 return _T("Modified");
\r
1936 if(action & CTGitPath::LOGACTIONS_REPLACED)
\r
1937 return _T("Rename");
\r
1938 if(action & CTGitPath::LOGACTIONS_COPY)
\r
1939 return _T("Copy");
\r
1941 if(action & CTGitPath::LOGACTIONS_FORWORD )
\r
1942 return _T("Forward");
\r
1944 if(action & CTGitPath::LOGACTIONS_REBASE_EDIT)
\r
1945 return _T("Edit");
\r
1946 if(action & CTGitPath::LOGACTIONS_REBASE_SQUASH)
\r
1947 return _T("Squash");
\r
1948 if(action & CTGitPath::LOGACTIONS_REBASE_PICK)
\r
1949 return _T("Pick");
\r
1950 if(action & CTGitPath::LOGACTIONS_REBASE_SKIP)
\r
1951 return _T("Skip");
\r
1953 return _T("Unknown");
\r
1955 CString CTGitPath::GetActionName()
\r
1957 return GetActionName(m_Action);
\r
1960 int CTGitPathList::GetAction()
\r