1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "UnicodeUtils.h"
23 #include "GitAdminDir.h"
24 #include "PathUtils.h"
27 #include "../TortoiseShell/Globals.h"
28 #include "StringUtils.h"
29 #include "SmartHandle.h"
30 #include "../Resources/LoglistCommonResource.h"
35 CTGitPath::CTGitPath(void)
36 : m_bDirectoryKnown(false)
37 , m_bIsDirectory(false)
39 , m_bHasAdminDirKnown(false)
40 , m_bHasAdminDir(false)
41 , m_bIsValidOnWindowsKnown(false)
42 , m_bIsValidOnWindows(false)
43 , m_bIsReadOnly(false)
44 , m_bIsAdminDirKnown(false)
45 , m_bIsAdminDir(false)
47 , m_bExistsKnown(false)
48 , m_bLastWriteTimeKnown(0)
50 , m_bIsSpecialDirectoryKnown(false)
51 , m_bIsSpecialDirectory(false)
52 , m_bIsWCRootKnown(false)
62 CTGitPath::~CTGitPath(void)
65 // Create a TGitPath object from an unknown path type (same as using SetFromUnknown)
66 CTGitPath::CTGitPath(const CString
& sUnknownPath
) : CTGitPath()
68 SetFromUnknown(sUnknownPath
);
71 int CTGitPath::ParserAction(BYTE action
)
73 //action=action.TrimLeft();
74 //TCHAR c=action.GetAt(0);
76 m_Action
|= LOGACTIONS_MODIFIED
;
78 m_Action
|= LOGACTIONS_REPLACED
;
80 m_Action
|= LOGACTIONS_ADDED
;
82 m_Action
|= LOGACTIONS_DELETED
;
84 m_Action
|= LOGACTIONS_UNMERGED
;
86 m_Action
|= LOGACTIONS_DELETED
;
88 m_Action
|= LOGACTIONS_COPY
;
90 m_Action
|= LOGACTIONS_MODIFIED
;
95 int CTGitPath::ParserAction(git_delta_t action
)
97 if (action
== GIT_DELTA_MODIFIED
)
98 m_Action
|= LOGACTIONS_MODIFIED
;
99 if (action
== GIT_DELTA_RENAMED
)
100 m_Action
|= LOGACTIONS_REPLACED
;
101 if (action
== GIT_DELTA_ADDED
)
102 m_Action
|= LOGACTIONS_ADDED
;
103 if (action
== GIT_DELTA_DELETED
)
104 m_Action
|= LOGACTIONS_DELETED
;
105 if (action
== GIT_DELTA_UNMODIFIED
)
106 m_Action
|= LOGACTIONS_UNMERGED
;
107 if (action
== GIT_DELTA_COPIED
)
108 m_Action
|= LOGACTIONS_COPY
;
109 if (action
== GIT_DELTA_TYPECHANGE
)
110 m_Action
|= LOGACTIONS_MODIFIED
;
115 void CTGitPath::SetFromGit(const char* pPath
)
120 int len
= MultiByteToWideChar(CP_UTF8
, 0, pPath
, -1, nullptr, 0);
123 len
= MultiByteToWideChar(CP_UTF8
, 0, pPath
, -1, m_sFwdslashPath
.GetBuffer(len
+1), len
+1);
124 m_sFwdslashPath
.ReleaseBuffer(len
-1);
126 SanitizeRootPath(m_sFwdslashPath
, true);
129 void CTGitPath::SetFromGit(const char* pPath
, bool bIsDirectory
)
132 m_bDirectoryKnown
= true;
133 m_bIsDirectory
= bIsDirectory
;
136 void CTGitPath::SetFromGit(const TCHAR
* pPath
, bool bIsDirectory
)
141 m_sFwdslashPath
= pPath
;
142 SanitizeRootPath(m_sFwdslashPath
, true);
144 m_bDirectoryKnown
= true;
145 m_bIsDirectory
= bIsDirectory
;
148 void CTGitPath::SetFromGit(const CString
& sPath
,CString
*oldpath
)
151 m_sFwdslashPath
= sPath
;
152 SanitizeRootPath(m_sFwdslashPath
, true);
154 m_sOldFwdslashPath
= *oldpath
;
157 void CTGitPath::SetFromWin(LPCTSTR pPath
)
160 m_sBackslashPath
= pPath
;
161 m_sBackslashPath
.Replace(L
"\\\\?\\", L
"");
162 SanitizeRootPath(m_sBackslashPath
, false);
163 ATLASSERT(m_sBackslashPath
.Find('/')<0);
165 void CTGitPath::SetFromWin(const CString
& sPath
)
168 m_sBackslashPath
= sPath
;
169 m_sBackslashPath
.Replace(L
"\\\\?\\", L
"");
170 SanitizeRootPath(m_sBackslashPath
, false);
172 void CTGitPath::SetFromWin(LPCTSTR pPath
, bool bIsDirectory
)
175 m_sBackslashPath
= pPath
;
176 m_bIsDirectory
= bIsDirectory
;
177 m_bDirectoryKnown
= true;
178 SanitizeRootPath(m_sBackslashPath
, false);
180 void CTGitPath::SetFromWin(const CString
& sPath
, bool bIsDirectory
)
183 m_sBackslashPath
= sPath
;
184 m_bIsDirectory
= bIsDirectory
;
185 m_bDirectoryKnown
= true;
186 SanitizeRootPath(m_sBackslashPath
, false);
188 void CTGitPath::SetFromUnknown(const CString
& sPath
)
191 // Just set whichever path we think is most likely to be used
192 // GitAdminDir admin;
194 // if(admin.HasAdminDir(sPath,&p))
195 // SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));
197 SetFwdslashPath(sPath
);
200 LPCTSTR
CTGitPath::GetWinPath() const
204 if(m_sBackslashPath
.IsEmpty())
205 SetBackslashPath(m_sFwdslashPath
);
206 return m_sBackslashPath
;
208 // This is a temporary function, to be used during the migration to
209 // the path class. Ultimately, functions consuming paths should take a CTGitPath&, not a CString
210 const CString
& CTGitPath::GetWinPathString() const
212 if(m_sBackslashPath
.IsEmpty())
213 SetBackslashPath(m_sFwdslashPath
);
214 return m_sBackslashPath
;
217 const CString
& CTGitPath::GetGitPathString() const
219 if(m_sFwdslashPath
.IsEmpty())
220 SetFwdslashPath(m_sBackslashPath
);
221 return m_sFwdslashPath
;
224 const CString
&CTGitPath::GetGitOldPathString() const
226 return m_sOldFwdslashPath
;
229 const CString
& CTGitPath::GetUIPathString() const
231 if (m_sUIPath
.IsEmpty())
232 m_sUIPath
= GetWinPathString();
236 void CTGitPath::SetFwdslashPath(const CString
& sPath
) const
238 CString path
= sPath
;
239 path
.Replace('\\', '/');
241 // We don't leave a trailing /
243 path
.Replace(L
"//?/", L
"");
245 SanitizeRootPath(path
, true);
247 path
.Replace(_T("file:////"), _T("file://"));
248 m_sFwdslashPath
= path
;
251 void CTGitPath::SetBackslashPath(const CString
& sPath
) const
253 CString path
= sPath
;
254 path
.Replace('/', '\\');
255 path
.TrimRight('\\');
256 SanitizeRootPath(path
, false);
257 m_sBackslashPath
= path
;
260 void CTGitPath::SanitizeRootPath(CString
& sPath
, bool bIsForwardPath
) const
262 // Make sure to add the trailing slash to root paths such as 'C:'
263 if (sPath
.GetLength() == 2 && sPath
[1] == ':')
264 sPath
+= (bIsForwardPath
) ? _T("/") : _T("\\");
267 bool CTGitPath::IsDirectory() const
269 if(!m_bDirectoryKnown
)
271 return m_bIsDirectory
;
274 bool CTGitPath::Exists() const
281 bool CTGitPath::Delete(bool bTrash
, bool bShowErrorUI
) const
283 EnsureBackslashPathSet();
284 ::SetFileAttributes(m_sBackslashPath
, FILE_ATTRIBUTE_NORMAL
);
288 if ((bTrash
)||(IsDirectory()))
290 auto buf
= std::make_unique
<TCHAR
[]>(m_sBackslashPath
.GetLength() + 2);
291 _tcscpy_s(buf
.get(), m_sBackslashPath
.GetLength() + 2, m_sBackslashPath
);
292 buf
[m_sBackslashPath
.GetLength()] = 0;
293 buf
[m_sBackslashPath
.GetLength()+1] = 0;
294 bRet
= CTGitPathList::DeleteViaShell(buf
.get(), bTrash
, bShowErrorUI
);
297 bRet
= !!::DeleteFile(m_sBackslashPath
);
300 m_bExistsKnown
= true;
304 __int64
CTGitPath::GetLastWriteTime() const
306 if(!m_bLastWriteTimeKnown
)
308 return m_lastWriteTime
;
311 __int64
CTGitPath::GetFileSize() const
313 if(!m_bDirectoryKnown
)
318 bool CTGitPath::IsReadOnly() const
320 if(!m_bLastWriteTimeKnown
)
322 return m_bIsReadOnly
;
325 void CTGitPath::UpdateAttributes() const
327 EnsureBackslashPathSet();
328 WIN32_FILE_ATTRIBUTE_DATA attribs
;
329 if (m_sBackslashPath
.GetLength() >= 248)
330 m_sLongBackslashPath
= _T("\\\\?\\") + m_sBackslashPath
;
331 if(GetFileAttributesEx(m_sBackslashPath
.GetLength() >= 248 ? m_sLongBackslashPath
: m_sBackslashPath
, GetFileExInfoStandard
, &attribs
))
333 m_bIsDirectory
= !!(attribs
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
334 // don't cast directly to an __int64:
335 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724284%28v=vs.85%29.aspx
336 // "Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value
337 // because it can cause alignment faults on 64-bit Windows."
338 m_lastWriteTime
= static_cast<__int64
>(attribs
.ftLastWriteTime
.dwHighDateTime
) << 32 | attribs
.ftLastWriteTime
.dwLowDateTime
;
342 m_fileSize
= ((INT64
)( (DWORD
)(attribs
.nFileSizeLow
) ) | ( (INT64
)( (DWORD
)(attribs
.nFileSizeHigh
) )<<32 ));
343 m_bIsReadOnly
= !!(attribs
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
);
348 m_bIsDirectory
= false;
351 DWORD err
= GetLastError();
352 if ((err
== ERROR_FILE_NOT_FOUND
)||(err
== ERROR_PATH_NOT_FOUND
)||(err
== ERROR_INVALID_NAME
))
360 m_bDirectoryKnown
= true;
361 m_bLastWriteTimeKnown
= true;
362 m_bExistsKnown
= true;
365 CTGitPath
CTGitPath::GetSubPath(const CTGitPath
&root
)
369 if (CStringUtils::StartsWith(GetWinPathString(), root
.GetWinPathString()))
371 CString str
=GetWinPathString();
372 path
.SetFromWin(str
.Right(str
.GetLength()-root
.GetWinPathString().GetLength()-1));
377 void CTGitPath::EnsureBackslashPathSet() const
379 if(m_sBackslashPath
.IsEmpty())
381 SetBackslashPath(m_sFwdslashPath
);
382 ATLASSERT(IsEmpty() || !m_sBackslashPath
.IsEmpty());
385 void CTGitPath::EnsureFwdslashPathSet() const
387 if(m_sFwdslashPath
.IsEmpty())
389 SetFwdslashPath(m_sBackslashPath
);
390 ATLASSERT(IsEmpty() || !m_sFwdslashPath
.IsEmpty());
395 // Reset all the caches
396 void CTGitPath::Reset()
398 m_bDirectoryKnown
= false;
400 m_bLastWriteTimeKnown
= false;
401 m_bHasAdminDirKnown
= false;
402 m_bIsValidOnWindowsKnown
= false;
403 m_bIsAdminDirKnown
= false;
404 m_bExistsKnown
= false;
405 m_bIsSpecialDirectoryKnown
= false;
406 m_bIsSpecialDirectory
= false;
408 m_sBackslashPath
.Empty();
409 m_sFwdslashPath
.Empty();
411 this->m_StatAdd
.Empty();
412 this->m_StatDel
.Empty();
414 ATLASSERT(IsEmpty());
417 CTGitPath
CTGitPath::GetDirectory() const
419 if ((IsDirectory())||(!Exists()))
421 return GetContainingDirectory();
424 CTGitPath
CTGitPath::GetContainingDirectory() const
426 EnsureBackslashPathSet();
428 CString sDirName
= m_sBackslashPath
.Left(m_sBackslashPath
.ReverseFind('\\'));
429 if(sDirName
.GetLength() == 2 && sDirName
[1] == ':')
431 // This is a root directory, which needs a trailing slash
433 if(sDirName
== m_sBackslashPath
)
435 // We were clearly provided with a root path to start with - we should return nothing now
439 if(sDirName
.GetLength() == 1 && sDirName
[0] == '\\')
441 // We have an UNC path and we already are the root
445 retVal
.SetFromWin(sDirName
);
449 CString
CTGitPath::GetRootPathString() const
451 EnsureBackslashPathSet();
452 CString workingPath
= m_sBackslashPath
;
453 LPTSTR pPath
= workingPath
.GetBuffer(MAX_PATH
); // MAX_PATH ok here.
454 ATLVERIFY(::PathStripToRoot(pPath
));
455 workingPath
.ReleaseBuffer();
460 CString
CTGitPath::GetFilename() const
462 //ATLASSERT(!IsDirectory());
463 return GetFileOrDirectoryName();
466 CString
CTGitPath::GetFileOrDirectoryName() const
468 EnsureBackslashPathSet();
469 return m_sBackslashPath
.Mid(m_sBackslashPath
.ReverseFind('\\')+1);
472 CString
CTGitPath::GetUIFileOrDirectoryName() const
475 return m_sUIPath
.Mid(m_sUIPath
.ReverseFind('\\')+1);
478 CString
CTGitPath::GetFileExtension() const
482 EnsureBackslashPathSet();
483 int dotPos
= m_sBackslashPath
.ReverseFind('.');
484 int slashPos
= m_sBackslashPath
.ReverseFind('\\');
485 if (dotPos
> slashPos
)
486 return m_sBackslashPath
.Mid(dotPos
);
490 CString
CTGitPath::GetBaseFilename() const
493 CString filename
=GetFilename();
494 dot
= filename
.ReverseFind(_T('.'));
496 filename
.Truncate(dot
);
500 bool CTGitPath::ArePathStringsEqual(const CString
& sP1
, const CString
& sP2
)
502 int length
= sP1
.GetLength();
503 if(length
!= sP2
.GetLength())
508 // We work from the end of the strings, because path differences
509 // are more likely to occur at the far end of a string
510 LPCTSTR pP1Start
= sP1
;
511 LPCTSTR pP1
= pP1Start
+(length
-1);
512 LPCTSTR pP2
= ((LPCTSTR
)sP2
)+(length
-1);
515 if(_totlower(*pP1
--) != _totlower(*pP2
--))
521 bool CTGitPath::ArePathStringsEqualWithCase(const CString
& sP1
, const CString
& sP2
)
523 int length
= sP1
.GetLength();
524 if(length
!= sP2
.GetLength())
529 // We work from the end of the strings, because path differences
530 // are more likely to occur at the far end of a string
531 LPCTSTR pP1Start
= sP1
;
532 LPCTSTR pP1
= pP1Start
+(length
-1);
533 LPCTSTR pP2
= ((LPCTSTR
)sP2
)+(length
-1);
536 if((*pP1
--) != (*pP2
--))
542 bool CTGitPath::IsEmpty() const
544 // Check the backward slash path first, since the chance that this
545 // one is set is higher. In case of a 'false' return value it's a little
547 return m_sBackslashPath
.IsEmpty() && m_sFwdslashPath
.IsEmpty();
550 // Test if both paths refer to the same item
551 // Ignores case and slash direction
552 bool CTGitPath::IsEquivalentTo(const CTGitPath
& rhs
) const
554 // Try and find a slash direction which avoids having to convert
556 if(!m_sBackslashPath
.IsEmpty())
558 // *We've* got a \ path - make sure that the RHS also has a \ path
559 rhs
.EnsureBackslashPathSet();
560 return ArePathStringsEqualWithCase(m_sBackslashPath
, rhs
.m_sBackslashPath
);
564 // Assume we've got a fwdslash path and make sure that the RHS has one
565 rhs
.EnsureFwdslashPathSet();
566 return ArePathStringsEqualWithCase(m_sFwdslashPath
, rhs
.m_sFwdslashPath
);
570 bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath
& rhs
) const
572 // Try and find a slash direction which avoids having to convert
574 if(!m_sBackslashPath
.IsEmpty())
576 // *We've* got a \ path - make sure that the RHS also has a \ path
577 rhs
.EnsureBackslashPathSet();
578 return ArePathStringsEqual(m_sBackslashPath
, rhs
.m_sBackslashPath
);
582 // Assume we've got a fwdslash path and make sure that the RHS has one
583 rhs
.EnsureFwdslashPathSet();
584 return ArePathStringsEqual(m_sFwdslashPath
, rhs
.m_sFwdslashPath
);
588 bool CTGitPath::IsAncestorOf(const CTGitPath
& possibleDescendant
) const
590 possibleDescendant
.EnsureBackslashPathSet();
591 EnsureBackslashPathSet();
593 bool bPathStringsEqual
= ArePathStringsEqual(m_sBackslashPath
, possibleDescendant
.m_sBackslashPath
.Left(m_sBackslashPath
.GetLength()));
594 if (m_sBackslashPath
.GetLength() >= possibleDescendant
.GetWinPathString().GetLength())
596 return bPathStringsEqual
;
599 return (bPathStringsEqual
&&
600 ((possibleDescendant
.m_sBackslashPath
[m_sBackslashPath
.GetLength()] == '\\')||
601 (m_sBackslashPath
.GetLength()==3 && m_sBackslashPath
[1]==':')));
604 // Get a string representing the file path, optionally with a base
605 // section stripped off the front.
606 CString
CTGitPath::GetDisplayString(const CTGitPath
* pOptionalBasePath
/* = nullptr*/) const
608 EnsureFwdslashPathSet();
609 if (pOptionalBasePath
)
611 // Find the length of the base-path without having to do an 'ensure' on it
612 int baseLength
= max(pOptionalBasePath
->m_sBackslashPath
.GetLength(), pOptionalBasePath
->m_sFwdslashPath
.GetLength());
614 // Now, chop that baseLength of the front of the path
615 return m_sFwdslashPath
.Mid(baseLength
).TrimLeft('/');
617 return m_sFwdslashPath
;
620 int CTGitPath::Compare(const CTGitPath
& left
, const CTGitPath
& right
)
622 left
.EnsureBackslashPathSet();
623 right
.EnsureBackslashPathSet();
624 return left
.m_sBackslashPath
.CompareNoCase(right
.m_sBackslashPath
);
627 bool operator<(const CTGitPath
& left
, const CTGitPath
& right
)
629 return CTGitPath::Compare(left
, right
) < 0;
632 bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath
& left
, const CTGitPath
& right
)
634 return left
.IsEquivalentTo(right
);
637 bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath
& left
, const CTGitPath
& right
)
639 if (left
.IsAdminDir() && right
.IsAdminDir())
645 l
= l
.GetContainingDirectory();
646 } while(l
.HasAdminDir());
649 r
= r
.GetContainingDirectory();
650 } while(r
.HasAdminDir());
651 return l
.GetContainingDirectory().IsEquivalentTo(r
.GetContainingDirectory());
653 return left
.GetDirectory().IsEquivalentTo(right
.GetDirectory());
656 bool CTGitPath::CheckChild(const CTGitPath
&parent
, const CTGitPath
& child
)
658 return parent
.IsAncestorOf(child
);
661 void CTGitPath::AppendRawString(const CString
& sAppend
)
663 EnsureFwdslashPathSet();
664 CString strCopy
= m_sFwdslashPath
+= sAppend
;
665 SetFromUnknown(strCopy
);
668 void CTGitPath::AppendPathString(const CString
& sAppend
)
670 EnsureBackslashPathSet();
671 CString
cleanAppend(sAppend
);
672 cleanAppend
.Replace('/', '\\');
673 cleanAppend
.TrimLeft('\\');
674 m_sBackslashPath
.TrimRight('\\');
675 CString strCopy
= m_sBackslashPath
;
677 strCopy
+= cleanAppend
;
681 bool CTGitPath::IsWCRoot() const
683 if (m_bIsWCRootKnown
)
686 m_bIsWCRootKnown
= true;
689 CString topDirectory
;
690 if (!IsDirectory() || !HasAdminDir(&topDirectory
))
693 if (IsEquivalentToWithoutCase(topDirectory
))
699 bool CTGitPath::HasAdminDir() const
701 if (m_bHasAdminDirKnown
)
702 return m_bHasAdminDir
;
704 EnsureBackslashPathSet();
705 m_bHasAdminDir
= GitAdminDir::HasAdminDir(m_sBackslashPath
, IsDirectory(), &m_sProjectRoot
);
706 m_bHasAdminDirKnown
= true;
707 return m_bHasAdminDir
;
710 bool CTGitPath::HasSubmodules() const
714 CString path
= m_sProjectRoot
;
715 path
+= _T("\\.gitmodules");
716 if( PathFileExists(path
) )
722 int CTGitPath::GetAdminDirMask() const
726 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir
))
729 // ITEMIS_INGIT will be revoked if necessary in TortoiseShell/ContextMenu.cpp
730 status
|= ITEMIS_INGIT
|ITEMIS_INVERSIONEDFOLDER
;
734 status
|= ITEMIS_FOLDERINGIT
;
737 status
|= ITEMIS_WCROOT
;
739 CString topProjectDir
;
740 if (GitAdminDir::HasAdminDir(GetWinPathString(), false, &topProjectDir
))
742 if (PathFileExists(topProjectDir
+ _T("\\.gitmodules")))
744 CAutoConfig
config(true);
745 git_config_add_file_ondisk(config
, CGit::GetGitPathStringA(topProjectDir
+ _T("\\.gitmodules")), GIT_CONFIG_LEVEL_APP
, FALSE
);
746 CString relativePath
= GetWinPathString().Mid(topProjectDir
.GetLength());
747 relativePath
.Replace(_T("\\"), _T("/"));
748 relativePath
.Trim(_T("/"));
749 CStringA submodulePath
= CUnicodeUtils::GetUTF8(relativePath
);
750 if (git_config_foreach_match(config
, "submodule\\..*\\.path",
751 [](const git_config_entry
*entry
, void *data
) { return entry
->value
== *(CStringA
*)data
? GIT_EUSER
: 0; }, &submodulePath
) == GIT_EUSER
)
752 status
|= ITEMIS_SUBMODULE
;
759 GitAdminDir::GetAdminDirPath(topdir
, dotGitPath
);
761 if (PathFileExists(dotGitPath
+ _T("BISECT_START")))
762 status
|= ITEMIS_BISECT
;
764 if (PathFileExists(dotGitPath
+ _T("MERGE_HEAD")))
765 status
|= ITEMIS_MERGEACTIVE
;
767 if (HasStashDir(dotGitPath
))
768 status
|= ITEMIS_STASH
;
770 if (PathFileExists(dotGitPath
+ _T("svn")))
771 status
|= ITEMIS_GITSVN
;
773 if (PathFileExists(topdir
+ _T("\\.gitmodules")))
774 status
|= ITEMIS_SUBMODULECONTAINER
;
779 bool CTGitPath::HasStashDir(const CString
& dotGitPath
) const
781 if (PathFileExists(dotGitPath
+ L
"refs\\stash"))
784 CAutoFile hfile
= CreateFile(dotGitPath
+ L
"packed-refs", GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_DELETE
| FILE_SHARE_WRITE
, nullptr, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, nullptr);
788 DWORD filesize
= ::GetFileSize(hfile
, nullptr);
793 auto buff
= std::make_unique
<char[]>(filesize
+ 1);
794 ReadFile(hfile
, buff
.get(), filesize
, &size
, nullptr);
795 buff
.get()[filesize
] = '\0';
797 if (size
!= filesize
)
800 for (DWORD i
= 0; i
< filesize
;)
802 if (buff
[i
] == '#' || buff
[i
] == '^')
804 while (buff
[i
] != '\n')
816 while (buff
[i
] != ' ')
827 if (i
<= filesize
- 10 && (buff
[i
+ 10] == '\n' || buff
[i
+ 10] == '\0') && !strncmp("refs/stash", buff
.get() + i
, 10))
829 while (buff
[i
] != '\n')
836 while (buff
[i
] == '\n')
846 bool CTGitPath::HasStashDir() const
849 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir
))
853 GitAdminDir::GetAdminDirPath(topdir
, dotGitPath
);
855 return HasStashDir(dotGitPath
);
858 bool CTGitPath::HasGitSVNDir() const
861 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir
))
865 GitAdminDir::GetAdminDirPath(topdir
, dotGitPath
);
867 return !!PathFileExists(dotGitPath
+ _T("svn"));
869 bool CTGitPath::IsBisectActive() const
872 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir
))
876 GitAdminDir::GetAdminDirPath(topdir
, dotGitPath
);
878 return !!PathFileExists(dotGitPath
+ _T("BISECT_START"));
880 bool CTGitPath::IsMergeActive() const
883 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir
))
887 GitAdminDir::GetAdminDirPath(topdir
, dotGitPath
);
889 return !!PathFileExists(dotGitPath
+ _T("MERGE_HEAD"));
891 bool CTGitPath::HasRebaseApply() const
894 if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir
))
898 GitAdminDir::GetAdminDirPath(topdir
, dotGitPath
);
900 return !!PathFileExists(dotGitPath
+ _T("rebase-apply"));
903 bool CTGitPath::HasAdminDir(CString
*ProjectTopDir
) const
905 if (m_bHasAdminDirKnown
)
908 *ProjectTopDir
= m_sProjectRoot
;
909 return m_bHasAdminDir
;
912 EnsureBackslashPathSet();
913 m_bHasAdminDir
= GitAdminDir::HasAdminDir(m_sBackslashPath
, IsDirectory(), &m_sProjectRoot
);
914 m_bHasAdminDirKnown
= true;
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]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
948 sPattern
= _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
952 std::tr1::wregex
rx(sPattern
, std::tr1::regex_constants::icase
| std::tr1::regex_constants::ECMAScript
);
953 std::tr1::wsmatch match
;
955 std::wstring rmatch
= std::wstring((LPCTSTR
)sMatch
);
956 if (std::tr1::regex_match(rmatch
, match
, rx
))
958 if (std::wstring(match
[0]).compare(sMatch
)==0)
959 m_bIsValidOnWindows
= true;
961 if (m_bIsValidOnWindows
)
963 // now check for illegal filenames
964 std::tr1::wregex
rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), std::tr1::regex_constants::icase
| std::tr1::regex_constants::ECMAScript
);
965 rmatch
= m_sBackslashPath
;
966 if (std::tr1::regex_search(rmatch
, rx2
, std::tr1::regex_constants::match_default
))
967 m_bIsValidOnWindows
= false;
970 catch (std::exception
) {}
972 m_bIsValidOnWindowsKnown
= true;
973 return m_bIsValidOnWindows
;
976 //////////////////////////////////////////////////////////////////////////
978 CTGitPathList::CTGitPathList()
983 // A constructor which allows a path list to be easily built which one initial entry in
984 CTGitPathList::CTGitPathList(const CTGitPath
& firstEntry
)
989 int CTGitPathList::ParserFromLsFile(BYTE_VECTOR
&out
,bool /*staged*/)
997 while (pos
>= 0 && pos
< (int)out
.size())
1002 CGit::StringAppend(&one
, &out
[pos
], CP_UTF8
);
1004 // m_Action is never used and propably never worked (needs to be set after path.SetFromGit)
1005 // also dropped LOGACTIONS_CACHE for 'H'
1006 // path.m_Action=path.ParserAction(out[pos]);
1007 one
.Tokenize(_T("\t"),tabstart
);
1010 path
.SetFromGit(one
.Right(one
.GetLength()-tabstart
));
1016 part
=one
.Tokenize(_T(" "),tabstart
); //Tag
1020 part
=one
.Tokenize(_T(" "),tabstart
); //Mode
1024 part
=one
.Tokenize(_T(" "),tabstart
); //Hash
1028 part
=one
.Tokenize(_T("\t"),tabstart
); //Stage
1032 path
.m_Stage
=_ttol(part
);
1034 this->AddPath(path
);
1036 pos
=out
.findNextString(pos
);
1040 int CTGitPathList::FillUnRev(unsigned int action
, CTGitPathList
*list
, CString
*err
)
1049 count
=list
->GetCount();
1050 for (int i
= 0; i
< count
; ++i
)
1056 if(action
& CTGitPath::LOGACTIONS_IGNORE
)
1061 cmd
=_T("git.exe ls-files --exclude-standard --full-name --others -z");
1066 { cmd
.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z%s -- \"%s\""),
1068 (*list
)[i
].GetWinPath());
1071 BYTE_VECTOR out
, errb
;
1073 if (g_Git
.Run(cmd
, &out
, &errb
))
1076 CGit::StringAppend(err
, &errb
[0], CP_UTF8
, (int)errb
.size());
1082 while (pos
>= 0 && pos
< (int)out
.size())
1085 CGit::StringAppend(&one
, &out
[pos
], CP_UTF8
);
1088 //SetFromGit will clear all status
1089 path
.SetFromGit(one
);
1090 path
.m_Action
=action
;
1093 pos
=out
.findNextString(pos
);
1099 int CTGitPathList::FillBasedOnIndexFlags(unsigned short flag
, unsigned short flagextended
, CTGitPathList
* list
/*nullptr*/)
1104 CAutoRepository
repository(g_Git
.GetGitRepository());
1109 if (git_repository_index(index
.GetPointer(), repository
))
1113 if (list
== nullptr)
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
& flag
) || (e
->flags_extended
& flagextended
)) || !e
->path
)
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())) && CStringUtils::StartsWith(one
, (*list
)[j
].GetGitPathString() + L
'/'))))
1131 //SetFromGit will clear all status
1132 path
.SetFromGit(one
);
1133 if (e
->flags_extended
& GIT_IDXENTRY_SKIP_WORKTREE
)
1134 path
.m_Action
= CTGitPath::LOGACTIONS_SKIPWORKTREE
;
1135 else if (e
->flags
& GIT_IDXENTRY_VALID
)
1136 path
.m_Action
= CTGitPath::LOGACTIONS_ASSUMEVALID
;
1143 int CTGitPathList::ParserFromLog(BYTE_VECTOR
&log
, bool parseDeletes
/*false*/)
1146 std::map
<CString
, size_t> duplicateMap
;
1150 int logend
= (int)log
.size();
1151 while (pos
>= 0 && pos
< logend
)
1163 if (pos
+ 1 >= logend
)
1165 if(log
[pos
+1] ==':')
1167 int end
=log
.find(0,pos
);
1169 int file1
=-1,file2
=-1;
1172 actionstart
=log
.find(' ',end
-6);
1178 if (actionstart
>= logend
)
1181 file1
= log
.find(0,actionstart
);
1187 if( log
[actionstart
] == 'C' || log
[actionstart
] == 'R' )
1190 file1
= log
.find(0,file1
);
1203 CGit::StringAppend(&pathname1
, &log
[file1
], CP_UTF8
);
1205 CGit::StringAppend(&pathname2
, &log
[file2
], CP_UTF8
);
1207 if (actionstart
< 0)
1210 auto existing
= duplicateMap
.find(pathname1
);
1211 if (existing
!= duplicateMap
.end())
1213 CTGitPath
& p
= m_paths
[existing
->second
];
1214 p
.ParserAction(log
[actionstart
]);
1217 p
.m_Action
|= CTGitPath::LOGACTIONS_MERGED
;
1218 m_Action
|= p
.m_Action
;
1222 int ac
=path
.ParserAction(log
[actionstart
] );
1223 ac
|= merged
?CTGitPath::LOGACTIONS_MERGED
:0;
1225 path
.SetFromGit(pathname1
,&pathname2
);
1227 //action must be set after setfromgit. SetFromGit will clear all status.
1231 duplicateMap
.insert(std::pair
<CString
, size_t>(path
.GetGitPathString(), m_paths
.size() - 1));
1243 tabstart
=log
.find('\t',pos
);
1247 CGit::StringAppend(&StatAdd
, &log
[pos
], CP_UTF8
);
1251 tabstart
=log
.find('\t',pos
);
1256 CGit::StringAppend(&StatDel
, &log
[pos
], CP_UTF8
);
1260 if(log
[pos
] == 0) //rename
1263 CGit::StringAppend(&file2
, &log
[pos
], CP_UTF8
);
1264 int sec
=log
.find(0,pos
);
1268 CGit::StringAppend(&file1
, &log
[sec
], CP_UTF8
);
1274 CGit::StringAppend(&file1
, &log
[pos
], CP_UTF8
);
1276 path
.SetFromGit(file1
,&file2
);
1278 auto existing
= duplicateMap
.find(path
.GetGitPathString());
1279 if (existing
!= duplicateMap
.end())
1281 CTGitPath
& p
= m_paths
[existing
->second
];
1282 p
.m_StatAdd
= StatAdd
;
1283 p
.m_StatDel
= StatDel
;
1287 //path.SetFromGit(pathname);
1290 path
.m_StatAdd
=_T("0");
1291 path
.m_StatDel
=_T("0");
1292 path
.m_Action
|= CTGitPath::LOGACTIONS_DELETED
| CTGitPath::LOGACTIONS_MISSING
;
1296 path
.m_StatAdd
=StatAdd
;
1297 path
.m_StatDel
=StatDel
;
1300 duplicateMap
.insert(std::pair
<CString
, size_t>(path
.GetGitPathString(), m_paths
.size() - 1));
1303 pos
=log
.findNextString(pos
);
1308 void CTGitPathList::AddPath(const CTGitPath
& newPath
)
1310 m_paths
.push_back(newPath
);
1311 m_commonBaseDirectory
.Reset();
1313 int CTGitPathList::GetCount() const
1315 return (int)m_paths
.size();
1317 bool CTGitPathList::IsEmpty() const
1319 return m_paths
.empty();
1321 void CTGitPathList::Clear()
1324 m_commonBaseDirectory
.Reset();
1327 const CTGitPath
& CTGitPathList::operator[](INT_PTR index
) const
1329 ATLASSERT(index
>= 0 && index
< (INT_PTR
)m_paths
.size());
1330 return m_paths
[index
];
1333 bool CTGitPathList::AreAllPathsFiles() const
1335 // Look through the vector for any directories - if we find them, return false
1336 return std::find_if(m_paths
.cbegin(), m_paths
.cend(), std::mem_fun_ref(&CTGitPath::IsDirectory
)) == m_paths
.end();
1339 #if defined(_MFC_VER)
1341 bool CTGitPathList::LoadFromFile(const CTGitPath
& filename
)
1347 CStdioFile
file(filename
.GetWinPath(), CFile::typeBinary
| CFile::modeRead
| CFile::shareDenyWrite
);
1349 // for every selected file/folder
1351 while (file
.ReadString(strLine
))
1353 path
.SetFromUnknown(strLine
);
1358 catch (CFileException
* pE
)
1360 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException loading target file list\n");
1361 TCHAR error
[10000] = {0};
1362 pE
->GetErrorMessage(error
, 10000);
1363 // CMessageBox::Show(nullptr, error, _T("TortoiseGit"), MB_ICONERROR);
1370 bool CTGitPathList::WriteToFile(const CString
& sFilename
, bool bANSI
/* = false */) const
1376 CStdioFile
file(sFilename
, CFile::typeText
| CFile::modeReadWrite
| CFile::modeCreate
);
1377 for (const auto& path
: m_paths
)
1379 CStringA line
= CStringA(path
.GetGitPathString()) + '\n';
1380 file
.Write(line
, line
.GetLength());
1386 CStdioFile
file(sFilename
, CFile::typeBinary
| CFile::modeReadWrite
| CFile::modeCreate
);
1387 for (const auto& path
: m_paths
)
1388 file
.WriteString(path
.GetGitPathString() + _T("\n"));
1392 catch (CFileException
* pE
)
1394 CTraceToOutputDebugString::Instance()(__FUNCTION__
": CFileException in writing temp file\n");
1401 void CTGitPathList::LoadFromAsteriskSeparatedString(const CString
& sPathString
)
1407 temp
= sPathString
.Tokenize(_T("*"),pos
);
1410 AddPath(CTGitPath(CPathUtils::GetLongPathname(temp
)));
1414 CString
CTGitPathList::CreateAsteriskSeparatedString() const
1417 for (const auto& path
: m_paths
)
1419 if (!sRet
.IsEmpty())
1421 sRet
+= path
.GetWinPathString();
1428 CTGitPathList::AreAllPathsFilesInOneDirectory() const
1430 // Check if all the paths are files and in the same directory
1431 m_commonBaseDirectory
.Reset();
1432 for (const auto& path
: m_paths
)
1434 if (path
.IsDirectory())
1436 const CTGitPath
& baseDirectory
= path
.GetDirectory();
1437 if(m_commonBaseDirectory
.IsEmpty())
1438 m_commonBaseDirectory
= baseDirectory
;
1439 else if(!m_commonBaseDirectory
.IsEquivalentTo(baseDirectory
))
1442 m_commonBaseDirectory
.Reset();
1449 CTGitPath
CTGitPathList::GetCommonDirectory() const
1451 if (m_commonBaseDirectory
.IsEmpty())
1453 for (const auto& path
: m_paths
)
1455 const CTGitPath
& baseDirectory
= path
.GetDirectory();
1456 if(m_commonBaseDirectory
.IsEmpty())
1457 m_commonBaseDirectory
= baseDirectory
;
1458 else if(!m_commonBaseDirectory
.IsEquivalentTo(baseDirectory
))
1461 m_commonBaseDirectory
.Reset();
1466 // since we only checked strings, not paths,
1467 // we have to make sure now that we really return a *path* here
1468 for (const auto& path
: m_paths
)
1470 if (!m_commonBaseDirectory
.IsAncestorOf(path
))
1472 m_commonBaseDirectory
= m_commonBaseDirectory
.GetContainingDirectory();
1476 return m_commonBaseDirectory
;
1479 CTGitPath
CTGitPathList::GetCommonRoot() const
1484 if (GetCount() == 1)
1487 // first entry is common root for itself
1488 // (add trailing '\\' to detect partial matches of the last path element)
1489 CString root
= m_paths
[0].GetWinPathString() + _T('\\');
1490 int rootLength
= root
.GetLength();
1492 // determine common path string prefix
1493 for (auto it
= m_paths
.cbegin() + 1; it
!= m_paths
.cend(); ++it
)
1495 CString path
= it
->GetWinPathString() + _T('\\');
1497 int newLength
= CStringUtils::GetMatchingLength(root
, path
);
1498 if (newLength
!= rootLength
)
1500 root
.Delete(newLength
, rootLength
);
1501 rootLength
= newLength
;
1505 // remove the last (partial) path element
1507 root
.Delete(root
.ReverseFind(_T('\\')), rootLength
);
1510 return CTGitPath(root
);
1513 void CTGitPathList::SortByPathname(bool bReverse
/*= false*/)
1515 std::sort(m_paths
.begin(), m_paths
.end());
1517 std::reverse(m_paths
.begin(), m_paths
.end());
1520 void CTGitPathList::DeleteAllFiles(bool bTrash
, bool bFilesOnly
, bool bShowErrorUI
)
1522 if (m_paths
.empty())
1524 PathVector::const_iterator it
;
1525 SortByPathname(true); // nested ones first
1528 for (it
= m_paths
.cbegin(); it
!= m_paths
.cend(); ++it
)
1530 if ((it
->Exists()) && ((it
->IsDirectory() != bFilesOnly
) || !bFilesOnly
))
1532 if (!it
->IsDirectory())
1533 ::SetFileAttributes(it
->GetWinPath(), FILE_ATTRIBUTE_NORMAL
);
1535 sPaths
+= it
->GetWinPath();
1539 if (sPaths
.IsEmpty())
1543 DeleteViaShell((LPCTSTR
)sPaths
, bTrash
, bShowErrorUI
);
1547 bool CTGitPathList::DeleteViaShell(LPCTSTR path
, bool bTrash
, bool bShowErrorUI
)
1549 SHFILEOPSTRUCT shop
= {0};
1550 shop
.wFunc
= FO_DELETE
;
1552 shop
.fFlags
= FOF_NOCONFIRMATION
|FOF_NO_CONNECTED_ELEMENTS
;
1554 shop
.fFlags
|= FOF_NOERRORUI
| FOF_SILENT
;
1556 shop
.fFlags
|= FOF_ALLOWUNDO
;
1557 const bool bRet
= (SHFileOperation(&shop
) == 0);
1561 void CTGitPathList::RemoveDuplicates()
1564 // Remove the duplicates
1565 // (Unique moves them to the end of the vector, then erase chops them off)
1566 m_paths
.erase(std::unique(m_paths
.begin(), m_paths
.end(), &CTGitPath::PredLeftEquivalentToRight
), m_paths
.end());
1569 void CTGitPathList::RemoveAdminPaths()
1571 PathVector::iterator it
;
1572 for(it
= m_paths
.begin(); it
!= m_paths
.end(); )
1574 if (it
->IsAdminDir())
1577 it
= m_paths
.begin();
1584 void CTGitPathList::RemovePath(const CTGitPath
& path
)
1586 PathVector::iterator it
;
1587 for(it
= m_paths
.begin(); it
!= m_paths
.end(); ++it
)
1589 if (it
->IsEquivalentTo(path
))
1597 void CTGitPathList::RemoveItem(CTGitPath
& path
)
1599 PathVector::iterator it
;
1600 for(it
= m_paths
.begin(); it
!= m_paths
.end(); ++it
)
1602 if (CTGitPath::ArePathStringsEqualWithCase(it
->GetGitPathString(), path
.GetGitPathString()))
1609 void CTGitPathList::RemoveChildren()
1612 m_paths
.erase(std::unique(m_paths
.begin(), m_paths
.end(), &CTGitPath::CheckChild
), m_paths
.end());
1615 bool CTGitPathList::IsEqual(const CTGitPathList
& list
)
1617 if (list
.GetCount() != GetCount())
1619 for (int i
=0; i
<list
.GetCount(); ++i
)
1621 if (!list
[i
].IsEquivalentTo(m_paths
[i
]))
1627 const CTGitPath
* CTGitPathList::LookForGitPath(const CString
& path
)
1630 for (i
= 0; i
< this->GetCount(); ++i
)
1632 if (CTGitPath::ArePathStringsEqualWithCase((*this)[i
].GetGitPathString(), path
))
1633 return (CTGitPath
*)&(*this)[i
];
1638 CString
CTGitPath::GetActionName(int action
)
1640 if(action
& CTGitPath::LOGACTIONS_UNMERGED
)
1641 return MAKEINTRESOURCE(IDS_PATHACTIONS_CONFLICT
);
1642 if(action
& CTGitPath::LOGACTIONS_ADDED
)
1643 return MAKEINTRESOURCE(IDS_PATHACTIONS_ADD
);
1644 if (action
& CTGitPath::LOGACTIONS_MISSING
)
1645 return MAKEINTRESOURCE(IDS_PATHACTIONS_MISSING
);
1646 if(action
& CTGitPath::LOGACTIONS_DELETED
)
1647 return MAKEINTRESOURCE(IDS_PATHACTIONS_DELETE
);
1648 if(action
& CTGitPath::LOGACTIONS_MERGED
)
1649 return MAKEINTRESOURCE(IDS_PATHACTIONS_MERGED
);
1651 if(action
& CTGitPath::LOGACTIONS_MODIFIED
)
1652 return MAKEINTRESOURCE(IDS_PATHACTIONS_MODIFIED
);
1653 if(action
& CTGitPath::LOGACTIONS_REPLACED
)
1654 return MAKEINTRESOURCE(IDS_PATHACTIONS_RENAME
);
1655 if(action
& CTGitPath::LOGACTIONS_COPY
)
1656 return MAKEINTRESOURCE(IDS_PATHACTIONS_COPY
);
1658 if (action
& CTGitPath::LOGACTIONS_ASSUMEVALID
)
1659 return MAKEINTRESOURCE(IDS_PATHACTIONS_ASSUMEUNCHANGED
);
1660 if (action
& CTGitPath::LOGACTIONS_SKIPWORKTREE
)
1661 return MAKEINTRESOURCE(IDS_PATHACTIONS_SKIPWORKTREE
);
1663 if (action
& CTGitPath::LOGACTIONS_IGNORE
)
1664 return MAKEINTRESOURCE(IDS_PATHACTIONS_IGNORED
);
1666 return MAKEINTRESOURCE(IDS_PATHACTIONS_UNKNOWN
);
1668 CString
CTGitPath::GetActionName()
1670 return GetActionName(m_Action
);
1673 int CTGitPathList::GetAction()
1678 CString
CTGitPath::GetAbbreviatedRename()
1680 if (GetGitOldPathString().IsEmpty())
1681 return GetFileOrDirectoryName();
1683 // Find common prefix which ends with a slash
1684 int prefix_length
= 0;
1685 for (int i
= 0, maxLength
= min(m_sOldFwdslashPath
.GetLength(), m_sFwdslashPath
.GetLength()); i
< maxLength
; ++i
)
1687 if (m_sOldFwdslashPath
[i
] != m_sFwdslashPath
[i
])
1689 if (m_sOldFwdslashPath
[i
] == L
'/')
1690 prefix_length
= i
+ 1;
1693 LPCTSTR oldName
= (LPCTSTR
)m_sOldFwdslashPath
+ m_sOldFwdslashPath
.GetLength();
1694 LPCTSTR newName
= (LPCTSTR
)m_sFwdslashPath
+ m_sFwdslashPath
.GetLength();
1696 int suffix_length
= 0;
1697 int prefix_adjust_for_slash
= (prefix_length
? 1 : 0);
1698 while ((LPCTSTR
)m_sOldFwdslashPath
+ prefix_length
- prefix_adjust_for_slash
<= oldName
&&
1699 (LPCTSTR
)m_sFwdslashPath
+ prefix_length
- prefix_adjust_for_slash
<= newName
&&
1700 *oldName
== *newName
)
1702 if (*oldName
== L
'/')
1703 suffix_length
= m_sOldFwdslashPath
.GetLength() - (int)(oldName
- (LPCTSTR
)m_sOldFwdslashPath
);
1709 * pfx{old_midlen => new_midlen}sfx
1710 * {pfx-old => pfx-new}sfx
1711 * pfx{sfx-old => sfx-new}
1712 * name-old => name-new
1714 int old_midlen
= m_sOldFwdslashPath
.GetLength() - prefix_length
- suffix_length
;
1715 int new_midlen
= m_sFwdslashPath
.GetLength() - prefix_length
- suffix_length
;
1722 if (prefix_length
+ suffix_length
)
1724 ret
= m_sOldFwdslashPath
.Left(prefix_length
);
1727 ret
+= m_sOldFwdslashPath
.Mid(prefix_length
, old_midlen
);
1729 ret
+= m_sFwdslashPath
.Mid(prefix_length
, new_midlen
);
1730 if (prefix_length
+ suffix_length
)
1733 ret
+= m_sFwdslashPath
.Mid(m_sFwdslashPath
.GetLength() - suffix_length
, suffix_length
);