コード例 #1
0
int CGitIgnoreList::CheckIgnore(const CString &path, const CString &projectroot, bool isDir)
{
	CString temp = CombinePath(projectroot, path);
	temp.Replace(_T('/'), _T('\\'));

	CStringA patha = CUnicodeUtils::GetMulti(path, CP_UTF8);
	patha.Replace('\\', '/');

	int type = 0;
	if (isDir)
	{
		type = DT_DIR;

		// strip directory name
		// we do not need to check for a .ignore file inside a directory we might ignore
		int i = temp.ReverseFind(_T('\\'));
		if (i >= 0)
			temp.Truncate(i);
	}
	else
	{
		type = DT_REG;

		int x = temp.ReverseFind(_T('\\'));
		if (x >= 2)
			temp.Truncate(x);
	}

	int pos = patha.ReverseFind('/');
	const char * base = (pos >= 0) ? ((const char*)patha + pos + 1) : patha;

	int ret = -1;

	CAutoReadLock lock(m_SharedMutex);
	while (!temp.IsEmpty())
	{
		CString tempOrig = temp;
		temp += _T("\\.git");

		if (CGit::GitPathFileExists(temp))
		{
			CString gitignore = temp;
			gitignore += _T("ignore");
			if ((ret = CheckFileAgainstIgnoreList(gitignore, patha, base, type)) != -1)
				break;

			CString adminDir = g_AdminDirMap.GetAdminDir(tempOrig);
			CString wcglobalgitignore = adminDir;
			wcglobalgitignore += _T("info\\exclude");
			if ((ret = CheckFileAgainstIgnoreList(wcglobalgitignore, patha, base, type)) != -1)
				break;

			CString excludesFile = m_CoreExcludesfiles[adminDir];
			if (!excludesFile.IsEmpty())
				ret = CheckFileAgainstIgnoreList(excludesFile, patha, base, type);

			break;
		}

		temp += _T("ignore");
		if ((ret = CheckFileAgainstIgnoreList(temp, patha, base, type)) != -1)
			break;

		int found = 0;
		int i;
		for (i = temp.GetLength() - 1; i >= 0; i--)
		{
			if (temp[i] == _T('\\'))
				++found;

			if (found == 2)
				break;
		}

		temp.Truncate(i);
	}

	return ret;
}
コード例 #2
0
ファイル: GitIndex.cpp プロジェクト: Jopie64/tortoisegit
int CGitIgnoreList::CheckIgnore(const CString &path,const CString &projectroot)
{
    __int64 time = 0;
    bool dir = 0;
    CString temp = projectroot + _T("\\") + path;
    temp.Replace(_T('/'), _T('\\'));

    CStringA patha = CUnicodeUtils::GetMulti(path, CP_UTF8);
    patha.Replace('\\', '/');

    if(g_Git.GetFileModifyTime(temp, &time, &dir))
        return -1;

    int type = 0;
    if (dir)
    {
        type = DT_DIR;

        // strip directory name
        // we do not need to check for a .ignore file inside a directory we might ignore
        int i = temp.ReverseFind(_T('\\'));
        if (i >= 0)
            temp = temp.Left(i);
    }
    else
        type = DT_REG;

    char * base = NULL;
    int pos = patha.ReverseFind('/');
    base = pos >= 0 ? patha.GetBuffer() + pos + 1 : patha.GetBuffer();

    int ret = -1;

    CAutoReadLock lock(&this->m_SharedMutex);
    while (!temp.IsEmpty())
    {
        CString tempOrig = temp;
        temp += _T("\\.git");

        if (CGit::GitPathFileExists(temp))
        {
            CString gitignore = temp;
            gitignore += _T("ignore");
            if ((ret = CheckFileAgainstIgnoreList(gitignore, patha, base, type)) != -1)
                break;

            CString adminDir = g_AdminDirMap.GetAdminDir(tempOrig);
            CString wcglobalgitignore = adminDir + _T("info\\exclude");
            if ((ret = CheckFileAgainstIgnoreList(wcglobalgitignore, patha, base, type)) != -1)
                break;

            m_SharedMutex.AcquireShared();
            CString excludesFile = m_CoreExcludesfiles[adminDir];
            m_SharedMutex.ReleaseShared();
            if (!excludesFile.IsEmpty())
                ret = CheckFileAgainstIgnoreList(excludesFile, patha, base, type);

            break;
        }
        else
        {
            temp += _T("ignore");
            if ((ret = CheckFileAgainstIgnoreList(temp, patha, base, type)) != -1)
                break;
        }

        int found = 0;
        int i;
        for (i = temp.GetLength() - 1; i >= 0; i--)
        {
            if (temp[i] == _T('\\'))
                ++found;

            if (found == 2)
                break;
        }

        temp = temp.Left(i);
    }

    patha.ReleaseBuffer();

    return ret;
}