/**
 * Add a TNE for the given item to the TN of the directory.
 * The given fields may be the either the current or baseline
 * values (we don't care here); use whichever values you want
 * to have in the synthetic/hybrid treenode that needs to be
 * created for the full/partial commit.
 *
 * We optionally return a (read-only) handle the TNE.
 * you DO NOT own this.
 *
 */
void sg_wc_tx__commit__queue__utils__add_tne(SG_context * pCtx,
											 SG_treenode * pTN,
											 const char * pszGid,
											 const char * pszEntryname,
											 SG_treenode_entry_type tneType,
											 const char * pszHidContent,
											 SG_int64 attrbits,
											 const SG_treenode_entry ** ppTNE_ref)
{
	SG_treenode_entry * pTNE_allocated = NULL;
	const SG_treenode_entry * pTNE_ref;		// we do not own this

	SG_ERR_CHECK(  SG_TREENODE_ENTRY__ALLOC(pCtx, &pTNE_allocated)  );

	SG_ERR_CHECK(  SG_treenode_entry__set_entry_name(    pCtx, pTNE_allocated, pszEntryname)  );
	SG_ERR_CHECK(  SG_treenode_entry__set_entry_type(    pCtx, pTNE_allocated, tneType)  );
	SG_ERR_CHECK(  SG_treenode_entry__set_hid_blob(      pCtx, pTNE_allocated, pszHidContent)  );
	SG_ERR_CHECK(  SG_treenode_entry__set_attribute_bits(pCtx, pTNE_allocated, attrbits)  );

	pTNE_ref = pTNE_allocated;	// next line steals ownership
	SG_ERR_CHECK(  SG_treenode__add_entry(pCtx, pTN, pszGid, &pTNE_allocated)  );

	if (ppTNE_ref)
		*ppTNE_ref = pTNE_ref;
	return;

fail:
	SG_TREENODE_ENTRY_NULLFREE(pCtx, pTNE_allocated);
}
예제 #2
0
void SG_treendx__get_path_in_dagnode(SG_context* pCtx, SG_treendx* pTreeNdx, const char* psz_search_item_gid, const char* psz_changeset, SG_treenode_entry ** ppTreeNodeEntry)
{
	SG_rbtree_iterator * rb_it = NULL;
	const char * pPath = NULL;
	SG_changeset * pChangeset = NULL;
	SG_stringarray * pPaths = NULL;
	const char* pszHidTreeNode = NULL;
	SG_treenode * pTreenodeRoot = NULL;
	char* pszReturnedGID = NULL;
	SG_uint32 i = 0;
	SG_uint32 count = 0;

	SG_ERR_CHECK_RETURN(  SG_gid__argcheck(pCtx, psz_search_item_gid)  );

	SG_ERR_CHECK(  SG_treendx__get_all_paths(pCtx, pTreeNdx, psz_search_item_gid, &pPaths)   );
	*ppTreeNodeEntry = NULL;
	SG_ERR_CHECK(  SG_changeset__load_from_repo(pCtx, pTreeNdx->pRepo, psz_changeset, &pChangeset)  );
	SG_ERR_CHECK(  SG_changeset__get_root(pCtx, pChangeset, &pszHidTreeNode) );
	SG_ERR_CHECK(  SG_treenode__load_from_repo(pCtx, pTreeNdx->pRepo, pszHidTreeNode, &pTreenodeRoot)  );
	SG_ERR_CHECK(  SG_stringarray__count(pCtx, pPaths, &count )  );
	for (i = 0; i < count; i++)
	{
		SG_ERR_CHECK(  SG_stringarray__get_nth(pCtx, pPaths, i, &pPath)  );
		SG_ERR_CHECK(  SG_treenode__find_treenodeentry_by_path(pCtx, pTreeNdx->pRepo, pTreenodeRoot, pPath, &pszReturnedGID, ppTreeNodeEntry)  );
		if (*ppTreeNodeEntry != NULL && strcmp(pszReturnedGID, psz_search_item_gid) == 0)
		{
			break;
		}
		else if (*ppTreeNodeEntry != NULL)
		{
			SG_TREENODE_ENTRY_NULLFREE(pCtx, *ppTreeNodeEntry);
			*ppTreeNodeEntry = NULL; //It's not the right GID, even though it's in the right spot.
		}
	}

	SG_NULLFREE(pCtx, pszReturnedGID);
	SG_CHANGESET_NULLFREE(pCtx, pChangeset);
	SG_TREENODE_NULLFREE(pCtx, pTreenodeRoot);
	SG_STRINGARRAY_NULLFREE(pCtx, pPaths);
	SG_RBTREE_ITERATOR_NULLFREE(pCtx, rb_it);
	return;
fail:
	SG_NULLFREE(pCtx, pszReturnedGID);
	SG_CHANGESET_NULLFREE(pCtx, pChangeset);
	SG_STRINGARRAY_NULLFREE(pCtx, pPaths);
	SG_RBTREE_ITERATOR_NULLFREE(pCtx, rb_it);
	return;

}