Use CUnicodeUtils::GetUnicode instead of CGit::StringAppend if possible
[TortoiseGit.git] / src / Git / TGitPath.cpp
blob8fd39a54bac72957ef015ed2399f93419e5a195a
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 "../TortoiseShell/Globals.h"
29 #include "StringUtils.h"
30 #include "../Resources/LoglistCommonResource.h"
31 #include <memory>
33 #ifndef ASSERT
34 #define ASSERT()
35 #endif
36 extern CGit g_Git;
38 CTGitPath::CTGitPath(void)
39 : m_bDirectoryKnown(false)
40 , m_bIsDirectory(false)
41 , m_bURLKnown(false)
42 , m_bHasAdminDirKnown(false)
43 , m_bHasAdminDir(false)
44 , m_bIsValidOnWindowsKnown(false)
45 , m_bIsValidOnWindows(false)
46 , m_bIsReadOnly(false)
47 , m_bIsAdminDirKnown(false)
48 , m_bIsAdminDir(false)
49 , m_bExists(false)
50 , m_bExistsKnown(false)
51 , m_bLastWriteTimeKnown(0)
52 , m_lastWriteTime(0)
53 , m_customData(NULL)
54 , m_bIsSpecialDirectoryKnown(false)
55 , m_bIsSpecialDirectory(false)
56 , m_bIsWCRootKnown(false)
57 , m_bIsWCRoot(false)
58 , m_fileSize(0)
59 , m_Checked(false)
61 m_Action=0;
62 m_ParentNo=0;
63 m_Stage = 0;
66 CTGitPath::~CTGitPath(void)
69 // Create a TGitPath object from an unknown path type (same as using SetFromUnknown)
70 CTGitPath::CTGitPath(const CString& sUnknownPath) :
71 m_bDirectoryKnown(false)
72 , m_bIsDirectory(false)
73 , m_bURLKnown(false)
74 , m_bHasAdminDirKnown(false)
75 , m_bHasAdminDir(false)
76 , m_bIsValidOnWindowsKnown(false)
77 , m_bIsValidOnWindows(false)
78 , m_bIsReadOnly(false)
79 , m_bIsAdminDirKnown(false)
80 , m_bIsAdminDir(false)
81 , m_bExists(false)
82 , m_bExistsKnown(false)
83 , m_bLastWriteTimeKnown(0)
84 , m_lastWriteTime(0)
85 , m_customData(NULL)
86 , m_bIsSpecialDirectoryKnown(false)
87 , m_bIsSpecialDirectory(false)
88 , m_bIsWCRootKnown(false)
89 , m_bIsWCRoot(false)
90 , m_fileSize(0)
91 , m_Checked(false)
93 SetFromUnknown(sUnknownPath);
94 m_Action=0;
95 m_Stage=0;
96 m_ParentNo=0;
99 int CTGitPath::ParserAction(BYTE action)
101 //action=action.TrimLeft();
102 //TCHAR c=action.GetAt(0);
103 if(action == 'M')
104 m_Action|= LOGACTIONS_MODIFIED;
105 if(action == 'R')
106 m_Action|= LOGACTIONS_REPLACED;
107 if(action == 'A')
108 m_Action|= LOGACTIONS_ADDED;
109 if(action == 'D')
110 m_Action|= LOGACTIONS_DELETED;
111 if(action == 'U')
112 m_Action|= LOGACTIONS_UNMERGED;
113 if(action == 'K')
114 m_Action|= LOGACTIONS_DELETED;
115 if(action == 'H')
116 m_Action|= LOGACTIONS_CACHE;
117 if(action == 'C' )
118 m_Action|= LOGACTIONS_COPY;
119 if(action == 'T')
120 m_Action|= LOGACTIONS_MODIFIED;
122 return m_Action;
124 void CTGitPath::SetFromGit(const char* pPath)
126 Reset();
127 if (pPath == NULL)
128 return;
129 int len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, NULL, 0);
130 if (len)
132 len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, m_sFwdslashPath.GetBuffer(len+1), len+1);
133 m_sFwdslashPath.ReleaseBuffer(len-1);
135 SanitizeRootPath(m_sFwdslashPath, true);
138 void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
140 SetFromGit(pPath);
141 m_bDirectoryKnown = true;
142 m_bIsDirectory = bIsDirectory;
145 void CTGitPath::SetFromGit(const TCHAR* pPath, bool bIsDirectory)
147 Reset();
148 if (pPath)
150 m_sFwdslashPath = pPath;
151 SanitizeRootPath(m_sFwdslashPath, true);
153 m_bDirectoryKnown = true;
154 m_bIsDirectory = bIsDirectory;
157 void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)
159 Reset();
160 m_sFwdslashPath = sPath;
161 SanitizeRootPath(m_sFwdslashPath, true);
162 if(oldpath)
163 m_sOldFwdslashPath = *oldpath;
166 void CTGitPath::SetFromWin(LPCTSTR pPath)
168 Reset();
169 m_sBackslashPath = pPath;
170 m_sBackslashPath.Replace(L"\\\\?\\", L"");
171 SanitizeRootPath(m_sBackslashPath, false);
172 ATLASSERT(m_sBackslashPath.Find('/')<0);
174 void CTGitPath::SetFromWin(const CString& sPath)
176 Reset();
177 m_sBackslashPath = sPath;
178 m_sBackslashPath.Replace(L"\\\\?\\", L"");
179 SanitizeRootPath(m_sBackslashPath, false);
181 void CTGitPath::SetFromWin(LPCTSTR pPath, bool bIsDirectory)
183 Reset();
184 m_sBackslashPath = pPath;
185 m_bIsDirectory = bIsDirectory;
186 m_bDirectoryKnown = true;
187 SanitizeRootPath(m_sBackslashPath, false);
189 void CTGitPath::SetFromWin(const CString& sPath, bool bIsDirectory)
191 Reset();
192 m_sBackslashPath = sPath;
193 m_bIsDirectory = bIsDirectory;
194 m_bDirectoryKnown = true;
195 SanitizeRootPath(m_sBackslashPath, false);
197 void CTGitPath::SetFromUnknown(const CString& sPath)
199 Reset();
200 // Just set whichever path we think is most likely to be used
201 // GitAdminDir admin;
202 // CString p;
203 // if(admin.HasAdminDir(sPath,&p))
204 // SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));
205 // else
206 SetFwdslashPath(sPath);
209 LPCTSTR CTGitPath::GetWinPath() const
211 if(IsEmpty())
213 return _T("");
215 if(m_sBackslashPath.IsEmpty())
217 SetBackslashPath(m_sFwdslashPath);
219 return m_sBackslashPath;
221 // This is a temporary function, to be used during the migration to
222 // the path class. Ultimately, functions consuming paths should take a CTGitPath&, not a CString
223 const CString& CTGitPath::GetWinPathString() const
225 if(m_sBackslashPath.IsEmpty())
227 SetBackslashPath(m_sFwdslashPath);
229 return m_sBackslashPath;
232 const CString& CTGitPath::GetGitPathString() const
234 if(m_sFwdslashPath.IsEmpty())
236 SetFwdslashPath(m_sBackslashPath);
238 return m_sFwdslashPath;
241 const CString &CTGitPath::GetGitOldPathString() const
243 return m_sOldFwdslashPath;
246 const CString& CTGitPath::GetUIPathString() const
248 if (m_sUIPath.IsEmpty())
250 m_sUIPath = GetWinPathString();
252 return m_sUIPath;
255 void CTGitPath::SetFwdslashPath(const CString& sPath) const
257 CString path = sPath;
258 path.Replace('\\', '/');
260 // We don't leave a trailing /
261 path.TrimRight('/');
262 path.Replace(L"//?/", L"");
264 SanitizeRootPath(path, true);
266 path.Replace(_T("file:////"), _T("file://"));
267 m_sFwdslashPath = path;
269 m_sUTF8FwdslashPath.Empty();
272 void CTGitPath::SetBackslashPath(const CString& sPath) const
274 CString path = sPath;
275 path.Replace('/', '\\');
276 path.TrimRight('\\');
277 SanitizeRootPath(path, false);
278 m_sBackslashPath = path;
281 void CTGitPath::SetUTF8FwdslashPath(const CString& sPath) const
283 m_sUTF8FwdslashPath = CUnicodeUtils::GetUTF8(sPath);
286 void CTGitPath::SanitizeRootPath(CString& sPath, bool bIsForwardPath) const
288 // Make sure to add the trailing slash to root paths such as 'C:'
289 if (sPath.GetLength() == 2 && sPath[1] == ':')
291 sPath += (bIsForwardPath) ? _T("/") : _T("\\");
295 bool CTGitPath::IsDirectory() const
297 if(!m_bDirectoryKnown)
299 UpdateAttributes();
301 return m_bIsDirectory;
304 bool CTGitPath::Exists() const
306 if (!m_bExistsKnown)
308 UpdateAttributes();
310 return m_bExists;
313 bool CTGitPath::Delete(bool bTrash) const
315 EnsureBackslashPathSet();
316 ::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);
317 bool bRet = false;
318 if (Exists())
320 if ((bTrash)||(IsDirectory()))
322 std::unique_ptr<TCHAR[]> buf(new TCHAR[m_sBackslashPath.GetLength() + 2]);
323 _tcscpy_s(buf.get(), m_sBackslashPath.GetLength() + 2, m_sBackslashPath);
324 buf[m_sBackslashPath.GetLength()] = 0;
325 buf[m_sBackslashPath.GetLength()+1] = 0;
326 bRet = CTGitPathList::DeleteViaShell(buf.get(), bTrash);
328 else
330 bRet = !!::DeleteFile(m_sBackslashPath);
333 m_bExists = false;
334 m_bExistsKnown = true;
335 return bRet;
338 __int64 CTGitPath::GetLastWriteTime() const
340 if(!m_bLastWriteTimeKnown)
342 UpdateAttributes();
344 return m_lastWriteTime;
347 __int64 CTGitPath::GetFileSize() const
349 if(!m_bDirectoryKnown)
351 UpdateAttributes();
353 return m_fileSize;
356 bool CTGitPath::IsReadOnly() const
358 if(!m_bLastWriteTimeKnown)
360 UpdateAttributes();
362 return m_bIsReadOnly;
365 void CTGitPath::UpdateAttributes() const
367 EnsureBackslashPathSet();
368 WIN32_FILE_ATTRIBUTE_DATA attribs;
369 if (m_sBackslashPath.GetLength() >= 248)
370 m_sLongBackslashPath = _T("\\\\?\\") + m_sBackslashPath;
371 if(GetFileAttributesEx(m_sBackslashPath.GetLength() >= 248 ? m_sLongBackslashPath : m_sBackslashPath, GetFileExInfoStandard, &attribs))
373 m_bIsDirectory = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
374 // don't cast directly to an __int64:
375 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724284%28v=vs.85%29.aspx
376 // "Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value
377 // because it can cause alignment faults on 64-bit Windows."
378 m_lastWriteTime = static_cast<__int64>(attribs.ftLastWriteTime.dwHighDateTime) << 32 | attribs.ftLastWriteTime.dwLowDateTime;
379 if (m_bIsDirectory)
381 m_fileSize = 0;
383 else
385 m_fileSize = ((INT64)( (DWORD)(attribs.nFileSizeLow) ) | ( (INT64)( (DWORD)(attribs.nFileSizeHigh) )<<32 ));
387 m_bIsReadOnly = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_READONLY);
388 m_bExists = true;
390 else
392 m_bIsDirectory = false;
393 m_lastWriteTime = 0;
394 m_fileSize = 0;
395 DWORD err = GetLastError();
396 if ((err == ERROR_FILE_NOT_FOUND)||(err == ERROR_PATH_NOT_FOUND)||(err == ERROR_INVALID_NAME))
398 m_bExists = false;
400 else
402 m_bExists = true;
403 return;
406 m_bDirectoryKnown = true;
407 m_bLastWriteTimeKnown = true;
408 m_bExistsKnown = true;
411 CTGitPath CTGitPath::GetSubPath(const CTGitPath &root)
413 CTGitPath path;
415 if(GetWinPathString().Left(root.GetWinPathString().GetLength()) == root.GetWinPathString())
417 CString str=GetWinPathString();
418 path.SetFromWin(str.Right(str.GetLength()-root.GetWinPathString().GetLength()-1));
420 return path;
423 void CTGitPath::EnsureBackslashPathSet() const
425 if(m_sBackslashPath.IsEmpty())
427 SetBackslashPath(m_sFwdslashPath);
428 ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());
431 void CTGitPath::EnsureFwdslashPathSet() const
433 if(m_sFwdslashPath.IsEmpty())
435 SetFwdslashPath(m_sBackslashPath);
436 ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());
441 // Reset all the caches
442 void CTGitPath::Reset()
444 m_bDirectoryKnown = false;
445 m_bURLKnown = false;
446 m_bLastWriteTimeKnown = false;
447 m_bHasAdminDirKnown = false;
448 m_bIsValidOnWindowsKnown = false;
449 m_bIsAdminDirKnown = false;
450 m_bExistsKnown = false;
451 m_bIsSpecialDirectoryKnown = false;
452 m_bIsSpecialDirectory = false;
454 m_sBackslashPath.Empty();
455 m_sFwdslashPath.Empty();
456 m_sUTF8FwdslashPath.Empty();
457 this->m_Action=0;
458 this->m_StatAdd=_T("");
459 this->m_StatDel=_T("");
460 m_ParentNo=0;
461 ATLASSERT(IsEmpty());
464 CTGitPath CTGitPath::GetDirectory() const
466 if ((IsDirectory())||(!Exists()))
468 return *this;
470 return GetContainingDirectory();
473 CTGitPath CTGitPath::GetContainingDirectory() const
475 EnsureBackslashPathSet();
477 CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));
478 if(sDirName.GetLength() == 2 && sDirName[1] == ':')
480 // This is a root directory, which needs a trailing slash
481 sDirName += '\\';
482 if(sDirName == m_sBackslashPath)
484 // We were clearly provided with a root path to start with - we should return nothing now
485 sDirName.Empty();
488 if(sDirName.GetLength() == 1 && sDirName[0] == '\\')
490 // We have an UNC path and we already are the root
491 sDirName.Empty();
493 CTGitPath retVal;
494 retVal.SetFromWin(sDirName);
495 return retVal;
498 CString CTGitPath::GetRootPathString() const
500 EnsureBackslashPathSet();
501 CString workingPath = m_sBackslashPath;
502 LPTSTR pPath = workingPath.GetBuffer(MAX_PATH); // MAX_PATH ok here.
503 ATLVERIFY(::PathStripToRoot(pPath));
504 workingPath.ReleaseBuffer();
505 return workingPath;
509 CString CTGitPath::GetFilename() const
511 //ATLASSERT(!IsDirectory());
512 return GetFileOrDirectoryName();
515 CString CTGitPath::GetFileOrDirectoryName() const
517 EnsureBackslashPathSet();
518 return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);
521 CString CTGitPath::GetUIFileOrDirectoryName() const
523 GetUIPathString();
524 return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);
527 CString CTGitPath::GetFileExtension() const
529 if(!IsDirectory())
531 EnsureBackslashPathSet();
532 int dotPos = m_sBackslashPath.ReverseFind('.');
533 int slashPos = m_sBackslashPath.ReverseFind('\\');
534 if (dotPos > slashPos)
535 return m_sBackslashPath.Mid(dotPos);
537 return CString();
539 CString CTGitPath::GetBaseFilename() const
541 int dot;
542 CString filename=GetFilename();
543 dot = filename.ReverseFind(_T('.'));
544 if(dot>0)
545 return filename.Left(dot);
546 else
547 return filename;
550 bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)
552 int length = sP1.GetLength();
553 if(length != sP2.GetLength())
555 // Different lengths
556 return false;
558 // We work from the end of the strings, because path differences
559 // are more likely to occur at the far end of a string
560 LPCTSTR pP1Start = sP1;
561 LPCTSTR pP1 = pP1Start+(length-1);
562 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
563 while(length-- > 0)
565 if(_totlower(*pP1--) != _totlower(*pP2--))
567 return false;
570 return true;
573 bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)
575 int length = sP1.GetLength();
576 if(length != sP2.GetLength())
578 // Different lengths
579 return false;
581 // We work from the end of the strings, because path differences
582 // are more likely to occur at the far end of a string
583 LPCTSTR pP1Start = sP1;
584 LPCTSTR pP1 = pP1Start+(length-1);
585 LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
586 while(length-- > 0)
588 if((*pP1--) != (*pP2--))
590 return false;
593 return true;
596 bool CTGitPath::IsEmpty() const
598 // Check the backward slash path first, since the chance that this
599 // one is set is higher. In case of a 'false' return value it's a little
600 // bit faster.
601 return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();
604 // Test if both paths refer to the same item
605 // Ignores case and slash direction
606 bool CTGitPath::IsEquivalentTo(const CTGitPath& rhs) const
608 // Try and find a slash direction which avoids having to convert
609 // both filenames
610 if(!m_sBackslashPath.IsEmpty())
612 // *We've* got a \ path - make sure that the RHS also has a \ path
613 rhs.EnsureBackslashPathSet();
614 return ArePathStringsEqualWithCase(m_sBackslashPath, rhs.m_sBackslashPath);
616 else
618 // Assume we've got a fwdslash path and make sure that the RHS has one
619 rhs.EnsureFwdslashPathSet();
620 return ArePathStringsEqualWithCase(m_sFwdslashPath, rhs.m_sFwdslashPath);
624 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const
626 // Try and find a slash direction which avoids having to convert
627 // both filenames
628 if(!m_sBackslashPath.IsEmpty())
630 // *We've* got a \ path - make sure that the RHS also has a \ path
631 rhs.EnsureBackslashPathSet();
632 return ArePathStringsEqual(m_sBackslashPath, rhs.m_sBackslashPath);
634 else
636 // Assume we've got a fwdslash path and make sure that the RHS has one
637 rhs.EnsureFwdslashPathSet();
638 return ArePathStringsEqual(m_sFwdslashPath, rhs.m_sFwdslashPath);
642 bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const
644 possibleDescendant.EnsureBackslashPathSet();
645 EnsureBackslashPathSet();
647 bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));
648 if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())
650 return bPathStringsEqual;
653 return (bPathStringsEqual &&
654 ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||
655 (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));
658 // Get a string representing the file path, optionally with a base
659 // section stripped off the front.
660 CString CTGitPath::GetDisplayString(const CTGitPath* pOptionalBasePath /* = NULL*/) const
662 EnsureFwdslashPathSet();
663 if(pOptionalBasePath != NULL)
665 // Find the length of the base-path without having to do an 'ensure' on it
666 int baseLength = max(pOptionalBasePath->m_sBackslashPath.GetLength(), pOptionalBasePath->m_sFwdslashPath.GetLength());
668 // Now, chop that baseLength of the front of the path
669 return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');
671 return m_sFwdslashPath;
674 int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)
676 left.EnsureBackslashPathSet();
677 right.EnsureBackslashPathSet();
678 return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);
681 bool operator<(const CTGitPath& left, const CTGitPath& right)
683 return CTGitPath::Compare(left, right) < 0;
686 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)
688 return left.IsEquivalentTo(right);
691 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)
693 if (left.IsAdminDir() && right.IsAdminDir())
695 CTGitPath l = left;
696 CTGitPath r = right;
699 l = l.GetContainingDirectory();
700 } while(l.HasAdminDir());
703 r = r.GetContainingDirectory();
704 } while(r.HasAdminDir());
705 return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());
707 return left.GetDirectory().IsEquivalentTo(right.GetDirectory());
710 bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)
712 return parent.IsAncestorOf(child);
715 void CTGitPath::AppendRawString(const CString& sAppend)
717 EnsureFwdslashPathSet();
718 CString strCopy = m_sFwdslashPath += sAppend;
719 SetFromUnknown(strCopy);
722 void CTGitPath::AppendPathString(const CString& sAppend)
724 EnsureBackslashPathSet();
725 CString cleanAppend(sAppend);
726 cleanAppend.Replace('/', '\\');
727 cleanAppend.TrimLeft('\\');
728 m_sBackslashPath.TrimRight('\\');
729 CString strCopy = m_sBackslashPath + _T("\\") + cleanAppend;
730 SetFromWin(strCopy);
733 bool CTGitPath::IsWCRoot() const
735 if (m_bIsWCRootKnown)
736 return m_bIsWCRoot;
738 m_bIsWCRootKnown = true;
739 m_bIsWCRoot = false;
741 CString topDirectory;
742 if (!IsDirectory() || !HasAdminDir(&topDirectory))
744 return m_bIsWCRoot;
747 if (IsEquivalentToWithoutCase(topDirectory))
749 m_bIsWCRoot = true;
752 return m_bIsWCRoot;
755 bool CTGitPath::HasAdminDir() const
757 if (m_bHasAdminDirKnown)
758 return m_bHasAdminDir;
760 EnsureBackslashPathSet();
761 m_bHasAdminDir = GitAdminDir::HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
762 m_bHasAdminDirKnown = true;
763 return m_bHasAdminDir;
766 bool CTGitPath::HasSubmodules() const
768 if (HasAdminDir())
770 CString path = m_sProjectRoot;
771 path += _T("\\.gitmodules");
772 if( PathFileExists(path) )
773 return true;
775 return false;
778 int CTGitPath::GetAdminDirMask() const
780 int status = 0;
781 CString topdir;
782 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
784 return status;
787 // ITEMIS_INGIT will be revoked if necessary in TortoiseShell/ContextMenu.cpp
788 status |= ITEMIS_INGIT|ITEMIS_INVERSIONEDFOLDER;
790 if (IsDirectory())
792 status |= ITEMIS_FOLDERINGIT;
793 if (IsWCRoot())
795 status |= ITEMIS_WCROOT;
797 CString topProjectDir;
798 if (GitAdminDir::HasAdminDir(GetWinPathString(), false, &topProjectDir))
800 if (PathFileExists(topProjectDir + _T("\\.gitmodules")))
802 CAutoConfig config(true);
803 git_config_add_file_ondisk(config, CGit::GetGitPathStringA(topProjectDir + _T("\\.gitmodules")), GIT_CONFIG_LEVEL_APP, FALSE);
804 CString relativePath = GetWinPathString().Mid(topProjectDir.GetLength());
805 relativePath.Replace(_T("\\"), _T("/"));
806 relativePath.Trim(_T("/"));
807 CStringA submodulePath = CUnicodeUtils::GetUTF8(relativePath);
808 if (git_config_foreach_match(config, "submodule\\..*\\.path",
809 [](const git_config_entry *entry, void *data) { return entry->value == *(CStringA *)data ? GIT_EUSER : 0; }, &submodulePath) == GIT_EUSER)
810 status |= ITEMIS_SUBMODULE;
816 CString dotGitPath;
817 GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
819 if (PathFileExists(dotGitPath + _T("BISECT_START")))
820 status |= ITEMIS_BISECT;
822 if (PathFileExists(dotGitPath + _T("MERGE_HEAD")))
823 status |= ITEMIS_MERGEACTIVE;
825 if (PathFileExists(dotGitPath + _T("refs\\stash")))
826 status |= ITEMIS_STASH;
828 if (PathFileExists(dotGitPath + _T("svn")))
829 status |= ITEMIS_GITSVN;
831 if (PathFileExists(topdir + _T("\\.gitmodules")))
832 status |= ITEMIS_SUBMODULECONTAINER;
834 return status;
837 bool CTGitPath::HasStashDir() const
839 CString topdir;
840 if(!GitAdminDir::HasAdminDir(GetWinPathString(),&topdir))
842 return false;
845 CString dotGitPath;
846 GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
848 return !!PathFileExists(dotGitPath + _T("\\refs\\stash"));
850 bool CTGitPath::HasGitSVNDir() const
852 CString topdir;
853 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
855 return false;
858 CString dotGitPath;
859 GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
861 return !!PathFileExists(dotGitPath + _T("svn"));
863 bool CTGitPath::IsBisectActive() const
865 CString topdir;
866 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
868 return false;
871 CString dotGitPath;
872 GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
874 return !!PathFileExists(dotGitPath + _T("BISECT_START"));
876 bool CTGitPath::IsMergeActive() const
878 CString topdir;
879 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
881 return false;
884 CString dotGitPath;
885 GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
887 return !!PathFileExists(dotGitPath + _T("MERGE_HEAD"));
889 bool CTGitPath::HasRebaseApply() const
891 CString topdir;
892 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
894 return false;
897 CString dotGitPath;
898 GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
900 return !!PathFileExists(dotGitPath + _T("rebase-apply"));
903 bool CTGitPath::HasAdminDir(CString *ProjectTopDir) const
905 if (m_bHasAdminDirKnown)
907 if (ProjectTopDir)
908 *ProjectTopDir = m_sProjectRoot;
909 return m_bHasAdminDir;
912 EnsureBackslashPathSet();
913 m_bHasAdminDir = GitAdminDir::HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
914 m_bHasAdminDirKnown = true;
915 if (ProjectTopDir)
916 *ProjectTopDir = m_sProjectRoot;
917 return m_bHasAdminDir;
920 bool CTGitPath::IsAdminDir() const
922 if (m_bIsAdminDirKnown)
923 return m_bIsAdminDir;
925 EnsureBackslashPathSet();
926 m_bIsAdminDir = GitAdminDir::IsAdminDirPath(m_sBackslashPath);
927 m_bIsAdminDirKnown = true;
928 return m_bIsAdminDir;
931 bool CTGitPath::IsValidOnWindows() const
933 if (m_bIsValidOnWindowsKnown)
934 return m_bIsValidOnWindows;
936 m_bIsValidOnWindows = false;
937 EnsureBackslashPathSet();
938 CString sMatch = m_sBackslashPath + _T("\r\n");
939 std::wstring sPattern;
940 // the 'file://' URL is just a normal windows path:
941 if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)
943 sMatch = sMatch.Mid(7);
944 sMatch.TrimLeft(_T("\\"));
945 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
947 else
949 sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
954 std::tr1::wregex rx(sPattern, std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
955 std::tr1::wsmatch match;
957 std::wstring rmatch = std::wstring((LPCTSTR)sMatch);
958 if (std::tr1::regex_match(rmatch, match, rx))
960 if (std::wstring(match[0]).compare(sMatch)==0)
961 m_bIsValidOnWindows = true;
963 if (m_bIsValidOnWindows)
965 // now check for illegal filenames
966 std::tr1::wregex rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
967 rmatch = m_sBackslashPath;
968 if (std::tr1::regex_search(rmatch, rx2, std::tr1::regex_constants::match_default))
969 m_bIsValidOnWindows = false;
972 catch (std::exception) {}
974 m_bIsValidOnWindowsKnown = true;
975 return m_bIsValidOnWindows;
978 //////////////////////////////////////////////////////////////////////////
980 CTGitPathList::CTGitPathList()
982 m_Action = 0;
985 // A constructor which allows a path list to be easily built which one initial entry in
986 CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)
988 m_Action = 0;
989 AddPath(firstEntry);
991 int CTGitPathList::ParserFromLsFile(BYTE_VECTOR &out,bool /*staged*/)
993 int pos=0;
994 CString one;
995 CTGitPath path;
996 CString part;
997 this->Clear();
999 while (pos >= 0 && pos < (int)out.size())
1001 one.Empty();
1002 path.Reset();
1004 CGit::StringAppend(&one, &out[pos], CP_UTF8);
1005 int tabstart=0;
1006 path.m_Action=path.ParserAction(out[pos]);
1007 one.Tokenize(_T("\t"),tabstart);
1009 if(tabstart>=0)
1010 path.SetFromGit(one.Right(one.GetLength()-tabstart));
1011 else
1012 return -1;
1014 tabstart=0;
1016 part=one.Tokenize(_T(" "),tabstart); //Tag
1017 if (tabstart < 0)
1018 return -1;
1020 part=one.Tokenize(_T(" "),tabstart); //Mode
1021 if (tabstart < 0)
1022 return -1;
1024 part=one.Tokenize(_T(" "),tabstart); //Hash
1025 if (tabstart < 0)
1026 return -1;
1028 part=one.Tokenize(_T("\t"),tabstart); //Stage
1029 if (tabstart < 0)
1030 return -1;
1032 path.m_Stage=_ttol(part);
1034 this->AddPath(path);
1036 pos=out.findNextString(pos);
1038 return 0;
1040 int CTGitPathList::FillUnRev(unsigned int action, CTGitPathList *list, CString *err)
1042 this->Clear();
1043 CTGitPath path;
1045 int count;
1046 if(list==NULL)
1047 count=1;
1048 else
1049 count=list->GetCount();
1050 for (int i = 0; i < count; ++i)
1052 CString cmd;
1053 int pos = 0;
1055 CString ignored;
1056 if(action & CTGitPath::LOGACTIONS_IGNORE)
1057 ignored= _T(" -i");
1059 if(list==NULL)
1061 cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");
1062 cmd+=ignored;
1065 else
1066 { cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z%s -- \"%s\""),
1067 ignored,
1068 (*list)[i].GetWinPathString());
1071 BYTE_VECTOR out, errb;
1072 out.clear();
1073 if (g_Git.Run(cmd, &out, &errb))
1075 if (err != nullptr)
1076 CGit::StringAppend(err, &errb[0], CP_UTF8, (int)errb.size());
1077 return -1;
1080 pos=0;
1081 CString one;
1082 while (pos >= 0 && pos < (int)out.size())
1084 one.Empty();
1085 CGit::StringAppend(&one, &out[pos], CP_UTF8);
1086 if(!one.IsEmpty())
1088 //SetFromGit will clear all status
1089 path.SetFromGit(one);
1090 path.m_Action=action;
1091 AddPath(path);
1093 pos=out.findNextString(pos);
1097 return 0;
1099 int CTGitPathList::FillBasedOnIndexFlags(unsigned short flag, CTGitPathList* list /*nullptr*/)
1101 Clear();
1102 CTGitPath path;
1104 CAutoRepository repository(g_Git.GetGitRepository());
1105 if (!repository)
1106 return -1;
1108 CAutoIndex index;
1109 if (git_repository_index(index.GetPointer(), repository))
1110 return -1;
1112 int count;
1113 if (list == nullptr)
1114 count = 1;
1115 else
1116 count = list->GetCount();
1117 for (int j = 0; j < count; ++j)
1119 for (size_t i = 0, ecount = git_index_entrycount(index); i < ecount; ++i)
1121 const git_index_entry *e = git_index_get_byindex(index, i);
1123 if (!e || !((e->flags | e->flags_extended) & flag) || !e->path)
1124 continue;
1126 CString one = CUnicodeUtils::GetUnicode(e->path);
1128 if (!(!list || (*list)[j].GetWinPathString().IsEmpty() || one == (*list)[j].GetGitPathString() || (PathIsDirectory(g_Git.CombinePath((*list)[j].GetWinPathString())) && one.Find((*list)[j].GetGitPathString() + _T("/")) == 0)))
1129 continue;
1131 //SetFromGit will clear all status
1132 path.SetFromGit(one);
1133 if ((e->flags | e->flags_extended) & GIT_IDXENTRY_SKIP_WORKTREE)
1134 path.m_Action = CTGitPath::LOGACTIONS_SKIPWORKTREE;
1135 else if ((e->flags | e->flags_extended) & GIT_IDXENTRY_VALID)
1136 path.m_Action = CTGitPath::LOGACTIONS_ASSUMEVALID;
1137 AddPath(path);
1140 RemoveDuplicates();
1141 return 0;
1143 int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/)
1145 this->Clear();
1146 int pos=0;
1147 CTGitPath path;
1148 m_Action=0;
1149 while (pos >= 0 && pos < (int)log.size())
1151 path.Reset();
1152 if(log[pos]=='\n')
1153 ++pos;
1155 if(log[pos]==':')
1157 bool merged=false;
1158 if(log[pos+1] ==':')
1160 merged=true;
1162 int end=log.find(0,pos);
1163 int actionstart=-1;
1164 int file1=-1,file2=-1;
1165 if( end>0 )
1167 actionstart=log.find(' ',end-6);
1168 pos=actionstart;
1170 if( actionstart>0 )
1172 ++actionstart;
1174 file1 = log.find(0,actionstart);
1175 if( file1>=0 )
1177 ++file1;
1178 pos=file1;
1180 if( log[actionstart] == 'C' || log[actionstart] == 'R' )
1182 file2=file1;
1183 file1 = log.find(0,file1);
1184 if(file1>=0 )
1186 ++file1;
1187 pos=file1;
1193 CString pathname1;
1194 CString pathname2;
1196 if( file1>=0 )
1197 CGit::StringAppend(&pathname1, &log[file1], CP_UTF8);
1198 if( file2>=0 )
1199 CGit::StringAppend(&pathname2, &log[file2], CP_UTF8);
1201 CTGitPath *GitPath=LookForGitPath(pathname1);
1203 if(GitPath)
1205 GitPath->ParserAction( log[actionstart] );
1207 if(merged)
1209 GitPath->m_Action |= CTGitPath::LOGACTIONS_MERGED;
1210 GitPath->m_Action &= ~CTGitPath::LOGACTIONS_FORWORD;
1212 m_Action |=GitPath->m_Action;
1215 else
1217 int ac=path.ParserAction(log[actionstart] );
1218 ac |= merged?CTGitPath::LOGACTIONS_MERGED:0;
1220 path.SetFromGit(pathname1,&pathname2);
1221 path.m_Action=ac;
1222 //action must be set after setfromgit. SetFromGit will clear all status.
1223 this->m_Action|=ac;
1225 AddPath(path);
1230 else
1232 int tabstart=0;
1233 path.Reset();
1234 CString StatAdd;
1235 CString StatDel;
1236 CString file1;
1237 CString file2;
1239 tabstart=log.find('\t',pos);
1240 if(tabstart >=0)
1242 log[tabstart]=0;
1243 CGit::StringAppend(&StatAdd, &log[pos], CP_UTF8);
1244 pos=tabstart+1;
1247 tabstart=log.find('\t',pos);
1248 if(tabstart >=0)
1250 log[tabstart]=0;
1252 CGit::StringAppend(&StatDel, &log[pos], CP_UTF8);
1253 pos=tabstart+1;
1256 if(log[pos] == 0) //rename
1258 ++pos;
1259 CGit::StringAppend(&file2, &log[pos], CP_UTF8);
1260 int sec=log.find(0,pos);
1261 if(sec>=0)
1263 ++sec;
1264 CGit::StringAppend(&file1, &log[sec], CP_UTF8);
1266 pos=sec;
1269 else
1271 CGit::StringAppend(&file1, &log[pos], CP_UTF8);
1273 path.SetFromGit(file1,&file2);
1275 CTGitPath *GitPath=LookForGitPath(path.GetGitPathString());
1276 if(GitPath)
1278 GitPath->m_StatAdd=StatAdd;
1279 GitPath->m_StatDel=StatDel;
1281 else
1283 //path.SetFromGit(pathname);
1284 if (parseDeletes)
1286 path.m_StatAdd=_T("0");
1287 path.m_StatDel=_T("0");
1288 path.m_Action |= CTGitPath::LOGACTIONS_DELETED;
1290 else
1292 path.m_StatAdd=StatAdd;
1293 path.m_StatDel=StatDel;
1294 path.m_Action |= CTGitPath::LOGACTIONS_FORWORD;
1296 AddPath(path);
1300 pos=log.findNextString(pos);
1302 return pos;
1305 void CTGitPathList::AddPath(const CTGitPath& newPath)
1307 m_paths.push_back(newPath);
1308 m_commonBaseDirectory.Reset();
1310 int CTGitPathList::GetCount() const
1312 return (int)m_paths.size();
1314 bool CTGitPathList::IsEmpty() const
1316 return m_paths.empty();
1318 void CTGitPathList::Clear()
1320 m_paths.clear();
1321 m_commonBaseDirectory.Reset();
1324 const CTGitPath& CTGitPathList::operator[](INT_PTR index) const
1326 ATLASSERT(index >= 0 && index < (INT_PTR)m_paths.size());
1327 return m_paths[index];
1330 bool CTGitPathList::AreAllPathsFiles() const
1332 // Look through the vector for any directories - if we find them, return false
1333 return std::find_if(m_paths.begin(), m_paths.end(), std::mem_fun_ref(&CTGitPath::IsDirectory)) == m_paths.end();
1337 #if defined(_MFC_VER)
1339 bool CTGitPathList::LoadFromFile(const CTGitPath& filename)
1341 Clear();
1344 CString strLine;
1345 CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite);
1347 // for every selected file/folder
1348 CTGitPath path;
1349 while (file.ReadString(strLine))
1351 path.SetFromUnknown(strLine);
1352 AddPath(path);
1354 file.Close();
1356 catch (CFileException* pE)
1358 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException loading target file list\n");
1359 TCHAR error[10000] = {0};
1360 pE->GetErrorMessage(error, 10000);
1361 // CMessageBox::Show(NULL, error, _T("TortoiseGit"), MB_ICONERROR);
1362 pE->Delete();
1363 return false;
1365 return true;
1368 bool CTGitPathList::WriteToFile(const CString& sFilename, bool bANSI /* = false */) const
1372 if (bANSI)
1374 CStdioFile file(sFilename, CFile::typeText | CFile::modeReadWrite | CFile::modeCreate);
1375 PathVector::const_iterator it;
1376 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1378 CStringA line = CStringA(it->GetGitPathString()) + '\n';
1379 file.Write(line, line.GetLength());
1381 file.Close();
1383 else
1385 CStdioFile file(sFilename, CFile::typeBinary | CFile::modeReadWrite | CFile::modeCreate);
1386 PathVector::const_iterator it;
1387 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1389 file.WriteString(it->GetGitPathString()+_T("\n"));
1391 file.Close();
1394 catch (CFileException* pE)
1396 CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException in writing temp file\n");
1397 pE->Delete();
1398 return false;
1400 return true;
1404 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString& sPathString)
1406 int pos = 0;
1407 CString temp;
1408 for(;;)
1410 temp = sPathString.Tokenize(_T("*"),pos);
1411 if(temp.IsEmpty())
1413 break;
1415 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp)));
1419 CString CTGitPathList::CreateAsteriskSeparatedString() const
1421 CString sRet;
1422 PathVector::const_iterator it;
1423 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1425 if (!sRet.IsEmpty())
1426 sRet += _T("*");
1427 sRet += it->GetWinPathString();
1429 return sRet;
1431 #endif // _MFC_VER
1433 bool
1434 CTGitPathList::AreAllPathsFilesInOneDirectory() const
1436 // Check if all the paths are files and in the same directory
1437 PathVector::const_iterator it;
1438 m_commonBaseDirectory.Reset();
1439 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1441 if(it->IsDirectory())
1443 return false;
1445 const CTGitPath& baseDirectory = it->GetDirectory();
1446 if(m_commonBaseDirectory.IsEmpty())
1448 m_commonBaseDirectory = baseDirectory;
1450 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
1452 // Different path
1453 m_commonBaseDirectory.Reset();
1454 return false;
1457 return true;
1460 CTGitPath CTGitPathList::GetCommonDirectory() const
1462 if (m_commonBaseDirectory.IsEmpty())
1464 PathVector::const_iterator it;
1465 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1467 const CTGitPath& baseDirectory = it->GetDirectory();
1468 if(m_commonBaseDirectory.IsEmpty())
1470 m_commonBaseDirectory = baseDirectory;
1472 else if(!m_commonBaseDirectory.IsEquivalentTo(baseDirectory))
1474 // Different path
1475 m_commonBaseDirectory.Reset();
1476 break;
1480 // since we only checked strings, not paths,
1481 // we have to make sure now that we really return a *path* here
1482 PathVector::const_iterator iter;
1483 for(iter = m_paths.begin(); iter != m_paths.end(); ++iter)
1485 if (!m_commonBaseDirectory.IsAncestorOf(*iter))
1487 m_commonBaseDirectory = m_commonBaseDirectory.GetContainingDirectory();
1488 break;
1491 return m_commonBaseDirectory;
1494 CTGitPath CTGitPathList::GetCommonRoot() const
1496 if (IsEmpty())
1497 return CTGitPath();
1499 if (GetCount() == 1)
1500 return m_paths[0];
1502 // first entry is common root for itself
1503 // (add trailing '\\' to detect partial matches of the last path element)
1504 CString root = m_paths[0].GetWinPathString() + _T('\\');
1505 int rootLength = root.GetLength();
1507 // determine common path string prefix
1508 for (PathVector::const_iterator it = m_paths.begin() + 1; it != m_paths.end(); ++it)
1510 CString path = it->GetWinPathString() + _T('\\');
1512 int newLength = CStringUtils::GetMatchingLength(root, path);
1513 if (newLength != rootLength)
1515 root.Delete(newLength, rootLength);
1516 rootLength = newLength;
1520 // remove the last (partial) path element
1521 if (rootLength > 0)
1522 root.Delete(root.ReverseFind(_T('\\')), rootLength);
1524 // done
1525 return CTGitPath(root);
1528 void CTGitPathList::SortByPathname(bool bReverse /*= false*/)
1530 std::sort(m_paths.begin(), m_paths.end());
1531 if (bReverse)
1532 std::reverse(m_paths.begin(), m_paths.end());
1535 void CTGitPathList::DeleteAllFiles(bool bTrash, bool bFilesOnly)
1537 PathVector::const_iterator it;
1538 SortByPathname(true); // nested ones first
1540 CString sPaths;
1541 for (it = m_paths.begin(); it != m_paths.end(); ++it)
1543 if ((it->Exists()) && ((it->IsDirectory() != bFilesOnly) || !bFilesOnly))
1545 if (!it->IsDirectory())
1546 ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL);
1548 sPaths += it->GetWinPath();
1549 sPaths += '\0';
1552 sPaths += '\0';
1553 sPaths += '\0';
1554 DeleteViaShell((LPCTSTR)sPaths, bTrash);
1555 Clear();
1558 bool CTGitPathList::DeleteViaShell(LPCTSTR path, bool bTrash)
1560 SHFILEOPSTRUCT shop = {0};
1561 shop.wFunc = FO_DELETE;
1562 shop.pFrom = path;
1563 shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT|FOF_NO_CONNECTED_ELEMENTS;
1564 if (bTrash)
1565 shop.fFlags |= FOF_ALLOWUNDO;
1566 const bool bRet = (SHFileOperation(&shop) == 0);
1567 return bRet;
1570 void CTGitPathList::RemoveDuplicates()
1572 SortByPathname();
1573 // Remove the duplicates
1574 // (Unique moves them to the end of the vector, then erase chops them off)
1575 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::PredLeftEquivalentToRight), m_paths.end());
1578 void CTGitPathList::RemoveAdminPaths()
1580 PathVector::iterator it;
1581 for(it = m_paths.begin(); it != m_paths.end(); )
1583 if (it->IsAdminDir())
1585 m_paths.erase(it);
1586 it = m_paths.begin();
1588 else
1589 ++it;
1593 void CTGitPathList::RemovePath(const CTGitPath& path)
1595 PathVector::iterator it;
1596 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1598 if (it->IsEquivalentTo(path))
1600 m_paths.erase(it);
1601 return;
1606 void CTGitPathList::RemoveItem(CTGitPath & path)
1608 PathVector::iterator it;
1609 for(it = m_paths.begin(); it != m_paths.end(); ++it)
1611 if (it->GetGitPathString()==path.GetGitPathString())
1613 m_paths.erase(it);
1614 return;
1618 void CTGitPathList::RemoveChildren()
1620 SortByPathname();
1621 m_paths.erase(std::unique(m_paths.begin(), m_paths.end(), &CTGitPath::CheckChild), m_paths.end());
1624 bool CTGitPathList::IsEqual(const CTGitPathList& list)
1626 if (list.GetCount() != GetCount())
1627 return false;
1628 for (int i=0; i<list.GetCount(); ++i)
1630 if (!list[i].IsEquivalentTo(m_paths[i]))
1631 return false;
1633 return true;
1636 #if 0
1637 #if defined(_DEBUG)
1638 // Some test cases for these classes
1639 static class CTGitPathTests
1641 public:
1642 CTGitPathTests()
1644 GetDirectoryTest();
1645 AdminDirTest();
1646 SortTest();
1647 RawAppendTest();
1648 PathAppendTest();
1649 RemoveDuplicatesTest();
1650 RemoveChildrenTest();
1651 ContainingDirectoryTest();
1652 AncestorTest();
1653 SubversionPathTest();
1654 GetCommonRootTest();
1655 #if defined(_MFC_VER)
1656 ValidPathAndUrlTest();
1657 ListLoadingTest();
1658 #endif
1661 private:
1662 void GetDirectoryTest()
1664 // Bit tricky, this test, because we need to know something about the file
1665 // layout on the machine which is running the test
1666 TCHAR winDir[MAX_PATH+1] = {0};
1667 GetWindowsDirectory(winDir, MAX_PATH);
1668 CString sWinDir(winDir);
1670 CTGitPath testPath;
1671 // This is a file which we know will always be there
1672 testPath.SetFromUnknown(sWinDir + _T("\\win.ini"));
1673 ATLASSERT(!testPath.IsDirectory());
1674 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
1675 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() == sWinDir);
1677 // Now do the test on the win directory itself - It's hard to be sure about the containing directory
1678 // but we know it must be different to the directory itself
1679 testPath.SetFromUnknown(sWinDir);
1680 ATLASSERT(testPath.IsDirectory());
1681 ATLASSERT(testPath.GetDirectory().GetWinPathString() == sWinDir);
1682 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString() != sWinDir);
1683 ATLASSERT(testPath.GetContainingDirectory().GetWinPathString().GetLength() < sWinDir.GetLength());
1685 // Try a root path
1686 testPath.SetFromUnknown(_T("C:\\"));
1687 ATLASSERT(testPath.IsDirectory());
1688 ATLASSERT(testPath.GetDirectory().GetWinPathString().CompareNoCase(_T("C:\\"))==0);
1689 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
1690 // Try a root UNC path
1691 testPath.SetFromUnknown(_T("\\MYSTATION"));
1692 ATLASSERT(testPath.GetContainingDirectory().IsEmpty());
1695 void AdminDirTest()
1697 CTGitPath testPath;
1698 testPath.SetFromUnknown(_T("c:\\.svndir"));
1699 ATLASSERT(!testPath.IsAdminDir());
1700 testPath.SetFromUnknown(_T("c:\\test.svn"));
1701 ATLASSERT(!testPath.IsAdminDir());
1702 testPath.SetFromUnknown(_T("c:\\.svn"));
1703 ATLASSERT(testPath.IsAdminDir());
1704 testPath.SetFromUnknown(_T("c:\\.svndir\\test"));
1705 ATLASSERT(!testPath.IsAdminDir());
1706 testPath.SetFromUnknown(_T("c:\\.svn\\test"));
1707 ATLASSERT(testPath.IsAdminDir());
1709 CTGitPathList pathList;
1710 pathList.AddPath(CTGitPath(_T("c:\\.svndir")));
1711 pathList.AddPath(CTGitPath(_T("c:\\.svn")));
1712 pathList.AddPath(CTGitPath(_T("c:\\.svn\\test")));
1713 pathList.AddPath(CTGitPath(_T("c:\\test")));
1714 pathList.RemoveAdminPaths();
1715 ATLASSERT(pathList.GetCount()==2);
1716 pathList.Clear();
1717 pathList.AddPath(CTGitPath(_T("c:\\test")));
1718 pathList.RemoveAdminPaths();
1719 ATLASSERT(pathList.GetCount()==1);
1722 void SortTest()
1724 CTGitPathList testList;
1725 CTGitPath testPath;
1726 testPath.SetFromUnknown(_T("c:/Z"));
1727 testList.AddPath(testPath);
1728 testPath.SetFromUnknown(_T("c:/B"));
1729 testList.AddPath(testPath);
1730 testPath.SetFromUnknown(_T("c:\\a"));
1731 testList.AddPath(testPath);
1732 testPath.SetFromUnknown(_T("c:/Test"));
1733 testList.AddPath(testPath);
1735 testList.SortByPathname();
1737 ATLASSERT(testList[0].GetWinPathString() == _T("c:\\a"));
1738 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\B"));
1739 ATLASSERT(testList[2].GetWinPathString() == _T("c:\\Test"));
1740 ATLASSERT(testList[3].GetWinPathString() == _T("c:\\Z"));
1743 void RawAppendTest()
1745 CTGitPath testPath(_T("c:/test/"));
1746 testPath.AppendRawString(_T("/Hello"));
1747 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
1749 testPath.AppendRawString(_T("\\T2"));
1750 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
1752 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
1753 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
1754 testBasePath.AppendRawString(testFilePath.GetFileExtension());
1755 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt.ini"));
1758 void PathAppendTest()
1760 CTGitPath testPath(_T("c:/test/"));
1761 testPath.AppendPathString(_T("/Hello"));
1762 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello"));
1764 testPath.AppendPathString(_T("T2"));
1765 ATLASSERT(testPath.GetWinPathString() == _T("c:\\test\\Hello\\T2"));
1767 CTGitPath testFilePath(_T("C:\\windows\\win.ini"));
1768 CTGitPath testBasePath(_T("c:/temp/myfile.txt"));
1769 // You wouldn't want to do this in real life - you'd use append-raw
1770 testBasePath.AppendPathString(testFilePath.GetFileExtension());
1771 ATLASSERT(testBasePath.GetWinPathString() == _T("c:\\temp\\myfile.txt\\.ini"));
1774 void RemoveDuplicatesTest()
1776 CTGitPathList list;
1777 list.AddPath(CTGitPath(_T("Z")));
1778 list.AddPath(CTGitPath(_T("A")));
1779 list.AddPath(CTGitPath(_T("E")));
1780 list.AddPath(CTGitPath(_T("E")));
1782 ATLASSERT(list[2].IsEquivalentTo(list[3]));
1783 ATLASSERT(list[2]==list[3]);
1785 ATLASSERT(list.GetCount() == 4);
1787 list.RemoveDuplicates();
1789 ATLASSERT(list.GetCount() == 3);
1791 ATLASSERT(list[0].GetWinPathString() == _T("A"));
1792 ATLASSERT(list[1].GetWinPathString().Compare(_T("E")) == 0);
1793 ATLASSERT(list[2].GetWinPathString() == _T("Z"));
1796 void RemoveChildrenTest()
1798 CTGitPathList list;
1799 list.AddPath(CTGitPath(_T("c:\\test")));
1800 list.AddPath(CTGitPath(_T("c:\\test\\file")));
1801 list.AddPath(CTGitPath(_T("c:\\testfile")));
1802 list.AddPath(CTGitPath(_T("c:\\parent")));
1803 list.AddPath(CTGitPath(_T("c:\\parent\\child")));
1804 list.AddPath(CTGitPath(_T("c:\\parent\\child1")));
1805 list.AddPath(CTGitPath(_T("c:\\parent\\child2")));
1807 ATLASSERT(list.GetCount() == 7);
1809 list.RemoveChildren();
1811 ATLTRACE("count = %d\n", list.GetCount());
1812 ATLASSERT(list.GetCount() == 3);
1814 list.SortByPathname();
1816 ATLASSERT(list[0].GetWinPathString().Compare(_T("c:\\parent")) == 0);
1817 ATLASSERT(list[1].GetWinPathString().Compare(_T("c:\\test")) == 0);
1818 ATLASSERT(list[2].GetWinPathString().Compare(_T("c:\\testfile")) == 0);
1821 #if defined(_MFC_VER)
1822 void ListLoadingTest()
1824 TCHAR buf[MAX_PATH] = {0};
1825 GetCurrentDirectory(MAX_PATH, buf);
1826 CString sPathList(_T("Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"));
1827 CTGitPathList testList;
1828 testList.LoadFromAsteriskSeparatedString(sPathList);
1830 ATLASSERT(testList.GetCount() == 3);
1831 ATLASSERT(testList[0].GetWinPathString() == CString(buf) + _T("\\Path1"));
1832 ATLASSERT(testList[1].GetWinPathString() == _T("c:\\path2 with spaces and stuff"));
1833 ATLASSERT(testList[2].GetWinPathString() == _T("\\funnypath"));
1835 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T(""));
1836 testList.Clear();
1837 sPathList = _T("c:\\path2 with spaces and stuff*c:\\funnypath\\*");
1838 testList.LoadFromAsteriskSeparatedString(sPathList);
1839 ATLASSERT(testList.GetCommonRoot().GetWinPathString() == _T("c:\\"));
1841 #endif
1843 void ContainingDirectoryTest()
1846 CTGitPath testPath;
1847 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
1848 CTGitPath dir;
1849 dir = testPath.GetContainingDirectory();
1850 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c\\d"));
1851 dir = dir.GetContainingDirectory();
1852 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b\\c"));
1853 dir = dir.GetContainingDirectory();
1854 ATLASSERT(dir.GetWinPathString() == _T("c:\\a\\b"));
1855 dir = dir.GetContainingDirectory();
1856 ATLASSERT(dir.GetWinPathString() == _T("c:\\a"));
1857 dir = dir.GetContainingDirectory();
1858 ATLASSERT(dir.GetWinPathString() == _T("c:\\"));
1859 dir = dir.GetContainingDirectory();
1860 ATLASSERT(dir.IsEmpty());
1861 ATLASSERT(dir.GetWinPathString() == _T(""));
1864 void AncestorTest()
1866 CTGitPath testPath;
1867 testPath.SetFromWin(_T("c:\\windows"));
1868 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\")))==false);
1869 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows"))));
1870 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windowsdummy")))==false);
1871 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\test.txt"))));
1872 ATLASSERT(testPath.IsAncestorOf(CTGitPath(_T("c:\\windows\\system32\\test.txt"))));
1875 void SubversionPathTest()
1877 CTGitPath testPath;
1878 testPath.SetFromWin(_T("c:\\"));
1879 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:") == 0);
1880 testPath.SetFromWin(_T("c:\\folder"));
1881 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/folder") == 0);
1882 testPath.SetFromWin(_T("c:\\a\\b\\c\\d\\e"));
1883 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "c:/a/b/c/d/e") == 0);
1884 testPath.SetFromUnknown(_T("http://testing/"));
1885 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing") == 0);
1886 testPath.SetFromGit(NULL);
1887 ATLASSERT(strlen(testPath.GetGitApiPath(pool))==0);
1888 #if defined(_MFC_VER)
1889 testPath.SetFromUnknown(_T("http://testing again"));
1890 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
1891 testPath.SetFromUnknown(_T("http://testing%20again"));
1892 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20again") == 0);
1893 testPath.SetFromUnknown(_T("http://testing special chars \344\366\374"));
1894 ATLASSERT(strcmp(testPath.GetGitApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0);
1895 #endif
1898 void GetCommonRootTest()
1900 CTGitPath pathA (_T("C:\\Development\\LogDlg.cpp"));
1901 CTGitPath pathB (_T("C:\\Development\\LogDlg.h"));
1902 CTGitPath pathC (_T("C:\\Development\\SomeDir\\LogDlg.h"));
1904 CTGitPathList list;
1905 list.AddPath(pathA);
1906 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development\\LogDlg.cpp"))==0);
1907 list.AddPath(pathB);
1908 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
1909 list.AddPath(pathC);
1910 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("C:\\Development"))==0);
1911 #ifdef _MFC_VER
1912 list.Clear();
1913 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");
1914 list.LoadFromAsteriskSeparatedString(sPathList);
1915 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("D:\\Development\\StExBar"))==0);
1917 list.Clear();
1918 sPathList = _T("c:\\windows\\explorer.exe*c:\\windows");
1919 list.LoadFromAsteriskSeparatedString(sPathList);
1920 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
1922 list.Clear();
1923 sPathList = _T("c:\\windows\\*c:\\windows");
1924 list.LoadFromAsteriskSeparatedString(sPathList);
1925 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
1927 list.Clear();
1928 sPathList = _T("c:\\windows\\system32*c:\\windows\\system");
1929 list.LoadFromAsteriskSeparatedString(sPathList);
1930 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\windows"))==0);
1932 list.Clear();
1933 sPathList = _T("c:\\windowsdummy*c:\\windows");
1934 list.LoadFromAsteriskSeparatedString(sPathList);
1935 ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(_T("c:\\"))==0);
1936 #endif
1939 void ValidPathAndUrlTest()
1941 CTGitPath testPath;
1942 testPath.SetFromWin(_T("c:\\a\\b\\c.test.txt"));
1943 ATLASSERT(testPath.IsValidOnWindows());
1944 testPath.SetFromWin(_T("c:\\"));
1945 ATLASSERT(testPath.IsValidOnWindows());
1946 testPath.SetFromWin(_T("D:\\.Net\\SpindleSearch\\"));
1947 ATLASSERT(testPath.IsValidOnWindows());
1948 testPath.SetFromWin(_T("c"));
1949 ATLASSERT(testPath.IsValidOnWindows());
1950 testPath.SetFromWin(_T("c:\\test folder\\file"));
1951 ATLASSERT(testPath.IsValidOnWindows());
1952 testPath.SetFromWin(_T("c:\\folder\\"));
1953 ATLASSERT(testPath.IsValidOnWindows());
1954 testPath.SetFromWin(_T("c:\\ext.ext.ext\\ext.ext.ext.ext"));
1955 ATLASSERT(testPath.IsValidOnWindows());
1956 testPath.SetFromWin(_T("c:\\.svn"));
1957 ATLASSERT(testPath.IsValidOnWindows());
1958 testPath.SetFromWin(_T("c:\\com\\file"));
1959 ATLASSERT(testPath.IsValidOnWindows());
1960 testPath.SetFromWin(_T("c:\\test\\conf"));
1961 ATLASSERT(testPath.IsValidOnWindows());
1962 testPath.SetFromWin(_T("c:\\LPT"));
1963 ATLASSERT(testPath.IsValidOnWindows());
1964 testPath.SetFromWin(_T("c:\\test\\LPT"));
1965 ATLASSERT(testPath.IsValidOnWindows());
1966 testPath.SetFromWin(_T("c:\\com1test"));
1967 ATLASSERT(testPath.IsValidOnWindows());
1968 testPath.SetFromWin(_T("\\\\?\\c:\\test\\com1test"));
1969 ATLASSERT(testPath.IsValidOnWindows());
1971 testPath.SetFromWin(_T("\\\\Share\\filename"));
1972 ATLASSERT(testPath.IsValidOnWindows());
1973 testPath.SetFromWin(_T("\\\\Share\\filename.extension"));
1974 ATLASSERT(testPath.IsValidOnWindows());
1975 testPath.SetFromWin(_T("\\\\Share\\.svn"));
1976 ATLASSERT(testPath.IsValidOnWindows());
1978 // now the negative tests
1979 testPath.SetFromWin(_T("c:\\test:folder"));
1980 ATLASSERT(!testPath.IsValidOnWindows());
1981 testPath.SetFromWin(_T("c:\\file<name"));
1982 ATLASSERT(!testPath.IsValidOnWindows());
1983 testPath.SetFromWin(_T("c:\\something*else"));
1984 ATLASSERT(!testPath.IsValidOnWindows());
1985 testPath.SetFromWin(_T("c:\\folder\\file?nofile"));
1986 ATLASSERT(!testPath.IsValidOnWindows());
1987 testPath.SetFromWin(_T("c:\\ext.>ension"));
1988 ATLASSERT(!testPath.IsValidOnWindows());
1989 testPath.SetFromWin(_T("c:\\com1\\filename"));
1990 ATLASSERT(!testPath.IsValidOnWindows());
1991 testPath.SetFromWin(_T("c:\\com1"));
1992 ATLASSERT(!testPath.IsValidOnWindows());
1993 testPath.SetFromWin(_T("c:\\com1\\AuX"));
1994 ATLASSERT(!testPath.IsValidOnWindows());
1996 testPath.SetFromWin(_T("\\\\Share\\lpt9\\filename"));
1997 ATLASSERT(!testPath.IsValidOnWindows());
1998 testPath.SetFromWin(_T("\\\\Share\\prn"));
1999 ATLASSERT(!testPath.IsValidOnWindows());
2000 testPath.SetFromWin(_T("\\\\Share\\NUL"));
2001 ATLASSERT(!testPath.IsValidOnWindows());
2003 // now come some URL tests
2004 testPath.SetFromGit(_T("http://myserver.com/repos/trunk"));
2005 ATLASSERT(testPath.IsValidOnWindows());
2006 testPath.SetFromGit(_T("https://myserver.com/repos/trunk/file%20with%20spaces"));
2007 ATLASSERT(testPath.IsValidOnWindows());
2008 testPath.SetFromGit(_T("svn://myserver.com/repos/trunk/file with spaces"));
2009 ATLASSERT(testPath.IsValidOnWindows());
2010 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk"));
2011 ATLASSERT(testPath.IsValidOnWindows());
2012 testPath.SetFromGit(_T("http://localhost:90/repos/trunk"));
2013 ATLASSERT(testPath.IsValidOnWindows());
2014 testPath.SetFromGit(_T("file:///C:/GitRepos/Tester/Proj1/tags/t2"));
2015 ATLASSERT(testPath.IsValidOnWindows());
2016 // and some negative URL tests
2017 testPath.SetFromGit(_T("httpp://myserver.com/repos/trunk"));
2018 ATLASSERT(!testPath.IsValidOnWindows());
2019 testPath.SetFromGit(_T("https://myserver.com/rep:os/trunk/file%20with%20spaces"));
2020 ATLASSERT(!testPath.IsValidOnWindows());
2021 testPath.SetFromGit(_T("svn://myserver.com/rep<os/trunk/file with spaces"));
2022 ATLASSERT(!testPath.IsValidOnWindows());
2023 testPath.SetFromGit(_T("svn+ssh://www.myserver.com/repos/trunk/prn/"));
2024 ATLASSERT(!testPath.IsValidOnWindows());
2025 testPath.SetFromGit(_T("http://localhost:90/repos/trunk/com1"));
2026 ATLASSERT(!testPath.IsValidOnWindows());
2030 } TGitPathTestobject;
2031 #endif
2032 #endif
2034 CTGitPath * CTGitPathList::LookForGitPath(CString path)
2036 int i=0;
2037 for (i = 0; i < this->GetCount(); ++i)
2039 if((*this)[i].GetGitPathString() == path )
2040 return (CTGitPath*)&(*this)[i];
2042 return NULL;
2044 CString CTGitPath::GetActionName(int action)
2046 if(action & CTGitPath::LOGACTIONS_UNMERGED)
2047 return MAKEINTRESOURCE(IDS_PATHACTIONS_CONFLICT);
2048 if(action & CTGitPath::LOGACTIONS_ADDED)
2049 return MAKEINTRESOURCE(IDS_PATHACTIONS_ADD);
2050 if(action & CTGitPath::LOGACTIONS_DELETED)
2051 return MAKEINTRESOURCE(IDS_PATHACTIONS_DELETE);
2052 if(action & CTGitPath::LOGACTIONS_MERGED )
2053 return MAKEINTRESOURCE(IDS_PATHACTIONS_MERGED);
2055 if(action & CTGitPath::LOGACTIONS_MODIFIED)
2056 return MAKEINTRESOURCE(IDS_PATHACTIONS_MODIFIED);
2057 if(action & CTGitPath::LOGACTIONS_REPLACED)
2058 return MAKEINTRESOURCE(IDS_PATHACTIONS_RENAME);
2059 if(action & CTGitPath::LOGACTIONS_COPY)
2060 return MAKEINTRESOURCE(IDS_PATHACTIONS_COPY);
2062 if(action & CTGitPath::LOGACTIONS_FORWORD )
2063 return MAKEINTRESOURCE(IDS_PATHACTIONS_FORWARD);
2065 if (action & CTGitPath::LOGACTIONS_ASSUMEVALID)
2066 return MAKEINTRESOURCE(IDS_PATHACTIONS_ASSUMEUNCHANGED);
2067 if (action & CTGitPath::LOGACTIONS_SKIPWORKTREE)
2068 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIPWORKTREE);
2070 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN);
2072 CString CTGitPath::GetActionName()
2074 return GetActionName(m_Action);
2077 int CTGitPathList::GetAction()
2079 return m_Action;