예제 #1
0
void SG_vector_i64__alloc__from_varray(SG_context* pCtx, SG_varray* pva, SG_vector_i64 ** ppVector)
{
    SG_uint32 count = 0;
    SG_uint32 i = 0;
    SG_vector_i64* pvec = NULL;

    SG_ERR_CHECK(  SG_varray__count(pCtx, pva, &count)  );
    SG_ERR_CHECK(  SG_vector_i64__alloc(pCtx, &pvec, count)  );
    for (i=0; i<count; i++)
    {
        SG_int64 v = 0;

        SG_ERR_CHECK(  SG_varray__get__int64(pCtx, pva, i, &v)  );
        SG_ERR_CHECK(  SG_vector_i64__append(pCtx, pvec, v, NULL)  );
    }

    *ppVector = pvec;
    pvec = NULL;

    return;

fail:
    SG_VECTOR_I64_NULLFREE(pCtx, pvec);

    return;
}
void MyFn(test_W2771)(SG_context * pCtx)
{
	SG_vector_i64 * pVec = NULL;
	SG_int64 i64 = 0x123456789abcdefLL;
	SG_uint32 len;

	// allocate a vector with a hint of at least 1 cell.
	// (the minimum chunk size will override this, but we don't care.)
	VERIFY_ERR_CHECK(  SG_vector_i64__alloc(pCtx,&pVec,1)  );

	// verify size-in-use is 0.
	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==0));

	// do a hard-reserve with zero-fill of the vector.
	// (we pick a size larger than any pre-defined chunk size.)
	VERIFY_ERR_CHECK(  SG_vector_i64__reserve(pCtx, pVec, 1000)  );
	VERIFY_ERR_CHECK(  SG_vector_i64__get(pCtx, pVec, 999, &i64)  );
	VERIFY_COND("get[1000]", (i64 == 0));

	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==1000));

fail:
	SG_VECTOR_I64_NULLFREE(pCtx, pVec);
}
예제 #3
0
void MyFn(test1)(SG_context * pCtx)
{
	SG_vector_i64 * pVec = NULL;
	SG_uint32 k, ndx, len;

	VERIFY_ERR_CHECK(  SG_vector_i64__alloc(pCtx,&pVec,20)  );

	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==0));

	for (k=0; k<100; k++)
	{
		SG_int64 kValue = (SG_int64)k;
		VERIFY_ERR_CHECK(  SG_vector_i64__append(pCtx,pVec,kValue,&ndx)  );
		VERIFY_COND("append",(ndx==k));
	}
	for (k=0; k<100; k++)
	{
		SG_int64 value;
		VERIFY_ERR_CHECK(  SG_vector_i64__get(pCtx,pVec,k,&value)  );
		VERIFY_COND("get1",(value == ((SG_int64)k)));
	}

	for (k=0; k<100; k++)
	{
		SG_int64 kValue = (SG_int64)k+10000;
		VERIFY_ERR_CHECK(  SG_vector_i64__set(pCtx,pVec,k,kValue)  );
	}
	for (k=0; k<100; k++)
	{
		SG_int64 value;
		VERIFY_ERR_CHECK(  SG_vector_i64__get(pCtx,pVec,k,&value)  );
		VERIFY_COND("get2",(value == ((SG_int64)(k+10000))));
	}

	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==100));

	VERIFY_ERR_CHECK(  SG_vector_i64__clear(pCtx,pVec)  );

	VERIFY_ERR_CHECK(  SG_vector_i64__length(pCtx,pVec,&len)  );
	VERIFY_COND("test1",(len==0));

	// fall thru to common cleanup

fail:
	SG_VECTOR_I64_NULLFREE(pCtx, pVec);
}
void SG_mrg_cset_entry_conflict__append_change(SG_context * pCtx,
											   SG_mrg_cset_entry_conflict * pMrgCSetEntryConflict,
											   SG_mrg_cset_entry * pMrgCSetEntry_Leaf_k,
											   SG_mrg_cset_entry_neq neq)
{
	SG_NULLARGCHECK_RETURN(pMrgCSetEntryConflict);
	SG_NULLARGCHECK_RETURN(pMrgCSetEntry_Leaf_k);

	if (!pMrgCSetEntryConflict->pVec_MrgCSetEntry_Changes)
		SG_ERR_CHECK_RETURN(  SG_vector__alloc(pCtx,&pMrgCSetEntryConflict->pVec_MrgCSetEntry_Changes,2)  );

	SG_ERR_CHECK_RETURN(  SG_vector__append(pCtx,pMrgCSetEntryConflict->pVec_MrgCSetEntry_Changes,(void *)pMrgCSetEntry_Leaf_k,NULL)  );

	if (!pMrgCSetEntryConflict->pVec_MrgCSetEntryNeq_Changes)
		SG_ERR_CHECK_RETURN(  SG_vector_i64__alloc(pCtx,&pMrgCSetEntryConflict->pVec_MrgCSetEntryNeq_Changes,2)  );

	SG_ERR_CHECK_RETURN(  SG_vector_i64__append(pCtx,pMrgCSetEntryConflict->pVec_MrgCSetEntryNeq_Changes,(SG_int64)neq,NULL)  );

	//////////////////////////////////////////////////////////////////
	// add the value of the changed fields to the prbUnique_ rbtrees so that we can get a count of the unique new values.
	//
	//////////////////////////////////////////////////////////////////
	// the values for RENAME, MOVE, ATTRBITS, SYMLINKS, and SUBMODULES are collapsable.  that is, if we
	// have something like:
	//        A
	//       / \.
	//     L0   a0
	//         /  \.
	//        L1   L2
	//
	// and a rename in each Leaf, then we can either:
	// [a] prompt for them to choose L1 or L2's name and then
	//     prompt for them to choose L0 or the name from step 1.
	//
	// [b] prompt for them to choose L0, L1, or L2 in one question.
	//
	// unlike file-content-merging, the net-net is that we have 1 new value
	// that is one of the inputs (or maybe we let them pick a new onw), but
	// it is not a combination of them and so we don't need to display the
	// immediate ancestor in the prompt.
	//
	// so we carry-forward the unique values from the leaves for each of
	// these fields.  so the final merge-result may have more unique values
	// that it has direct parents.
	//////////////////////////////////////////////////////////////////

	if (neq & SG_MRG_CSET_ENTRY_NEQ__ATTRBITS)
	{
		SG_int_to_string_buffer buf;
		SG_int64_to_sz((SG_int64)pMrgCSetEntry_Leaf_k->attrBits, buf);

		if (!pMrgCSetEntryConflict->prbUnique_AttrBits)
			SG_ERR_CHECK_RETURN(  SG_RBTREE__ALLOC(pCtx,&pMrgCSetEntryConflict->prbUnique_AttrBits)  );

		SG_ERR_CHECK_RETURN(  _update_1_rbUnique(pCtx,pMrgCSetEntryConflict->prbUnique_AttrBits,buf,pMrgCSetEntry_Leaf_k)  );

		if (pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict && pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_AttrBits)
			SG_ERR_CHECK_RETURN(  _carry_forward_unique_values(pCtx,
															   pMrgCSetEntryConflict->prbUnique_AttrBits,
															   pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_AttrBits)  );
	}

	if (neq & SG_MRG_CSET_ENTRY_NEQ__ENTRYNAME)
	{
		if (!pMrgCSetEntryConflict->prbUnique_Entryname)
			SG_ERR_CHECK_RETURN(  SG_RBTREE__ALLOC(pCtx,&pMrgCSetEntryConflict->prbUnique_Entryname)  );

		SG_ERR_CHECK_RETURN(  _update_1_rbUnique(pCtx,
												 pMrgCSetEntryConflict->prbUnique_Entryname,
												 SG_string__sz(pMrgCSetEntry_Leaf_k->pStringEntryname),
												 pMrgCSetEntry_Leaf_k)  );

		if (pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict && pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_Entryname)
			SG_ERR_CHECK_RETURN(  _carry_forward_unique_values(pCtx,
															   pMrgCSetEntryConflict->prbUnique_Entryname,
															   pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_Entryname)  );
	}

	if (neq & SG_MRG_CSET_ENTRY_NEQ__GID_PARENT)
	{
		if (!pMrgCSetEntryConflict->prbUnique_GidParent)
			SG_ERR_CHECK_RETURN(  SG_RBTREE__ALLOC(pCtx,&pMrgCSetEntryConflict->prbUnique_GidParent)  );

		SG_ERR_CHECK_RETURN(  _update_1_rbUnique(pCtx,pMrgCSetEntryConflict->prbUnique_GidParent,pMrgCSetEntry_Leaf_k->bufGid_Parent,pMrgCSetEntry_Leaf_k)  );

		if (pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict && pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_GidParent)
			SG_ERR_CHECK_RETURN(  _carry_forward_unique_values(pCtx,
															   pMrgCSetEntryConflict->prbUnique_GidParent,
															   pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_GidParent)  );
	}

	if (neq & SG_MRG_CSET_ENTRY_NEQ__SYMLINK_HID_BLOB)
	{
		if (!pMrgCSetEntryConflict->prbUnique_Symlink_HidBlob)
			SG_ERR_CHECK_RETURN(  SG_RBTREE__ALLOC(pCtx,&pMrgCSetEntryConflict->prbUnique_Symlink_HidBlob)  );

		SG_ERR_CHECK_RETURN(  _update_1_rbUnique(pCtx,pMrgCSetEntryConflict->prbUnique_Symlink_HidBlob,pMrgCSetEntry_Leaf_k->bufHid_Blob,pMrgCSetEntry_Leaf_k)  );

		if (pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict && pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_Symlink_HidBlob)
			SG_ERR_CHECK_RETURN(  _carry_forward_unique_values(pCtx,
															   pMrgCSetEntryConflict->prbUnique_Symlink_HidBlob,
															   pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_Symlink_HidBlob)  );
	}

	if (neq & SG_MRG_CSET_ENTRY_NEQ__SUBMODULE_HID_BLOB)
	{
		if (!pMrgCSetEntryConflict->prbUnique_Submodule_HidBlob)
			SG_ERR_CHECK_RETURN(  SG_RBTREE__ALLOC(pCtx,&pMrgCSetEntryConflict->prbUnique_Submodule_HidBlob)  );

		SG_ERR_CHECK_RETURN(  _update_1_rbUnique(pCtx,pMrgCSetEntryConflict->prbUnique_Submodule_HidBlob,pMrgCSetEntry_Leaf_k->bufHid_Blob,pMrgCSetEntry_Leaf_k)  );

		if (pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict && pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_Submodule_HidBlob)
			SG_ERR_CHECK_RETURN(  _carry_forward_unique_values(pCtx,
															   pMrgCSetEntryConflict->prbUnique_Submodule_HidBlob,
															   pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_Submodule_HidBlob)  );
	}

	// 2010/09/13 Update: we now do the carry-forward on the set of
	//            unique HIDs for the various versions of the file
	//            content from each of the leaves.  This lets us
	//            completely flatten the sub-merges into one final
	//            result (with upto n values).
	//
	//            This means we won't be creating the auto-merge-plan
	//            at this point.
	//
	//            The problem with the auto-merge-plan as originally
	//            designed is that it was being driven based upon
	//            the overall topology of the DAG as a whole rather
	//            than the topology/history of the individual file.
	//            And by respecting the history of the individual
	//            file, I think we can get closer ancestors and better
	//            per-file merging and perhaps fewer criss-crosses
	//            and/or we push all of these issues to RESOLVE.

	if (neq & SG_MRG_CSET_ENTRY_NEQ__FILE_HID_BLOB)
	{
		if (!pMrgCSetEntryConflict->prbUnique_File_HidBlob)
			SG_ERR_CHECK_RETURN(  SG_RBTREE__ALLOC(pCtx,&pMrgCSetEntryConflict->prbUnique_File_HidBlob)  );

		SG_ASSERT(  (pMrgCSetEntry_Leaf_k->bufHid_Blob[0])  );

		// TODO 2010/09/13 the code that sets __FILE_HID_BLOB probably cannot tell
		// TODO            whether this branch did not change the file content
		// TODO            relative to the LCA or whether it did change it back to
		// TODO            the original value (an UNDO of the edits).  I would argue
		// TODO            that we should not list the former as a change, but that
		// TODO            we SHOULD list the latter.  The fix doesn't belong here,
		// TODO            but this is just where I was typing when I thought of it.
		
		SG_ERR_CHECK_RETURN(  _update_1_rbUnique(pCtx,pMrgCSetEntryConflict->prbUnique_File_HidBlob,pMrgCSetEntry_Leaf_k->bufHid_Blob,pMrgCSetEntry_Leaf_k)  );

		if (pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict && pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_File_HidBlob)
			SG_ERR_CHECK_RETURN(  _carry_forward_unique_values(pCtx,
															   pMrgCSetEntryConflict->prbUnique_File_HidBlob,
															   pMrgCSetEntry_Leaf_k->pMrgCSetEntryConflict->prbUnique_File_HidBlob)  );
	}
}