static void _add_parents_to_work_queue(SG_context * pCtx, SG_dagnode * pDagnode, SG_rbtree* prb_WorkQueue) { const char ** aszHidParents = NULL; SG_uint32 k, nrParents; SG_ERR_CHECK( SG_dagnode__get_parents(pCtx,pDagnode,&nrParents,&aszHidParents) ); for (k=0; k<nrParents; k++) { SG_ERR_CHECK( SG_rbtree__update(pCtx,prb_WorkQueue,aszHidParents[k]) ); } // fall thru to common cleanup fail: SG_NULLFREE(pCtx, aszHidParents); }
static void _add_parents(SG_context * pCtx, SG_dagfrag* pFrag, SG_dagnode * pDagnode) { const char ** aszHidParents = NULL; SG_uint32 k, nrParents; SG_ERR_CHECK( SG_dagnode__get_parents(pCtx,pDagnode,&nrParents,&aszHidParents) ); for (k=0; k<nrParents; k++) { SG_ERR_CHECK( _add_one_parent(pCtx,pFrag,aszHidParents[k]) ); } // fall thru to common cleanup fail: SG_NULLFREE(pCtx, aszHidParents); }
/** * Recursively compare dagnodes depth-first. */ static void _compare_dagnodes(SG_context* pCtx, SG_repo* pRepo1, SG_dagnode* pDagnode1, SG_repo* pRepo2, SG_dagnode* pDagnode2, SG_bool* pbIdentical) { SG_bool bDagnodesEqual = SG_FALSE; SG_uint32 iParentCount1, iParentCount2; const char** paParentIds1 = NULL; const char** paParentIds2 = NULL; SG_dagnode* pParentDagnode1 = NULL; SG_dagnode* pParentDagnode2 = NULL; SG_NULLARGCHECK_RETURN(pDagnode1); SG_NULLARGCHECK_RETURN(pDagnode2); SG_NULLARGCHECK_RETURN(pbIdentical); *pbIdentical = SG_TRUE; // Compare the dagnodes. If they're different, return false. SG_ERR_CHECK( SG_dagnode__equal(pCtx, pDagnode1, pDagnode2, &bDagnodesEqual) ); if (!bDagnodesEqual) { #if TRACE_SYNC SG_ERR_CHECK( SG_console(pCtx, SG_CS_STDERR, "dagnodes not equal\n") ); #endif *pbIdentical = SG_FALSE; return; } // The dagnodes are identical. Look at their parents. SG_ERR_CHECK( SG_dagnode__get_parents(pCtx, pDagnode1, &iParentCount1, &paParentIds1) ); SG_ERR_CHECK( SG_dagnode__get_parents(pCtx, pDagnode2, &iParentCount2, &paParentIds2) ); if (iParentCount1 == iParentCount2) { // The dagnodes have the same number of parents. Compare the parents recursively. SG_uint32 i; for (i = 0; i < iParentCount1; i++) { SG_ERR_CHECK( SG_repo__fetch_dagnode(pCtx, pRepo1, paParentIds1[i], &pParentDagnode1) ); SG_ERR_CHECK( SG_repo__fetch_dagnode(pCtx, pRepo2, paParentIds2[i], &pParentDagnode2) ); SG_ERR_CHECK( _compare_dagnodes(pCtx, pRepo1, pParentDagnode1, pRepo2, pParentDagnode2, pbIdentical) ); SG_DAGNODE_NULLFREE(pCtx, pParentDagnode1); SG_DAGNODE_NULLFREE(pCtx, pParentDagnode2); if (!(*pbIdentical)) break; } } else { // The dagnodes have a different number of parents. *pbIdentical = SG_FALSE; } // fall through fail: SG_NULLFREE(pCtx, paParentIds1); SG_NULLFREE(pCtx, paParentIds2); SG_DAGNODE_NULLFREE(pCtx, pParentDagnode1); SG_DAGNODE_NULLFREE(pCtx, pParentDagnode2); }