Make rebase faster by separating rebase related actions from GitRev.GetAction() to...
[TortoiseGit.git] / src / Git / TGitPath.cpp
blobe8d7d4808cc70248c0a2c53906e78c15b546bdd4
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2010-2014 Sven Strickroth <email@cs-ware.de>
5 // Copyright (C) 2003-2008 - TortoiseSVN
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "stdafx.h"
22 #include "TGitPath.h"
23 #include "UnicodeUtils.h"
24 #include "GitAdminDir.h"
25 #include "PathUtils.h"
26 #include <regex>
27 #include "Git.h"
28 #include "Globals.h"
29 #include "StringUtils.h"
30 #include "../Resources/LoglistCommonResource.h"
31 #include <memory>
33 #if defined(_MFC_VER)
34 //#include "MessageBox.h"
35 //#include "AppUtils.h"
36 #endif
38 #ifndef ASSERT
39 #define ASSERT()
40 #endif
41 extern CGit g_Git;
43 CTGitPath::CTGitPath(void)
44 : m_bDirectoryKnown(false)
45 , m_bIsDirectory(false)
46 , m_bURLKnown(false)
47 , m_bHasAdminDirKnown(false)
48 , m_bHasAdminDir(false)
49 , m_bIsValidOnWindowsKnown(false)
50 , m_bIsValidOnWindows(false)
51 , m_bIsReadOnly(false)
52 , m_bIsAdminDirKnown(false)
53 , m_bIsAdminDir(false)
54 , m_bExists(false)
55 , m_bExistsKnown(false)
56 , m_bLastWriteTimeKnown(0)
57 , m_lastWriteTime(0)
58 , m_customData(NULL)
59 , m_bIsSpecialDirectoryKnown(false)
60 , m_bIsSpecialDirectory(false)
61 , m_bIsWCRootKnown(false)
62 , m_bIsWCRoot(false)
63 , m_fileSize(0)
64 , m_Checked(false)
66 m_Action=0;
67 m_ParentNo=0;
68 m_Stage = 0;
71 CTGitPath::~CTGitPath(void)
74 // Create a TGitPath object from an unknown path type (same as using SetFromUnknown)
75 CTGitPath::CTGitPath(const CString& sUnknownPath) :
76 m_bDirectoryKnown(false)
77 , m_bIsDirectory(false)
78 , m_bURLKnown(false)
79 , m_bHasAdminDirKnown(false)
80 , m_bHasAdminDir(false)
81 , m_bIsValidOnWindowsKnown(false)
82 , m_bIsValidOnWindows(false)
83 , m_bIsReadOnly(false)
84 , m_bIsAdminDirKnown(false)
85 , m_bIsAdminDir(false)
86 , m_bExists(false)
87 , m_bExistsKnown(false)
88 , m_bLastWriteTimeKnown(0)
89 , m_lastWriteTime(0)
90 , m_customData(NULL)
91 , m_bIsSpecialDirectoryKnown(false)
92 , m_bIsSpecialDirectory(false)
93 , m_bIsWCRootKnown(false)
94 , m_bIsWCRoot(false)
95 , m_fileSize(0)
96 , m_Checked(false)
98 SetFromUnknown(sUnknownPath);
99 m_Action=0;
100 m_Stage=0;
101 m_ParentNo=0;
104 int CTGitPath::ParserAction(BYTE action)
106 //action=action.TrimLeft();
107 //TCHAR c=action.GetAt(0);
108 if(action == 'M')
109 m_Action|= LOGACTIONS_MODIFIED;
110 if(action == 'R')
111 m_Action|= LOGACTIONS_REPLACED;
112 if(action == 'A')
113 m_Action|= LOGACTIONS_ADDED;
114 if(action == 'D')
115 m_Action|= LOGACTIONS_DELETED;
116 if(action == 'U')
117 m_Action|= LOGACTIONS_UNMERGED;
118 if(action == 'K')
119 m_Action|= LOGACTIONS_DELETED;
120 if(action == 'H')
121 m_Action|= LOGACTIONS_CACHE;
122 if(action == 'C' )
123 m_Action|= LOGACTIONS_COPY;
125 return m_Action;
127 void CTGitPath::SetFromGit(const char* pPath)
129 Reset();
130 if (pPath == NULL)
131 return;
132 int len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, NULL, 0);
133 if (len)
135 len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, m_sFwdslashPath.GetBuffer(len+1), len+1);
136 m_sFwdslashPath.ReleaseBuffer(len-1);
138 SanitizeRootPath(m_sFwdslashPath, true);
141 void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
143 SetFromGit(pPath);
144 m_bDirectoryKnown = true;
145 m_bIsDirectory = bIsDirectory;
148 void CTGitPath::SetFromGit(const TCHAR* pPath, bool bIsDirectory)
150 Reset();
151 if (pPath)
153 m_sFwdslashPath = pPath;
154 SanitizeRootPath(m_sFwdslashPath, true);
156 m_bDirectoryKnown = true;
157 m_bIsDirectory = bIsDirectory;
160 void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)
162 Reset();
163 m_sFwdslashPath = sPath;
164 SanitizeRootPath(m_sFwdslashPath, true);
165 if(oldpath)
166 m_sOldFwdslashPath = *oldpath;
169 void CTGitPath::SetFromWin(LPCTSTR pPath)
171 Reset();
172 m_sBackslashPath = pPath;
173 m_sBackslashPath.Replace(L"\\\\?\\", L"");
174 SanitizeRootPath(m_sBackslashPath, false);
175 ATLASSERT(m_sBackslashPath.Find('/')<0);
177 void CTGitPath::SetFromWin(const CString& sPath)
179 Reset();
180 m_sBackslashPath = sPath;
181 m_sBackslashPath.Replace(L"\\\\?\\", L"");
182 SanitizeRootPath(m_sBackslashPath, false);
184 void CTGitPath::SetFromWin(LPCTSTR pPath, bool bIsDirectory)
186 Reset();
187 m_sBackslashPath = pPath;
188 m_bIsDirectory = bIsDirectory;
189 m_bDirectoryKnown = true;
190 SanitizeRootPath(m_sBackslashPath, false);
192 void CTGitPath::SetFromWin(const CString& sPath, bool bIsDirectory)
194 Reset();
195 m_sBackslashPath = sPath;
196 m_bIsDirectory = bIsDirectory;
197 m_bDirectoryKnown = true;
198 SanitizeRootPath(m_sBackslashPath, false);
200 void CTGitPath::SetFromUnknown(const CString& sPath)
202 Reset();
203 // Just set whichever path we think is most likely to be used
204 // GitAdminDir admin;
205 // CString p;
206 // if(admin.HasAdminDir(sPath,&p))
207 // SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));
208 // else
209 SetFwdslashPath(sPath);
212 LPCTSTR CTGitPath::GetWinPath() const
214 if(IsEmpty())
216 return _T("");
218 if(m_sBackslashPath.IsEmpty())
220 SetBackslashPath(m_sFwdslashPath);
222 return m_sBackslashPath;
224 // This is a temporary function, to be used during the migration to
225 // the path class. Ultimately, functions consuming paths should take a CTGitPath&, not a CString
226 const CString& CTGitPath::GetWinPathString() const
228 if(m_sBackslashPath.IsEmpty())
230 SetBackslashPath(m_sFwdslashPath);
232 return m_sBackslashPath;
235 const CString& CTGitPath::GetGitPathString() const
237 if(m_sFwdslashPath.IsEmpty())
239 SetFwdslashPath(m_sBackslashPath);
241 return m_sFwdslashPath;
244 const CString &CTGitPath::GetGitOldPathString() const
246 return m_sOldFwdslashPath;
248 #if 0
249 const char* CTGitPath::GetGitApiPath(apr_pool_t *pool) const
251 // This funny-looking 'if' is to avoid a subtle problem with empty paths, whereby
252 // each call to GetGitApiPath returns a different pointer value.
253 // If you made multiple calls to GetGitApiPath on the same string, only the last
254 // one would give you a valid pointer to an empty string, because each
255 // call would invalidate the previous call's return.
256 if(IsEmpty())
258 return "";
260 if(m_sFwdslashPath.IsEmpty())
262 SetFwdslashPath(m_sBackslashPath);
264 if(m_sUTF8FwdslashPath.IsEmpty())
266 SetUTF8FwdslashPath(m_sFwdslashPath);
268 if (svn_path_is_url(m_sUTF8FwdslashPath))
270 m_sUTF8FwdslashPathEscaped = CPathUtils::PathEscape(m_sUTF8FwdslashPath);
271 m_sUTF8FwdslashPathEscaped.Replace("file:////", "file:///\\");
272 m_sUTF8FwdslashPathEscaped = svn_path_canonicalize(m_sUTF8FwdslashPathEscaped, pool);
273 return m_sUTF8FwdslashPathEscaped;
275 m_sUTF8FwdslashPath = svn_path_canonicalize(m_sUTF8FwdslashPath, pool);
277 return m_sUTF8FwdslashPath;
279 #endif
281 const CString& CTGitPath::GetUIPathString() const
283 if (m_sUIPath.IsEmpty())
285 m_sUIPath = GetWinPathString();
287 return m_sUIPath;
290 void CTGitPath::SetFwdslashPath(const CString& sPath) const
292 m_sFwdslashPath = sPath;
293 m_sFwdslashPath.Replace('\\', '/');
295 // We don't leave a trailing /
296 m_sFwdslashPath.TrimRight('/');
297 m_sFwdslashPath.Replace(L"//?/", L"");
299 SanitizeRootPath(m_sFwdslashPath, true);
301 m_sFwdslashPath.Replace(_T("file:////"), _T("file://"));
303 m_sUTF8FwdslashPath.Empty();
306 void CTGitPath::SetBackslashPath(const CString& sPath) const
308 m_sBackslashPath = sPath;
309 m_sBackslashPath.Replace('/', '\\');
310 m_sBackslashPath.TrimRight('\\');
311 SanitizeRootPath(m_sBackslashPath, false);
314 void CTGitPath::SetUTF8FwdslashPath(const CString& sPath) const
316 m_sUTF8FwdslashPath = CUnicodeUtils::GetUTF8(sPath);
319 void CTGitPath::SanitizeRootPath(CString& sPath, bool bIsForwardPath) const
321 // Make sure to add the trailing slash to root paths such as 'C:'
322 if (sPath.GetLength() == 2 && sPath[1] == ':')
324 sPath += (bIsForwardPath) ? _T("/") : _T("\\");
328 bool CTGitPath::IsDirectory() const
330 if(!m_bDirectoryKnown)
332 UpdateAttributes();
334 return m_bIsDirectory;
337 bool CTGitPath::Exists() const
339 if (!m_bExistsKnown)
341 UpdateAttributes();
343 return m_bExists;
346 bool CTGitPath::Delete(bool bTrash) const
348 EnsureBackslashPathSet();
349 ::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);
350 bool bRet = false;
351 if (Exists())
353 if ((bTrash)||(IsDirectory()))
355 std::unique_ptr<TCHAR[]> buf(new TCHAR[m_sBackslashPath.GetLength() + 2]);
356 _tcscpy_s(buf.get(), m_sBackslashPath.GetLength() + 2, m_sBackslashPath);
357 buf[m_sBackslashPath.GetLength()] = 0;
358 buf[m_sBackslashPath.GetLength()+1] = 0;
359 bRet = CTGitPathList::DeleteViaShell(buf.get(), bTrash);
361 else
363 bRet = !!::DeleteFile(m_sBackslashPath);
366 m_bExists = false;
367 m_bExistsKnown = true;
368 return bRet;
371 __int64 CTGitPath::GetLastWriteTime() const
373 if(!m_bLastWriteTimeKnown)
375 UpdateAttributes();
377 return m_lastWriteTime;
380 __int64 CTGitPath::GetFileSize() const
382 if(!m_bDirectoryKnown)
384 UpdateAttributes();
386 return m_fileSize;
389 bool CTGitPath::IsReadOnly() const
391 if(!m_bLastWriteTimeKnown)
393 UpdateAttributes();
395 return m_bIsReadOnly;
398 void CTGitPath::UpdateAttributes() const
400 EnsureBackslashPathSet();
401 WIN32_FILE_ATTRIBUTE_DATA attribs;
402 if (m_sBackslashPath.GetLength() >= 248)
403 m_sLongBackslashPath = _T("\\\\?\\") + m_sBackslashPath;
404 if(GetFileAttributesEx(m_sBackslashPath.GetLength() >= 248 ? m_sLongBackslashPath : m_sBackslashPath, GetFileExInfoStandard, &attribs))
406 m_bIsDirectory = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
407 m_lastWriteTime = *(__int64*)&attribs.ftLastWriteTime;
408 if (m_bIsDirectory)
410 m_fileSize = 0;
412 else
414 m_fileSize = ((INT64)( (DWORD)(attribs.nFileSizeLow) ) | ( (INT64)( (DWORD)(attribs.nFileSizeHigh) )<<32 ));
416 m_bIsReadOnly = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_READONLY);
417 m_bExists = true;
419 else
421 m_bIsDirectory = false;
422 m_lastWriteTime = 0;
423 m_fileSize = 0;
424 DWORD err = GetLastError();
425 if ((err == ERROR_FILE_NOT_FOUND)||(err == ERROR_PATH_NOT_FOUND)||(err == ERROR_INVALID_NAME))
427 m_bExists = false;
429 else
431 m_bExists = true;
432 return;
435 m_bDirectoryKnown = true;
436 m_bLastWriteTimeKnown = true;
437 m_bExistsKnown = true;
440 CTGitPath CTGitPath::GetSubPath(const CTGitPath &root)
442 CTGitPath path;
444 if(GetWinPathString().Left(root.GetWinPathString().GetLength()) == root.GetWinPathString())
446 CString str=GetWinPathString();
447 path.SetFromWin(str.Right(str.GetLength()-root.GetWinPathString().GetLength()-1));
449 return path;
452 void CTGitPath::EnsureBackslashPathSet() const
454 if(m_sBackslashPath.IsEmpty())
456 SetBackslashPath(m_sFwdslashPath);
457 ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());
460 void CTGitPath::EnsureFwdslashPathSet() const
462 if(m_sFwdslashPath.IsEmpty())
464 SetFwdslashPath(m_sBackslashPath);
465 ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());
470 // Reset all the caches
471 void CTGitPath::Reset()
473 m_bDirectoryKnown = false;
474 m_bURLKnown = false;
475 m_bLastWriteTimeKnown = false;
476 m_bHasAdminDirKnown = false;
477 m_bIsValidOnWindowsKnown = false;
478 m_bIsAdminDirKnown = false;
479 m_bExistsKnown = false;
480 m_bIsSpecialDirectoryKnown = false;
481 m_bIsSpecialDirectory = false;
483 m_sBackslashPath.Empty();
484 m_sFwdslashPath.Empty();
485 m_sUTF8FwdslashPath.Empty();
486 this->m_Action=0;
487 this->m_StatAdd=_T("");
488 this->m_StatDel=_T("");
489 m_ParentNo=0;
490 ATLASSERT(IsEmpty());
493 CTGitPath CTGitPath::GetDirectory() const
495 if ((IsDirectory())||(!Exists()))
497 return *this;
499 return GetContainingDirectory();
502 CTGitPath CTGitPath::GetContainingDirectory() const
504 EnsureBackslashPathSet();
506 CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));
507 if(sDirName.GetLength() == 2 && sDirName[1] == ':')
509 // This is a root directory, which needs a trailing slash
510 sDirName += '\\';
511 if(sDirName == m_sBackslashPath)
513 // We were clearly provided with a root path to start with - we should return nothing now
514 sDirName.Empty();
517 if(sDirName.GetLength() == 1 && sDirName[0] == '\\')
519 // We have an UNC path and we already are the root
520 sDirName.Empty();
522 CTGitPath retVal;
523 retVal.SetFromWin(sDirName);
524 return retVal;
527 CString CTGitPath::GetRootPathString() const
529 EnsureBackslashPathSet();
530 CString workingPath = m_sBackslashPath;
531 LPTSTR pPath = workingPath.GetBuffer(MAX_PATH); // MAX_PATH ok here.
532 ATLVERIFY(::PathStripToRoot(pPath));
533 workingPath.ReleaseBuffer();
534 return workingPath;
538 CString CTGitPath::GetFilename() const
540 //ATLASSERT(!IsDirectory());
541 return GetFileOrDirectoryName();
544 CString CTGitPath::GetFileOrDirectoryName() const
546 EnsureBackslashPathSet();
547 return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);
550 CString CTGitPath::GetUIFileOrDirectoryName() const
552 GetUIPathString();
553 return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);
556 CString CTGitPath::GetFileExtension() const
558 if(!IsDirectory())
560 EnsureBackslashPathSet();
561 int dotPos = m_sBackslashPath.ReverseFind('.');
562 int slashPos = m_sBackslashPath.ReverseFind('\\');
563 if (dotPos > slashPos)
564 return m_sBackslashPath.Mid(dotPos);
566 return CString();
568 CString CTGitPath::GetBaseFilename() const
570 int dot;
571 CString filename=GetFilename();
572 dot = filename.ReverseFind(_T('.'));
573 if(dot>0)
574 return filename.Left(dot);
575 else
576 return filename;
579 bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)
581 int length = sP1.GetLength();
582 if(length != sP2.GetLength())
584 // Different lengths
585 return false;
587 // We work from the end of the strings, because path differences
588 // are more likely to occur at the far end of a string
589 LPCTSTR pP1Start = sP1;
590 LPCTSTR pP1 = pP1Start+(length-1);
591 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
592 while(length-- > 0)
594 if(_totlower(*pP1--) != _totlower(*pP2--))
596 return false;
599 return true;
602 bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)
604 int length = sP1.GetLength();
605 if(length != sP2.GetLength())
607 // Different lengths
608 return false;
610 // We work from the end of the strings, because path differences
611 // are more likely to occur at the far end of a string
612 LPCTSTR pP1Start = sP1;
613 LPCTSTR pP1 = pP1Start+(length-1);
614 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
615 while(length-- > 0)
617 if((*pP1--) != (*pP2--))
619 return false;
622 return true;
625 bool CTGitPath::IsEmpty() const
627 // Check the backward slash path first, since the chance that this
628 // one is set is higher. In case of a 'false' return value it's a little
629 // bit faster.
630 return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();
633 // Test if both paths refer to the same item
634 // Ignores case and slash direction
635 bool CTGitPath::IsEquivalentTo(const CTGitPath& rhs) const
637 // Try and find a slash direction which avoids having to convert
638 // both filenames
639 if(!m_sBackslashPath.IsEmpty())
641 // *We've* got a \ path - make sure that the RHS also has a \ path
642 rhs.EnsureBackslashPathSet();
643 return ArePathStringsEqualWithCase(m_sBackslashPath, rhs.m_sBackslashPath);
645 else
647 // Assume we've got a fwdslash path and make sure that the RHS has one
648 rhs.EnsureFwdslashPathSet();
649 return ArePathStringsEqualWithCase(m_sFwdslashPath, rhs.m_sFwdslashPath);
653 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const
655 // Try and find a slash direction which avoids having to convert
656 // both filenames
657 if(!m_sBackslashPath.IsEmpty())
659 // *We've* got a \ path - make sure that the RHS also has a \ path
660 rhs.EnsureBackslashPathSet();
661 return ArePathStringsEqual(m_sBackslashPath, rhs.m_sBackslashPath);
663 else
665 // Assume we've got a fwdslash path and make sure that the RHS has one
666 rhs.EnsureFwdslashPathSet();
667 return ArePathStringsEqual(m_sFwdslashPath, rhs.m_sFwdslashPath);
671 bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const
673 possibleDescendant.EnsureBackslashPathSet();
674 EnsureBackslashPathSet();
676 bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));
677 if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())
679 return bPathStringsEqual;
682 return (bPathStringsEqual &&
683 ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||
684 (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));
687 // Get a string representing the file path, optionally with a base
688 // section stripped off the front.
689 CString CTGitPath::GetDisplayString(const CTGitPath* pOptionalBasePath /* = NULL*/) const
691 EnsureFwdslashPathSet();
692 if(pOptionalBasePath != NULL)
694 // Find the length of the base-path without having to do an 'ensure' on it
695 int baseLength = max(pOptionalBasePath->m_sBackslashPath.GetLength(), pOptionalBasePath->m_sFwdslashPath.GetLength());
697 // Now, chop that baseLength of the front of the path
698 return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');
700 return m_sFwdslashPath;
703 int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)
705 left.EnsureBackslashPathSet();
706 right.EnsureBackslashPathSet();
707 return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);
710 bool operator<(const CTGitPath& left, const CTGitPath& right)
712 return CTGitPath::Compare(left, right) < 0;
715 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)
717 return left.IsEquivalentTo(right);
720 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)
722 if (left.IsAdminDir() && right.IsAdminDir())
724 CTGitPath l = left;
725 CTGitPath r = right;
728 l = l.GetContainingDirectory();
729 } while(l.HasAdminDir());
732 r = r.GetContainingDirectory();
733 } while(r.HasAdminDir());
734 return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());
736 return left.GetDirectory().IsEquivalentTo(right.GetDirectory());
739 bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)
741 return parent.IsAncestorOf(child);
744 void CTGitPath::AppendRawString(const CString& sAppend)
746 EnsureFwdslashPathSet();
747 CString strCopy = m_sFwdslashPath += sAppend;
748 SetFromUnknown(strCopy);
751 void CTGitPath::AppendPathString(const CString& sAppend)
753 EnsureBackslashPathSet();
754 CString cleanAppend(sAppend);
755 cleanAppend.Replace('/', '\\');
756 cleanAppend.TrimLeft('\\');
757 m_sBackslashPath.TrimRight('\\');
758 CString strCopy = m_sBackslashPath + _T("\\") + cleanAppend;
759 SetFromWin(strCopy);
762 bool CTGitPath::IsWCRoot() const
764 if (m_bIsWCRootKnown)
765 return m_bIsWCRoot;
767 m_bIsWCRootKnown = true;
768 m_bIsWCRoot = false;
770 CString topDirectory;
771 if (!IsDirectory() || !HasAdminDir(&topDirectory))
773 return m_bIsWCRoot;
776 if (IsEquivalentToWithoutCase(topDirectory))
778 m_bIsWCRoot = true;
781 return m_bIsWCRoot;
784 bool CTGitPath::HasAdminDir() const
786 if (m_bHasAdminDirKnown)
787 return m_bHasAdminDir;
789 EnsureBackslashPathSet();
790 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
791 m_bHasAdminDirKnown = true;
792 return m_bHasAdminDir;
795 bool CTGitPath::HasSubmodules() const
797 if (HasAdminDir())
799 CString path = m_sProjectRoot;
800 path += _T("\\.gitmodules");
801 if( PathFileExists(path) )
802 return true;
804 return false;
807 int CTGitPath::GetAdminDirMask() const
809 int status = 0;
810 CString topdir;
811 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
813 return status;
816 // ITEMIS_INGIT will be revoked if necessary in TortoiseShell/ContextMenu.cpp
817 status |= ITEMIS_INGIT|ITEMIS_INVERSIONEDFOLDER;
819 if (IsDirectory())
821 status |= ITEMIS_FOLDERINGIT;
822 if (IsWCRoot())
824 status |= ITEMIS_WCROOT;
826 CString topProjectDir;
827 if (g_GitAdminDir.HasAdminDir(GetWinPathString(), false, &topProjectDir))
829 if (PathFileExists(topProjectDir + _T("\\.gitmodules")))
831 git_config * config;
832 git_config_new(&config);
833 git_config_add_file_ondisk(config, CGit::GetGitPathStringA(topProjectDir + _T("\\.gitmodules")), GIT_CONFIG_LEVEL_APP, FALSE);
834 CString relativePath = GetWinPathString().Mid(topProjectDir.GetLength());
835 relativePath.Replace(_T("\\"), _T("/"));
836 relativePath.Trim(_T("/"));
837 const char * out;
838 CStringA key(CUnicodeUtils::GetUTF8(_T("submodule.") + relativePath + _T(".path")));
839 if (!git_config_get_string(&out, config, key))
840 status |= ITEMIS_SUBMODULE;
841 git_config_free(config);
847 CString dotGitPath;
848 g_GitAdminDir.GetAdminDirPath(topdir, dotGitPath);
850 if (PathFileExists(dotGitPath + _T("BISECT_START")))
851 status |= ITEMIS_BISECT;
853 if (PathFileExists(dotGitPath + _T("MERGE_HEAD")))
854 status |= ITEMIS_MERGEACTIVE;
856 if (PathFileExists(dotGitPath + _T("refs\\stash")))
857 status |= ITEMIS_STASH;
859 if (PathFileExists(dotGitPath + _T("svn")))
860 status |= ITEMIS_GITSVN;
862 if (PathFileExists(topdir + _T("\\.gitmodules")))
863 status |= ITEMIS_SUBMODULECONTAINER;
865 return status;
868 bool CTGitPath::HasStashDir() const
870 CString topdir;
871 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
873 return false;
876 CString dotGitPath;
877 g_GitAdminDir.GetAdminDirPath(topdir, dotGitPath);
879 return !!PathFileExists(dotGitPath + _T("\\refs\\stash"));
881 bool CTGitPath::HasGitSVNDir() const
883 CString topdir;
884 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
886 return false;
889 CString dotGitPath;
890 g_GitAdminDir.GetAdminDirPath(topdir, dotGitPath);
892 return !!PathFileExists(dotGitPath + _T("svn"));
894 bool CTGitPath::IsBisectActive() const
896 CString topdir;
897 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
899 return false;
902 CString dotGitPath;
903 g_GitAdminDir.GetAdminDirPath(topdir, dotGitPath);
905 return !!PathFileExists(dotGitPath + _T("BISECT_START"));
907 bool CTGitPath::IsMergeActive() const
909 CString topdir;
910 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
912 return false;
915 CString dotGitPath;
916 g_GitAdminDir.GetAdminDirPath(topdir, dotGitPath);
918 return !!PathFileExists(dotGitPath + _T("MERGE_HEAD"));
920 bool CTGitPath::HasRebaseApply() const
922 CString topdir;
923 if(!g_GitAdminDir.HasAdminDir(GetWinPathString(),&topdir))
925 return false;
928 CString dotGitPath;
929 g_GitAdminDir.GetAdminDirPath(topdir, dotGitPath);
931 return !!PathFileExists(dotGitPath + _T("rebase-apply"));
934 bool CTGitPath::HasAdminDir(CString *ProjectTopDir) const
936 if (m_bHasAdminDirKnown)
938 if (ProjectTopDir)
939 *ProjectTopDir = m_sProjectRoot;
940 return m_bHasAdminDir;
943 EnsureBackslashPathSet();
944 m_bHasAdminDir = g_GitAdminDir.HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
945 m_bHasAdminDirKnown = true;
946 if (ProjectTopDir)
947 *ProjectTopDir = m_sProjectRoot;
948 return m_bHasAdminDir;
951 bool CTGitPath::IsAdminDir() const
953 if (m_bIsAdminDirKnown)
954 return m_bIsAdminDir;
956 EnsureBackslashPathSet();
957 m_bIsAdminDir = g_GitAdminDir.IsAdminDirPath(m_sBackslashPath);
958 m_bIsAdminDirKnown = true;
959 return m_bIsAdminDir;
962 bool CTGitPath::IsValidOnWindows() const
964 if (m_bIsValidOnWindowsKnown)
965 return m_bIsValidOnWindows;
967 m_bIsValidOnWindows = false;
968 EnsureBackslashPathSet();
969 CString sMatch = m_sBackslashPath + _T("\r\n");
970 std::wstring sPattern;
971 // the 'file://' URL is just a normal windows path:
972 if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)
974 sMatch = sMatch.Mid(7);
975 sMatch.TrimLeft(_T("\\"));
976 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
978 else
980 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
985 std::tr1::wregex rx(sPattern, std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
986 std::tr1::wsmatch match;
988 std::wstring rmatch = std::wstring((LPCTSTR)sMatch);
989 if (std::tr1::regex_match(rmatch, match, rx))
991 if (std::wstring(match[0]).compare(sMatch)==0)
992 m_bIsValidOnWindows = true;
994 if (m_bIsValidOnWindows)
996 // now check for illegal filenames
997 std::tr1::wregex rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
998 rmatch = m_sBackslashPath;
999 if (std::tr1::regex_search(rmatch, rx2, std::tr1::regex_constants::match_default))
1000 m_bIsValidOnWindows = false;
1003 catch (std::exception) {}
1005 m_bIsValidOnWindowsKnown = true;
1006 return m_bIsValidOnWindows;
1009 //////////////////////////////////////////////////////////////////////////
1011 CTGitPathList::CTGitPathList()
1013 m_Action = 0;
1016 // A constructor which allows a path list to be easily built which one initial entry in
1017 CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)
1019 m_Action = 0;
1020 AddPath(firstEntry);
1022 int CTGitPathList::ParserFromLsFile(BYTE_VECTOR &out,bool /*staged*/)
1024 unsigned int pos=0;
1025 CString one;
1026 CTGitPath path;
1027 CString part;
1028 this->Clear();
1030 while(pos>=0 && pos<out.size())
1032 one.Empty();
1033 path.Reset();
1035 g_Git.StringAppend(&one, &out[pos], CP_UTF8);
1036 int tabstart=0;
1037 path.m_Action=path.ParserAction(out[pos]);
1038 one.Tokenize(_T("\t"),tabstart);
1040 if(tabstart>=0)
1041 path.SetFromGit(one.Right(one.GetLength()-tabstart));
1042 else
1043 return -1;
1045 tabstart=0;
1047 part=one.Tokenize(_T(" "),tabstart); //Tag
1048 if (tabstart < 0)
1049 return -1;
1051 part=one.Tokenize(_T(" "),tabstart); //Mode
1052 if (tabstart < 0)
1053 return -1;
1055 part=one.Tokenize(_T(" "),tabstart); //Hash
1056 if (tabstart < 0)
1057 return -1;
1059 part=one.Tokenize(_T("\t"),tabstart); //Stage
1060 if (tabstart < 0)
1061 return -1;
1063 path.m_Stage=_ttol(part);
1065 this->AddPath(path);
1067 pos=out.findNextString(pos);
1069 return 0;
1071 int CTGitPathList::FillUnRev(unsigned int action,CTGitPathList *list)
1073 this->Clear();
1074 CTGitPath path;
1076 int count;
1077 if(list==NULL)
1078 count=1;
1079 else
1080 count=list->GetCount();
1081 for (int i = 0; i < count; ++i)
1083 CString cmd;
1084 int pos = 0;
1086 CString ignored;
1087 if(action & CTGitPath::LOGACTIONS_IGNORE)
1088 ignored= _T(" -i");
1090 if(list==NULL)
1092 cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");
1093 cmd+=ignored;
1096 else
1097 { cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z%s -- \"%s\""),
1098 ignored,
1099 (*list)[i].GetWinPathString());
1102 BYTE_VECTOR out;
1103 out.clear();
1104 g_Git.Run(cmd, &out);
1106 pos=0;
1107 CString one;
1108 while (pos >= 0 && pos < (int)out.size())
1110 one.Empty();
1111 g_Git.StringAppend(&one, &out[pos], CP_UTF8);
1112 if(!one.IsEmpty())
1114 //SetFromGit will clear all status
1115 path.SetFromGit(one);
1116 path.m_Action=action;
1117 AddPath(path);
1119 pos=out.findNextString(pos);
1123 return 0;
1125 int CTGitPathList::FillBasedOnIndexFlags(unsigned short flag, CTGitPathList* list /*nullptr*/)
1127 Clear();
1128 CTGitPath path;
1129 CString one;
1131 CStringA gitdir = CUnicodeUtils::GetMulti(g_Git.m_CurrentDir, CP_UTF8);
1132 git_repository *repository = nullptr;
1133 if (git_repository_open(&repository, gitdir.GetBuffer()))
1134 return -1;
1136 git_index *index = nullptr;
1137 if (git_repository_index(&index, repository))
1139 git_repository_free(repository);
1140 return -1;
1143 int count;
1144 if (list == nullptr)
1145 count = 1;
1146 else
1147 count = list->GetCount();
1148 for (int j = 0; j < count; ++j)
1150 for (size_t i = 0, ecount = git_index_entrycount(index); i < ecount; ++i)
1152 const git_index_entry *e = git_index_get_byindex(index, i);
1154 if (!e || !((e->flags | e->flags_extended) & flag) || !e->path)
1155 continue;
1157 one.Empty();
1158 g_Git.StringAppend(&one, (BYTE*)e->path, CP_UTF8);
1160 if (!(!list || (*list)[j].GetWinPathString().IsEmpty() || one == (*list)[j].GetWinPathString() || (PathIsDirectory(g_Git.m_CurrentDir + L"\\" + (*list)[j].GetWinPathString()) && one.Find((*list)[j].GetWinPathString() + _T("/")) == 0)))
1161 continue;
1163 //SetFromGit will clear all status
1164 path.SetFromGit(one);
1165 if ((e->flags | e->flags_extended) & GIT_IDXENTRY_SKIP_WORKTREE)
1166 path.m_Action = CTGitPath::LOGACTIONS_SKIPWORKTREE;
1167 else if ((e->flags | e->flags_extended) & GIT_IDXENTRY_VALID)
1168 path.m_Action = CTGitPath::LOGACTIONS_ASSUMEVALID;
1169 AddPath(path);
1172 git_index_free(index);
1173 RemoveDuplicates();
1174 git_repository_free(repository);
1175 return 0;
1177 int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/)
1179 this->Clear();
1180 int pos=0;
1181 //BYTE *p=&log[0];
1182 //CString one;
1183 CTGitPath path;
1184 m_Action=0;
1185 while (pos >= 0 && pos < (int)log.size())
1187 //one=log.Tokenize(_T("\n"),pos);
1188 path.Reset();
1189 if(log[pos]=='\n')
1190 ++pos;
1192 if(log[pos]==':')
1194 bool merged=false;
1195 if(log[pos+1] ==':')
1197 merged=true;
1199 int end=log.find(0,pos);
1200 int actionstart=-1;
1201 int file1=-1,file2=-1;
1202 if( end>0 )
1204 actionstart=log.find(' ',end-6);
1205 pos=actionstart;
1207 if( actionstart>0 )
1209 ++actionstart;
1211 file1 = log.find(0,actionstart);
1212 if( file1>=0 )
1214 ++file1;
1215 pos=file1;
1217 if( log[actionstart] == 'C' || log[actionstart] == 'R' )
1219 file2=file1;
1220 file1 = log.find(0,file1);
1221 if(file1>=0 )
1223 ++file1;
1224 pos=file1;
1230 CString pathname1;
1231 CString pathname2;
1233 if( file1>=0 )
1234 g_Git.StringAppend(&pathname1, &log[file1], CP_UTF8);
1235 if( file2>=0 )
1236 g_Git.StringAppend(&pathname2, &log[file2], CP_UTF8);
1238 CTGitPath *GitPath=LookForGitPath(pathname1);
1240 if(GitPath)
1242 GitPath->ParserAction( log[actionstart] );
1244 if(merged)
1246 GitPath->m_Action |= CTGitPath::LOGACTIONS_MERGED;
1247 GitPath->m_Action &= ~CTGitPath::LOGACTIONS_FORWORD;
1249 m_Action |=GitPath->m_Action;
1252 else
1254 int ac=path.ParserAction(log[actionstart] );
1255 ac |= merged?CTGitPath::LOGACTIONS_MERGED:0;
1257 path.SetFromGit(pathname1,&pathname2);
1258 path.m_Action=ac;
1259 //action must be set after setfromgit. SetFromGit will clear all status.
1260 this->m_Action|=ac;
1262 AddPath(path);
1267 else
1269 int tabstart=0;
1270 path.Reset();
1271 CString StatAdd;
1272 CString StatDel;
1273 CString file1;
1274 CString file2;
1276 tabstart=log.find('\t',pos);
1277 if(tabstart >=0)
1279 log[tabstart]=0;
1280 g_Git.StringAppend(&StatAdd,&log[pos],CP_UTF8);
1281 pos=tabstart+1;
1284 tabstart=log.find('\t',pos);
1285 if(tabstart >=0)
1287 log[tabstart]=0;
1289 g_Git.StringAppend(&StatDel,&log[pos],CP_UTF8);
1290 pos=tabstart+1;
1293 if(log[pos] == 0) //rename
1295 ++pos;
1296 g_Git.StringAppend(&file2, &log[pos], CP_UTF8);
1297 int sec=log.find(0,pos);
1298 if(sec>=0)
1300 ++sec;
1301 g_Git.StringAppend(&file1, &log[sec], CP_UTF8);
1303 pos=sec;
1306 else
1308 g_Git.StringAppend(&file1, &log[pos], CP_UTF8);
1310 path.SetFromGit(file1,&file2);
1312 CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());
1313 if(GitPath)
1315 GitPath->m_StatAdd=StatAdd;
1316 GitPath->m_StatDel=StatDel;
1318 else
1320 //path.SetFromGit(pathname);
1321 if (parseDeletes)
1323 path.m_StatAdd=_T("0");
1324 path.m_StatDel=_T("0");
1325 path.m_Action |= CTGitPath::LOGACTIONS_DELETED;
1327 else
1329 path.m_StatAdd=StatAdd;
1330 path.m_StatDel=StatDel;
1331 path.m_Action |= CTGitPath::LOGACTIONS_FORWORD;
1333 AddPath(path);
1337 pos=log.findNextString(pos);
1339 return pos;
1342 void CTGitPathList::AddPath(const CTGitPath& newPath)
1344 m_paths.push_back(newPath);
1345 m_commonBaseDirectory.Reset();
1347 int CTGitPathList::GetCount() const
1349 return (int)m_paths.size();
1351 bool CTGitPathList::IsEmpty() const
1353 return m_paths.empty();
1355 void CTGitPathList::Clear()
1357 m_paths.clear();
1358 m_commonBaseDirectory.Reset();
1361 const CTGitPath& CTGitPathList::operator[](INT_PTR index) const
1363 ATLASSERT(index >= 0 && index < (INT_PTR)m_paths.size());
1364 return m_paths[index];
1367 bool CTGitPathList::AreAllPathsFiles() const
1369 // Look through the vector for any directories - if we find them, return false
1370 return std::find_if(m_paths.begin(), m_paths.end(), std::mem_fun_ref(&CTGitPath::IsDirectory)) == m_paths.end();
1374 #if defined(_MFC_VER)
1376 bool CTGitPathList::LoadFromFile(const CTGitPath& filename)
1378 Clear();
1381 CString strLine;
1382 CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite);
1384 // for every selected file/folder
1385 CTGitPath path;
1386 while (file.ReadString(strLine))
1388 path.SetFromUnknown(strLine);
1389 AddPath(path);
1391 file.Close();
1393 catch (CFileException* pE)
1395 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading target file list\n");
1396 TCHAR error[10000] = {0};
1397 pE->GetErrorMessage(error, 10000);
1398 // CMessageBox::Show(NULL, error, _T("TortoiseGit"), MB_ICONERROR);
1399 pE->Delete();
1400 return false;
1402 return true;
1405 bool CTGitPathList::WriteToFile(const CString& sFilename, bool bANSI /* = false */) const
1409 if (bANSI)
1411 CStdioFile file(sFilename, CFile::typeText | CFile::modeReadWrite | CFile::modeCreate);
1412 PathVector::const_iterator it;
1413 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1415 CStringA line = CStringA(it->GetGitPathString()) + '\n';
1416 file.Write(line, line.GetLength());
1418 file.Close();
1420 else
1422 CStdioFile file(sFilename, CFile::typeBinary | CFile::modeReadWrite | CFile::modeCreate);
1423 PathVector::const_iterator it;
1424 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1426 file.WriteString(it->GetGitPathString()+_T("\n"));
1428 file.Close();
1431 catch (CFileException* pE)
1433 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException in writing temp file\n");
1434 pE->Delete();
1435 return false;
1437 return true;
1441 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString& sPathString)
1443 int pos = 0;
1444 CString temp;
1445 for(;;)
1447 temp = sPathString.Tokenize(_T("*"),pos);
1448 if(temp.IsEmpty())
1450 break;
1452 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp)));
1456 CString CTGitPathList::CreateAsteriskSeparatedString() const
1458 CString sRet;
1459 PathVector::const_iterator it;
1460 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1462 if (!sRet.IsEmpty())
1463 sRet += _T("*");
1464 sRet += it->GetWinPathString();
1466 return sRet;
1468 #endif // _MFC_VER
1470 bool
1471 CTGitPathList::AreAllPathsFilesInOneDirectory() const
1473 // Check if all the paths are files and in the same directory
1474 PathVector::const_iterator it;
1475 m_commonBaseDirectory.Reset();
1476 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1478 if(it->IsDirectory())
1480 return false;
1482 const CTGitPath& baseDirectory = it->GetDirectory();
1483 if(m_commonBaseDirectory.IsEmpty())
1485 m_commonBaseDirectory = baseDirectory;
1487 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
1489 // Different path
1490 m_commonBaseDirectory.Reset();
1491 return false;
1494 return true;
1497 CTGitPath CTGitPathList::GetCommonDirectory() const
1499 if (m_commonBaseDirectory.IsEmpty())
1501 PathVector::const_iterator it;
1502 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1504 const CTGitPath& baseDirectory = it->GetDirectory();
1505 if(m_commonBaseDirectory.IsEmpty())
1507 m_commonBaseDirectory = baseDirectory;
1509 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
1511 // Different path
1512 m_commonBaseDirectory.Reset();
1513 break;
1517 // since we only checked strings, not paths,
1518 // we have to make sure now that we really return a *path* here
1519 PathVector::const_iterator iter;
1520 for(iter = m_paths.begin(); iter != m_paths.end(); ++iter)
1522 if (!m_commonBaseDirectory.IsAncestorOf(*iter))
1524 m_commonBaseDirectory = m_commonBaseDirectory.GetContainingDirectory();
1525 break;
1528 return m_commonBaseDirectory;
1531 CTGitPath CTGitPathList::GetCommonRoot() const
1533 if (IsEmpty())
1534 return CTGitPath();
1536 if (GetCount() == 1)
1537 return m_paths[0];
1539 // first entry is common root for itself
1540 // (add trailing '\\' to detect partial matches of the last path element)
1541 CString root = m_paths[0].GetWinPathString() + _T('\\');
1542 int rootLength = root.GetLength();
1544 // determine common path string prefix
1545 for (PathVector::const_iterator it = m_paths.begin() + 1; it != m_paths.end(); ++it)
1547 CString path = it->GetWinPathString() + _T('\\');
1549 int newLength = CStringUtils::GetMatchingLength(root, path);
1550 if (newLength != rootLength)
1552 root.Delete(newLength, rootLength);
1553 rootLength = newLength;
1557 // remove the last (partial) path element
1558 if (rootLength > 0)
1559 root.Delete(root.ReverseFind(_T('\\')), rootLength);
1561 // done
1562 return CTGitPath(root);
1565 void CTGitPathList::SortByPathname(bool bReverse /*= false*/)
1567 std::sort(m_paths.begin(), m_paths.end());
1568 if (bReverse)
1569 std::reverse(m_paths.begin(), m_paths.end());
1572 void CTGitPathList::DeleteAllFiles(bool bTrash, bool bFilesOnly)
1574 PathVector::const_iterator it;
1575 SortByPathname(true); // nested ones first
1577 CString sPaths;
1578 for (it = m_paths.begin(); it != m_paths.end(); ++it)
1580 if ((it->Exists()) && ((it->IsDirectory() != bFilesOnly) || !bFilesOnly))
1582 if (!it->IsDirectory())
1583 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
1585 sPaths += it->GetWinPath();
1586 sPaths += '\0';
1589 sPaths += '\0';
1590 sPaths += '\0';
1591 DeleteViaShell((LPCTSTR)sPaths, bTrash);
1592 Clear();
1595 bool CTGitPathList::DeleteViaShell(LPCTSTR path, bool bTrash)
1597 SHFILEOPSTRUCT shop = {0};
1598 shop.wFunc = FO_DELETE;
1599 shop.pFrom = path;
1600 shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT|FOF_NO_CONNECTED_ELEMENTS;
1601 if (bTrash)
1602 shop.fFlags |= FOF_ALLOWUNDO;
1603 const bool bRet = (SHFileOperation(&shop) == 0);
1604 return bRet;
1607 void CTGitPathList::RemoveDuplicates()
1609 SortByPathname();
1610 // Remove the duplicates
1611 // (Unique moves them to the end of the vector, then erase chops them off)
1612 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::PredLeftEquivalentToRight), m_paths.end());
1615 void CTGitPathList::RemoveAdminPaths()
1617 PathVector::iterator it;
1618 for(it = m_paths.begin(); it != m_paths.end(); )
1620 if (it->IsAdminDir())
1622 m_paths.erase(it);
1623 it = m_paths.begin();
1625 else
1626 ++it;
1630 void CTGitPathList::RemovePath(const CTGitPath& path)
1632 PathVector::iterator it;
1633 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1635 if (it->IsEquivalentTo(path))
1637 m_paths.erase(it);
1638 return;
1643 void CTGitPathList::RemoveItem(CTGitPath & path)
1645 PathVector::iterator it;
1646 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1648 if (it->GetGitPathString()==path.GetGitPathString())
1650 m_paths.erase(it);
1651 return;
1655 void CTGitPathList::RemoveChildren()
1657 SortByPathname();
1658 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::CheckChild), m_paths.end());
1661 bool CTGitPathList::IsEqual(const CTGitPathList& list)
1663 if (list.GetCount() != GetCount())
1664 return false;
1665 for (int i=0; i<list.GetCount(); ++i)
1667 if (!list[i].IsEquivalentTo(m_paths[i]))
1668 return false;
1670 return true;
1673 //////////////////////////////////////////////////////////////////////////
1674 #if 0
1675 apr_array_header_t * CTGitPathList::MakePathArray (apr_pool_t *pool) const
1677 apr_array_header_t *targets = apr_array_make (pool, GetCount(), sizeof(const char *));
1679 for (int nItem = 0; nItem < GetCount(); ++nItem)
1681 const char * target = m_paths[nItem].GetGitApiPath(pool);
1682 (*((const char **) apr_array_push (targets))) = target;
1685 return targets;
1687 #endif
1688 //////////////////////////////////////////////////////////////////////////
1690 #if 0
1691 #if defined(_DEBUG)
1692 // Some test cases for these classes
1693 static class CTGitPathTests
1695 public:
1696 CTGitPathTests()
1698 apr_initialize();
1699 pool = svn_pool_create(NULL);
1700 GetDirectoryTest();
1701 AdminDirTest();
1702 SortTest();
1703 RawAppendTest();
1704 PathAppendTest();
1705 RemoveDuplicatesTest();
1706 RemoveChildrenTest();
1707 ContainingDirectoryTest();
1708 AncestorTest();
1709 SubversionPathTest();
1710 GetCommonRootTest();
1711 #if defined(_MFC_VER)
1712 ValidPathAndUrlTest();
1713 ListLoadingTest();
1714 #endif
1715 apr_terminate();
1718 private:
1719 // apr_pool_t * pool;
1720 void GetDirectoryTest()
1722 // Bit tricky, this test, because we need to know something about the file
1723 // layout on the machine which is running the test
1724 TCHAR winDir[MAX_PATH+1] = {0};
1725 GetWindowsDirectory(winDir, MAX_PATH);
1726 CString sWinDir(winDir);
1728 CTGitPath testPath;
1729 // This is a file which we know will always be there
1730 testPath.SetFromUnknown(sWinDir + _T("\\win.ini"));
1731 ATLASSERT(!testPath.IsDirectory());
1732 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
1733 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() == sWinDir);
1735 // Now do the test on the win directory itself - It's hard to be sure about the containing directory
1736 // but we know it must be different to the directory itself
1737 testPath.SetFromUnknown(sWinDir);
1738 ATLASSERT(testPath.IsDirectory());
1739 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
1740 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() != sWinDir);
1741 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString().GetLength() < sWinDir.GetLength());
1743 // Try a root path
1744 testPath.SetFromUnknown(_T("C:\\"));
1745 ATLASSERT(testPath.IsDirectory());
1746 ATLASSERT(testPath.GetDirectory().GetWinPathString().CompareNoCase(_T("C:\\"))==0);
1747 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
1748 // Try a root UNC path
1749 testPath.SetFromUnknown(_T("\\MYSTATION"));
1750 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
1753 void AdminDirTest()
1755 CTGitPath testPath;
1756 testPath.SetFromUnknown(_T("c:\\.svndir"));
1757 ATLASSERT(!testPath.IsAdminDir());
1758 testPath.SetFromUnknown(_T("c:\\test.svn"));
1759 ATLASSERT(!testPath.IsAdminDir());
1760 testPath.SetFromUnknown(_T("c:\\.svn"));
1761 ATLASSERT(testPath.IsAdminDir());
1762 testPath.SetFromUnknown(_T("c:\\.svndir\\test"));
1763 ATLASSERT(!testPath.IsAdminDir());
1764 testPath.SetFromUnknown(_T("c:\\.svn\\test"));
1765 ATLASSERT(testPath.IsAdminDir());
1767 CTGitPathList pathList;
1768 pathList.AddPath(CTGitPath(_T("c:\\.svndir")));
1769 pathList.AddPath(CTGitPath(_T("c:\\.svn")));
1770 pathList.AddPath(CTGitPath(_T("c:\\.svn\\test")));
1771 pathList.AddPath(CTGitPath(_T("c:\\test")));
1772 pathList.RemoveAdminPaths();
1773 ATLASSERT(pathList.GetCount()==2);
1774 pathList.Clear();
1775 pathList.AddPath(CTGitPath(_T("c:\\test")));
1776 pathList.RemoveAdminPaths();
1777 ATLASSERT(pathList.GetCount()==1);
1780 void SortTest()
1782 CTGitPathList testList;
1783 CTGitPath testPath;
1784 testPath.SetFromUnknown(_T("c:/Z"));
1785 testList.AddPath(testPath);
1786 testPath.SetFromUnknown(_T("c:/B"));
1787 testList.AddPath(testPath);
1788 testPath.SetFromUnknown(_T("c:\\a"));
1789 testList.AddPath(testPath);
1790 testPath.SetFromUnknown(_T("c:/Test"));
1791 testList.AddPath(testPath);
1793 testList.SortByPathname();
1795 ATLASSERT(testList[0].GetWinPathString() == _T("c:\\a"));
1796 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\B"));
1797 ATLASSERT(testList[2].GetWinPathString() == _T("c:\\Test"));
1798 ATLASSERT(testList[3].GetWinPathString() == _T("c:\\Z"));
1801 void RawAppendTest()
1803 CTGitPath testPath(_T("c:/test/"));
1804 testPath.AppendRawString(_T("/Hello"));
1805 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
1807 testPath.AppendRawString(_T("\\T2"));
1808 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
1810 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
1811 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
1812 testBasePath.AppendRawString(testFilePath.GetFileExtension());
1813 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt.ini"));
1816 void PathAppendTest()
1818 CTGitPath testPath(_T("c:/test/"));
1819 testPath.AppendPathString(_T("/Hello"));
1820 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
1822 testPath.AppendPathString(_T("T2"));
1823 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
1825 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
1826 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
1827 // You wouldn't want to do this in real life - you'd use append-raw
1828 testBasePath.AppendPathString(testFilePath.GetFileExtension());
1829 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt\\.ini"));
1832 void RemoveDuplicatesTest()
1834 CTGitPathList list;
1835 list.AddPath(CTGitPath(_T("Z")));
1836 list.AddPath(CTGitPath(_T("A")));
1837 list.AddPath(CTGitPath(_T("E")));
1838 list.AddPath(CTGitPath(_T("E")));
1840 ATLASSERT(list[2].IsEquivalentTo(list[3]));
1841 ATLASSERT(list[2]==list[3]);
1843 ATLASSERT(list.GetCount() == 4);
1845 list.RemoveDuplicates();
1847 ATLASSERT(list.GetCount() == 3);
1849 ATLASSERT(list[0].GetWinPathString() == _T("A"));
1850 ATLASSERT(list[1].GetWinPathString().Compare(_T("E")) == 0);
1851 ATLASSERT(list[2].GetWinPathString() == _T("Z"));
1854 void RemoveChildrenTest()
1856 CTGitPathList list;
1857 list.AddPath(CTGitPath(_T("c:\\test")));
1858 list.AddPath(CTGitPath(_T("c:\\test\\file")));
1859 list.AddPath(CTGitPath(_T("c:\\testfile")));
1860 list.AddPath(CTGitPath(_T("c:\\parent")));
1861 list.AddPath(CTGitPath(_T("c:\\parent\\child")));
1862 list.AddPath(CTGitPath(_T("c:\\parent\\child1")));
1863 list.AddPath(CTGitPath(_T("c:\\parent\\child2")));
1865 ATLASSERT(list.GetCount() == 7);
1867 list.RemoveChildren();
1869 ATLTRACE("count = %d\n", list.GetCount());
1870 ATLASSERT(list.GetCount() == 3);
1872 list.SortByPathname();
1874 ATLASSERT(list[0].GetWinPathString().Compare(_T("c:\\parent")) == 0);
1875 ATLASSERT(list[1].GetWinPathString().Compare(_T("c:\\test")) == 0);
1876 ATLASSERT(list[2].GetWinPathString().Compare(_T("c:\\testfile")) == 0);
1879 #if defined(_MFC_VER)
1880 void ListLoadingTest()
1882 TCHAR buf[MAX_PATH] = {0};
1883 GetCurrentDirectory(MAX_PATH, buf);
1884 CString sPathList(_T("Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"));
1885 CTGitPathList testList;
1886 testList.LoadFromAsteriskSeparatedString(sPathList);
1888 ATLASSERT(testList.GetCount() == 3);
1889 ATLASSERT(testList[0].GetWinPathString() == CString(buf) + _T("\\Path1"));
1890 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\path2 with spaces and stuff"));
1891 ATLASSERT(testList[2].GetWinPathString() == _T("\\funnypath"));
1893 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T(""));
1894 testList.Clear();
1895 sPathList = _T("c:\\path2 with spaces and stuff*c:\\funnypath\\*");
1896 testList.LoadFromAsteriskSeparatedString(sPathList);
1897 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T("c:\\"));
1899 #endif
1901 void ContainingDirectoryTest()
1904 CTGitPath testPath;
1905 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
1906 CTGitPath dir;
1907 dir = testPath.GetContainingDirectory();
1908 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c\\d"));
1909 dir = dir.GetContainingDirectory();
1910 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c"));
1911 dir = dir.GetContainingDirectory();
1912 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b"));
1913 dir = dir.GetContainingDirectory();
1914 ATLASSERT(dir.GetWinPathString() == _T("c:\\a"));
1915 dir = dir.GetContainingDirectory();
1916 ATLASSERT(dir.GetWinPathString() == _T("c:\\"));
1917 dir = dir.GetContainingDirectory();
1918 ATLASSERT(dir.IsEmpty());
1919 ATLASSERT(dir.GetWinPathString() == _T(""));
1922 void AncestorTest()
1924 CTGitPath testPath;
1925 testPath.SetFromWin(_T("c:\\windows"));
1926 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\")))==false);
1927 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows"))));
1928 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windowsdummy")))==false);
1929 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\test.txt"))));
1930 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\system32\\test.txt"))));
1933 void SubversionPathTest()
1935 CTGitPath testPath;
1936 testPath.SetFromWin(_T("c:\\"));
1937 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:") == 0);
1938 testPath.SetFromWin(_T("c:\\folder"));
1939 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);
1940 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
1941 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);
1942 testPath.SetFromUnknown(_T("http://testing/"));
1943 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);
1944 testPath.SetFromGit(NULL);
1945 ATLASSERT(strlen(testPath.GetGitApiPath(pool))==0);
1946 #if defined(_MFC_VER)
1947 testPath.SetFromUnknown(_T("http://testing again"));
1948 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
1949 testPath.SetFromUnknown(_T("http://testing%20again"));
1950 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
1951 testPath.SetFromUnknown(_T("http://testing special chars \344\366\374"));
1952 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);
1953 #endif
1956 void GetCommonRootTest()
1958 CTGitPath pathA (_T("C:\\Development\\LogDlg.cpp"));
1959 CTGitPath pathB (_T("C:\\Development\\LogDlg.h"));
1960 CTGitPath pathC (_T("C:\\Development\\SomeDir\\LogDlg.h"));
1962 CTGitPathList list;
1963 list.AddPath(pathA);
1964 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development\\LogDlg.cpp"))==0);
1965 list.AddPath(pathB);
1966 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
1967 list.AddPath(pathC);
1968 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
1969 #ifdef _MFC_VER
1970 list.Clear();
1971 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");
1972 list.LoadFromAsteriskSeparatedString(sPathList);
1973 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("D:\\Development\\StExBar"))==0);
1975 list.Clear();
1976 sPathList = _T("c:\\windows\\explorer.exe*c:\\windows");
1977 list.LoadFromAsteriskSeparatedString(sPathList);
1978 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
1980 list.Clear();
1981 sPathList = _T("c:\\windows\\*c:\\windows");
1982 list.LoadFromAsteriskSeparatedString(sPathList);
1983 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
1985 list.Clear();
1986 sPathList = _T("c:\\windows\\system32*c:\\windows\\system");
1987 list.LoadFromAsteriskSeparatedString(sPathList);
1988 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
1990 list.Clear();
1991 sPathList = _T("c:\\windowsdummy*c:\\windows");
1992 list.LoadFromAsteriskSeparatedString(sPathList);
1993 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\"))==0);
1994 #endif
1997 void ValidPathAndUrlTest()
1999 CTGitPath testPath;
2000 testPath.SetFromWin(_T("c:\\a\\b\\c.test.txt"));
2001 ATLASSERT(testPath.IsValidOnWindows());
2002 testPath.SetFromWin(_T("c:\\"));
2003 ATLASSERT(testPath.IsValidOnWindows());
2004 testPath.SetFromWin(_T("D:\\.Net\\SpindleSearch\\"));
2005 ATLASSERT(testPath.IsValidOnWindows());
2006 testPath.SetFromWin(_T("c"));
2007 ATLASSERT(testPath.IsValidOnWindows());
2008 testPath.SetFromWin(_T("c:\\test folder\\file"));
2009 ATLASSERT(testPath.IsValidOnWindows());
2010 testPath.SetFromWin(_T("c:\\folder\\"));
2011 ATLASSERT(testPath.IsValidOnWindows());
2012 testPath.SetFromWin(_T("c:\\ext.ext.ext\\ext.ext.ext.ext"));
2013 ATLASSERT(testPath.IsValidOnWindows());
2014 testPath.SetFromWin(_T("c:\\.svn"));
2015 ATLASSERT(testPath.IsValidOnWindows());
2016 testPath.SetFromWin(_T("c:\\com\\file"));
2017 ATLASSERT(testPath.IsValidOnWindows());
2018 testPath.SetFromWin(_T("c:\\test\\conf"));
2019 ATLASSERT(testPath.IsValidOnWindows());
2020 testPath.SetFromWin(_T("c:\\LPT"));
2021 ATLASSERT(testPath.IsValidOnWindows());
2022 testPath.SetFromWin(_T("c:\\test\\LPT"));
2023 ATLASSERT(testPath.IsValidOnWindows());
2024 testPath.SetFromWin(_T("c:\\com1test"));
2025 ATLASSERT(testPath.IsValidOnWindows());
2026 testPath.SetFromWin(_T("\\\\?\\c:\\test\\com1test"));
2027 ATLASSERT(testPath.IsValidOnWindows());
2029 testPath.SetFromWin(_T("\\\\Share\\filename"));
2030 ATLASSERT(testPath.IsValidOnWindows());
2031 testPath.SetFromWin(_T("\\\\Share\\filename.extension"));
2032 ATLASSERT(testPath.IsValidOnWindows());
2033 testPath.SetFromWin(_T("\\\\Share\\.svn"));
2034 ATLASSERT(testPath.IsValidOnWindows());
2036 // now the negative tests
2037 testPath.SetFromWin(_T("c:\\test:folder"));
2038 ATLASSERT(!testPath.IsValidOnWindows());
2039 testPath.SetFromWin(_T("c:\\file<name"));
2040 ATLASSERT(!testPath.IsValidOnWindows());
2041 testPath.SetFromWin(_T("c:\\something*else"));
2042 ATLASSERT(!testPath.IsValidOnWindows());
2043 testPath.SetFromWin(_T("c:\\folder\\file?nofile"));
2044 ATLASSERT(!testPath.IsValidOnWindows());
2045 testPath.SetFromWin(_T("c:\\ext.>ension"));
2046 ATLASSERT(!testPath.IsValidOnWindows());
2047 testPath.SetFromWin(_T("c:\\com1\\filename"));
2048 ATLASSERT(!testPath.IsValidOnWindows());
2049 testPath.SetFromWin(_T("c:\\com1"));
2050 ATLASSERT(!testPath.IsValidOnWindows());
2051 testPath.SetFromWin(_T("c:\\com1\\AuX"));
2052 ATLASSERT(!testPath.IsValidOnWindows());
2054 testPath.SetFromWin(_T("\\\\Share\\lpt9\\filename"));
2055 ATLASSERT(!testPath.IsValidOnWindows());
2056 testPath.SetFromWin(_T("\\\\Share\\prn"));
2057 ATLASSERT(!testPath.IsValidOnWindows());
2058 testPath.SetFromWin(_T("\\\\Share\\NUL"));
2059 ATLASSERT(!testPath.IsValidOnWindows());
2061 // now come some URL tests
2062 testPath.SetFromGit(_T("http://myserver.com/repos/trunk"));
2063 ATLASSERT(testPath.IsValidOnWindows());
2064 testPath.SetFromGit(_T("https://myserver.com/repos/trunk/file%20with%20spaces"));
2065 ATLASSERT(testPath.IsValidOnWindows());
2066 testPath.SetFromGit(_T("svn://myserver.com/repos/trunk/file with spaces"));
2067 ATLASSERT(testPath.IsValidOnWindows());
2068 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk"));
2069 ATLASSERT(testPath.IsValidOnWindows());
2070 testPath.SetFromGit(_T("http://localhost:90/repos/trunk"));
2071 ATLASSERT(testPath.IsValidOnWindows());
2072 testPath.SetFromGit(_T("file:///C:/GitRepos/Tester/Proj1/tags/t2"));
2073 ATLASSERT(testPath.IsValidOnWindows());
2074 // and some negative URL tests
2075 testPath.SetFromGit(_T("httpp://myserver.com/repos/trunk"));
2076 ATLASSERT(!testPath.IsValidOnWindows());
2077 testPath.SetFromGit(_T("https://myserver.com/rep:os/trunk/file%20with%20spaces"));
2078 ATLASSERT(!testPath.IsValidOnWindows());
2079 testPath.SetFromGit(_T("svn://myserver.com/rep<os/trunk/file with spaces"));
2080 ATLASSERT(!testPath.IsValidOnWindows());
2081 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk/prn/"));
2082 ATLASSERT(!testPath.IsValidOnWindows());
2083 testPath.SetFromGit(_T("http://localhost:90/repos/trunk/com1"));
2084 ATLASSERT(!testPath.IsValidOnWindows());
2088 } TGitPathTestobject;
2089 #endif
2090 #endif
2092 CTGitPath * CTGitPathList::LookForGitPath(CString path)
2094 int i=0;
2095 for (i = 0; i < this->GetCount(); ++i)
2097 if((*this)[i].GetGitPathString() == path )
2098 return (CTGitPath*)&(*this)[i];
2100 return NULL;
2102 CString CTGitPath::GetActionName(int action)
2104 if(action & CTGitPath::LOGACTIONS_UNMERGED)
2105 return MAKEINTRESOURCE(IDS_PATHACTIONS_CONFLICT);
2106 if(action & CTGitPath::LOGACTIONS_ADDED)
2107 return MAKEINTRESOURCE(IDS_PATHACTIONS_ADD);
2108 if(action & CTGitPath::LOGACTIONS_DELETED)
2109 return MAKEINTRESOURCE(IDS_PATHACTIONS_DELETE);
2110 if(action & CTGitPath::LOGACTIONS_MERGED )
2111 return MAKEINTRESOURCE(IDS_PATHACTIONS_MERGED);
2113 if(action & CTGitPath::LOGACTIONS_MODIFIED)
2114 return MAKEINTRESOURCE(IDS_PATHACTIONS_MODIFIED);
2115 if(action & CTGitPath::LOGACTIONS_REPLACED)
2116 return MAKEINTRESOURCE(IDS_PATHACTIONS_RENAME);
2117 if(action & CTGitPath::LOGACTIONS_COPY)
2118 return MAKEINTRESOURCE(IDS_PATHACTIONS_COPY);
2120 if(action & CTGitPath::LOGACTIONS_FORWORD )
2121 return MAKEINTRESOURCE(IDS_PATHACTIONS_FORWARD);
2123 if (action & CTGitPath::LOGACTIONS_ASSUMEVALID)
2124 return MAKEINTRESOURCE(IDS_PATHACTIONS_ASSUMEUNCHANGED);
2125 if (action & CTGitPath::LOGACTIONS_SKIPWORKTREE)
2126 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIPWORKTREE);
2128 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
2130 CString CTGitPath::GetActionName()
2132 return GetActionName(m_Action);
2135 int CTGitPathList::GetAction()
2137 return m_Action;