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
107 void CTGitPath::SetFromGit(const char* pPath)
\r
112 int len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, NULL, 0);
\r
115 len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, m_sFwdslashPath.GetBuffer(len+1), len+1);
\r
116 m_sFwdslashPath.ReleaseBuffer(len-1);
\r
118 SanitizeRootPath(m_sFwdslashPath, true);
\r
121 void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
\r
124 m_bDirectoryKnown = true;
\r
125 m_bIsDirectory = bIsDirectory;
\r
128 void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)
\r
131 m_sFwdslashPath = sPath;
\r
132 SanitizeRootPath(m_sFwdslashPath, true);
\r
134 m_sOldFwdslashPath = *oldpath;
\r
137 void CTGitPath::SetFromWin(LPCTSTR pPath)
\r
140 m_sBackslashPath = pPath;
\r
141 SanitizeRootPath(m_sBackslashPath, false);
\r
142 ATLASSERT(m_sBackslashPath.Find('/')<0);
\r
144 void CTGitPath::SetFromWin(const CString& sPath)
\r
147 m_sBackslashPath = sPath;
\r
148 SanitizeRootPath(m_sBackslashPath, false);
\r
150 void CTGitPath::SetFromWin(const CString& sPath, bool bIsDirectory)
\r
153 m_sBackslashPath = sPath;
\r
154 m_bIsDirectory = bIsDirectory;
\r
155 m_bDirectoryKnown = true;
\r
156 SanitizeRootPath(m_sBackslashPath, false);
\r
158 void CTGitPath::SetFromUnknown(const CString& sPath)
\r
161 // Just set whichever path we think is most likely to be used
\r
162 // GitAdminDir admin;
\r
164 // if(admin.HasAdminDir(sPath,&p))
\r
165 // SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));
\r
167 SetFwdslashPath(sPath);
\r
170 LPCTSTR CTGitPath::GetWinPath() const
\r
176 if(m_sBackslashPath.IsEmpty())
\r
178 SetBackslashPath(m_sFwdslashPath);
\r
180 return m_sBackslashPath;
\r
182 // This is a temporary function, to be used during the migration to
\r
183 // the path class. Ultimately, functions consuming paths should take a CTGitPath&, not a CString
\r
184 const CString& CTGitPath::GetWinPathString() const
\r
186 if(m_sBackslashPath.IsEmpty())
\r
188 SetBackslashPath(m_sFwdslashPath);
\r
190 return m_sBackslashPath;
\r
193 const CString& CTGitPath::GetGitPathString() const
\r
195 if(m_sFwdslashPath.IsEmpty())
\r
197 SetFwdslashPath(m_sBackslashPath);
\r
199 return m_sFwdslashPath;
\r
202 const CString &CTGitPath::GetGitOldPathString() const
\r
204 return m_sOldFwdslashPath;
\r
207 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const
\r
209 // This funny-looking 'if' is to avoid a subtle problem with empty paths, whereby
\r
210 // each call to GetGitApiPath returns a different pointer value.
\r
211 // If you made multiple calls to GetGitApiPath on the same string, only the last
\r
212 // one would give you a valid pointer to an empty string, because each
\r
213 // call would invalidate the previous call's return.
\r
218 if(m_sFwdslashPath.IsEmpty())
\r
220 SetFwdslashPath(m_sBackslashPath);
\r
222 if(m_sUTF8FwdslashPath.IsEmpty())
\r
224 SetUTF8FwdslashPath(m_sFwdslashPath);
\r
226 if (svn_path_is_url(m_sUTF8FwdslashPath))
\r
228 m_sUTF8FwdslashPathEscaped = CPathUtils::PathEscape(m_sUTF8FwdslashPath);
\r
229 m_sUTF8FwdslashPathEscaped.Replace("file:////", "file:///\\");
\r
230 m_sUTF8FwdslashPathEscaped = svn_path_canonicalize(m_sUTF8FwdslashPathEscaped, pool);
\r
231 return m_sUTF8FwdslashPathEscaped;
\r
233 m_sUTF8FwdslashPath = svn_path_canonicalize(m_sUTF8FwdslashPath, pool);
\r
235 return m_sUTF8FwdslashPath;
\r
239 const CString& CTGitPath::GetUIPathString() const
\r
241 if (m_sUIPath.IsEmpty())
\r
243 #if defined(_MFC_VER)
\r
244 //BUGBUG HORRIBLE!!! - CPathUtils::IsEscaped doesn't need to be MFC-only
\r
247 m_sUIPath = CPathUtils::PathUnescape(GetGitPathString());
\r
248 m_sUIPath.Replace(_T("file:////"), _T("file:///\\"));
\r
254 m_sUIPath = GetWinPathString();
\r
260 void CTGitPath::SetFwdslashPath(const CString& sPath) const
\r
262 m_sFwdslashPath = sPath;
\r
263 m_sFwdslashPath.Replace('\\', '/');
\r
265 // We don't leave a trailing /
\r
266 m_sFwdslashPath.TrimRight('/');
\r
268 SanitizeRootPath(m_sFwdslashPath, true);
\r
270 m_sFwdslashPath.Replace(_T("file:////"), _T("file:///\\"));
\r
272 m_sUTF8FwdslashPath.Empty();
\r
275 void CTGitPath::SetBackslashPath(const CString& sPath) const
\r
277 m_sBackslashPath = sPath;
\r
278 m_sBackslashPath.Replace('/', '\\');
\r
279 m_sBackslashPath.TrimRight('\\');
\r
280 SanitizeRootPath(m_sBackslashPath, false);
\r
283 void CTGitPath::SetUTF8FwdslashPath(const CString& sPath) const
\r
285 m_sUTF8FwdslashPath = CUnicodeUtils::GetUTF8(sPath);
\r
288 void CTGitPath::SanitizeRootPath(CString& sPath, bool bIsForwardPath) const
\r
290 // Make sure to add the trailing slash to root paths such as 'C:'
\r
291 if (sPath.GetLength() == 2 && sPath[1] == ':')
\r
293 sPath += (bIsForwardPath) ? _T("/") : _T("\\");
\r
297 bool CTGitPath::IsUrl() const
\r
302 EnsureFwdslashPathSet();
\r
303 if(m_sUTF8FwdslashPath.IsEmpty())
\r
305 SetUTF8FwdslashPath(m_sFwdslashPath);
\r
307 m_bIsURL = !!svn_path_is_url(m_sUTF8FwdslashPath);
\r
308 m_bURLKnown = true;
\r
315 bool CTGitPath::IsDirectory() const
\r
317 if(!m_bDirectoryKnown)
\r
319 UpdateAttributes();
\r
321 return m_bIsDirectory;
\r
324 bool CTGitPath::Exists() const
\r
326 if (!m_bExistsKnown)
\r
328 UpdateAttributes();
\r
333 bool CTGitPath::Delete(bool bTrash) const
\r
335 EnsureBackslashPathSet();
\r
336 ::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);
\r
340 if ((bTrash)||(IsDirectory()))
\r
342 TCHAR * buf = new TCHAR[m_sBackslashPath.GetLength()+2];
\r
343 _tcscpy_s(buf, m_sBackslashPath.GetLength()+2, m_sBackslashPath);
\r
344 buf[m_sBackslashPath.GetLength()] = 0;
\r
345 buf[m_sBackslashPath.GetLength()+1] = 0;
\r
346 SHFILEOPSTRUCT shop = {0};
\r
347 shop.wFunc = FO_DELETE;
\r
349 shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
\r
351 shop.fFlags |= FOF_ALLOWUNDO;
\r
352 bRet = (SHFileOperation(&shop) == 0);
\r
357 bRet = !!::DeleteFile(m_sBackslashPath);
\r
361 m_bExistsKnown = true;
\r
365 __int64 CTGitPath::GetLastWriteTime() const
\r
367 if(!m_bLastWriteTimeKnown)
\r
369 UpdateAttributes();
\r
371 return m_lastWriteTime;
\r
374 bool CTGitPath::IsReadOnly() const
\r
376 if(!m_bLastWriteTimeKnown)
\r
378 UpdateAttributes();
\r
380 return m_bIsReadOnly;
\r
383 void CTGitPath::UpdateAttributes() const
\r
385 EnsureBackslashPathSet();
\r
386 WIN32_FILE_ATTRIBUTE_DATA attribs;
\r
387 if(GetFileAttributesEx(m_sBackslashPath, GetFileExInfoStandard, &attribs))
\r
389 m_bIsDirectory = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
\r
390 m_lastWriteTime = *(__int64*)&attribs.ftLastWriteTime;
\r
391 m_bIsReadOnly = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_READONLY);
\r
396 DWORD err = GetLastError();
\r
397 if ((err == ERROR_FILE_NOT_FOUND)||(err == ERROR_PATH_NOT_FOUND)||(err == ERROR_INVALID_NAME))
\r
399 m_bIsDirectory = false;
\r
400 m_lastWriteTime = 0;
\r
405 m_bIsDirectory = false;
\r
406 m_lastWriteTime = 0;
\r
411 m_bDirectoryKnown = true;
\r
412 m_bLastWriteTimeKnown = true;
\r
413 m_bExistsKnown = true;
\r
417 void CTGitPath::EnsureBackslashPathSet() const
\r
419 if(m_sBackslashPath.IsEmpty())
\r
421 SetBackslashPath(m_sFwdslashPath);
\r
422 ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());
\r
425 void CTGitPath::EnsureFwdslashPathSet() const
\r
427 if(m_sFwdslashPath.IsEmpty())
\r
429 SetFwdslashPath(m_sBackslashPath);
\r
430 ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());
\r
435 // Reset all the caches
\r
436 void CTGitPath::Reset()
\r
438 m_bDirectoryKnown = false;
\r
439 m_bURLKnown = false;
\r
440 m_bLastWriteTimeKnown = false;
\r
441 m_bHasAdminDirKnown = false;
\r
442 m_bIsValidOnWindowsKnown = false;
\r
443 m_bIsAdminDirKnown = false;
\r
444 m_bExistsKnown = false;
\r
445 m_bIsSpecialDirectoryKnown = false;
\r
446 m_bIsSpecialDirectory = false;
\r
448 m_sBackslashPath.Empty();
\r
449 m_sFwdslashPath.Empty();
\r
450 m_sUTF8FwdslashPath.Empty();
\r
452 this->m_StatAdd=_T("");
\r
453 this->m_StatDel=_T("");
\r
454 ATLASSERT(IsEmpty());
\r
457 CTGitPath CTGitPath::GetDirectory() const
\r
459 if ((IsDirectory())||(!Exists()))
\r
463 return GetContainingDirectory();
\r
466 CTGitPath CTGitPath::GetContainingDirectory() const
\r
468 EnsureBackslashPathSet();
\r
470 CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));
\r
471 if(sDirName.GetLength() == 2 && sDirName[1] == ':')
\r
473 // This is a root directory, which needs a trailing slash
\r
475 if(sDirName == m_sBackslashPath)
\r
477 // We were clearly provided with a root path to start with - we should return nothing now
\r
481 if(sDirName.GetLength() == 1 && sDirName[0] == '\\')
\r
483 // We have an UNC path and we already are the root
\r
487 retVal.SetFromWin(sDirName);
\r
491 CString CTGitPath::GetRootPathString() const
\r
493 EnsureBackslashPathSet();
\r
494 CString workingPath = m_sBackslashPath;
\r
495 LPTSTR pPath = workingPath.GetBuffer(MAX_PATH); // MAX_PATH ok here.
\r
496 ATLVERIFY(::PathStripToRoot(pPath));
\r
497 workingPath.ReleaseBuffer();
\r
498 return workingPath;
\r
502 CString CTGitPath::GetFilename() const
\r
504 ATLASSERT(!IsDirectory());
\r
505 return GetFileOrDirectoryName();
\r
508 CString CTGitPath::GetFileOrDirectoryName() const
\r
510 EnsureBackslashPathSet();
\r
511 return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);
\r
514 CString CTGitPath::GetUIFileOrDirectoryName() const
\r
517 return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);
\r
520 CString CTGitPath::GetFileExtension() const
\r
524 EnsureBackslashPathSet();
\r
525 int dotPos = m_sBackslashPath.ReverseFind('.');
\r
526 int slashPos = m_sBackslashPath.ReverseFind('\\');
\r
527 if (dotPos > slashPos)
\r
528 return m_sBackslashPath.Mid(dotPos);
\r
532 CString CTGitPath::GetBaseFilename() const
\r
535 CString filename=GetFilename();
\r
536 dot = filename.ReverseFind(_T('.'));
\r
538 return filename.Left(dot-1);
\r
543 bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)
\r
545 int length = sP1.GetLength();
\r
546 if(length != sP2.GetLength())
\r
548 // Different lengths
\r
551 // We work from the end of the strings, because path differences
\r
552 // are more likely to occur at the far end of a string
\r
553 LPCTSTR pP1Start = sP1;
\r
554 LPCTSTR pP1 = pP1Start+(length-1);
\r
555 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
\r
556 while(length-- > 0)
\r
558 if(_totlower(*pP1--) != _totlower(*pP2--))
\r
566 bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)
\r
568 int length = sP1.GetLength();
\r
569 if(length != sP2.GetLength())
\r
571 // Different lengths
\r
574 // We work from the end of the strings, because path differences
\r
575 // are more likely to occur at the far end of a string
\r
576 LPCTSTR pP1Start = sP1;
\r
577 LPCTSTR pP1 = pP1Start+(length-1);
\r
578 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
\r
579 while(length-- > 0)
\r
581 if((*pP1--) != (*pP2--))
\r
589 bool CTGitPath::IsEmpty() const
\r
591 // Check the backward slash path first, since the chance that this
\r
592 // one is set is higher. In case of a 'false' return value it's a little
\r
594 return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();
\r
597 // Test if both paths refer to the same item
\r
598 // Ignores case and slash direction
\r
599 bool CTGitPath::IsEquivalentTo(const CTGitPath& rhs) const
\r
601 // Try and find a slash direction which avoids having to convert
\r
603 if(!m_sBackslashPath.IsEmpty())
\r
605 // *We've* got a \ path - make sure that the RHS also has a \ path
\r
606 rhs.EnsureBackslashPathSet();
\r
607 return ArePathStringsEqualWithCase(m_sBackslashPath, rhs.m_sBackslashPath);
\r
611 // Assume we've got a fwdslash path and make sure that the RHS has one
\r
612 rhs.EnsureFwdslashPathSet();
\r
613 return ArePathStringsEqualWithCase(m_sFwdslashPath, rhs.m_sFwdslashPath);
\r
617 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const
\r
619 // Try and find a slash direction which avoids having to convert
\r
621 if(!m_sBackslashPath.IsEmpty())
\r
623 // *We've* got a \ path - make sure that the RHS also has a \ path
\r
624 rhs.EnsureBackslashPathSet();
\r
625 return ArePathStringsEqual(m_sBackslashPath, rhs.m_sBackslashPath);
\r
629 // Assume we've got a fwdslash path and make sure that the RHS has one
\r
630 rhs.EnsureFwdslashPathSet();
\r
631 return ArePathStringsEqual(m_sFwdslashPath, rhs.m_sFwdslashPath);
\r
635 bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const
\r
637 possibleDescendant.EnsureBackslashPathSet();
\r
638 EnsureBackslashPathSet();
\r
640 bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));
\r
641 if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())
\r
643 return bPathStringsEqual;
\r
646 return (bPathStringsEqual &&
\r
647 ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||
\r
648 (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));
\r
651 // Get a string representing the file path, optionally with a base
\r
652 // section stripped off the front.
\r
653 CString CTGitPath::GetDisplayString(const CTGitPath* pOptionalBasePath /* = NULL*/) const
\r
655 EnsureFwdslashPathSet();
\r
656 if(pOptionalBasePath != NULL)
\r
658 // Find the length of the base-path without having to do an 'ensure' on it
\r
659 int baseLength = max(pOptionalBasePath->m_sBackslashPath.GetLength(), pOptionalBasePath->m_sFwdslashPath.GetLength());
\r
661 // Now, chop that baseLength of the front of the path
\r
662 return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');
\r
664 return m_sFwdslashPath;
\r
667 int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)
\r
669 left.EnsureBackslashPathSet();
\r
670 right.EnsureBackslashPathSet();
\r
671 return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);
\r
674 bool operator<(const CTGitPath& left, const CTGitPath& right)
\r
676 return CTGitPath::Compare(left, right) < 0;
\r
679 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)
\r
681 return left.IsEquivalentTo(right);
\r
684 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)
\r
686 if (left.IsAdminDir() && right.IsAdminDir())
\r
688 CTGitPath l = left;
\r
689 CTGitPath r = right;
\r
692 l = l.GetContainingDirectory();
\r
693 } while(l.HasAdminDir());
\r
696 r = r.GetContainingDirectory();
\r
697 } while(r.HasAdminDir());
\r
698 return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());
\r
700 return left.GetDirectory().IsEquivalentTo(right.GetDirectory());
\r
703 bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)
\r
705 return parent.IsAncestorOf(child);
\r
708 void CTGitPath::AppendRawString(const CString& sAppend)
\r
710 EnsureFwdslashPathSet();
\r
711 CString strCopy = m_sFwdslashPath += sAppend;
\r
712 SetFromUnknown(strCopy);
\r
715 void CTGitPath::AppendPathString(const CString& sAppend)
\r
717 EnsureBackslashPathSet();
\r
718 CString cleanAppend(sAppend);
\r
719 cleanAppend.Replace('/', '\\');
\r
720 cleanAppend.TrimLeft('\\');
\r
721 m_sBackslashPath.TrimRight('\\');
\r
722 CString strCopy = m_sBackslashPath + _T("\\") + cleanAppend;
\r
723 SetFromWin(strCopy);
\r
726 bool CTGitPath::HasAdminDir() const
\r
728 if (m_bHasAdminDirKnown)
\r
729 return m_bHasAdminDir;
\r
731 EnsureBackslashPathSet();
\r
732 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
\r
733 m_bHasAdminDirKnown = true;
\r
734 return m_bHasAdminDir;
\r
737 bool CTGitPath::HasAdminDir(CString *ProjectTopDir) const
\r
739 if (m_bHasAdminDirKnown)
\r
742 *ProjectTopDir = m_sProjectRoot;
\r
743 return m_bHasAdminDir;
\r
746 EnsureBackslashPathSet();
\r
747 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
\r
748 m_bHasAdminDirKnown = true;
\r
750 *ProjectTopDir = m_sProjectRoot;
\r
751 return m_bHasAdminDir;
\r
754 bool CTGitPath::IsAdminDir() const
\r
756 if (m_bIsAdminDirKnown)
\r
757 return m_bIsAdminDir;
\r
759 EnsureBackslashPathSet();
\r
760 m_bIsAdminDir = g_GitAdminDir.IsAdminDirPath(m_sBackslashPath);
\r
761 m_bIsAdminDirKnown = true;
\r
762 return m_bIsAdminDir;
\r
765 bool CTGitPath::IsValidOnWindows() const
\r
767 if (m_bIsValidOnWindowsKnown)
\r
768 return m_bIsValidOnWindows;
\r
770 m_bIsValidOnWindows = false;
\r
771 EnsureBackslashPathSet();
\r
772 CString sMatch = m_sBackslashPath + _T("\r\n");
\r
774 // the 'file://' URL is just a normal windows path:
\r
775 if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)
\r
777 sMatch = sMatch.Mid(7);
\r
778 sMatch.TrimLeft(_T("\\"));
\r
779 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
783 sPattern = _T("^((http|https|svn|svn\\+ssh|file)\\:\\\\+([^\\\\@\\:]+\\:[^\\\\@\\:]+@)?\\\\[^\\\\]+(\\:\\d+)?)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<>\\. ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
787 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
\r
792 tr1::wregex rx(sPattern, tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
793 tr1::wsmatch match;
\r
795 wstring rmatch = wstring((LPCTSTR)sMatch);
\r
796 if (tr1::regex_match(rmatch, match, rx))
\r
798 if (wstring(match[0]).compare(sMatch)==0)
\r
799 m_bIsValidOnWindows = true;
\r
801 if (m_bIsValidOnWindows)
\r
803 // now check for illegal filenames
\r
804 tr1::wregex rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
\r
805 rmatch = m_sBackslashPath;
\r
806 if (tr1::regex_search(rmatch, rx2, tr1::regex_constants::match_default))
\r
807 m_bIsValidOnWindows = false;
\r
810 catch (exception) {}
\r
812 m_bIsValidOnWindowsKnown = true;
\r
813 return m_bIsValidOnWindows;
\r
816 bool CTGitPath::IsSpecialDirectory() const
\r
818 if (m_bIsSpecialDirectoryKnown)
\r
819 return m_bIsSpecialDirectory;
\r
821 static LPCTSTR specialDirectories[]
\r
822 = { _T("trunk"), _T("tags"), _T("branches") };
\r
824 for (int i=0 ; i<(sizeof(specialDirectories) / sizeof(specialDirectories[0])) ; ++i)
\r
826 CString name = GetFileOrDirectoryName();
\r
827 if (0 == name.CompareNoCase(specialDirectories[i]))
\r
829 m_bIsSpecialDirectory = true;
\r
834 m_bIsSpecialDirectoryKnown = true;
\r
836 return m_bIsSpecialDirectory;
\r
839 //////////////////////////////////////////////////////////////////////////
\r
841 CTGitPathList::CTGitPathList()
\r
846 // A constructor which allows a path list to be easily built which one initial entry in
\r
847 CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)
\r
849 AddPath(firstEntry);
\r
851 int CTGitPathList::ParserFromLsFile(BYTE_VECTOR &out,bool staged)
\r
857 while(pos>=0 && pos<out.size())
\r
862 g_Git.StringAppend(&one,&out[pos],CP_OEMCP);
\r
864 path.m_Action=path.ParserAction(out[pos]);
\r
865 one.Tokenize(_T("\t"),tabstart);
\r
868 path.SetFromGit(one.Right(one.GetLength()-tabstart));
\r
872 part=one.Tokenize(_T(" "),tabstart); //Tag
\r
874 part=one.Tokenize(_T(" "),tabstart); //Mode
\r
876 part=one.Tokenize(_T(" "),tabstart); //Hash
\r
878 part=one.Tokenize(_T("\t"),tabstart); //Stage
\r
880 path.m_Stage=_ttol(part);
\r
882 this->AddPath(path);
\r
884 pos=out.findNextString(pos);
\r
888 int CTGitPathList::FillUnRev(int action,CTGitPathList *list)
\r
898 count=list->GetCount();
\r
899 for(int i=0;i<count;i++)
\r
905 if(action & CTGitPath::LOGACTIONS_IGNORE)
\r
906 ignored= _T(" --ignored");
\r
910 cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");
\r
915 { cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z %s-- \"%s\""),
\r
917 (*list)[i].GetWinPathString());
\r
922 g_Git.Run(cmd,&out);
\r
926 while( pos>=0 && pos<out.size())
\r
929 g_Git.StringAppend(&one,&out[pos],CP_OEMCP);
\r
932 //SetFromGit will clear all status
\r
933 path.SetFromGit(one);
\r
934 path.m_Action=action;
\r
937 pos=out.findNextString(pos);
\r
943 int CTGitPathList::ParserFromLog(BYTE_VECTOR &log)
\r
951 while( pos>=0 && pos<log.size())
\r
953 //one=log.Tokenize(_T("\n"),pos);
\r
960 int end=log.find(0,pos);
\r
961 int actionstart=-1;
\r
963 int file1=-1,file2=-1;
\r
966 actionstart=log.find(' ',end-6);
\r
969 if( actionstart>0 )
\r
973 file1 = log.find(0,actionstart);
\r
979 if( log[actionstart] == 'C' || log[actionstart] == 'R' )
\r
983 file1 = log.find(0,file1);
\r
997 g_Git.StringAppend(&pathname1,&log[file1],CP_OEMCP);
\r
999 g_Git.StringAppend(&pathname2,&log[file2],CP_OEMCP);
\r
1001 CTGitPath *GitPath=LookForGitPath(pathname1);
\r
1005 this->m_Action|=GitPath->ParserAction( log[actionstart] );
\r
1009 int ac=path.ParserAction(log[actionstart] );
\r
1011 path.SetFromGit(pathname1,&pathname2);
\r
1013 //action must be set after setfromgit. SetFromGit will clear all status.
\r
1014 this->m_Action|=ac;
\r
1028 tabstart=log.find('\t',pos);
\r
1032 g_Git.StringAppend(&StatAdd,&log[pos],CP_UTF8);
\r
1036 tabstart=log.find('\t',pos);
\r
1041 g_Git.StringAppend(&StatDel,&log[pos],CP_UTF8);
\r
1045 if(log[pos] == 0) //rename
\r
1048 g_Git.StringAppend(&file2,&log[pos],CP_OEMCP);
\r
1049 int sec=log.find(0,pos);
\r
1053 g_Git.StringAppend(&file1,&log[sec],CP_OEMCP);
\r
1058 g_Git.StringAppend(&file1,&log[pos],CP_OEMCP);
\r
1060 path.SetFromGit(file1,&file2);
\r
1062 CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());
\r
1065 GitPath->m_StatAdd=StatAdd;
\r
1066 GitPath->m_StatDel=StatDel;
\r
1069 //path.SetFromGit(pathname);
\r
1070 path.m_StatAdd=StatAdd;
\r
1071 path.m_StatDel=StatDel;
\r
1076 pos=log.findNextString(pos);
\r
1081 void CTGitPathList::AddPath(const CTGitPath& newPath)
\r
1083 m_paths.push_back(newPath);
\r
1084 m_commonBaseDirectory.Reset();
\r
1086 int CTGitPathList::GetCount() const
\r
1088 return (int)m_paths.size();
\r
1090 void CTGitPathList::Clear()
\r
1093 m_commonBaseDirectory.Reset();
\r
1096 const CTGitPath& CTGitPathList::operator[](INT_PTR index) const
\r
1098 ATLASSERT(index >= 0 && index < (INT_PTR)m_paths.size());
\r
1099 return m_paths[index];
\r
1102 bool CTGitPathList::AreAllPathsFiles() const
\r
1104 // Look through the vector for any directories - if we find them, return false
\r
1105 return std::find_if(m_paths.begin(), m_paths.end(), std::mem_fun_ref(&CTGitPath::IsDirectory)) == m_paths.end();
\r
1109 #if defined(_MFC_VER)
\r
1111 bool CTGitPathList::LoadFromFile(const CTGitPath& filename)
\r
1117 CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite);
\r
1119 // for every selected file/folder
\r
1121 while (file.ReadString(strLine))
\r
1123 path.SetFromUnknown(strLine);
\r
1128 catch (CFileException* pE)
\r
1130 TRACE("CFileException loading target file list\n");
\r
1131 TCHAR error[10000] = {0};
\r
1132 pE->GetErrorMessage(error, 10000);
\r
1133 // CMessageBox::Show(NULL, error, _T("TortoiseGit"), MB_ICONERROR);
\r
1140 bool CTGitPathList::WriteToFile(const CString& sFilename, bool bANSI /* = false */) const
\r
1146 CStdioFile file(sFilename, CFile::typeText | CFile::modeReadWrite | CFile::modeCreate);
\r
1147 PathVector::const_iterator it;
\r
1148 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1150 CStringA line = CStringA(it->GetGitPathString()) + '\n';
\r
1151 file.Write(line, line.GetLength());
\r
1157 CStdioFile file(sFilename, CFile::typeBinary | CFile::modeReadWrite | CFile::modeCreate);
\r
1158 PathVector::const_iterator it;
\r
1159 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1161 file.WriteString(it->GetGitPathString()+_T("\n"));
\r
1166 catch (CFileException* pE)
\r
1168 TRACE("CFileException in writing temp file\n");
\r
1176 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString& sPathString)
\r
1182 temp = sPathString.Tokenize(_T("*"),pos);
\r
1183 if(temp.IsEmpty())
\r
1187 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp)));
\r
1191 CString CTGitPathList::CreateAsteriskSeparatedString() const
\r
1194 PathVector::const_iterator it;
\r
1195 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1197 if (!sRet.IsEmpty())
\r
1199 sRet += it->GetWinPathString();
\r
1203 #endif // _MFC_VER
\r
1206 CTGitPathList::AreAllPathsFilesInOneDirectory() const
\r
1208 // Check if all the paths are files and in the same directory
\r
1209 PathVector::const_iterator it;
\r
1210 m_commonBaseDirectory.Reset();
\r
1211 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1213 if(it->IsDirectory())
\r
1217 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1218 if(m_commonBaseDirectory.IsEmpty())
\r
1220 m_commonBaseDirectory = baseDirectory;
\r
1222 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1225 m_commonBaseDirectory.Reset();
\r
1232 CTGitPath CTGitPathList::GetCommonDirectory() const
\r
1234 if (m_commonBaseDirectory.IsEmpty())
\r
1236 PathVector::const_iterator it;
\r
1237 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1239 const CTGitPath& baseDirectory = it->GetDirectory();
\r
1240 if(m_commonBaseDirectory.IsEmpty())
\r
1242 m_commonBaseDirectory = baseDirectory;
\r
1244 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
\r
1247 m_commonBaseDirectory.Reset();
\r
1252 // since we only checked strings, not paths,
\r
1253 // we have to make sure now that we really return a *path* here
\r
1254 PathVector::const_iterator iter;
\r
1255 for(iter = m_paths.begin(); iter != m_paths.end(); ++iter)
\r
1257 if (!m_commonBaseDirectory.IsAncestorOf(*iter))
\r
1259 m_commonBaseDirectory = m_commonBaseDirectory.GetContainingDirectory();
\r
1263 return m_commonBaseDirectory;
\r
1266 CTGitPath CTGitPathList::GetCommonRoot() const
\r
1268 PathVector::const_iterator it;
\r
1269 CString sRoot, sTempRoot;
\r
1270 bool bEqual = true;
\r
1272 if (GetCount() == 1)
\r
1273 return m_paths[0];
\r
1275 int backSlashPos = 0;
\r
1276 int searchStartPos = 0;
\r
1279 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1281 if (backSlashPos == 0)
\r
1283 backSlashPos = it->GetWinPathString().Find('\\', searchStartPos+1);
\r
1284 if ((backSlashPos < 0)&&(searchStartPos != it->GetWinPathString().GetLength()))
\r
1285 backSlashPos = it->GetWinPathString().GetLength();
\r
1287 else if (it->GetWinPathString().Find('\\', searchStartPos+1) != backSlashPos)
\r
1289 if (it->GetWinPathString().Find('\\', searchStartPos+1) < 0)
\r
1291 if (it->GetWinPathString().GetLength() != backSlashPos)
\r
1303 if (backSlashPos < 0)
\r
1309 if (bEqual == false)
\r
1311 if (searchStartPos)
\r
1312 sRoot = m_paths[0].GetWinPathString().Left(searchStartPos+1);
\r
1316 searchStartPos = backSlashPos;
\r
1321 return CTGitPath(sRoot.TrimRight('\\'));
\r
1324 void CTGitPathList::SortByPathname(bool bReverse /*= false*/)
\r
1326 std::sort(m_paths.begin(), m_paths.end());
\r
1328 std::reverse(m_paths.begin(), m_paths.end());
\r
1331 void CTGitPathList::DeleteAllFiles(bool bTrash)
\r
1333 PathVector::const_iterator it;
\r
1338 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1340 if ((it->Exists())&&(!it->IsDirectory()))
\r
1342 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1343 sPaths += it->GetWinPath();
\r
1349 SHFILEOPSTRUCT shop = {0};
\r
1350 shop.wFunc = FO_DELETE;
\r
1351 shop.pFrom = (LPCTSTR)sPaths;
\r
1352 shop.fFlags = FOF_ALLOWUNDO|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT;
\r
1353 SHFileOperation(&shop);
\r
1357 for (it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1359 if (!it->IsDirectory())
\r
1361 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
\r
1362 ::DeleteFile(it->GetWinPath());
\r
1369 void CTGitPathList::RemoveDuplicates()
\r
1372 // Remove the duplicates
\r
1373 // (Unique moves them to the end of the vector, then erase chops them off)
\r
1374 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::PredLeftEquivalentToRight), m_paths.end());
\r
1377 void CTGitPathList::RemoveAdminPaths()
\r
1379 PathVector::iterator it;
\r
1380 for(it = m_paths.begin(); it != m_paths.end(); )
\r
1382 if (it->IsAdminDir())
\r
1384 m_paths.erase(it);
\r
1385 it = m_paths.begin();
\r
1392 void CTGitPathList::RemovePath(const CTGitPath& path)
\r
1394 PathVector::iterator it;
\r
1395 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1397 if (it->IsEquivalentTo(path))
\r
1399 m_paths.erase(it);
\r
1405 void CTGitPathList::RemoveItem(CTGitPath & path)
\r
1407 PathVector::iterator it;
\r
1408 for(it = m_paths.begin(); it != m_paths.end(); ++it)
\r
1410 if (it->GetGitPathString()==path.GetGitPathString())
\r
1412 m_paths.erase(it);
\r
1417 void CTGitPathList::RemoveChildren()
\r
1420 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::CheckChild), m_paths.end());
\r
1423 bool CTGitPathList::IsEqual(const CTGitPathList& list)
\r
1425 if (list.GetCount() != GetCount())
\r
1427 for (int i=0; i<list.GetCount(); ++i)
\r
1429 if (!list[i].IsEquivalentTo(m_paths[i]))
\r
1435 //////////////////////////////////////////////////////////////////////////
\r
1437 apr_array_header_t * CTGitPathList::MakePathArray (apr_pool_t *pool) const
\r
1439 apr_array_header_t *targets = apr_array_make (pool, GetCount(), sizeof(const char *));
\r
1441 for(int nItem = 0; nItem < GetCount(); nItem++)
\r
1443 const char * target = m_paths[nItem].GetGitApiPath(pool);
\r
1444 (*((const char **) apr_array_push (targets))) = target;
\r
1450 //////////////////////////////////////////////////////////////////////////
\r
1453 #if defined(_DEBUG)
\r
1454 // Some test cases for these classes
\r
1455 static class CTGitPathTests
\r
1461 pool = svn_pool_create(NULL);
\r
1462 GetDirectoryTest();
\r
1467 RemoveDuplicatesTest();
\r
1468 RemoveChildrenTest();
\r
1469 ContainingDirectoryTest();
\r
1471 SubversionPathTest();
\r
1472 GetCommonRootTest();
\r
1473 #if defined(_MFC_VER)
\r
1474 ValidPathAndUrlTest();
\r
1475 ListLoadingTest();
\r
1481 // apr_pool_t * pool;
\r
1482 void GetDirectoryTest()
\r
1484 // Bit tricky, this test, because we need to know something about the file
\r
1485 // layout on the machine which is running the test
\r
1486 TCHAR winDir[MAX_PATH+1];
\r
1487 GetWindowsDirectory(winDir, MAX_PATH);
\r
1488 CString sWinDir(winDir);
\r
1490 CTGitPath testPath;
\r
1491 // This is a file which we know will always be there
\r
1492 testPath.SetFromUnknown(sWinDir + _T("\\win.ini"));
\r
1493 ATLASSERT(!testPath.IsDirectory());
\r
1494 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
\r
1495 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() == sWinDir);
\r
1497 // Now do the test on the win directory itself - It's hard to be sure about the containing directory
\r
1498 // but we know it must be different to the directory itself
\r
1499 testPath.SetFromUnknown(sWinDir);
\r
1500 ATLASSERT(testPath.IsDirectory());
\r
1501 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
\r
1502 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() != sWinDir);
\r
1503 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString().GetLength() < sWinDir.GetLength());
\r
1505 // Try a root path
\r
1506 testPath.SetFromUnknown(_T("C:\\"));
\r
1507 ATLASSERT(testPath.IsDirectory());
\r
1508 ATLASSERT(testPath.GetDirectory().GetWinPathString().CompareNoCase(_T("C:\\"))==0);
\r
1509 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
\r
1510 // Try a root UNC path
\r
1511 testPath.SetFromUnknown(_T("\\MYSTATION"));
\r
1512 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
\r
1515 void AdminDirTest()
\r
1517 CTGitPath testPath;
\r
1518 testPath.SetFromUnknown(_T("c:\\.svndir"));
\r
1519 ATLASSERT(!testPath.IsAdminDir());
\r
1520 testPath.SetFromUnknown(_T("c:\\test.svn"));
\r
1521 ATLASSERT(!testPath.IsAdminDir());
\r
1522 testPath.SetFromUnknown(_T("c:\\.svn"));
\r
1523 ATLASSERT(testPath.IsAdminDir());
\r
1524 testPath.SetFromUnknown(_T("c:\\.svndir\\test"));
\r
1525 ATLASSERT(!testPath.IsAdminDir());
\r
1526 testPath.SetFromUnknown(_T("c:\\.svn\\test"));
\r
1527 ATLASSERT(testPath.IsAdminDir());
\r
1529 CTGitPathList pathList;
\r
1530 pathList.AddPath(CTGitPath(_T("c:\\.svndir")));
\r
1531 pathList.AddPath(CTGitPath(_T("c:\\.svn")));
\r
1532 pathList.AddPath(CTGitPath(_T("c:\\.svn\\test")));
\r
1533 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1534 pathList.RemoveAdminPaths();
\r
1535 ATLASSERT(pathList.GetCount()==2);
\r
1537 pathList.AddPath(CTGitPath(_T("c:\\test")));
\r
1538 pathList.RemoveAdminPaths();
\r
1539 ATLASSERT(pathList.GetCount()==1);
\r
1544 CTGitPathList testList;
\r
1545 CTGitPath testPath;
\r
1546 testPath.SetFromUnknown(_T("c:/Z"));
\r
1547 testList.AddPath(testPath);
\r
1548 testPath.SetFromUnknown(_T("c:/B"));
\r
1549 testList.AddPath(testPath);
\r
1550 testPath.SetFromUnknown(_T("c:\\a"));
\r
1551 testList.AddPath(testPath);
\r
1552 testPath.SetFromUnknown(_T("c:/Test"));
\r
1553 testList.AddPath(testPath);
\r
1555 testList.SortByPathname();
\r
1557 ATLASSERT(testList[0].GetWinPathString() == _T("c:\\a"));
\r
1558 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\B"));
\r
1559 ATLASSERT(testList[2].GetWinPathString() == _T("c:\\Test"));
\r
1560 ATLASSERT(testList[3].GetWinPathString() == _T("c:\\Z"));
\r
1563 void RawAppendTest()
\r
1565 CTGitPath testPath(_T("c:/test/"));
\r
1566 testPath.AppendRawString(_T("/Hello"));
\r
1567 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1569 testPath.AppendRawString(_T("\\T2"));
\r
1570 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\r
1572 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
\r
1573 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
\r
1574 testBasePath.AppendRawString(testFilePath.GetFileExtension());
\r
1575 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt.ini"));
\r
1578 void PathAppendTest()
\r
1580 CTGitPath testPath(_T("c:/test/"));
\r
1581 testPath.AppendPathString(_T("/Hello"));
\r
1582 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
\r
1584 testPath.AppendPathString(_T("T2"));
\r
1585 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
\r
1587 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
\r
1588 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
\r
1589 // You wouldn't want to do this in real life - you'd use append-raw
\r
1590 testBasePath.AppendPathString(testFilePath.GetFileExtension());
\r
1591 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt\\.ini"));
\r
1594 void RemoveDuplicatesTest()
\r
1596 CTGitPathList list;
\r
1597 list.AddPath(CTGitPath(_T("Z")));
\r
1598 list.AddPath(CTGitPath(_T("A")));
\r
1599 list.AddPath(CTGitPath(_T("E")));
\r
1600 list.AddPath(CTGitPath(_T("E")));
\r
1602 ATLASSERT(list[2].IsEquivalentTo(list[3]));
\r
1603 ATLASSERT(list[2]==list[3]);
\r
1605 ATLASSERT(list.GetCount() == 4);
\r
1607 list.RemoveDuplicates();
\r
1609 ATLASSERT(list.GetCount() == 3);
\r
1611 ATLASSERT(list[0].GetWinPathString() == _T("A"));
\r
1612 ATLASSERT(list[1].GetWinPathString().Compare(_T("E")) == 0);
\r
1613 ATLASSERT(list[2].GetWinPathString() == _T("Z"));
\r
1616 void RemoveChildrenTest()
\r
1618 CTGitPathList list;
\r
1619 list.AddPath(CTGitPath(_T("c:\\test")));
\r
1620 list.AddPath(CTGitPath(_T("c:\\test\\file")));
\r
1621 list.AddPath(CTGitPath(_T("c:\\testfile")));
\r
1622 list.AddPath(CTGitPath(_T("c:\\parent")));
\r
1623 list.AddPath(CTGitPath(_T("c:\\parent\\child")));
\r
1624 list.AddPath(CTGitPath(_T("c:\\parent\\child1")));
\r
1625 list.AddPath(CTGitPath(_T("c:\\parent\\child2")));
\r
1627 ATLASSERT(list.GetCount() == 7);
\r
1629 list.RemoveChildren();
\r
1631 ATLTRACE("count = %d\n", list.GetCount());
\r
1632 ATLASSERT(list.GetCount() == 3);
\r
1634 list.SortByPathname();
\r
1636 ATLASSERT(list[0].GetWinPathString().Compare(_T("c:\\parent")) == 0);
\r
1637 ATLASSERT(list[1].GetWinPathString().Compare(_T("c:\\test")) == 0);
\r
1638 ATLASSERT(list[2].GetWinPathString().Compare(_T("c:\\testfile")) == 0);
\r
1641 #if defined(_MFC_VER)
\r
1642 void ListLoadingTest()
\r
1644 TCHAR buf[MAX_PATH];
\r
1645 GetCurrentDirectory(MAX_PATH, buf);
\r
1646 CString sPathList(_T("Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"));
\r
1647 CTGitPathList testList;
\r
1648 testList.LoadFromAsteriskSeparatedString(sPathList);
\r
1650 ATLASSERT(testList.GetCount() == 3);
\r
1651 ATLASSERT(testList[0].GetWinPathString() == CString(buf) + _T("\\Path1"));
\r
1652 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\path2 with spaces and stuff"));
\r
1653 ATLASSERT(testList[2].GetWinPathString() == _T("\\funnypath"));
\r
1655 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T(""));
\r
1657 sPathList = _T("c:\\path2 with spaces and stuff*c:\\funnypath\\*");
\r
1658 testList.LoadFromAsteriskSeparatedString(sPathList);
\r
1659 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T("c:\\"));
\r
1663 void ContainingDirectoryTest()
\r
1666 CTGitPath testPath;
\r
1667 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\r
1669 dir = testPath.GetContainingDirectory();
\r
1670 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c\\d"));
\r
1671 dir = dir.GetContainingDirectory();
\r
1672 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c"));
\r
1673 dir = dir.GetContainingDirectory();
\r
1674 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b"));
\r
1675 dir = dir.GetContainingDirectory();
\r
1676 ATLASSERT(dir.GetWinPathString() == _T("c:\\a"));
\r
1677 dir = dir.GetContainingDirectory();
\r
1678 ATLASSERT(dir.GetWinPathString() == _T("c:\\"));
\r
1679 dir = dir.GetContainingDirectory();
\r
1680 ATLASSERT(dir.IsEmpty());
\r
1681 ATLASSERT(dir.GetWinPathString() == _T(""));
\r
1684 void AncestorTest()
\r
1686 CTGitPath testPath;
\r
1687 testPath.SetFromWin(_T("c:\\windows"));
\r
1688 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\")))==false);
\r
1689 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows"))));
\r
1690 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windowsdummy")))==false);
\r
1691 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\test.txt"))));
\r
1692 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\system32\\test.txt"))));
\r
1695 void SubversionPathTest()
\r
1697 CTGitPath testPath;
\r
1698 testPath.SetFromWin(_T("c:\\"));
\r
1699 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:") == 0);
\r
1700 testPath.SetFromWin(_T("c:\\folder"));
\r
1701 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);
\r
1702 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
\r
1703 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);
\r
1704 testPath.SetFromUnknown(_T("http://testing/"));
\r
1705 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);
\r
1706 testPath.SetFromGit(NULL);
\r
1707 ATLASSERT(strlen(testPath.GetGitApiPath(pool))==0);
\r
1708 #if defined(_MFC_VER)
\r
1709 testPath.SetFromUnknown(_T("http://testing again"));
\r
1710 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
\r
1711 testPath.SetFromUnknown(_T("http://testing%20again"));
\r
1712 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
\r
1713 testPath.SetFromUnknown(_T("http://testing special chars \344\366\374"));
\r
1714 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);
\r
1718 void GetCommonRootTest()
\r
1720 CTGitPath pathA (_T("C:\\Development\\LogDlg.cpp"));
\r
1721 CTGitPath pathB (_T("C:\\Development\\LogDlg.h"));
\r
1722 CTGitPath pathC (_T("C:\\Development\\SomeDir\\LogDlg.h"));
\r
1724 CTGitPathList list;
\r
1725 list.AddPath(pathA);
\r
1726 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development\\LogDlg.cpp"))==0);
\r
1727 list.AddPath(pathB);
\r
1728 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
\r
1729 list.AddPath(pathC);
\r
1730 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
\r
1733 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
1734 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1735 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("D:\\Development\\StExBar"))==0);
\r
1738 sPathList = _T("c:\\windows\\explorer.exe*c:\\windows");
\r
1739 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1740 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1743 sPathList = _T("c:\\windows\\*c:\\windows");
\r
1744 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1745 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1748 sPathList = _T("c:\\windows\\system32*c:\\windows\\system");
\r
1749 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1750 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
\r
1753 sPathList = _T("c:\\windowsdummy*c:\\windows");
\r
1754 list.LoadFromAsteriskSeparatedString(sPathList);
\r
1755 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\"))==0);
\r
1759 void ValidPathAndUrlTest()
\r
1761 CTGitPath testPath;
\r
1762 testPath.SetFromWin(_T("c:\\a\\b\\c.test.txt"));
\r
1763 ATLASSERT(testPath.IsValidOnWindows());
\r
1764 testPath.SetFromWin(_T("c:\\"));
\r
1765 ATLASSERT(testPath.IsValidOnWindows());
\r
1766 testPath.SetFromWin(_T("D:\\.Net\\SpindleSearch\\"));
\r
1767 ATLASSERT(testPath.IsValidOnWindows());
\r
1768 testPath.SetFromWin(_T("c"));
\r
1769 ATLASSERT(testPath.IsValidOnWindows());
\r
1770 testPath.SetFromWin(_T("c:\\test folder\\file"));
\r
1771 ATLASSERT(testPath.IsValidOnWindows());
\r
1772 testPath.SetFromWin(_T("c:\\folder\\"));
\r
1773 ATLASSERT(testPath.IsValidOnWindows());
\r
1774 testPath.SetFromWin(_T("c:\\ext.ext.ext\\ext.ext.ext.ext"));
\r
1775 ATLASSERT(testPath.IsValidOnWindows());
\r
1776 testPath.SetFromWin(_T("c:\\.svn"));
\r
1777 ATLASSERT(testPath.IsValidOnWindows());
\r
1778 testPath.SetFromWin(_T("c:\\com\\file"));
\r
1779 ATLASSERT(testPath.IsValidOnWindows());
\r
1780 testPath.SetFromWin(_T("c:\\test\\conf"));
\r
1781 ATLASSERT(testPath.IsValidOnWindows());
\r
1782 testPath.SetFromWin(_T("c:\\LPT"));
\r
1783 ATLASSERT(testPath.IsValidOnWindows());
\r
1784 testPath.SetFromWin(_T("c:\\test\\LPT"));
\r
1785 ATLASSERT(testPath.IsValidOnWindows());
\r
1786 testPath.SetFromWin(_T("c:\\com1test"));
\r
1787 ATLASSERT(testPath.IsValidOnWindows());
\r
1788 testPath.SetFromWin(_T("\\\\?\\c:\\test\\com1test"));
\r
1789 ATLASSERT(testPath.IsValidOnWindows());
\r
1791 testPath.SetFromWin(_T("\\\\Share\\filename"));
\r
1792 ATLASSERT(testPath.IsValidOnWindows());
\r
1793 testPath.SetFromWin(_T("\\\\Share\\filename.extension"));
\r
1794 ATLASSERT(testPath.IsValidOnWindows());
\r
1795 testPath.SetFromWin(_T("\\\\Share\\.svn"));
\r
1796 ATLASSERT(testPath.IsValidOnWindows());
\r
1798 // now the negative tests
\r
1799 testPath.SetFromWin(_T("c:\\test:folder"));
\r
1800 ATLASSERT(!testPath.IsValidOnWindows());
\r
1801 testPath.SetFromWin(_T("c:\\file<name"));
\r
1802 ATLASSERT(!testPath.IsValidOnWindows());
\r
1803 testPath.SetFromWin(_T("c:\\something*else"));
\r
1804 ATLASSERT(!testPath.IsValidOnWindows());
\r
1805 testPath.SetFromWin(_T("c:\\folder\\file?nofile"));
\r
1806 ATLASSERT(!testPath.IsValidOnWindows());
\r
1807 testPath.SetFromWin(_T("c:\\ext.>ension"));
\r
1808 ATLASSERT(!testPath.IsValidOnWindows());
\r
1809 testPath.SetFromWin(_T("c:\\com1\\filename"));
\r
1810 ATLASSERT(!testPath.IsValidOnWindows());
\r
1811 testPath.SetFromWin(_T("c:\\com1"));
\r
1812 ATLASSERT(!testPath.IsValidOnWindows());
\r
1813 testPath.SetFromWin(_T("c:\\com1\\AuX"));
\r
1814 ATLASSERT(!testPath.IsValidOnWindows());
\r
1816 testPath.SetFromWin(_T("\\\\Share\\lpt9\\filename"));
\r
1817 ATLASSERT(!testPath.IsValidOnWindows());
\r
1818 testPath.SetFromWin(_T("\\\\Share\\prn"));
\r
1819 ATLASSERT(!testPath.IsValidOnWindows());
\r
1820 testPath.SetFromWin(_T("\\\\Share\\NUL"));
\r
1821 ATLASSERT(!testPath.IsValidOnWindows());
\r
1823 // now come some URL tests
\r
1824 testPath.SetFromGit(_T("http://myserver.com/repos/trunk"));
\r
1825 ATLASSERT(testPath.IsValidOnWindows());
\r
1826 testPath.SetFromGit(_T("https://myserver.com/repos/trunk/file%20with%20spaces"));
\r
1827 ATLASSERT(testPath.IsValidOnWindows());
\r
1828 testPath.SetFromGit(_T("svn://myserver.com/repos/trunk/file with spaces"));
\r
1829 ATLASSERT(testPath.IsValidOnWindows());
\r
1830 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk"));
\r
1831 ATLASSERT(testPath.IsValidOnWindows());
\r
1832 testPath.SetFromGit(_T("http://localhost:90/repos/trunk"));
\r
1833 ATLASSERT(testPath.IsValidOnWindows());
\r
1834 testPath.SetFromGit(_T("file:///C:/GitRepos/Tester/Proj1/tags/t2"));
\r
1835 ATLASSERT(testPath.IsValidOnWindows());
\r
1836 // and some negative URL tests
\r
1837 testPath.SetFromGit(_T("httpp://myserver.com/repos/trunk"));
\r
1838 ATLASSERT(!testPath.IsValidOnWindows());
\r
1839 testPath.SetFromGit(_T("https://myserver.com/rep:os/trunk/file%20with%20spaces"));
\r
1840 ATLASSERT(!testPath.IsValidOnWindows());
\r
1841 testPath.SetFromGit(_T("svn://myserver.com/rep<os/trunk/file with spaces"));
\r
1842 ATLASSERT(!testPath.IsValidOnWindows());
\r
1843 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk/prn/"));
\r
1844 ATLASSERT(!testPath.IsValidOnWindows());
\r
1845 testPath.SetFromGit(_T("http://localhost:90/repos/trunk/com1"));
\r
1846 ATLASSERT(!testPath.IsValidOnWindows());
\r
1850 } TGitPathTestobject;
\r
1854 CTGitPath * CTGitPathList::LookForGitPath(CString path)
\r
1857 for(i=0;i<this->GetCount();i++)
\r
1859 if((*this)[i].GetGitPathString() == path )
\r
1860 return (CTGitPath*)&(*this)[i];
\r
1865 CString CTGitPath::GetActionName()
\r
1867 if(m_Action & CTGitPath::LOGACTIONS_ADDED)
\r
1868 return _T("Added");
\r
1869 if(m_Action & CTGitPath::LOGACTIONS_DELETED)
\r
1870 return _T("Deleted");
\r
1871 if(m_Action & CTGitPath::LOGACTIONS_UNMERGED)
\r
1872 return _T("Conflict");
\r
1873 if(m_Action & CTGitPath::LOGACTIONS_MODIFIED)
\r
1874 return _T("Modified");
\r
1875 if(m_Action & CTGitPath::LOGACTIONS_REPLACED)
\r
1876 return _T("Rename");
\r
1877 return _T("Unknown");
\r
1880 int CTGitPathList::GetAction()
\r