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 #include "Globals.h"
\r
28 #if defined(_MFC_VER)
\r
29 //#include "MessageBox.h"
\r
30 //#include "AppUtils.h"
\r
36 using namespace std;
\r
39 CTGitPath::CTGitPath(void) :
\r
40 m_bDirectoryKnown(false),
\r
41 m_bIsDirectory(false),
\r
44 m_bHasAdminDirKnown(false),
\r
45 m_bHasAdminDir(false),
\r
46 m_bIsValidOnWindowsKnown(false),
\r
47 m_bIsReadOnly(false),
\r
48 m_bIsAdminDirKnown(false),
\r
49 m_bIsAdminDir(false),
\r
51 m_bExistsKnown(false),
\r
52 m_bLastWriteTimeKnown(0),
\r
55 m_bIsSpecialDirectoryKnown(false),
\r
56 m_bIsSpecialDirectory(false)
\r
61 CTGitPath::~CTGitPath(void)
\r
64 // Create a TGitPath object from an unknown path type (same as using SetFromUnknown)
\r
65 CTGitPath::CTGitPath(const CString& sUnknownPath) :
\r
66 m_bDirectoryKnown(false),
\r
67 m_bIsDirectory(false),
\r
70 m_bHasAdminDirKnown(false),
\r
71 m_bHasAdminDir(false),
\r
72 m_bIsValidOnWindowsKnown(false),
\r
73 m_bIsReadOnly(false),
\r
74 m_bIsAdminDirKnown(false),
\r
75 m_bIsAdminDir(false),
\r
77 m_bExistsKnown(false),
\r
78 m_bLastWriteTimeKnown(0),
\r
81 m_bIsSpecialDirectoryKnown(false),
\r
82 m_bIsSpecialDirectory(false)
\r
84 SetFromUnknown(sUnknownPath);
\r
89 int CTGitPath::ParserAction(BYTE action)
\r
91 //action=action.TrimLeft();
\r
92 //TCHAR c=action.GetAt(0);
\r
94 m_Action|= LOGACTIONS_MODIFIED;
\r
96 m_Action|= LOGACTIONS_REPLACED;
\r
98 m_Action|= LOGACTIONS_ADDED;
\r
100 m_Action|= LOGACTIONS_DELETED;
\r
102 m_Action|= LOGACTIONS_UNMERGED;
\r
104 m_Action|= LOGACTIONS_DELETED;
\r
106 m_Action|= LOGACTIONS_CACHE;
\r
108 m_Action|= LOGACTIONS_COPY;
\r
112 void CTGitPath::SetFromGit(const char* pPath)
\r
117 int len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, NULL, 0);
\r
120 len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, m_sFwdslashPath.GetBuffer(len+1), len+1);
\r
121 m_sFwdslashPath.ReleaseBuffer(len-1);
\r
123 SanitizeRootPath(m_sFwdslashPath, true);
\r
126 void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
\r
129 m_bDirectoryKnown = true;
\r
130 m_bIsDirectory = bIsDirectory;
\r
133 void CTGitPath::SetFromGit(const TCHAR* pPath, bool bIsDirectory)
\r
138 m_sFwdslashPath = pPath;
\r
139 SanitizeRootPath(m_sFwdslashPath, true);
\r
141 m_bDirectoryKnown = true;
\r
142 m_bIsDirectory = bIsDirectory;
\r
145 void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)
\r
148 m_sFwdslashPath = sPath;
\r
149 SanitizeRootPath(m_sFwdslashPath, true);
\r
151 m_sOldFwdslashPath = *oldpath;
\r
154 void CTGitPath::SetFromWin(LPCTSTR pPath)
\r
157 m_sBackslashPath = pPath;
\r
158 SanitizeRootPath(m_sBackslashPath, false);
\r
159 ATLASSERT(m_sBackslashPath.Find('/')<0);
\r
161 void CTGitPath::SetFromWin(const CString& sPath)
\r
164 m_sBackslashPath = sPath;
\r
165 SanitizeRootPath(m_sBackslashPath, false);
\r
167 void CTGitPath::SetFromWin(const CString& sPath, bool bIsDirectory)
\r
170 m_sBackslashPath = sPath;
\r
171 m_bIsDirectory = bIsDirectory;
\r
172 m_bDirectoryKnown = true;
\r
173 SanitizeRootPath(m_sBackslashPath, false);
\r
175 void CTGitPath::SetFromUnknown(const CString& sPath)
\r
178 // Just set whichever path we think is most likely to be used
\r
179 // GitAdminDir admin;
\r
181 // if(admin.HasAdminDir(sPath,&p))
\r
182 // SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));
\r
184 SetFwdslashPath(sPath);
\r
187 LPCTSTR CTGitPath::GetWinPath() const
\r
193 if(m_sBackslashPath.IsEmpty())
\r
195 SetBackslashPath(m_sFwdslashPath);
\r
197 return m_sBackslashPath;
\r
199 // This is a temporary function, to be used during the migration to
\r
200 // the path class. Ultimately, functions consuming paths should take a CTGitPath&, not a CString
\r
201 const CString& CTGitPath::GetWinPathString() const
\r
203 if(m_sBackslashPath.IsEmpty())
\r
205 SetBackslashPath(m_sFwdslashPath);
\r
207 return m_sBackslashPath;
\r
210 const CString& CTGitPath::GetGitPathString() const
\r
212 if(m_sFwdslashPath.IsEmpty())
\r
214 SetFwdslashPath(m_sBackslashPath);
\r
216 return m_sFwdslashPath;
\r
219 const CString &CTGitPath::GetGitOldPathString() const
\r
221 return m_sOldFwdslashPath;
\r
224 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const
\r
226 // This funny-looking 'if' is to avoid a subtle problem with empty paths, whereby
\r
227 // each call to GetGitApiPath returns a different pointer value.
\r
228 // If you made multiple calls to GetGitApiPath on the same string, only the last
\r
229 // one would give you a valid pointer to an empty string, because each
\r
230 // call would invalidate the previous call's return.
\r
235 if(m_sFwdslashPath.IsEmpty())
\r
237 SetFwdslashPath(m_sBackslashPath);
\r
239 if(m_sUTF8FwdslashPath.IsEmpty())
\r
241 SetUTF8FwdslashPath(m_sFwdslashPath);
\r
243 if (svn_path_is_url(m_sUTF8FwdslashPath))
\r
245 m_sUTF8FwdslashPathEscaped = CPathUtils::PathEscape(m_sUTF8FwdslashPath);
\r
246 m_sUTF8FwdslashPathEscaped.Replace("file:////", "file:///\\");
\r
247 m_sUTF8FwdslashPathEscaped = svn_path_canonicalize(m_sUTF8FwdslashPathEscaped, pool);
\r
248 return m_sUTF8FwdslashPathEscaped;
\r
250 m_sUTF8FwdslashPath = svn_path_canonicalize(m_sUTF8FwdslashPath, pool);
\r
252 return m_sUTF8FwdslashPath;
\r
256 const CString& CTGitPath::GetUIPathString() const
\r
258 if (m_sUIPath.IsEmpty())
\r
260 #if defined(_MFC_VER)
\r
261 //BUGBUG HORRIBLE!!! - CPathUtils::IsEscaped doesn't need to be MFC-only
\r
264 m_sUIPath = CPathUtils::PathUnescape(GetGitPathString());
\r
265 m_sUIPath.Replace(_T("file:////"), _T("file:///\\"));
\r
271 m_sUIPath = GetWinPathString();
\r
277 void CTGitPath::SetFwdslashPath(const CString& sPath) const
\r
279 m_sFwdslashPath = sPath;
\r
280 m_sFwdslashPath.Replace('\\', '/');
\r
282 // We don't leave a trailing /
\r
283 m_sFwdslashPath.TrimRight('/');
\r
285 SanitizeRootPath(m_sFwdslashPath, true);
\r
287 m_sFwdslashPath.Replace(_T("file:////"), _T("file:///\\"));
\r
289 m_sUTF8FwdslashPath.Empty();
\r
292 void CTGitPath::SetBackslashPath(const CString& sPath) const
\r
294 m_sBackslashPath = sPath;
\r
295 m_sBackslashPath.Replace('/', '\\');
\r
296 m_sBackslashPath.TrimRight('\\');
\r
297 SanitizeRootPath(m_sBackslashPath, false);
\r
300 void CTGitPath::SetUTF8FwdslashPath(const CString& sPath) const
\r
302 m_sUTF8FwdslashPath = CUnicodeUtils::GetUTF8(sPath);
\r
305 void CTGitPath::SanitizeRootPath(CString& sPath, bool bIsForwardPath) const
\r
307 // Make sure to add the trailing slash to root paths such as 'C:'
\r
308 if (sPath.GetLength() == 2 && sPath[1] == ':')
\r
310 sPath += (bIsForwardPath) ? _T("/") : _T("\\");
\r
314 bool CTGitPath::IsUrl() const
\r
319 EnsureFwdslashPathSet();
\r
320 if(m_sUTF8FwdslashPath.IsEmpty())
\r
322 SetUTF8FwdslashPath(m_sFwdslashPath);
\r
324 m_bIsURL = !!svn_path_is_url(m_sUTF8FwdslashPath);
\r
325 m_bURLKnown = true;
\r
332 bool CTGitPath::IsDirectory() const
\r
334 if(!m_bDirectoryKnown)
\r
336 UpdateAttributes();
\r
338 return m_bIsDirectory;
\r
341 bool CTGitPath::Exists() const
\r
343 if (!m_bExistsKnown)
\r
345 UpdateAttributes();
\r
350 bool CTGitPath::Delete(bool bTrash) const
\r
352 EnsureBackslashPathSet();
\r
353 ::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);
\r
357 if ((bTrash)||(IsDirectory()))
\r
359 TCHAR * buf = new TCHAR[m_sBackslashPath.GetLength()+2];
\r
360 _tcscpy_s(buf, m_sBackslashPath.GetLength()+2, m_sBackslashPath);
\r
361 buf[m_sBackslashPath.GetLength()] = 0;
\r
362 buf[m_sBackslashPath.GetLength()+1] = 0;
\r
363 SHFILEOPSTRUCT shop = {0};
\r
364 shop.wFunc = FO_DELETE;
\r
366 shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
\r
368 shop.fFlags |= FOF_ALLOWUNDO;
\r
369 bRet = (SHFileOperation(&shop) == 0);
\r
374 bRet = !!::DeleteFile(m_sBackslashPath);
\r
378 m_bExistsKnown = true;
\r
382 __int64 CTGitPath::GetLastWriteTime() const
\r
384 if(!m_bLastWriteTimeKnown)
\r
386 UpdateAttributes();
\r
388 return m_lastWriteTime;
\r
391 bool CTGitPath::IsReadOnly() const
\r
393 if(!m_bLastWriteTimeKnown)
\r
395 UpdateAttributes();
\r
397 return m_bIsReadOnly;
\r
400 void CTGitPath::UpdateAttributes() const
\r
402 EnsureBackslashPathSet();
\r
403 WIN32_FILE_ATTRIBUTE_DATA attribs;
\r
404 if(GetFileAttributesEx(m_sBackslashPath, GetFileExInfoStandard, &attribs))
\r
406 m_bIsDirectory = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
\r
407 m_lastWriteTime = *(__int64*)&attribs.ftLastWriteTime;
\r
408 m_bIsReadOnly = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_READONLY);
\r
413 DWORD err = GetLastError();
\r
414 if ((err == ERROR_FILE_NOT_FOUND)||(err == ERROR_PATH_NOT_FOUND)||(err == ERROR_INVALID_NAME))
\r
416 m_bIsDirectory = false;
\r
417 m_lastWriteTime = 0;
\r
422 m_bIsDirectory = false;
\r
423 m_lastWriteTime = 0;
\r
428 m_bDirectoryKnown = true;
\r
429 m_bLastWriteTimeKnown = true;
\r
430 m_bExistsKnown = true;
\r
433 CTGitPath CTGitPath::GetSubPath(CTGitPath &root)
\r
437 if(GetWinPathString().Left(root.GetWinPathString().GetLength()) == root.GetWinPathString())
\r
439 CString str=GetWinPathString();
\r
440 path.SetFromWin(str.Right(str.GetLength()-root.GetWinPathString().GetLength()-1));
\r
445 void CTGitPath::EnsureBackslashPathSet() const
\r
447 if(m_sBackslashPath.IsEmpty())
\r
449 SetBackslashPath(m_sFwdslashPath);
\r
450 ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());
\r
453 void CTGitPath::EnsureFwdslashPathSet() const
\r
455 if(m_sFwdslashPath.IsEmpty())
\r
457 SetFwdslashPath(m_sBackslashPath);
\r
458 ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());
\r
463 // Reset all the caches
\r
464 void CTGitPath::Reset()
\r
466 m_bDirectoryKnown = false;
\r
467 m_bURLKnown = false;
\r
468 m_bLastWriteTimeKnown = false;
\r
469 m_bHasAdminDirKnown = false;
\r
470 m_bIsValidOnWindowsKnown = false;
\r
471 m_bIsAdminDirKnown = false;
\r
472 m_bExistsKnown = false;
\r
473 m_bIsSpecialDirectoryKnown = false;
\r
474 m_bIsSpecialDirectory = false;
\r
476 m_sBackslashPath.Empty();
\r
477 m_sFwdslashPath.Empty();
\r
478 m_sUTF8FwdslashPath.Empty();
\r
480 this->m_StatAdd=_T("");
\r
481 this->m_StatDel=_T("");
\r
482 ATLASSERT(IsEmpty());
\r
485 CTGitPath CTGitPath::GetDirectory() const
\r
487 if ((IsDirectory())||(!Exists()))
\r
491 return GetContainingDirectory();
\r
494 CTGitPath CTGitPath::GetContainingDirectory() const
\r
496 EnsureBackslashPathSet();
\r
498 CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));
\r
499 if(sDirName.GetLength() == 2 && sDirName[1] == ':')
\r
501 // This is a root directory, which needs a trailing slash
\r
503 if(sDirName == m_sBackslashPath)
\r
505 // We were clearly provided with a root path to start with - we should return nothing now
\r
509 if(sDirName.GetLength() == 1 && sDirName[0] == '\\')
\r
511 // We have an UNC path and we already are the root
\r
515 retVal.SetFromWin(sDirName);
\r
519 CString CTGitPath::GetRootPathString() const
\r
521 EnsureBackslashPathSet();
\r
522 CString workingPath = m_sBackslashPath;
\r
523 LPTSTR pPath = workingPath.GetBuffer(MAX_PATH); // MAX_PATH ok here.
\r
524 ATLVERIFY(::PathStripToRoot(pPath));
\r
525 workingPath.ReleaseBuffer();
\r
526 return workingPath;
\r
530 CString CTGitPath::GetFilename() const
\r
532 ATLASSERT(!IsDirectory());
\r
533 return GetFileOrDirectoryName();
\r
536 CString CTGitPath::GetFileOrDirectoryName() const
\r
538 EnsureBackslashPathSet();
\r
539 return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);
\r
542 CString CTGitPath::GetUIFileOrDirectoryName() const
\r
545 return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);
\r
548 CString CTGitPath::GetFileExtension() const
\r
552 EnsureBackslashPathSet();
\r
553 int dotPos = m_sBackslashPath.ReverseFind('.');
\r
554 int slashPos = m_sBackslashPath.ReverseFind('\\');
\r
555 if (dotPos > slashPos)
\r
556 return m_sBackslashPath.Mid(dotPos);
\r
560 CString CTGitPath::GetBaseFilename() const
\r
563 CString filename=GetFilename();
\r
564 dot = filename.ReverseFind(_T('.'));
\r
566 return filename.Left(dot);
\r
571 bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)
\r
573 int length = sP1.GetLength();
\r
574 if(length != sP2.GetLength())
\r
576 // Different lengths
\r
579 // We work from the end of the strings, because path differences
\r
580 // are more likely to occur at the far end of a string
\r
581 LPCTSTR pP1Start = sP1;
\r
582 LPCTSTR pP1 = pP1Start+(length-1);
\r
583 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
\r
584 while(length-- > 0)
\r
586 if(_totlower(*pP1--) != _totlower(*pP2--))
\r
594 bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)
\r
596 int length = sP1.GetLength();
\r
597 if(length != sP2.GetLength())
\r
599 // Different lengths
\r
602 // We work from the end of the strings, because path differences
\r
603 // are more likely to occur at the far end of a string
\r
604 LPCTSTR pP1Start = sP1;
\r
605 LPCTSTR pP1 = pP1Start+(length-1);
\r
606 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
\r
607 while(length-- > 0)
\r
609 if((*pP1--) != (*pP2--))
\r
617 bool CTGitPath::IsEmpty() const
\r
619 // Check the backward slash path first, since the chance that this
\r
620 // one is set is higher. In case of a 'false' return value it's a little
\r
622 return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();
\r
625 // Test if both paths refer to the same item
\r
626 // Ignores case and slash direction
\r
627 bool CTGitPath::IsEquivalentTo(const CTGitPath& rhs) const
\r
629 // Try and find a slash direction which avoids having to convert
\r
631 if(!m_sBackslashPath.IsEmpty())
\r
633 // *We've* got a \ path - make sure that the RHS also has a \ path
\r
634 rhs.EnsureBackslashPathSet();
\r
635 return ArePathStringsEqualWithCase(m_sBackslashPath, rhs.m_sBackslashPath);
\r
639 // Assume we've got a fwdslash path and make sure that the RHS has one
\r
640 rhs.EnsureFwdslashPathSet();
\r
641 return ArePathStringsEqualWithCase(m_sFwdslashPath, rhs.m_sFwdslashPath);
\r
645 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const
\r
647 // Try and find a slash direction which avoids having to convert
\r
649 if(!m_sBackslashPath.IsEmpty())
\r
651 // *We've* got a \ path - make sure that the RHS also has a \ path
\r
652 rhs.EnsureBackslashPathSet();
\r
653 return ArePathStringsEqual(m_sBackslashPath, rhs.m_sBackslashPath);
\r
657 // Assume we've got a fwdslash path and make sure that the RHS has one
\r
658 rhs.EnsureFwdslashPathSet();
\r
659 return ArePathStringsEqual(m_sFwdslashPath, rhs.m_sFwdslashPath);
\r
663 bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const
\r
665 possibleDescendant.EnsureBackslashPathSet();
\r
666 EnsureBackslashPathSet();
\r
668 bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));
\r
669 if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())
\r
671 return bPathStringsEqual;
\r
674 return (bPathStringsEqual &&
\r
675 ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||
\r
676 (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));
\r
679 // Get a string representing the file path, optionally with a base
\r
680 // section stripped off the front.
\r
681 CString CTGitPath::GetDisplayString(const CTGitPath* pOptionalBasePath /* = NULL*/) const
\r
683 EnsureFwdslashPathSet();
\r
684 if(pOptionalBasePath != NULL)
\r
686 // Find the length of the base-path without having to do an 'ensure' on it
\r
687 int baseLength = max(pOptionalBasePath->m_sBackslashPath.GetLength(), pOptionalBasePath->m_sFwdslashPath.GetLength());
\r
689 // Now, chop that baseLength of the front of the path
\r
690 return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');
\r
692 return m_sFwdslashPath;
\r
695 int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)
\r
697 left.EnsureBackslashPathSet();
\r
698 right.EnsureBackslashPathSet();
\r
699 return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);
\r
702 bool operator<(const CTGitPath& left, const CTGitPath& right)
\r
704 return CTGitPath::Compare(left, right) < 0;
\r
707 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)
\r
709 return left.IsEquivalentTo(right);
\r
712 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)
\r
714 if (left.IsAdminDir() && right.IsAdminDir())
\r
716 CTGitPath l = left;
\r
717 CTGitPath r = right;
\r
720 l = l.GetContainingDirectory();
\r
721 } while(l.HasAdminDir());
\r
724 r = r.GetContainingDirectory();
\r
725 } while(r.HasAdminDir());
\r
726 return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());
\r
728 return left.GetDirectory().IsEquivalentTo(right.GetDirectory());
\r
731 bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)
\r
733 return parent.IsAncestorOf(child);
\r
736 void CTGitPath::AppendRawString(const CString& sAppend)
\r
738 EnsureFwdslashPathSet();
\r
739 CString strCopy = m_sFwdslashPath += sAppend;
\r
740 SetFromUnknown(strCopy);
\r
743 void CTGitPath::AppendPathString(const CString& sAppend)
\r
745 EnsureBackslashPathSet();
\r
746 CString cleanAppend(sAppend);
\r
747 cleanAppend.Replace('/', '\\');
\r
748 cleanAppend.TrimLeft('\\');
\r
749 m_sBackslashPath.TrimRight('\\');
\r
750 CString strCopy = m_sBackslashPath + _T("\\") + cleanAppend;
\r
751 SetFromWin(strCopy);
\r
754 bool CTGitPath::HasAdminDir() const
\r
756 if (m_bHasAdminDirKnown)
\r
757 return m_bHasAdminDir;
\r
759 EnsureBackslashPathSet();
\r
760 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
\r
761 m_bHasAdminDirKnown = true;
\r
762 return m_bHasAdminDir;
\r
765 bool CTGitPath::HasSubmodules() const
\r
767 return !g_GitAdminDir.GetSuperProjectRoot(GetWinPathString()).IsEmpty();
\r
770 int CTGitPath::GetAdminDirMask() const
\r
773 CString topdir,path;
\r
774 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
\r
779 status |= ITEMIS_INSVN|ITEMIS_FOLDERINSVN;
\r
783 path+=g_GitAdminDir.GetAdminDirName();
\r
784 path+=_T("\\refs\\stash");
\r
785 if( PathFileExists(path) )
\r
786 status |= ITEMIS_STASH;
\r
790 path+=g_GitAdminDir.GetAdminDirName();
\r
792 if( PathFileExists(path) )
\r
793 status |= ITEMIS_GITSVN;
\r
796 path+=_T("\\.gitmodules");
\r
797 if( PathFileExists(path) )
\r
798 status |= ITEMIS_SUBMODULE;
\r
803 bool CTGitPath::HasStashDir() const
\r
806 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
\r
811 topdir+=g_GitAdminDir.GetAdminDirName();
\r
812 topdir+=_T("\\refs\stash");
\r
813 return PathFileExists(topdir);
\r
815 bool CTGitPath::HasGitSVNDir() const
\r
818 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
\r
823 topdir+=g_GitAdminDir.GetAdminDirName();
\r
824 topdir+=_T("\\svn");
\r
825 return PathFileExists(topdir);
\r
827 bool CTGitPath::HasAdminDir(CString *ProjectTopDir) const
\r
829 if (m_bHasAdminDirKnown)
\r
832 *ProjectTopDir = m_sProjectRoot;
\r
833 return m_bHasAdminDir;
\r
836 EnsureBackslashPathSet();
\r
837 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
\r
838 m_bHasAdminDirKnown = true;
\r
840 *ProjectTopDir = m_sProjectRoot;
\r
841 return m_bHasAdminDir;
\r
844 bool CTGitPath::IsAdminDir() const
\r
846 if (m_bIsAdminDirKnown)
\r
847 return m_bIsAdminDir;
\r
849 EnsureBackslashPathSet();
\r
850 m_bIsAdminDir = g_GitAdminDir.IsAdminDirPath(m_sBackslashPath);
\r
851 m_bIsAdminDirKnown = true;
\r
852 return m_bIsAdminDir;
\r
855 bool CTGitPath::IsValidOnWindows() const
\r
857 if (m_bIsValidOnWindowsKnown)
\r
858 return m_bIsValidOnWindows;
\r
860 m_bIsValidOnWindows = false;
\r
861 EnsureBackslashPathSet();
\r
862 CString sMatch = m_sBackslashPath + _T("\r\n");
\r
864 // the 'file://' URL is just a normal windows path:
\r
865 if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)
\r
867 sMatch = sMatch.Mid(7);
\r
868 sMatch.TrimLeft(_T("\\"));
\r
869 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
873 sPattern = _T("^((http|https|svn|svn\\+ssh|file)\\:\\\\+([^\\\\@\\:]+\\:[^\\\\@\\:]+@)?\\\\[^\\\\]+(\\:\\d+)?)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
877 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
882 tr1::wregex rx(sPattern, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
883 tr1::wsmatch match;
\r
885 wstring rmatch = wstring((LPCTSTR)sMatch);
\r
886 if (tr1::regex_match(rmatch, match, rx))
\r
888 if (wstring(match[0]).compare(sMatch)==0)
\r
889 m_bIsValidOnWindows = true;
\r
891 if (m_bIsValidOnWindows)
\r
893 // now check for illegal filenames
\r
894 tr1::wregex rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
895 rmatch = m_sBackslashPath;
\r
896 if (tr1::regex_search(rmatch, rx2, tr1::regex_constants::match_default))
\r
897 m_bIsValidOnWindows = false;
\r
900 catch (exception) {}
\r
902 m_bIsValidOnWindowsKnown = true;
\r
903 return m_bIsValidOnWindows;
\r
906 bool CTGitPath::IsSpecialDirectory() const
\r
908 if (m_bIsSpecialDirectoryKnown)
\r
909 return m_bIsSpecialDirectory;
\r
911 static LPCTSTR specialDirectories[]
\r
912 = { _T("trunk"), _T("tags"), _T("branches") };
\r
914 for (int i=0 ; i<(sizeof(specialDirectories) / sizeof(specialDirectories[0])) ; ++i)
\r
916 CString name = GetFileOrDirectoryName();
\r
917 if (0 == name.CompareNoCase(specialDirectories[i]))
\r
919 m_bIsSpecialDirectory = true;
\r
924 m_bIsSpecialDirectoryKnown = true;
\r
926 return m_bIsSpecialDirectory;
\r
929 //////////////////////////////////////////////////////////////////////////
\r
931 CTGitPathList::CTGitPathList()
\r
936 // A constructor which allows a path list to be easily built which one initial entry in
\r
937 CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)
\r
939 AddPath(firstEntry);
\r
941 int CTGitPathList::ParserFromLsFile(BYTE_VECTOR &out,bool staged)
\r
949 while(pos>=0 && pos<out.size())
\r
954 g_Git.StringAppend(&one,&out[pos],CP_ACP);
\r
956 path.m_Action=path.ParserAction(out[pos]);
\r
957 one.Tokenize(_T("\t"),tabstart);
\r
960 path.SetFromGit(one.Right(one.GetLength()-tabstart));
\r
964 part=one.Tokenize(_T(" "),tabstart); //Tag
\r
966 part=one.Tokenize(_T(" "),tabstart); //Mode
\r
968 part=one.Tokenize(_T(" "),tabstart); //Hash
\r
970 part=one.Tokenize(_T("\t"),tabstart); //Stage
\r
972 path.m_Stage=_ttol(part);
\r
974 this->AddPath(path);
\r
976 pos=out.findNextString(pos);
\r
980 int CTGitPathList::FillUnRev(int action,CTGitPathList *list)
\r
990 count=list->GetCount();
\r
991 for(int i=0;i<count;i++)
\r
997 if(action & CTGitPath::LOGACTIONS_IGNORE)
\r
998 ignored= _T(" --ignored");
\r
1002 cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");
\r
1007 { cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z %s-- \"%s\""),
\r
1009 (*list)[i].GetWinPathString());
\r
1014 g_Git.Run(cmd,&out);
\r
1018 while( pos>=0 && pos<out.size())
\r
1021 g_Git.StringAppend(&one,&out[pos],CP_ACP);
\r
1022 if(!one.IsEmpty())
\r
1024 //SetFromGit will clear all status
\r
1025 path.SetFromGit(one);
\r
1026 path.m_Action=action;
\r
1029 pos=out.findNextString(pos);
\r
1035 int CTGitPathList::ParserFromLog(BYTE_VECTOR &log)
\r
1039 //BYTE *p=&log[0];
\r
1043 while( pos>=0 && pos<log.size())
\r
1045 //one=log.Tokenize(_T("\n"),pos);
\r
1047 if(log[pos]=='\n')
\r
1052 bool merged=false;
\r
1053 if(log[pos+1] ==':')
\r
1057 int end=log.find(0,pos);
\r
1058 int actionstart=-1;
\r
1060 int file1=-1,file2=-1;
\r
1063 actionstart=log.find(' ',end-6);
\r
1066 if( actionstart>0 )
\r
1070 file1 = log.find(0,actionstart);
\r
1076 if( log[actionstart] == 'C' || log[actionstart] == 'R' )
\r
1080 file1 = log.find(0,file1);
\r
1090 CString pathname1;
\r
1091 CString pathname2;
\r
1094 g_Git.StringAppend(&pathname1,&log[file1],CP_ACP);
\r
1096 g_Git.StringAppend(&pathname2,&log[file2],CP_ACP);
\r
1098 CTGitPath *GitPath=LookForGitPath(pathname1);
\r
1102 GitPath->ParserAction( log[actionstart] );
\r
1106 GitPath->m_Action |= CTGitPath::LOGACTIONS_MERGED;
\r
1107 GitPath->m_Action &= ~CTGitPath::LOGACTIONS_FORWORD;
\r
1109 m_Action |=GitPath->m_Action;
\r
1113 int ac=path.ParserAction(log[actionstart] );
\r
1114 ac |= merged?CTGitPath::LOGACTIONS_MERGED:0;
\r
1116 path.SetFromGit(pathname1,&pathname2);
\r
1118 //action must be set after setfromgit. SetFromGit will clear all status.
\r
1119 this->m_Action|=ac;
\r
1134 tabstart=log.find('\t',pos);
\r
1138 g_Git.StringAppend(&StatAdd,&log[pos],CP_UTF8);
\r
1142 tabstart=log.find('\t',pos);
\r
1147 g_Git.StringAppend(&StatDel,&log[pos],CP_UTF8);
\r
1151 if(log[pos] == 0) //rename
\r
1154 g_Git.StringAppend(&file2,&log[pos],CP_ACP);
\r
1155 int sec=log.find(0,pos);
\r
1159 g_Git.StringAppend(&file1,&log[sec],CP_ACP);
\r
1165 g_Git.StringAppend(&file1,&log[pos],CP_ACP);
\r
1167 path.SetFromGit(file1,&file2);
\r
1169 CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());
\r
1172 GitPath->m_StatAdd=StatAdd;
\r
1173 GitPath->m_StatDel=StatDel;
\r
1176 //path.SetFromGit(pathname);
\r
1177 path.m_StatAdd=StatAdd;
\r
1178 path.m_StatDel=StatDel;
\r
1179 path.m_Action |= CTGitPath::LOGACTIONS_FORWORD;
\r
1184 pos=log.findNextString(pos);
\r
1189 void CTGitPathList::AddPath(const CTGitPath& newPath)
\r
1191 m_paths.push_back(newPath);
\r
1192 m_commonBaseDirectory.Reset();
\r
1194 int CTGitPathList::GetCount() const
\r
1196 return (int)m_paths.size();
\r
1198 void CTGitPathList::Clear()
\r
1201 m_commonBaseDirectory.Reset();
\r
1204 const CTGitPath& CTGitPathList::operator[](INT_PTR index) const
\r
1206 ATLASSERT(index >= 0 && index < (INT_PTR)m_paths.size());
\r
1207 return m_paths[index];
\r
1210 bool CTGitPathList::AreAllPathsFiles() const
\r
1212 // Look through the vector for any directories - if we find them, return false
\r
1213 return std::find_if(m_paths.begin(), m_paths.end(), std::mem_fun_ref(&CTGitPath::IsDirectory)) == m_paths.end();
\r
1217 #if defined(_MFC_VER)
\r
1219 bool CTGitPathList::LoadFromFile(const CTGitPath& filename)
\r
1225 CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite);
\r
1227 // for every selected file/folder
\r
1229 while (file.ReadString(strLine))
\r
1231 path.SetFromUnknown(strLine);
\r
1236 catch (CFileException* pE)
\r
1238 TRACE("CFileException loading target file list\n");
\r
1239 TCHAR error[10000] = {0};
\r
1240 pE->GetErrorMessage(error, 10000);
\r
1241 // CMessageBox::Show(NULL, error, _T("TortoiseGit"), MB_ICONERROR);
\r
1248 bool CTGitPathList::WriteToFile(const CString& sFilename, bool bANSI /* = false */) const
\r
1254 CStdioFile file(sFilename, CFile::typeText | CFile::modeReadWrite | CFile::modeCreate);
\r
1255 PathVector::const_iterator it;
\r
1256 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1258 CStringA line = CStringA(it->GetGitPathString()) + '\n';
\r
1259 file.Write(line, line.GetLength());
\r
1265 CStdioFile file(sFilename, CFile::typeBinary | CFile::modeReadWrite | CFile::modeCreate);
\r
1266 PathVector::const_iterator it;
\r
1267 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1269 file.WriteString(it->GetGitPathString()+_T("\n"));
\r
1274 catch (CFileException* pE)
\r
1276 TRACE("CFileException in writing temp file\n");
\r
1284 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString& sPathString)
\r
1290 temp = sPathString.Tokenize(_T("*"),pos);
\r
1291 if(temp.IsEmpty())
\r
1295 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp)));
\r
1299 CString CTGitPathList::CreateAsteriskSeparatedString() const
\r
1302 PathVector::const_iterator it;
\r
1303 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1305 if (!sRet.IsEmpty())
\r
1307 sRet += it->GetWinPathString();
\r
1311 #endif // _MFC_VER
\r
1314 CTGitPathList::AreAllPathsFilesInOneDirectory() const
\r
1316 // Check if all the paths are files and in the same directory
\r
1317 PathVector::const_iterator it;
\r
1318 m_commonBaseDirectory.Reset();
\r
1319 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1321 if(it->IsDirectory())
\r
1325 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1326 if(m_commonBaseDirectory.IsEmpty())
\r
1328 m_commonBaseDirectory = baseDirectory;
\r
1330 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1333 m_commonBaseDirectory.Reset();
\r
1340 CTGitPath CTGitPathList::GetCommonDirectory() const
\r
1342 if (m_commonBaseDirectory.IsEmpty())
\r
1344 PathVector::const_iterator it;
\r
1345 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1347 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1348 if(m_commonBaseDirectory.IsEmpty())
\r
1350 m_commonBaseDirectory = baseDirectory;
\r
1352 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1355 m_commonBaseDirectory.Reset();
\r
1360 // since we only checked strings, not paths,
\r
1361 // we have to make sure now that we really return a *path* here
\r
1362 PathVector::const_iterator iter;
\r
1363 for(iter = m_paths.begin(); iter != m_paths.end(); ++iter)
\r
1365 if (!m_commonBaseDirectory.IsAncestorOf(*iter))
\r
1367 m_commonBaseDirectory = m_commonBaseDirectory.GetContainingDirectory();
\r
1371 return m_commonBaseDirectory;
\r
1374 CTGitPath CTGitPathList::GetCommonRoot() const
\r
1376 PathVector::const_iterator it;
\r
1377 CString sRoot, sTempRoot;
\r
1378 bool bEqual = true;
\r
1380 if (GetCount() == 1)
\r
1381 return m_paths[0];
\r
1383 int backSlashPos = 0;
\r
1384 int searchStartPos = 0;
\r
1387 if(m_paths.empty())
\r
1390 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1392 if (backSlashPos == 0)
\r
1394 backSlashPos = it->GetWinPathString().Find('\\', searchStartPos+1);
\r
1395 if ((backSlashPos < 0)&&(searchStartPos != it->GetWinPathString().GetLength()))
\r
1396 backSlashPos = it->GetWinPathString().GetLength();
\r
1398 else if (it->GetWinPathString().Find('\\', searchStartPos+1) != backSlashPos)
\r
1400 if (it->GetWinPathString().Find('\\', searchStartPos+1) < 0)
\r
1402 if (it->GetWinPathString().GetLength() != backSlashPos)
\r
1414 if (backSlashPos < 0)
\r
1420 if (bEqual == false)
\r
1422 if (searchStartPos)
\r
1423 sRoot = m_paths[0].GetWinPathString().Left(searchStartPos+1);
\r
1427 searchStartPos = backSlashPos;
\r
1432 return CTGitPath(sRoot.TrimRight('\\'));
\r
1435 void CTGitPathList::SortByPathname(bool bReverse /*= false*/)
\r
1437 std::sort(m_paths.begin(), m_paths.end());
\r
1439 std::reverse(m_paths.begin(), m_paths.end());
\r
1442 void CTGitPathList::DeleteAllFiles(bool bTrash)
\r
1444 PathVector::const_iterator it;
\r
1449 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1451 if ((it->Exists())&&(!it->IsDirectory()))
\r
1453 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1454 sPaths += it->GetWinPath();
\r
1460 SHFILEOPSTRUCT shop = {0};
\r
1461 shop.wFunc = FO_DELETE;
\r
1462 shop.pFrom = (LPCTSTR)sPaths;
\r
1463 shop.fFlags = FOF_ALLOWUNDO|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
\r
1464 SHFileOperation(&shop);
\r
1468 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1470 if (!it->IsDirectory())
\r
1472 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1473 ::DeleteFile(it->GetWinPath());
\r
1480 void CTGitPathList::RemoveDuplicates()
\r
1483 // Remove the duplicates
\r
1484 // (Unique moves them to the end of the vector, then erase chops them off)
\r
1485 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::PredLeftEquivalentToRight), m_paths.end());
\r
1488 void CTGitPathList::RemoveAdminPaths()
\r
1490 PathVector::iterator it;
\r
1491 for(it = m_paths.begin(); it != m_paths.end(); )
\r
1493 if (it->IsAdminDir())
\r
1495 m_paths.erase(it);
\r
1496 it = m_paths.begin();
\r
1503 void CTGitPathList::RemovePath(const CTGitPath& path)
\r
1505 PathVector::iterator it;
\r
1506 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1508 if (it->IsEquivalentTo(path))
\r
1510 m_paths.erase(it);
\r
1516 void CTGitPathList::RemoveItem(CTGitPath & path)
\r
1518 PathVector::iterator it;
\r
1519 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1521 if (it->GetGitPathString()==path.GetGitPathString())
\r
1523 m_paths.erase(it);
\r
1528 void CTGitPathList::RemoveChildren()
\r
1531 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::CheckChild), m_paths.end());
\r
1534 bool CTGitPathList::IsEqual(const CTGitPathList& list)
\r
1536 if (list.GetCount() != GetCount())
\r
1538 for (int i=0; i<list.GetCount(); ++i)
\r
1540 if (!list[i].IsEquivalentTo(m_paths[i]))
\r
1546 //////////////////////////////////////////////////////////////////////////
\r
1548 apr_array_header_t * CTGitPathList::MakePathArray (apr_pool_t *pool) const
\r
1550 apr_array_header_t *targets = apr_array_make (pool, GetCount(), sizeof(const char *));
\r
1552 for(int nItem = 0; nItem < GetCount(); nItem++)
\r
1554 const char * target = m_paths[nItem].GetGitApiPath(pool);
\r
1555 (*((const char **) apr_array_push (targets))) = target;
\r
1561 //////////////////////////////////////////////////////////////////////////
\r
1564 #if defined(_DEBUG)
\r
1565 // Some test cases for these classes
\r
1566 static class CTGitPathTests
\r
1572 pool = svn_pool_create(NULL);
\r
1573 GetDirectoryTest();
\r
1578 RemoveDuplicatesTest();
\r
1579 RemoveChildrenTest();
\r
1580 ContainingDirectoryTest();
\r
1582 SubversionPathTest();
\r
1583 GetCommonRootTest();
\r
1584 #if defined(_MFC_VER)
\r
1585 ValidPathAndUrlTest();
\r
1586 ListLoadingTest();
\r
1592 // apr_pool_t * pool;
\r
1593 void GetDirectoryTest()
\r
1595 // Bit tricky, this test, because we need to know something about the file
\r
1596 // layout on the machine which is running the test
\r
1597 TCHAR winDir[MAX_PATH+1];
\r
1598 GetWindowsDirectory(winDir, MAX_PATH);
\r
1599 CString sWinDir(winDir);
\r
1601 CTGitPath testPath;
\r
1602 // This is a file which we know will always be there
\r
1603 testPath.SetFromUnknown(sWinDir + _T("\\win.ini"));
\r
1604 ATLASSERT(!testPath.IsDirectory());
\r
1605 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
\r
1606 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() == sWinDir);
\r
1608 // Now do the test on the win directory itself - It's hard to be sure about the containing directory
\r
1609 // but we know it must be different to the directory itself
\r
1610 testPath.SetFromUnknown(sWinDir);
\r
1611 ATLASSERT(testPath.IsDirectory());
\r
1612 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
\r
1613 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() != sWinDir);
\r
1614 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString().GetLength() < sWinDir.GetLength());
\r
1616 // Try a root path
\r
1617 testPath.SetFromUnknown(_T("C:\\"));
\r
1618 ATLASSERT(testPath.IsDirectory());
\r
1619 ATLASSERT(testPath.GetDirectory().GetWinPathString().CompareNoCase(_T("C:\\"))==0);
\r
1620 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
\r
1621 // Try a root UNC path
\r
1622 testPath.SetFromUnknown(_T("\\MYSTATION"));
\r
1623 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
\r
1626 void AdminDirTest()
\r
1628 CTGitPath testPath;
\r
1629 testPath.SetFromUnknown(_T("c:\\.svndir"));
\r
1630 ATLASSERT(!testPath.IsAdminDir());
\r
1631 testPath.SetFromUnknown(_T("c:\\test.svn"));
\r
1632 ATLASSERT(!testPath.IsAdminDir());
\r
1633 testPath.SetFromUnknown(_T("c:\\.svn"));
\r
1634 ATLASSERT(testPath.IsAdminDir());
\r
1635 testPath.SetFromUnknown(_T("c:\\.svndir\\test"));
\r
1636 ATLASSERT(!testPath.IsAdminDir());
\r
1637 testPath.SetFromUnknown(_T("c:\\.svn\\test"));
\r
1638 ATLASSERT(testPath.IsAdminDir());
\r
1640 CTGitPathList pathList;
\r
1641 pathList.AddPath(CTGitPath(_T("c:\\.svndir")));
\r
1642 pathList.AddPath(CTGitPath(_T("c:\\.svn")));
\r
1643 pathList.AddPath(CTGitPath(_T("c:\\.svn\\test")));
\r
1644 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1645 pathList.RemoveAdminPaths();
\r
1646 ATLASSERT(pathList.GetCount()==2);
\r
1648 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1649 pathList.RemoveAdminPaths();
\r
1650 ATLASSERT(pathList.GetCount()==1);
\r
1655 CTGitPathList testList;
\r
1656 CTGitPath testPath;
\r
1657 testPath.SetFromUnknown(_T("c:/Z"));
\r
1658 testList.AddPath(testPath);
\r
1659 testPath.SetFromUnknown(_T("c:/B"));
\r
1660 testList.AddPath(testPath);
\r
1661 testPath.SetFromUnknown(_T("c:\\a"));
\r
1662 testList.AddPath(testPath);
\r
1663 testPath.SetFromUnknown(_T("c:/Test"));
\r
1664 testList.AddPath(testPath);
\r
1666 testList.SortByPathname();
\r
1668 ATLASSERT(testList[0].GetWinPathString() == _T("c:\\a"));
\r
1669 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\B"));
\r
1670 ATLASSERT(testList[2].GetWinPathString() == _T("c:\\Test"));
\r
1671 ATLASSERT(testList[3].GetWinPathString() == _T("c:\\Z"));
\r
1674 void RawAppendTest()
\r
1676 CTGitPath testPath(_T("c:/test/"));
\r
1677 testPath.AppendRawString(_T("/Hello"));
\r
1678 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1680 testPath.AppendRawString(_T("\\T2"));
\r
1681 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\r
1683 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
\r
1684 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
\r
1685 testBasePath.AppendRawString(testFilePath.GetFileExtension());
\r
1686 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt.ini"));
\r
1689 void PathAppendTest()
\r
1691 CTGitPath testPath(_T("c:/test/"));
\r
1692 testPath.AppendPathString(_T("/Hello"));
\r
1693 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1695 testPath.AppendPathString(_T("T2"));
\r
1696 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\r
1698 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
\r
1699 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
\r
1700 // You wouldn't want to do this in real life - you'd use append-raw
\r
1701 testBasePath.AppendPathString(testFilePath.GetFileExtension());
\r
1702 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt\\.ini"));
\r
1705 void RemoveDuplicatesTest()
\r
1707 CTGitPathList list;
\r
1708 list.AddPath(CTGitPath(_T("Z")));
\r
1709 list.AddPath(CTGitPath(_T("A")));
\r
1710 list.AddPath(CTGitPath(_T("E")));
\r
1711 list.AddPath(CTGitPath(_T("E")));
\r
1713 ATLASSERT(list[2].IsEquivalentTo(list[3]));
\r
1714 ATLASSERT(list[2]==list[3]);
\r
1716 ATLASSERT(list.GetCount() == 4);
\r
1718 list.RemoveDuplicates();
\r
1720 ATLASSERT(list.GetCount() == 3);
\r
1722 ATLASSERT(list[0].GetWinPathString() == _T("A"));
\r
1723 ATLASSERT(list[1].GetWinPathString().Compare(_T("E")) == 0);
\r
1724 ATLASSERT(list[2].GetWinPathString() == _T("Z"));
\r
1727 void RemoveChildrenTest()
\r
1729 CTGitPathList list;
\r
1730 list.AddPath(CTGitPath(_T("c:\\test")));
\r
1731 list.AddPath(CTGitPath(_T("c:\\test\\file")));
\r
1732 list.AddPath(CTGitPath(_T("c:\\testfile")));
\r
1733 list.AddPath(CTGitPath(_T("c:\\parent")));
\r
1734 list.AddPath(CTGitPath(_T("c:\\parent\\child")));
\r
1735 list.AddPath(CTGitPath(_T("c:\\parent\\child1")));
\r
1736 list.AddPath(CTGitPath(_T("c:\\parent\\child2")));
\r
1738 ATLASSERT(list.GetCount() == 7);
\r
1740 list.RemoveChildren();
\r
1742 ATLTRACE("count = %d\n", list.GetCount());
\r
1743 ATLASSERT(list.GetCount() == 3);
\r
1745 list.SortByPathname();
\r
1747 ATLASSERT(list[0].GetWinPathString().Compare(_T("c:\\parent")) == 0);
\r
1748 ATLASSERT(list[1].GetWinPathString().Compare(_T("c:\\test")) == 0);
\r
1749 ATLASSERT(list[2].GetWinPathString().Compare(_T("c:\\testfile")) == 0);
\r
1752 #if defined(_MFC_VER)
\r
1753 void ListLoadingTest()
\r
1755 TCHAR buf[MAX_PATH];
\r
1756 GetCurrentDirectory(MAX_PATH, buf);
\r
1757 CString sPathList(_T("Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"));
\r
1758 CTGitPathList testList;
\r
1759 testList.LoadFromAsteriskSeparatedString(sPathList);
\r
1761 ATLASSERT(testList.GetCount() == 3);
\r
1762 ATLASSERT(testList[0].GetWinPathString() == CString(buf) + _T("\\Path1"));
\r
1763 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\path2 with spaces and stuff"));
\r
1764 ATLASSERT(testList[2].GetWinPathString() == _T("\\funnypath"));
\r
1766 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T(""));
\r
1768 sPathList = _T("c:\\path2 with spaces and stuff*c:\\funnypath\\*");
\r
1769 testList.LoadFromAsteriskSeparatedString(sPathList);
\r
1770 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T("c:\\"));
\r
1774 void ContainingDirectoryTest()
\r
1777 CTGitPath testPath;
\r
1778 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\r
1780 dir = testPath.GetContainingDirectory();
\r
1781 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c\\d"));
\r
1782 dir = dir.GetContainingDirectory();
\r
1783 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c"));
\r
1784 dir = dir.GetContainingDirectory();
\r
1785 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b"));
\r
1786 dir = dir.GetContainingDirectory();
\r
1787 ATLASSERT(dir.GetWinPathString() == _T("c:\\a"));
\r
1788 dir = dir.GetContainingDirectory();
\r
1789 ATLASSERT(dir.GetWinPathString() == _T("c:\\"));
\r
1790 dir = dir.GetContainingDirectory();
\r
1791 ATLASSERT(dir.IsEmpty());
\r
1792 ATLASSERT(dir.GetWinPathString() == _T(""));
\r
1795 void AncestorTest()
\r
1797 CTGitPath testPath;
\r
1798 testPath.SetFromWin(_T("c:\\windows"));
\r
1799 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\")))==false);
\r
1800 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows"))));
\r
1801 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windowsdummy")))==false);
\r
1802 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\test.txt"))));
\r
1803 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\system32\\test.txt"))));
\r
1806 void SubversionPathTest()
\r
1808 CTGitPath testPath;
\r
1809 testPath.SetFromWin(_T("c:\\"));
\r
1810 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:") == 0);
\r
1811 testPath.SetFromWin(_T("c:\\folder"));
\r
1812 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);
\r
1813 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\r
1814 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);
\r
1815 testPath.SetFromUnknown(_T("http://testing/"));
\r
1816 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);
\r
1817 testPath.SetFromGit(NULL);
\r
1818 ATLASSERT(strlen(testPath.GetGitApiPath(pool))==0);
\r
1819 #if defined(_MFC_VER)
\r
1820 testPath.SetFromUnknown(_T("http://testing again"));
\r
1821 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
\r
1822 testPath.SetFromUnknown(_T("http://testing%20again"));
\r
1823 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
\r
1824 testPath.SetFromUnknown(_T("http://testing special chars \344\366\374"));
\r
1825 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);
\r
1829 void GetCommonRootTest()
\r
1831 CTGitPath pathA (_T("C:\\Development\\LogDlg.cpp"));
\r
1832 CTGitPath pathB (_T("C:\\Development\\LogDlg.h"));
\r
1833 CTGitPath pathC (_T("C:\\Development\\SomeDir\\LogDlg.h"));
\r
1835 CTGitPathList list;
\r
1836 list.AddPath(pathA);
\r
1837 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development\\LogDlg.cpp"))==0);
\r
1838 list.AddPath(pathB);
\r
1839 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
\r
1840 list.AddPath(pathC);
\r
1841 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
\r
1844 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
1845 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1846 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("D:\\Development\\StExBar"))==0);
\r
1849 sPathList = _T("c:\\windows\\explorer.exe*c:\\windows");
\r
1850 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1851 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1854 sPathList = _T("c:\\windows\\*c:\\windows");
\r
1855 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1856 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1859 sPathList = _T("c:\\windows\\system32*c:\\windows\\system");
\r
1860 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1861 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1864 sPathList = _T("c:\\windowsdummy*c:\\windows");
\r
1865 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1866 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\"))==0);
\r
1870 void ValidPathAndUrlTest()
\r
1872 CTGitPath testPath;
\r
1873 testPath.SetFromWin(_T("c:\\a\\b\\c.test.txt"));
\r
1874 ATLASSERT(testPath.IsValidOnWindows());
\r
1875 testPath.SetFromWin(_T("c:\\"));
\r
1876 ATLASSERT(testPath.IsValidOnWindows());
\r
1877 testPath.SetFromWin(_T("D:\\.Net\\SpindleSearch\\"));
\r
1878 ATLASSERT(testPath.IsValidOnWindows());
\r
1879 testPath.SetFromWin(_T("c"));
\r
1880 ATLASSERT(testPath.IsValidOnWindows());
\r
1881 testPath.SetFromWin(_T("c:\\test folder\\file"));
\r
1882 ATLASSERT(testPath.IsValidOnWindows());
\r
1883 testPath.SetFromWin(_T("c:\\folder\\"));
\r
1884 ATLASSERT(testPath.IsValidOnWindows());
\r
1885 testPath.SetFromWin(_T("c:\\ext.ext.ext\\ext.ext.ext.ext"));
\r
1886 ATLASSERT(testPath.IsValidOnWindows());
\r
1887 testPath.SetFromWin(_T("c:\\.svn"));
\r
1888 ATLASSERT(testPath.IsValidOnWindows());
\r
1889 testPath.SetFromWin(_T("c:\\com\\file"));
\r
1890 ATLASSERT(testPath.IsValidOnWindows());
\r
1891 testPath.SetFromWin(_T("c:\\test\\conf"));
\r
1892 ATLASSERT(testPath.IsValidOnWindows());
\r
1893 testPath.SetFromWin(_T("c:\\LPT"));
\r
1894 ATLASSERT(testPath.IsValidOnWindows());
\r
1895 testPath.SetFromWin(_T("c:\\test\\LPT"));
\r
1896 ATLASSERT(testPath.IsValidOnWindows());
\r
1897 testPath.SetFromWin(_T("c:\\com1test"));
\r
1898 ATLASSERT(testPath.IsValidOnWindows());
\r
1899 testPath.SetFromWin(_T("\\\\?\\c:\\test\\com1test"));
\r
1900 ATLASSERT(testPath.IsValidOnWindows());
\r
1902 testPath.SetFromWin(_T("\\\\Share\\filename"));
\r
1903 ATLASSERT(testPath.IsValidOnWindows());
\r
1904 testPath.SetFromWin(_T("\\\\Share\\filename.extension"));
\r
1905 ATLASSERT(testPath.IsValidOnWindows());
\r
1906 testPath.SetFromWin(_T("\\\\Share\\.svn"));
\r
1907 ATLASSERT(testPath.IsValidOnWindows());
\r
1909 // now the negative tests
\r
1910 testPath.SetFromWin(_T("c:\\test:folder"));
\r
1911 ATLASSERT(!testPath.IsValidOnWindows());
\r
1912 testPath.SetFromWin(_T("c:\\file<name"));
\r
1913 ATLASSERT(!testPath.IsValidOnWindows());
\r
1914 testPath.SetFromWin(_T("c:\\something*else"));
\r
1915 ATLASSERT(!testPath.IsValidOnWindows());
\r
1916 testPath.SetFromWin(_T("c:\\folder\\file?nofile"));
\r
1917 ATLASSERT(!testPath.IsValidOnWindows());
\r
1918 testPath.SetFromWin(_T("c:\\ext.>ension"));
\r
1919 ATLASSERT(!testPath.IsValidOnWindows());
\r
1920 testPath.SetFromWin(_T("c:\\com1\\filename"));
\r
1921 ATLASSERT(!testPath.IsValidOnWindows());
\r
1922 testPath.SetFromWin(_T("c:\\com1"));
\r
1923 ATLASSERT(!testPath.IsValidOnWindows());
\r
1924 testPath.SetFromWin(_T("c:\\com1\\AuX"));
\r
1925 ATLASSERT(!testPath.IsValidOnWindows());
\r
1927 testPath.SetFromWin(_T("\\\\Share\\lpt9\\filename"));
\r
1928 ATLASSERT(!testPath.IsValidOnWindows());
\r
1929 testPath.SetFromWin(_T("\\\\Share\\prn"));
\r
1930 ATLASSERT(!testPath.IsValidOnWindows());
\r
1931 testPath.SetFromWin(_T("\\\\Share\\NUL"));
\r
1932 ATLASSERT(!testPath.IsValidOnWindows());
\r
1934 // now come some URL tests
\r
1935 testPath.SetFromGit(_T("http://myserver.com/repos/trunk"));
\r
1936 ATLASSERT(testPath.IsValidOnWindows());
\r
1937 testPath.SetFromGit(_T("https://myserver.com/repos/trunk/file%20with%20spaces"));
\r
1938 ATLASSERT(testPath.IsValidOnWindows());
\r
1939 testPath.SetFromGit(_T("svn://myserver.com/repos/trunk/file with spaces"));
\r
1940 ATLASSERT(testPath.IsValidOnWindows());
\r
1941 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk"));
\r
1942 ATLASSERT(testPath.IsValidOnWindows());
\r
1943 testPath.SetFromGit(_T("http://localhost:90/repos/trunk"));
\r
1944 ATLASSERT(testPath.IsValidOnWindows());
\r
1945 testPath.SetFromGit(_T("file:///C:/GitRepos/Tester/Proj1/tags/t2"));
\r
1946 ATLASSERT(testPath.IsValidOnWindows());
\r
1947 // and some negative URL tests
\r
1948 testPath.SetFromGit(_T("httpp://myserver.com/repos/trunk"));
\r
1949 ATLASSERT(!testPath.IsValidOnWindows());
\r
1950 testPath.SetFromGit(_T("https://myserver.com/rep:os/trunk/file%20with%20spaces"));
\r
1951 ATLASSERT(!testPath.IsValidOnWindows());
\r
1952 testPath.SetFromGit(_T("svn://myserver.com/rep<os/trunk/file with spaces"));
\r
1953 ATLASSERT(!testPath.IsValidOnWindows());
\r
1954 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk/prn/"));
\r
1955 ATLASSERT(!testPath.IsValidOnWindows());
\r
1956 testPath.SetFromGit(_T("http://localhost:90/repos/trunk/com1"));
\r
1957 ATLASSERT(!testPath.IsValidOnWindows());
\r
1961 } TGitPathTestobject;
\r
1965 CTGitPath * CTGitPathList::LookForGitPath(CString path)
\r
1968 for(i=0;i<this->GetCount();i++)
\r
1970 if((*this)[i].GetGitPathString() == path )
\r
1971 return (CTGitPath*)&(*this)[i];
\r
1975 CString CTGitPath::GetActionName(int action)
\r
1977 if(action & CTGitPath::LOGACTIONS_UNMERGED)
\r
1978 return _T("Conflict");
\r
1979 if(action & CTGitPath::LOGACTIONS_ADDED)
\r
1980 return _T("Added");
\r
1981 if(action & CTGitPath::LOGACTIONS_DELETED)
\r
1982 return _T("Deleted");
\r
1983 if(action & CTGitPath::LOGACTIONS_MERGED )
\r
1984 return _T("Merged");
\r
1986 if(action & CTGitPath::LOGACTIONS_MODIFIED)
\r
1987 return _T("Modified");
\r
1988 if(action & CTGitPath::LOGACTIONS_REPLACED)
\r
1989 return _T("Rename");
\r
1990 if(action & CTGitPath::LOGACTIONS_COPY)
\r
1991 return _T("Copy");
\r
1993 if(action & CTGitPath::LOGACTIONS_FORWORD )
\r
1994 return _T("Forward");
\r
1996 if(action & CTGitPath::LOGACTIONS_REBASE_EDIT)
\r
1997 return _T("Edit");
\r
1998 if(action & CTGitPath::LOGACTIONS_REBASE_SQUASH)
\r
1999 return _T("Squash");
\r
2000 if(action & CTGitPath::LOGACTIONS_REBASE_PICK)
\r
2001 return _T("Pick");
\r
2002 if(action & CTGitPath::LOGACTIONS_REBASE_SKIP)
\r
2003 return _T("Skip");
\r
2005 return _T("Unknown");
\r
2007 CString CTGitPath::GetActionName()
\r
2009 return GetActionName(m_Action);
\r
2012 int CTGitPathList::GetAction()
\r