예제 #1
0
static int GetBranchDescriptionsCallback(const git_config_entry *entry, void *data)
{
	MAP_STRING_STRING *descriptions = (MAP_STRING_STRING *) data;
	CString key = CUnicodeUtils::GetUnicode(entry->name, CP_UTF8);
	CString val = CUnicodeUtils::GetUnicode(entry->value, CP_UTF8);
	descriptions->insert(std::make_pair(key.Mid(7, key.GetLength() - 7 - 12), val)); // 7: branch., 12: .description
	return 0;
}
예제 #2
0
static int GetBranchDescriptionsCallback(const char *var_name, const char *value, void *data)
{
	MAP_STRING_STRING *descriptions = (MAP_STRING_STRING *) data;
	CString key = CUnicodeUtils::GetUnicode(var_name, CP_UTF8);
	CString val = CUnicodeUtils::GetUnicode(value, CP_UTF8);
	descriptions->insert(make_pair(key.Mid(7, key.GetLength() - 7 - 12), val)); // 7: branch., 12: .description
	return 0;
}
예제 #3
0
void CBrowseRefsDlg::Refresh(CString selectRef)
{
//	m_RefMap.clear();
//	g_Git.GetMapHashToFriendName(m_RefMap);

	if(!selectRef.IsEmpty())
	{
		if(selectRef == "HEAD")
		{
			selectRef = g_Git.GetSymbolicRef(selectRef, false);
		}
	}
	else
	{
		selectRef = GetSelectedRef(false, true);
	}

	m_RefTreeCtrl.DeleteAllItems();
	m_ListRefLeafs.DeleteAllItems();
	m_TreeRoot.m_ShadowTree.clear();
	m_TreeRoot.m_csRefName = "refs";
	m_TreeRoot.m_hTree=m_RefTreeCtrl.InsertItem(L"Refs",NULL,NULL);
	m_RefTreeCtrl.SetItemData(m_TreeRoot.m_hTree,(DWORD_PTR)&m_TreeRoot);

	CString allRefs, error;
	if (g_Git.Run(L"git.exe for-each-ref --format="
			  L"%(refname)%04"
			  L"%(objectname)%04"
			  L"%(authordate:relative)%04"
			  L"%(subject)%04"
			  L"%(authorname)%04"
			  L"%(authordate:iso8601)%03",
			  &allRefs, &error, CP_UTF8))
	{
		CMessageBox::Show(NULL, CString(_T("Get refs failed\n")) + error, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
	}

	int linePos=0;
	CString singleRef;

	MAP_STRING_STRING refMap;

	//First sort on ref name
	while(!(singleRef=allRefs.Tokenize(L"\03",linePos)).IsEmpty())
	{
		singleRef.TrimLeft(L"\r\n");
		int valuePos=0;
		CString refName=singleRef.Tokenize(L"\04",valuePos);
		if(refName.IsEmpty())
			continue;
		CString refRest=singleRef.Mid(valuePos);


		//Use ref based on m_pickRef_Kind
		if (wcsncmp(refName, L"refs/heads/", 11) == 0 && !(m_pickRef_Kind & gPickRef_Head))
			continue; //Skip
		if (wcsncmp(refName, L"refs/tags/", 10) == 0 && !(m_pickRef_Kind & gPickRef_Tag))
			continue; //Skip
		if (wcsncmp(refName, L"refs/remotes/", 13) == 0 && !(m_pickRef_Kind & gPickRef_Remote))
			continue; //Skip

		refMap[refName] = refRest; //Use
	}

	MAP_STRING_STRING descriptions = GetBranchDescriptions();

	//Populate ref tree
	for(MAP_STRING_STRING::iterator iterRefMap=refMap.begin();iterRefMap!=refMap.end();++iterRefMap)
	{
		CShadowTree& treeLeaf=GetTreeNode(iterRefMap->first,NULL,true);
		CString values=iterRefMap->second;
		values.Replace(L"\04" L"\04",L"\04 \04");//Workaround Tokenize problem (treating 2 tokens as one)

		int valuePos=0;
		treeLeaf.m_csRefHash=		values.Tokenize(L"\04",valuePos); if(valuePos < 0) continue;
		treeLeaf.m_csDate=			values.Tokenize(L"\04",valuePos); if(valuePos < 0) continue;
		treeLeaf.m_csSubject=		values.Tokenize(L"\04",valuePos); if(valuePos < 0) continue;
		treeLeaf.m_csAuthor=		values.Tokenize(L"\04",valuePos); if(valuePos < 0) continue;
		treeLeaf.m_csDate_Iso8601=	values.Tokenize(L"\04",valuePos);

		if (wcsncmp(iterRefMap->first, L"refs/heads/", 11) == 0)
			treeLeaf.m_csDescription = descriptions[treeLeaf.m_csRefName];
	}

	// try exact match first
	if(selectRef.IsEmpty() || !(SelectRef(selectRef, true) || SelectRef(selectRef, false)))
		//Probably not on a branch. Select root node.
		m_RefTreeCtrl.Expand(m_TreeRoot.m_hTree,TVE_EXPAND);

}