| 1615 | } |
| 1616 | |
| 1617 | CTGitPath CTGitPathList::GetCommonRoot() const |
| 1618 | { |
| 1619 | if (IsEmpty()) |
| 1620 | return CTGitPath(); |
| 1621 | |
| 1622 | if (GetCount() == 1) |
| 1623 | return m_paths[0]; |
| 1624 | |
| 1625 | // first entry is common root for itself |
| 1626 | // (add trailing '\\' to detect partial matches of the last path element) |
| 1627 | CString root = m_paths[0].GetWinPathString() + L'\\'; |
| 1628 | int rootLength = root.GetLength(); |
| 1629 | |
| 1630 | // determine common path string prefix |
| 1631 | for (auto it = m_paths.cbegin() + 1; it != m_paths.cend(); ++it) |
| 1632 | { |
| 1633 | CString path = it->GetWinPathString() + L'\\'; |
| 1634 | |
| 1635 | int newLength = CStringUtils::GetMatchingLength(root, path); |
| 1636 | if (newLength != rootLength) |
| 1637 | { |
| 1638 | root.Delete(newLength, rootLength); |
| 1639 | rootLength = newLength; |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | // remove the last (partial) path element |
| 1644 | if (rootLength > 0) |
| 1645 | root.Delete(root.ReverseFind(L'\\'), rootLength); |
| 1646 | |
| 1647 | // done |
| 1648 | return CTGitPath(root); |
| 1649 | } |
| 1650 | |
| 1651 | void CTGitPathList::SortByPathname(bool bReverse /*= false*/) |
| 1652 | { |