TGitPath.cpp 41.8 KB
Newer Older
李智's avatar
李智 committed
1 2
// TortoiseGit - a Windows shell extension for easy version control

3
// Copyright (C) 2008-2015 - TortoiseGit
4
// Copyright (C) 2003-2008 - TortoiseSVN
李智's avatar
李智 committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
20
#include "stdafx.h"
李智's avatar
李智 committed
21
#include "TGitPath.h"
李智's avatar
李智 committed
22 23 24 25
#include "UnicodeUtils.h"
#include "GitAdminDir.h"
#include "PathUtils.h"
#include <regex>
Sven Strickroth's avatar
Sven Strickroth committed
26
#include "Git.h"
Sven Strickroth's avatar
Sven Strickroth committed
27
#include "../TortoiseShell/Globals.h"
28
#include "StringUtils.h"
29
#include "../Resources/LoglistCommonResource.h"
Sven Strickroth's avatar
Sven Strickroth committed
30
#include <memory>
31

32
extern CGit g_Git;
李智's avatar
李智 committed
33

34 35
CTGitPath::CTGitPath(void)
	: m_bDirectoryKnown(false)
36 37 38 39 40
	, m_bIsDirectory(false)
	, m_bURLKnown(false)
	, m_bHasAdminDirKnown(false)
	, m_bHasAdminDir(false)
	, m_bIsValidOnWindowsKnown(false)
41
	, m_bIsValidOnWindows(false)
42 43 44 45 46 47 48 49 50 51
	, m_bIsReadOnly(false)
	, m_bIsAdminDirKnown(false)
	, m_bIsAdminDir(false)
	, m_bExists(false)
	, m_bExistsKnown(false)
	, m_bLastWriteTimeKnown(0)
	, m_lastWriteTime(0)
	, m_customData(NULL)
	, m_bIsSpecialDirectoryKnown(false)
	, m_bIsSpecialDirectory(false)
Sven Strickroth's avatar
Sven Strickroth committed
52 53
	, m_bIsWCRootKnown(false)
	, m_bIsWCRoot(false)
54
	, m_fileSize(0)
Sven Strickroth's avatar
Sven Strickroth committed
55
	, m_Checked(false)
李智's avatar
李智 committed
56
{
李智's avatar
李智 committed
57
	m_Action=0;
58
	m_ParentNo=0;
59
	m_Stage = 0;
李智's avatar
李智 committed
60 61 62 63 64
}

CTGitPath::~CTGitPath(void)
{
}
李智's avatar
李智 committed
65 66
// Create a TGitPath object from an unknown path type (same as using SetFromUnknown)
CTGitPath::CTGitPath(const CString& sUnknownPath) :
67 68 69 70 71 72
	  m_bDirectoryKnown(false)
	, m_bIsDirectory(false)
	, m_bURLKnown(false)
	, m_bHasAdminDirKnown(false)
	, m_bHasAdminDir(false)
	, m_bIsValidOnWindowsKnown(false)
73
	, m_bIsValidOnWindows(false)
74 75 76 77 78 79 80 81 82 83
	, m_bIsReadOnly(false)
	, m_bIsAdminDirKnown(false)
	, m_bIsAdminDir(false)
	, m_bExists(false)
	, m_bExistsKnown(false)
	, m_bLastWriteTimeKnown(0)
	, m_lastWriteTime(0)
	, m_customData(NULL)
	, m_bIsSpecialDirectoryKnown(false)
	, m_bIsSpecialDirectory(false)
Sven Strickroth's avatar
Sven Strickroth committed
84 85
	, m_bIsWCRootKnown(false)
	, m_bIsWCRoot(false)
86
	, m_fileSize(0)
Sven Strickroth's avatar
Sven Strickroth committed
87
	, m_Checked(false)
李智's avatar
李智 committed
88 89
{
	SetFromUnknown(sUnknownPath);
李智's avatar
李智 committed
90
	m_Action=0;
李智's avatar
李智 committed
91
	m_Stage=0;
92
	m_ParentNo=0;
李智's avatar
李智 committed
93 94
}

李智's avatar
李智 committed
95
int CTGitPath::ParserAction(BYTE action)
李智's avatar
李智 committed
96
{
李智's avatar
李智 committed
97 98 99
	//action=action.TrimLeft();
	//TCHAR c=action.GetAt(0);
	if(action == 'M')
李智's avatar
李智 committed
100
		m_Action|= LOGACTIONS_MODIFIED;
李智's avatar
李智 committed
101
	if(action == 'R')
李智's avatar
李智 committed
102
		m_Action|= LOGACTIONS_REPLACED;
李智's avatar
李智 committed
103
	if(action == 'A')
李智's avatar
李智 committed
104
		m_Action|= LOGACTIONS_ADDED;
李智's avatar
李智 committed
105
	if(action == 'D')
李智's avatar
李智 committed
106
		m_Action|= LOGACTIONS_DELETED;
李智's avatar
李智 committed
107 108
	if(action == 'U')
		m_Action|= LOGACTIONS_UNMERGED;
李智's avatar
李智 committed
109 110
	if(action == 'K')
		m_Action|= LOGACTIONS_DELETED;
111 112
	if(action == 'C' )
		m_Action|= LOGACTIONS_COPY;
ch3cooli's avatar
ch3cooli committed
113 114
	if(action == 'T')
		m_Action|= LOGACTIONS_MODIFIED;
115

李智's avatar
李智 committed
116 117
	return m_Action;
}
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

int CTGitPath::ParserAction(git_delta_t action)
{
	if (action == GIT_DELTA_MODIFIED)
		m_Action |= LOGACTIONS_MODIFIED;
	if (action == GIT_DELTA_RENAMED)
		m_Action |= LOGACTIONS_REPLACED;
	if (action == GIT_DELTA_ADDED)
		m_Action |= LOGACTIONS_ADDED;
	if (action == GIT_DELTA_DELETED)
		m_Action |= LOGACTIONS_DELETED;
	if (action == GIT_DELTA_UNMODIFIED)
		m_Action |= LOGACTIONS_UNMERGED;
	if (action == GIT_DELTA_COPIED)
		m_Action |= LOGACTIONS_COPY;
	if (action == GIT_DELTA_TYPECHANGE)
		m_Action |= LOGACTIONS_MODIFIED;

	return m_Action;
}

李智's avatar
李智 committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
void CTGitPath::SetFromGit(const char* pPath)
{
	Reset();
	if (pPath == NULL)
		return;
	int len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, NULL, 0);
	if (len)
	{
		len = MultiByteToWideChar(CP_UTF8, 0, pPath, -1, m_sFwdslashPath.GetBuffer(len+1), len+1);
		m_sFwdslashPath.ReleaseBuffer(len-1);
	}
	SanitizeRootPath(m_sFwdslashPath, true);
}

void CTGitPath::SetFromGit(const char* pPath, bool bIsDirectory)
{
	SetFromGit(pPath);
	m_bDirectoryKnown = true;
	m_bIsDirectory = bIsDirectory;
}

160 161 162 163 164 165 166 167 168 169 170 171
void CTGitPath::SetFromGit(const TCHAR* pPath, bool bIsDirectory)
{
	Reset();
	if (pPath)
	{
		m_sFwdslashPath = pPath;
		SanitizeRootPath(m_sFwdslashPath, true);
	}
	m_bDirectoryKnown = true;
	m_bIsDirectory = bIsDirectory;
}

李智's avatar
李智 committed
172
void CTGitPath::SetFromGit(const CString& sPath,CString *oldpath)
李智's avatar
李智 committed
173 174 175 176
{
	Reset();
	m_sFwdslashPath = sPath;
	SanitizeRootPath(m_sFwdslashPath, true);
李智's avatar
李智 committed
177 178
	if(oldpath)
		m_sOldFwdslashPath = *oldpath;
李智's avatar
李智 committed
179 180 181 182 183 184
}

void CTGitPath::SetFromWin(LPCTSTR pPath)
{
	Reset();
	m_sBackslashPath = pPath;
185
	m_sBackslashPath.Replace(L"\\\\?\\", L"");
李智's avatar
李智 committed
186 187 188 189 190 191 192
	SanitizeRootPath(m_sBackslashPath, false);
	ATLASSERT(m_sBackslashPath.Find('/')<0);
}
void CTGitPath::SetFromWin(const CString& sPath)
{
	Reset();
	m_sBackslashPath = sPath;
193
	m_sBackslashPath.Replace(L"\\\\?\\", L"");
李智's avatar
李智 committed
194 195
	SanitizeRootPath(m_sBackslashPath, false);
}
196 197 198 199 200 201 202 203
void CTGitPath::SetFromWin(LPCTSTR pPath, bool bIsDirectory)
{
	Reset();
	m_sBackslashPath = pPath;
	m_bIsDirectory = bIsDirectory;
	m_bDirectoryKnown = true;
	SanitizeRootPath(m_sBackslashPath, false);
}
李智's avatar
李智 committed
204 205 206 207 208 209 210 211 212 213 214 215
void CTGitPath::SetFromWin(const CString& sPath, bool bIsDirectory)
{
	Reset();
	m_sBackslashPath = sPath;
	m_bIsDirectory = bIsDirectory;
	m_bDirectoryKnown = true;
	SanitizeRootPath(m_sBackslashPath, false);
}
void CTGitPath::SetFromUnknown(const CString& sPath)
{
	Reset();
	// Just set whichever path we think is most likely to be used
李智's avatar
李智 committed
216 217 218 219 220 221
//	GitAdminDir admin;
//	CString p;
//	if(admin.HasAdminDir(sPath,&p))
//		SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));
//	else
		SetFwdslashPath(sPath);
李智's avatar
李智 committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235
}

LPCTSTR CTGitPath::GetWinPath() const
{
	if(IsEmpty())
	{
		return _T("");
	}
	if(m_sBackslashPath.IsEmpty())
	{
		SetBackslashPath(m_sFwdslashPath);
	}
	return m_sBackslashPath;
}
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
236
// This is a temporary function, to be used during the migration to
李智's avatar
李智 committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
// the path class.  Ultimately, functions consuming paths should take a CTGitPath&, not a CString
const CString& CTGitPath::GetWinPathString() const
{
	if(m_sBackslashPath.IsEmpty())
	{
		SetBackslashPath(m_sFwdslashPath);
	}
	return m_sBackslashPath;
}

const CString& CTGitPath::GetGitPathString() const
{
	if(m_sFwdslashPath.IsEmpty())
	{
		SetFwdslashPath(m_sBackslashPath);
	}
	return m_sFwdslashPath;
}

李智's avatar
李智 committed
256 257 258 259
const CString &CTGitPath::GetGitOldPathString() const
{
	return m_sOldFwdslashPath;
}
李智's avatar
李智 committed
260 261 262 263 264

const CString& CTGitPath::GetUIPathString() const
{
	if (m_sUIPath.IsEmpty())
	{
Sven Strickroth's avatar
Sven Strickroth committed
265
		m_sUIPath = GetWinPathString();
李智's avatar
李智 committed
266 267 268 269 270 271
	}
	return m_sUIPath;
}

void CTGitPath::SetFwdslashPath(const CString& sPath) const
{
272 273
	CString path = sPath;
	path.Replace('\\', '/');
李智's avatar
李智 committed
274 275

	// We don't leave a trailing /
276 277
	path.TrimRight('/');
	path.Replace(L"//?/", L"");
李智's avatar
李智 committed
278

279
	SanitizeRootPath(path, true);
李智's avatar
李智 committed
280

281 282
	path.Replace(_T("file:////"), _T("file://"));
	m_sFwdslashPath = path;
李智's avatar
李智 committed
283 284 285 286 287 288

	m_sUTF8FwdslashPath.Empty();
}

void CTGitPath::SetBackslashPath(const CString& sPath) const
{
289 290 291 292 293
	CString path = sPath;
	path.Replace('/', '\\');
	path.TrimRight('\\');
	SanitizeRootPath(path, false);
	m_sBackslashPath = path;
李智's avatar
李智 committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
}

void CTGitPath::SetUTF8FwdslashPath(const CString& sPath) const
{
	m_sUTF8FwdslashPath = CUnicodeUtils::GetUTF8(sPath);
}

void CTGitPath::SanitizeRootPath(CString& sPath, bool bIsForwardPath) const
{
	// Make sure to add the trailing slash to root paths such as 'C:'
	if (sPath.GetLength() == 2 && sPath[1] == ':')
	{
		sPath += (bIsForwardPath) ? _T("/") : _T("\\");
	}
}

bool CTGitPath::IsDirectory() const
{
	if(!m_bDirectoryKnown)
	{
		UpdateAttributes();
	}
	return m_bIsDirectory;
}

bool CTGitPath::Exists() const
{
	if (!m_bExistsKnown)
	{
		UpdateAttributes();
	}
	return m_bExists;
}

328
bool CTGitPath::Delete(bool bTrash, bool bShowErrorUI) const
李智's avatar
李智 committed
329 330 331 332 333 334 335 336
{
	EnsureBackslashPathSet();
	::SetFileAttributes(m_sBackslashPath, FILE_ATTRIBUTE_NORMAL);
	bool bRet = false;
	if (Exists())
	{
		if ((bTrash)||(IsDirectory()))
		{
Sven Strickroth's avatar
Sven Strickroth committed
337 338
			std::unique_ptr<TCHAR[]> buf(new TCHAR[m_sBackslashPath.GetLength() + 2]);
			_tcscpy_s(buf.get(), m_sBackslashPath.GetLength() + 2, m_sBackslashPath);
李智's avatar
李智 committed
339 340
			buf[m_sBackslashPath.GetLength()] = 0;
			buf[m_sBackslashPath.GetLength()+1] = 0;
341
			bRet = CTGitPathList::DeleteViaShell(buf.get(), bTrash, bShowErrorUI);
李智's avatar
李智 committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
		}
		else
		{
			bRet = !!::DeleteFile(m_sBackslashPath);
		}
	}
	m_bExists = false;
	m_bExistsKnown = true;
	return bRet;
}

__int64  CTGitPath::GetLastWriteTime() const
{
	if(!m_bLastWriteTimeKnown)
	{
		UpdateAttributes();
	}
	return m_lastWriteTime;
}

362 363 364 365 366 367 368 369 370
__int64 CTGitPath::GetFileSize() const
{
	if(!m_bDirectoryKnown)
	{
		UpdateAttributes();
	}
	return m_fileSize;
}

李智's avatar
李智 committed
371 372 373 374 375 376 377 378 379 380 381 382 383
bool CTGitPath::IsReadOnly() const
{
	if(!m_bLastWriteTimeKnown)
	{
		UpdateAttributes();
	}
	return m_bIsReadOnly;
}

void CTGitPath::UpdateAttributes() const
{
	EnsureBackslashPathSet();
	WIN32_FILE_ATTRIBUTE_DATA attribs;
384 385 386
	if (m_sBackslashPath.GetLength() >= 248)
		m_sLongBackslashPath = _T("\\\\?\\") + m_sBackslashPath;
	if(GetFileAttributesEx(m_sBackslashPath.GetLength() >= 248 ? m_sLongBackslashPath : m_sBackslashPath, GetFileExInfoStandard, &attribs))
李智's avatar
李智 committed
387 388
	{
		m_bIsDirectory = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
ch3cooli's avatar
ch3cooli committed
389 390 391 392 393
		// don't cast directly to an __int64:
		// http://msdn.microsoft.com/en-us/library/windows/desktop/ms724284%28v=vs.85%29.aspx
		// "Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value
		// because it can cause alignment faults on 64-bit Windows."
		m_lastWriteTime = static_cast<__int64>(attribs.ftLastWriteTime.dwHighDateTime) << 32 | attribs.ftLastWriteTime.dwLowDateTime;
394 395 396 397 398 399 400 401
		if (m_bIsDirectory)
		{
			m_fileSize = 0;
		}
		else
		{
			m_fileSize = ((INT64)( (DWORD)(attribs.nFileSizeLow) ) | ( (INT64)( (DWORD)(attribs.nFileSizeHigh) )<<32 ));
		}
李智's avatar
李智 committed
402 403 404 405 406
		m_bIsReadOnly = !!(attribs.dwFileAttributes & FILE_ATTRIBUTE_READONLY);
		m_bExists = true;
	}
	else
	{
407 408 409
		m_bIsDirectory = false;
		m_lastWriteTime = 0;
		m_fileSize = 0;
李智's avatar
李智 committed
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
		DWORD err = GetLastError();
		if ((err == ERROR_FILE_NOT_FOUND)||(err == ERROR_PATH_NOT_FOUND)||(err == ERROR_INVALID_NAME))
		{
			m_bExists = false;
		}
		else
		{
			m_bExists = true;
			return;
		}
	}
	m_bDirectoryKnown = true;
	m_bLastWriteTimeKnown = true;
	m_bExistsKnown = true;
}

李智's avatar
李智 committed
426
CTGitPath CTGitPath::GetSubPath(const CTGitPath &root)
427 428
{
	CTGitPath path;
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
429

430 431 432 433 434 435 436
	if(GetWinPathString().Left(root.GetWinPathString().GetLength()) == root.GetWinPathString())
	{
		CString str=GetWinPathString();
		path.SetFromWin(str.Right(str.GetLength()-root.GetWinPathString().GetLength()-1));
	}
	return path;
}
李智's avatar
李智 committed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471

void CTGitPath::EnsureBackslashPathSet() const
{
	if(m_sBackslashPath.IsEmpty())
	{
		SetBackslashPath(m_sFwdslashPath);
		ATLASSERT(IsEmpty() || !m_sBackslashPath.IsEmpty());
	}
}
void CTGitPath::EnsureFwdslashPathSet() const
{
	if(m_sFwdslashPath.IsEmpty())
	{
		SetFwdslashPath(m_sBackslashPath);
		ATLASSERT(IsEmpty() || !m_sFwdslashPath.IsEmpty());
	}
}


// Reset all the caches
void CTGitPath::Reset()
{
	m_bDirectoryKnown = false;
	m_bURLKnown = false;
	m_bLastWriteTimeKnown = false;
	m_bHasAdminDirKnown = false;
	m_bIsValidOnWindowsKnown = false;
	m_bIsAdminDirKnown = false;
	m_bExistsKnown = false;
	m_bIsSpecialDirectoryKnown = false;
	m_bIsSpecialDirectory = false;

	m_sBackslashPath.Empty();
	m_sFwdslashPath.Empty();
	m_sUTF8FwdslashPath.Empty();
李智's avatar
李智 committed
472 473 474
	this->m_Action=0;
	this->m_StatAdd=_T("");
	this->m_StatDel=_T("");
475
	m_ParentNo=0;
李智's avatar
李智 committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
	ATLASSERT(IsEmpty());
}

CTGitPath CTGitPath::GetDirectory() const
{
	if ((IsDirectory())||(!Exists()))
	{
		return *this;
	}
	return GetContainingDirectory();
}

CTGitPath CTGitPath::GetContainingDirectory() const
{
	EnsureBackslashPathSet();

	CString sDirName = m_sBackslashPath.Left(m_sBackslashPath.ReverseFind('\\'));
	if(sDirName.GetLength() == 2 && sDirName[1] == ':')
	{
		// This is a root directory, which needs a trailing slash
		sDirName += '\\';
		if(sDirName == m_sBackslashPath)
		{
			// We were clearly provided with a root path to start with - we should return nothing now
			sDirName.Empty();
		}
	}
	if(sDirName.GetLength() == 1 && sDirName[0] == '\\')
	{
		// We have an UNC path and we already are the root
		sDirName.Empty();
	}
	CTGitPath retVal;
	retVal.SetFromWin(sDirName);
	return retVal;
}

CString CTGitPath::GetRootPathString() const
{
	EnsureBackslashPathSet();
	CString workingPath = m_sBackslashPath;
	LPTSTR pPath = workingPath.GetBuffer(MAX_PATH);		// MAX_PATH ok here.
	ATLVERIFY(::PathStripToRoot(pPath));
	workingPath.ReleaseBuffer();
	return workingPath;
}


CString CTGitPath::GetFilename() const
{
526
	//ATLASSERT(!IsDirectory());
李智's avatar
李智 committed
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
	return GetFileOrDirectoryName();
}

CString CTGitPath::GetFileOrDirectoryName() const
{
	EnsureBackslashPathSet();
	return m_sBackslashPath.Mid(m_sBackslashPath.ReverseFind('\\')+1);
}

CString CTGitPath::GetUIFileOrDirectoryName() const
{
	GetUIPathString();
	return m_sUIPath.Mid(m_sUIPath.ReverseFind('\\')+1);
}

CString CTGitPath::GetFileExtension() const
{
	if(!IsDirectory())
	{
		EnsureBackslashPathSet();
		int dotPos = m_sBackslashPath.ReverseFind('.');
		int slashPos = m_sBackslashPath.ReverseFind('\\');
		if (dotPos > slashPos)
			return m_sBackslashPath.Mid(dotPos);
	}
	return CString();
}
李智's avatar
李智 committed
554 555 556 557 558 559
CString CTGitPath::GetBaseFilename() const
{
	int dot;
	CString filename=GetFilename();
	dot = filename.ReverseFind(_T('.'));
	if(dot>0)
560
		return filename.Left(dot);
李智's avatar
李智 committed
561 562 563
	else
		return filename;
}
李智's avatar
李智 committed
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664

bool CTGitPath::ArePathStringsEqual(const CString& sP1, const CString& sP2)
{
	int length = sP1.GetLength();
	if(length != sP2.GetLength())
	{
		// Different lengths
		return false;
	}
	// We work from the end of the strings, because path differences
	// are more likely to occur at the far end of a string
	LPCTSTR pP1Start = sP1;
	LPCTSTR pP1 = pP1Start+(length-1);
	LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
	while(length-- > 0)
	{
		if(_totlower(*pP1--) != _totlower(*pP2--))
		{
			return false;
		}
	}
	return true;
}

bool CTGitPath::ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2)
{
	int length = sP1.GetLength();
	if(length != sP2.GetLength())
	{
		// Different lengths
		return false;
	}
	// We work from the end of the strings, because path differences
	// are more likely to occur at the far end of a string
	LPCTSTR pP1Start = sP1;
	LPCTSTR pP1 = pP1Start+(length-1);
	LPCTSTR pP2 = ((LPCTSTR)sP2)+(length-1);
	while(length-- > 0)
	{
		if((*pP1--) != (*pP2--))
		{
			return false;
		}
	}
	return true;
}

bool CTGitPath::IsEmpty() const
{
	// Check the backward slash path first, since the chance that this
	// one is set is higher. In case of a 'false' return value it's a little
	// bit faster.
	return m_sBackslashPath.IsEmpty() && m_sFwdslashPath.IsEmpty();
}

// Test if both paths refer to the same item
// Ignores case and slash direction
bool CTGitPath::IsEquivalentTo(const CTGitPath& rhs) const
{
	// Try and find a slash direction which avoids having to convert
	// both filenames
	if(!m_sBackslashPath.IsEmpty())
	{
		// *We've* got a \ path - make sure that the RHS also has a \ path
		rhs.EnsureBackslashPathSet();
		return ArePathStringsEqualWithCase(m_sBackslashPath, rhs.m_sBackslashPath);
	}
	else
	{
		// Assume we've got a fwdslash path and make sure that the RHS has one
		rhs.EnsureFwdslashPathSet();
		return ArePathStringsEqualWithCase(m_sFwdslashPath, rhs.m_sFwdslashPath);
	}
}

bool CTGitPath::IsEquivalentToWithoutCase(const CTGitPath& rhs) const
{
	// Try and find a slash direction which avoids having to convert
	// both filenames
	if(!m_sBackslashPath.IsEmpty())
	{
		// *We've* got a \ path - make sure that the RHS also has a \ path
		rhs.EnsureBackslashPathSet();
		return ArePathStringsEqual(m_sBackslashPath, rhs.m_sBackslashPath);
	}
	else
	{
		// Assume we've got a fwdslash path and make sure that the RHS has one
		rhs.EnsureFwdslashPathSet();
		return ArePathStringsEqual(m_sFwdslashPath, rhs.m_sFwdslashPath);
	}
}

bool CTGitPath::IsAncestorOf(const CTGitPath& possibleDescendant) const
{
	possibleDescendant.EnsureBackslashPathSet();
	EnsureBackslashPathSet();

	bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength()));
	if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength())
	{
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
665
		return bPathStringsEqual;
李智's avatar
李智 committed
666
	}
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
667 668

	return (bPathStringsEqual &&
李智's avatar
李智 committed
669 670 671 672
			((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')||
			(m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':')));
}

Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
673
// Get a string representing the file path, optionally with a base
李智's avatar
李智 committed
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
// section stripped off the front.
CString CTGitPath::GetDisplayString(const CTGitPath* pOptionalBasePath /* = NULL*/) const
{
	EnsureFwdslashPathSet();
	if(pOptionalBasePath != NULL)
	{
		// Find the length of the base-path without having to do an 'ensure' on it
		int baseLength = max(pOptionalBasePath->m_sBackslashPath.GetLength(), pOptionalBasePath->m_sFwdslashPath.GetLength());

		// Now, chop that baseLength of the front of the path
		return m_sFwdslashPath.Mid(baseLength).TrimLeft('/');
	}
	return m_sFwdslashPath;
}

int CTGitPath::Compare(const CTGitPath& left, const CTGitPath& right)
{
	left.EnsureBackslashPathSet();
	right.EnsureBackslashPathSet();
	return left.m_sBackslashPath.CompareNoCase(right.m_sBackslashPath);
}

bool operator<(const CTGitPath& left, const CTGitPath& right)
{
	return CTGitPath::Compare(left, right) < 0;
}

bool CTGitPath::PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right)
{
	return left.IsEquivalentTo(right);
}

bool CTGitPath::PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right)
{
	if (left.IsAdminDir() && right.IsAdminDir())
	{
		CTGitPath l = left;
		CTGitPath r = right;
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
712
		do
李智's avatar
李智 committed
713 714 715
		{
			l = l.GetContainingDirectory();
		} while(l.HasAdminDir());
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
716
		do
李智's avatar
李智 committed
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
		{
			r = r.GetContainingDirectory();
		} while(r.HasAdminDir());
		return l.GetContainingDirectory().IsEquivalentTo(r.GetContainingDirectory());
	}
	return left.GetDirectory().IsEquivalentTo(right.GetDirectory());
}

bool CTGitPath::CheckChild(const CTGitPath &parent, const CTGitPath& child)
{
	return parent.IsAncestorOf(child);
}

void CTGitPath::AppendRawString(const CString& sAppend)
{
	EnsureFwdslashPathSet();
	CString strCopy = m_sFwdslashPath += sAppend;
	SetFromUnknown(strCopy);
}

void CTGitPath::AppendPathString(const CString& sAppend)
{
	EnsureBackslashPathSet();
	CString cleanAppend(sAppend);
	cleanAppend.Replace('/', '\\');
	cleanAppend.TrimLeft('\\');
	m_sBackslashPath.TrimRight('\\');
744 745 746
	CString strCopy = m_sBackslashPath;
	strCopy += _T('\\');
	strCopy += cleanAppend;
李智's avatar
李智 committed
747 748 749
	SetFromWin(strCopy);
}

Sven Strickroth's avatar
Sven Strickroth committed
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
bool CTGitPath::IsWCRoot() const
{
	if (m_bIsWCRootKnown)
		return m_bIsWCRoot;

	m_bIsWCRootKnown = true;
	m_bIsWCRoot = false;

	CString topDirectory;
	if (!IsDirectory() || !HasAdminDir(&topDirectory))
	{
		return m_bIsWCRoot;
	}

	if (IsEquivalentToWithoutCase(topDirectory))
	{
		m_bIsWCRoot = true;
	}

	return m_bIsWCRoot;
}

李智's avatar
李智 committed
772 773 774 775 776 777
bool CTGitPath::HasAdminDir() const
{
	if (m_bHasAdminDirKnown)
		return m_bHasAdminDir;

	EnsureBackslashPathSet();
778
	m_bHasAdminDir = GitAdminDir::HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
李智's avatar
李智 committed
779 780 781 782
	m_bHasAdminDirKnown = true;
	return m_bHasAdminDir;
}

783 784
bool CTGitPath::HasSubmodules() const
{
Sven Strickroth's avatar
Sven Strickroth committed
785 786 787 788 789 790 791 792
	if (HasAdminDir())
	{
		CString path = m_sProjectRoot;
		path += _T("\\.gitmodules");
		if( PathFileExists(path) )
			return true;
	}
	return false;
793 794
}

795 796 797
int CTGitPath::GetAdminDirMask() const
{
	int status = 0;
798
	CString topdir;
799
	if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
800 801 802 803
	{
		return status;
	}

804 805
	// ITEMIS_INGIT will be revoked if necessary in TortoiseShell/ContextMenu.cpp
	status |= ITEMIS_INGIT|ITEMIS_INVERSIONEDFOLDER;
806

807 808
	if (IsDirectory())
	{
809
		status |= ITEMIS_FOLDERINGIT;
810
		if (IsWCRoot())
811
		{
812
			status |= ITEMIS_WCROOT;
813

Sven Strickroth's avatar
Sven Strickroth committed
814
			CString topProjectDir;
815
			if (GitAdminDir::HasAdminDir(GetWinPathString(), false, &topProjectDir))
Sven Strickroth's avatar
Sven Strickroth committed
816 817 818
			{
				if (PathFileExists(topProjectDir + _T("\\.gitmodules")))
				{
819
					CAutoConfig config(true);
820
					git_config_add_file_ondisk(config, CGit::GetGitPathStringA(topProjectDir + _T("\\.gitmodules")), GIT_CONFIG_LEVEL_APP, FALSE);
Sven Strickroth's avatar
Sven Strickroth committed
821 822 823
					CString relativePath = GetWinPathString().Mid(topProjectDir.GetLength());
					relativePath.Replace(_T("\\"), _T("/"));
					relativePath.Trim(_T("/"));
824 825 826
					CStringA submodulePath = CUnicodeUtils::GetUTF8(relativePath);
					if (git_config_foreach_match(config, "submodule\\..*\\.path", 
						[](const git_config_entry *entry, void *data) { return entry->value == *(CStringA *)data ? GIT_EUSER : 0; }, &submodulePath) == GIT_EUSER)
Sven Strickroth's avatar
Sven Strickroth committed
827 828 829
						status |= ITEMIS_SUBMODULE;
				}
			}
830
		}
831
	}
832

833
	CString dotGitPath;
834
	GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
835 836

	if (PathFileExists(dotGitPath + _T("BISECT_START")))
Sven Strickroth's avatar
Sven Strickroth committed
837 838
		status |= ITEMIS_BISECT;

839 840 841
	if (PathFileExists(dotGitPath + _T("MERGE_HEAD")))
		status |= ITEMIS_MERGEACTIVE;

842
	if (PathFileExists(dotGitPath + _T("refs\\stash")))
843
		status |= ITEMIS_STASH;
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
844

845
	if (PathFileExists(dotGitPath + _T("svn")))
846 847
		status |= ITEMIS_GITSVN;

848
	if (PathFileExists(topdir + _T("\\.gitmodules")))
849
		status |= ITEMIS_SUBMODULECONTAINER;
850 851 852 853 854 855 856

	return status;
}

bool CTGitPath::HasStashDir() const
{
	CString topdir;
857
	if(!GitAdminDir::HasAdminDir(GetWinPathString(),&topdir))
858 859 860
	{
		return false;
	}
861 862

	CString dotGitPath;
863
	GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
864 865

	return !!PathFileExists(dotGitPath + _T("\\refs\\stash"));
866
}
867 868 869
bool CTGitPath::HasGitSVNDir() const
{
	CString topdir;
870
	if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
871 872 873
	{
		return false;
	}
874 875

	CString dotGitPath;
876
	GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
877 878

	return !!PathFileExists(dotGitPath + _T("svn"));
879
}
880 881 882
bool CTGitPath::IsBisectActive() const
{
	CString topdir;
883
	if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
884 885 886
	{
		return false;
	}
887 888

	CString dotGitPath;
889
	GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
890 891

	return !!PathFileExists(dotGitPath + _T("BISECT_START"));
892
}
893 894 895
bool CTGitPath::IsMergeActive() const
{
	CString topdir;
896
	if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
897 898 899
	{
		return false;
	}
900 901

	CString dotGitPath;
902
	GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
903 904

	return !!PathFileExists(dotGitPath + _T("MERGE_HEAD"));
905
}
李智's avatar
李智 committed
906 907 908
bool CTGitPath::HasRebaseApply() const
{
	CString topdir;
909
	if (!GitAdminDir::HasAdminDir(GetWinPathString(), &topdir))
李智's avatar
李智 committed
910 911 912
	{
		return false;
	}
913 914

	CString dotGitPath;
915
	GitAdminDir::GetAdminDirPath(topdir, dotGitPath);
916 917

	return !!PathFileExists(dotGitPath + _T("rebase-apply"));
李智's avatar
李智 committed
918 919
}

920 921 922 923 924 925 926 927 928 929
bool CTGitPath::HasAdminDir(CString *ProjectTopDir) const
{
	if (m_bHasAdminDirKnown)
	{
		if (ProjectTopDir)
			*ProjectTopDir = m_sProjectRoot;
		return m_bHasAdminDir;
	}

	EnsureBackslashPathSet();
930
	m_bHasAdminDir = GitAdminDir::HasAdminDir(m_sBackslashPath, IsDirectory(), &m_sProjectRoot);
931 932 933 934 935 936
	m_bHasAdminDirKnown = true;
	if (ProjectTopDir)
		*ProjectTopDir = m_sProjectRoot;
	return m_bHasAdminDir;
}

李智's avatar
李智 committed
937 938 939 940
bool CTGitPath::IsAdminDir() const
{
	if (m_bIsAdminDirKnown)
		return m_bIsAdminDir;
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
941

李智's avatar
李智 committed
942
	EnsureBackslashPathSet();
943
	m_bIsAdminDir = GitAdminDir::IsAdminDirPath(m_sBackslashPath);
李智's avatar
李智 committed
944 945 946 947 948 949 950 951 952 953 954 955
	m_bIsAdminDirKnown = true;
	return m_bIsAdminDir;
}

bool CTGitPath::IsValidOnWindows() const
{
	if (m_bIsValidOnWindowsKnown)
		return m_bIsValidOnWindows;

	m_bIsValidOnWindows = false;
	EnsureBackslashPathSet();
	CString sMatch = m_sBackslashPath + _T("\r\n");
ch3cooli's avatar
ch3cooli committed
956
	std::wstring sPattern;
李智's avatar
李智 committed
957 958 959 960 961 962 963 964 965 966 967 968 969 970
	// the 'file://' URL is just a normal windows path:
	if (sMatch.Left(7).CompareNoCase(_T("file:\\\\"))==0)
	{
		sMatch = sMatch.Mid(7);
		sMatch.TrimLeft(_T("\\"));
		sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
	}
	else
	{
		sPattern = _T("^(\\\\\\\\\\?\\\\)?(([a-zA-Z]:|\\\\)\\\\)?(((\\.)|(\\.\\.)|([^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?))\\\\)*[^\\\\/:\\*\\?\"\\|<> ](([^\\\\/:\\*\\?\"\\|<>\\. ])|([^\\\\/:\\*\\?\"\\|<>]*[^\\\\/:\\*\\?\"\\|<>\\. ]))?$");
	}

	try
	{
ch3cooli's avatar
ch3cooli committed
971 972
		std::tr1::wregex rx(sPattern, std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
		std::tr1::wsmatch match;
李智's avatar
李智 committed
973

ch3cooli's avatar
ch3cooli committed
974 975
		std::wstring rmatch = std::wstring((LPCTSTR)sMatch);
		if (std::tr1::regex_match(rmatch, match, rx))
李智's avatar
李智 committed
976
		{
ch3cooli's avatar
ch3cooli committed
977
			if (std::wstring(match[0]).compare(sMatch)==0)
李智's avatar
李智 committed
978 979 980 981 982
				m_bIsValidOnWindows = true;
		}
		if (m_bIsValidOnWindows)
		{
			// now check for illegal filenames
ch3cooli's avatar
ch3cooli committed
983
			std::tr1::wregex rx2(_T("\\\\(lpt\\d|com\\d|aux|nul|prn|con)(\\\\|$)"), std::tr1::regex_constants::icase | std::tr1::regex_constants::ECMAScript);
李智's avatar
李智 committed
984
			rmatch = m_sBackslashPath;
ch3cooli's avatar
ch3cooli committed
985
			if (std::tr1::regex_search(rmatch, rx2, std::tr1::regex_constants::match_default))
李智's avatar
李智 committed
986 987 988
				m_bIsValidOnWindows = false;
		}
	}
ch3cooli's avatar
ch3cooli committed
989
	catch (std::exception) {}
李智's avatar
李智 committed
990 991 992 993 994 995 996 997 998

	m_bIsValidOnWindowsKnown = true;
	return m_bIsValidOnWindows;
}

//////////////////////////////////////////////////////////////////////////

CTGitPathList::CTGitPathList()
{
999
	m_Action = 0;
李智's avatar
李智 committed
1000 1001 1002 1003 1004
}

// A constructor which allows a path list to be easily built which one initial entry in
CTGitPathList::CTGitPathList(const CTGitPath& firstEntry)
{
1005
	m_Action = 0;
李智's avatar
李智 committed
1006 1007
	AddPath(firstEntry);
}
李智's avatar
李智 committed
1008
int CTGitPathList::ParserFromLsFile(BYTE_VECTOR &out,bool /*staged*/)
李智's avatar
李智 committed
1009
{
1010
	int pos=0;
李智's avatar
李智 committed
1011 1012 1013
	CString one;
	CTGitPath path;
	CString part;
1014 1015
	this->Clear();

1016
	while (pos >= 0 && pos < (int)out.size())
李智's avatar
李智 committed
1017 1018 1019 1020
	{
		one.Empty();
		path.Reset();

1021
		CGit::StringAppend(&one, &out[pos], CP_UTF8);
李智's avatar
李智 committed
1022
		int tabstart=0;
1023
		// m_Action is never used and propably never worked (needs to be set after path.SetFromGit)
Sven Strickroth's avatar
Sven Strickroth committed
1024
		// also dropped LOGACTIONS_CACHE for 'H'
1025
		// path.m_Action=path.ParserAction(out[pos]);
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
1026
		one.Tokenize(_T("\t"),tabstart);
李智's avatar
李智 committed
1027 1028 1029

		if(tabstart>=0)
			path.SetFromGit(one.Right(one.GetLength()-tabstart));
1030 1031
		else
			return -1;
李智's avatar
李智 committed
1032 1033 1034 1035

		tabstart=0;

		part=one.Tokenize(_T(" "),tabstart); //Tag
1036 1037
		if (tabstart < 0)
			return -1;
李智's avatar
李智 committed
1038 1039

		part=one.Tokenize(_T(" "),tabstart); //Mode
1040 1041
		if (tabstart < 0)
			return -1;
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
1042

李智's avatar
李智 committed
1043
		part=one.Tokenize(_T(" "),tabstart); //Hash
1044 1045
		if (tabstart < 0)
			return -1;
李智's avatar
李智 committed
1046 1047

		part=one.Tokenize(_T("\t"),tabstart); //Stage
1048 1049
		if (tabstart < 0)
			return -1;
李智's avatar
李智 committed
1050 1051 1052 1053 1054 1055 1056

		path.m_Stage=_ttol(part);

		this->AddPath(path);

		pos=out.findNextString(pos);
	}
1057
	return 0;
李智's avatar
李智 committed
1058
}
1059
int CTGitPathList::FillUnRev(unsigned int action, CTGitPathList *list, CString *err)
1060 1061 1062
{
	this->Clear();
	CTGitPath path;
李智's avatar
李智 committed
1063

1064 1065 1066 1067 1068
	int count;
	if(list==NULL)
		count=1;
	else
		count=list->GetCount();
1069
	for (int i = 0; i < count; ++i)
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
1070
	{
1071
		CString cmd;
Sven Strickroth's avatar
Sven Strickroth committed
1072
		int pos = 0;
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
1073

1074 1075
		CString ignored;
		if(action & CTGitPath::LOGACTIONS_IGNORE)
1076
			ignored= _T(" -i");
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
1077

1078 1079
		if(list==NULL)
		{
李智's avatar
李智 committed
1080
			cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");
1081
			cmd+=ignored;
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
1082

1083 1084
		}
		else
1085
		{	cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z%s -- \"%s\""),
1086 1087
					(LPCTSTR)ignored,
					(*list)[i].GetWinPath());
1088
		}
1089

1090
		BYTE_VECTOR out, errb;
李智's avatar
李智 committed
1091
		out.clear();
1092 1093 1094
		if (g_Git.Run(cmd, &out, &errb))
		{
			if (err != nullptr)
1095
				CGit::StringAppend(err, &errb[0], CP_UTF8, (int)errb.size());
1096 1097
			return -1;
		}
Sven Strickroth's avatar
cleaups  
Sven Strickroth committed
1098

李智's avatar
李智 committed
1099
		pos=0;
1100
		CString one;
Sven Strickroth's avatar
Sven Strickroth committed
1101
		while (pos >= 0 && pos < (int)out.size())
1102
		{
1103
			one.Empty();
1104
			CGit::StringAppend(&one, &out[pos], CP_UTF8);
1105 1106 1107 1108 1109 1110 1111
			if(!one.IsEmpty())
			{
				//SetFromGit will clear all status
				path.SetFromGit(one);
				path.m_Action=action;
				AddPath(path);
			}
李智's avatar
李智 committed
1112
			pos=out.findNextString(pos);
1113
		}
李智's avatar
李智 committed
1114

1115 1116 1117
	}
	return 0;
}
1118 1119 1120 1121 1122
int CTGitPathList::FillBasedOnIndexFlags(unsigned short flag, CTGitPathList* list /*nullptr*/)
{
	Clear();
	CTGitPath path;

1123
	CAutoRepository repository(g_Git.GetGitRepository());
1124
	if (!repository)
1125 1126
		return -1;

1127 1128
	CAutoIndex index;
	if (git_repository_index(index.GetPointer(), repository))
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
		return -1;

	int count;
	if (list == nullptr)
		count = 1;
	else
		count = list->GetCount();
	for (int j = 0; j < count; ++j)
	{
		for (size_t i = 0, ecount = git_index_entrycount(index); i < ecount; ++i)
		{
			const git_index_entry *e = git_index_get_byindex(index, i);

			if (!e || !((e->flags | e->flags_extended) & flag) || !e->path)
				continue;

1145
			CString one = CUnicodeUtils::GetUnicode(e->path);
1146

ch3cooli's avatar
ch3cooli committed
1147
			if (!(!list || (*list)[j].GetWinPathString().IsEmpty() || one == (*list)[j].GetGitPathString() || (PathIsDirectory(g_Git.CombinePath((*list)[j].GetWinPathString())) && one.Find((*list)[j].GetGitPathString() + _T("/")) == 0)))
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161
				continue;

			//SetFromGit will clear all status
			path.SetFromGit(one);
			if ((e->flags | e->flags_extended) & GIT_IDXENTRY_SKIP_WORKTREE)
				path.m_Action = CTGitPath::LOGACTIONS_SKIPWORKTREE;
			else if ((e->flags | e->flags_extended) & GIT_IDXENTRY_VALID)
				path.m_Action = CTGitPath::LOGACTIONS_ASSUMEVALID;
			AddPath(path);
		}
	}
	RemoveDuplicates();
	return 0;
}
1162
int CTGitPathList::ParserFromLog(BYTE_VECTOR &log, bool parseDeletes /*false*/)
李智's avatar
李智 committed
1163 1164 1165 1166 1167
{
	this->Clear();
	int pos=0;
	CTGitPath path;
	m_Action=0;
Sven Strickroth's avatar
Sven Strickroth committed
1168 1169
	int logend = (int)log.size();
	while (pos >= 0 && pos < logend)
李智's avatar
李智 committed
1170
	{
李智's avatar
李智 committed
1171
		path.Reset();
李智's avatar
李智 committed
1172
		if(log[pos]=='\n')
1173
			++pos;